From 54ca5e471d9f1caf63c57dfe2655e177d26dca0f Mon Sep 17 00:00:00 2001 From: Sonia Sharma Date: Mon, 1 Apr 2019 05:40:27 -0700 Subject: [PATCH] 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/34634 Tested-by: Jenkins Reviewed-by: James Simmons Tested-by: Maloo Reviewed-by: Oleg Drokin --- libcfs/libcfs/module.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index 370c905..dba4bab 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; } -- 1.8.3.1