[PATCH 33/60] staging: lustre: libcfs: avoid stomping on module param cpu_pattern

From: James Simmons
Date: Sat Jan 28 2017 - 19:16:22 EST


From: Dmitry Eremin <dmitry.eremin@xxxxxxxxx>

The function cfs_cpt_table_create_pattern() alters the string
passed to it. Currently we are passing in the module parameter
string cpu_pattern which is incorrect. Instead lets duplicate
the module parameter string and pass that to the function
cfs_cpt_table_create_pattern().

Signed-off-by: Liang Zhen <liang.zhen@xxxxxxxxx>
Signed-off-by: Dmitry Eremin <dmitry.eremin@xxxxxxxxx>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5050
Reviewed-on: http://review.whamcloud.com/22377
Reviewed-by: James Simmons <uja.ornl@xxxxxxxxx>
Reviewed-by: Olaf Weber <olaf@xxxxxxx>
Reviewed-by: Oleg Drokin <oleg.drokin@xxxxxxxxx>
Signed-off-by: James Simmons <jsimmons@xxxxxxxxxxxxx>
---
drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c
index 427e219..71a5b19 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c
@@ -1050,7 +1050,15 @@ static int cfs_cpu_dead(unsigned int cpu)
ret = -EINVAL;

if (*cpu_pattern) {
- cfs_cpt_table = cfs_cpt_table_create_pattern(cpu_pattern);
+ char *cpu_pattern_dup = kstrdup(cpu_pattern, GFP_KERNEL);
+
+ if (!cpu_pattern_dup) {
+ CERROR("Failed to duplicate cpu_pattern\n");
+ goto failed;
+ }
+
+ cfs_cpt_table = cfs_cpt_table_create_pattern(cpu_pattern_dup);
+ kfree(cpu_pattern_dup);
if (!cfs_cpt_table) {
CERROR("Failed to create cptab from pattern %s\n",
cpu_pattern);
--
1.8.3.1