From: Amir Shehata Date: Wed, 27 Aug 2014 23:21:11 +0000 (-0700) Subject: LU-5540 lnet: fix crash due to NULL networks string X-Git-Tag: 2.6.53~87 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=ceccfb7d820829b76639b0789b0e12581e5b8019;hp=37807874074d8f9451fea93db4419863fa1fe56f LU-5540 lnet: 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: Amir Shehata Change-Id: Ifcc1f6f74a3e0e804cb65e3d1b83f85a24f44d9b Reviewed-on: http://review.whamcloud.com/11626 Tested-by: Jenkins Reviewed-by: Isaac Huang Reviewed-by: Doug Oucharek Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index 19e1a9c..cf87d5e 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -1762,7 +1762,6 @@ LNetNIInit(lnet_pid_t requested_pid) lnet_ping_info_t *pinfo; lnet_handle_md_t md_handle; struct list_head net_head; - char *nets; INIT_LIST_HEAD(&net_head); @@ -1777,13 +1776,11 @@ LNetNIInit(lnet_pid_t requested_pid) return rc; } - nets = lnet_get_networks(); - rc = lnet_prepare(requested_pid); if (rc != 0) goto failed0; - rc = lnet_parse_networks(&net_head, nets); + rc = lnet_parse_networks(&net_head, lnet_get_networks()); if (rc < 0) goto failed1; diff --git a/lnet/lnet/config.c b/lnet/lnet/config.c index 7dd588e..a5661f9 100644 --- a/lnet/lnet/config.c +++ b/lnet/lnet/config.c @@ -197,7 +197,7 @@ int lnet_parse_networks(struct list_head *nilist, char *networks) { struct cfs_expr_list *el = NULL; - int tokensize = strlen(networks) + 1; + int tokensize; char *tokens; char *str; char *tmp; @@ -205,6 +205,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks) __u32 net; int nnets = 0; + if (networks == NULL) { + CERROR("networks string is undefined\n"); + return -EINVAL; + } + if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) { /* _WAY_ conservative */ LCONSOLE_ERROR_MSG(0x112, "Can't parse networks: string too " @@ -212,6 +217,8 @@ lnet_parse_networks(struct list_head *nilist, char *networks) return -EINVAL; } + tokensize = strlen(networks) + 1; + LIBCFS_ALLOC(tokens, tokensize); if (tokens == NULL) { CERROR("Can't allocate net tokens\n");