]> git.karo-electronics.de Git - linux-beck.git/commitdiff
staging: lustre: fix crash due to NULL networks string
authorAmir Shehata <amir.shehata@intel.com>
Mon, 22 Feb 2016 22:29:04 +0000 (17:29 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 23 Feb 2016 02:05:49 +0000 (18:05 -0800)
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 <amir.shehata@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5540
Reviewed-on: http://review.whamcloud.com/11626
Reviewed-by: Isaac Huang <he.huang@intel.com>
Reviewed-by: Doug Oucharek <doug.s.oucharek@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lnet/lnet/api-ni.c
drivers/staging/lustre/lnet/lnet/config.c

index b2b914a78c649024188f3da7f0e3c914b4bca13d..c68d01e438f175de16a7b171e6c1ff923fa136db 100644 (file)
@@ -1535,7 +1535,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);
 
@@ -1550,13 +1549,11 @@ LNetNIInit(lnet_pid_t requested_pid)
                return rc;
        }
 
-       nets = lnet_get_networks();
-
        rc = lnet_prepare(requested_pid);
        if (rc)
                goto failed0;
 
-       rc = lnet_parse_networks(&net_head, nets);
+       rc = lnet_parse_networks(&net_head, lnet_get_networks());
        if (rc < 0)
                goto failed1;
 
index 1ef07cdd5fe0769bb007786e852b5930ce14ac06..013d41b47c23729d9bdfc925a6b46c747c2e0d9b 100644 (file)
@@ -184,7 +184,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;
@@ -192,6 +192,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
        __u32 net;
        int nnets = 0;
 
+       if (!networks) {
+               CERROR("networks string is undefined\n");
+               return -EINVAL;
+       }
+
        if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
                /* _WAY_ conservative */
                LCONSOLE_ERROR_MSG(0x112,
@@ -199,6 +204,8 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                return -EINVAL;
        }
 
+       tokensize = strlen(networks) + 1;
+
        LIBCFS_ALLOC(tokens, tokensize);
        if (!tokens) {
                CERROR("Can't allocate net tokens\n");