Whamcloud - gitweb
LU-11986 lnet: Avoid lnet debugfs read/write if ctl_table does not exist 22/34622/2
authorSonia Sharma <sharmaso@whamcloud.com>
Mon, 1 Apr 2019 12:40:27 +0000 (05:40 -0700)
committerOleg Drokin <green@whamcloud.com>
Sun, 21 Apr 2019 05:47:26 +0000 (05:47 +0000)
Running command "lctl get param -n stats" after lnet
is taken down leads to kernel panic because it
tries to read from the file which doesnt exist
anymore.

In lnet_debugfs_read() and lnet_debugfs_write(),
check if struct ctl_table is valid before trying
to read/write to it.

Change-Id: I2450d2f89c2e8a7db793680a4df581282ee46a16
Signed-off-by: Sonia Sharma <sharmaso@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/34622
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Amir Shehata <ashehata@whamcloud.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/libcfs/module.c

index 99b6f79..3a696e9 100644 (file)
@@ -491,11 +491,13 @@ static ssize_t lnet_debugfs_read(struct file *filp, char __user *buf,
                                 size_t count, loff_t *ppos)
 {
        struct ctl_table *table = filp->private_data;
-       ssize_t rc;
+       ssize_t rc = -EINVAL;
 
-       rc = table->proc_handler(table, 0, buf, &count, ppos);
-       if (!rc)
-               rc = count;
+       if (table) {
+               rc = table->proc_handler(table, 0, buf, &count, ppos);
+               if (!rc)
+                       rc = count;
+       }
 
        return rc;
 }
@@ -504,11 +506,14 @@ static ssize_t lnet_debugfs_write(struct file *filp, const char __user *buf,
                                  size_t count, loff_t *ppos)
 {
        struct ctl_table *table = filp->private_data;
-       ssize_t rc;
+       ssize_t rc = -EINVAL;
 
-       rc = table->proc_handler(table, 1, (void __user *)buf, &count, ppos);
-       if (!rc)
-               rc = count;
+       if (table) {
+               rc = table->proc_handler(table, 1, (void __user *)buf, &count,
+                                        ppos);
+               if (!rc)
+                       rc = count;
+       }
 
        return rc;
 }