From: Sonia Sharma Date: Mon, 1 Apr 2019 12:40:27 +0000 (-0700) Subject: LU-11986 lnet: Avoid lnet debugfs read/write if ctl_table does not exist X-Git-Tag: 2.12.53~34 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=013dafd857d1c8f045a704c865f99a53b777c5e3 LU-11986 lnet: Avoid lnet debugfs read/write if ctl_table does not exist 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 Reviewed-on: https://review.whamcloud.com/34622 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Amir Shehata Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index 99b6f79..3a696e9 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -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; }