Commit 8766cd12 authored by Amir Shehata's avatar Amir Shehata Committed by Greg Kroah-Hartman

staging: lustre: fix crash due to NULL networks string

If there is an invalid networks or ip2nets lnet_parse_networks()
gets called with a NULL 'network' string parameter

lnet_parse_networks() needs to sanitize its input string now that
it's being called from multiple places.  Instead, check for
a NULL string everytime the function is called, which reduces the
probability of errors with other code modifications.
Signed-off-by: default avatarAmir Shehata <amir.shehata@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5540
Reviewed-on: http://review.whamcloud.com/11626Reviewed-by: default avatarIsaac Huang <he.huang@intel.com>
Reviewed-by: default avatarDoug Oucharek <doug.s.oucharek@intel.com>
Reviewed-by: default avatarOleg Drokin <oleg.drokin@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2e9a51bd
...@@ -1535,7 +1535,6 @@ LNetNIInit(lnet_pid_t requested_pid) ...@@ -1535,7 +1535,6 @@ LNetNIInit(lnet_pid_t requested_pid)
lnet_ping_info_t *pinfo; lnet_ping_info_t *pinfo;
lnet_handle_md_t md_handle; lnet_handle_md_t md_handle;
struct list_head net_head; struct list_head net_head;
char *nets;
INIT_LIST_HEAD(&net_head); INIT_LIST_HEAD(&net_head);
...@@ -1550,13 +1549,11 @@ LNetNIInit(lnet_pid_t requested_pid) ...@@ -1550,13 +1549,11 @@ LNetNIInit(lnet_pid_t requested_pid)
return rc; return rc;
} }
nets = lnet_get_networks();
rc = lnet_prepare(requested_pid); rc = lnet_prepare(requested_pid);
if (rc) if (rc)
goto failed0; goto failed0;
rc = lnet_parse_networks(&net_head, nets); rc = lnet_parse_networks(&net_head, lnet_get_networks());
if (rc < 0) if (rc < 0)
goto failed1; goto failed1;
......
...@@ -184,7 +184,7 @@ int ...@@ -184,7 +184,7 @@ int
lnet_parse_networks(struct list_head *nilist, char *networks) lnet_parse_networks(struct list_head *nilist, char *networks)
{ {
struct cfs_expr_list *el = NULL; struct cfs_expr_list *el = NULL;
int tokensize = strlen(networks) + 1; int tokensize;
char *tokens; char *tokens;
char *str; char *str;
char *tmp; char *tmp;
...@@ -192,6 +192,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks) ...@@ -192,6 +192,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
__u32 net; __u32 net;
int nnets = 0; int nnets = 0;
if (!networks) {
CERROR("networks string is undefined\n");
return -EINVAL;
}
if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) { if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
/* _WAY_ conservative */ /* _WAY_ conservative */
LCONSOLE_ERROR_MSG(0x112, LCONSOLE_ERROR_MSG(0x112,
...@@ -199,6 +204,8 @@ lnet_parse_networks(struct list_head *nilist, char *networks) ...@@ -199,6 +204,8 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
return -EINVAL; return -EINVAL;
} }
tokensize = strlen(networks) + 1;
LIBCFS_ALLOC(tokens, tokensize); LIBCFS_ALLOC(tokens, tokensize);
if (!tokens) { if (!tokens) {
CERROR("Can't allocate net tokens\n"); CERROR("Can't allocate net tokens\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment