From ebef4989e39ef8cae29edcf26fa2ee16b6106ad6 Mon Sep 17 00:00:00 2001 From: Etienne AUJAMES Date: Wed, 6 Oct 2021 22:11:17 +0200 Subject: [PATCH] LU-15059 nrs: do not overwrite "cmd" in nrs_tbf_rule "cmd" pointer inside ptlrpc_lprocfs_nrs_tbf_rule_seq_write() and nrs_tbf_parse_cmd are static. This could cause a double kfree call because "cmd" could be overwriten by another "nrs_tbf_rule" write instance. Let's try to remove the "static" definition. Signed-off-by: Etienne AUJAMES Change-Id: I8cd7d9dd0483778c82bbf8711c07e49255983f4b Reviewed-on: https://review.whamcloud.com/45142 Tested-by: jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Li Xi --- lustre/ptlrpc/nrs_tbf.c | 24 ++++++++++++------------ lustre/tests/sanityn.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/lustre/ptlrpc/nrs_tbf.c b/lustre/ptlrpc/nrs_tbf.c index 653b55e..47724dc 100644 --- a/lustre/ptlrpc/nrs_tbf.c +++ b/lustre/ptlrpc/nrs_tbf.c @@ -3479,10 +3479,10 @@ nrs_tbf_parse_value_pairs(struct nrs_tbf_cmd *cmd, char *buffer) static struct nrs_tbf_cmd * nrs_tbf_parse_cmd(char *buffer, unsigned long count, __u32 type_flag) { - static struct nrs_tbf_cmd *cmd; - char *token; - char *val; - int rc = 0; + struct nrs_tbf_cmd *cmd; + char *token; + char *val; + int rc = 0; OBD_ALLOC_PTR(cmd); if (cmd == NULL) @@ -3580,15 +3580,15 @@ ptlrpc_lprocfs_nrs_tbf_rule_seq_write(struct file *file, const char __user *buffer, size_t count, loff_t *off) { - struct seq_file *m = file->private_data; - struct ptlrpc_service *svc = m->private; - char *kernbuf; - char *val; - int rc; - static struct nrs_tbf_cmd *cmd; + struct seq_file *m = file->private_data; + struct ptlrpc_service *svc = m->private; + char *kernbuf; + char *val; + int rc; + struct nrs_tbf_cmd *cmd; enum ptlrpc_nrs_queue_type queue = PTLRPC_NRS_QUEUE_BOTH; - unsigned long length; - char *token; + unsigned long length; + char *token; OBD_ALLOC(kernbuf, LPROCFS_WR_NRS_TBF_MAX_CMD); if (kernbuf == NULL) diff --git a/lustre/tests/sanityn.sh b/lustre/tests/sanityn.sh index 7f20a86..7a4cc88 100755 --- a/lustre/tests/sanityn.sh +++ b/lustre/tests/sanityn.sh @@ -4429,6 +4429,35 @@ test_77o() { } run_test 77o "Changing rank should not panic" +test_77q() { + local i + + (( $MDS1_VERSION > $(version_code 2.14.54) )) || + skip "need MDS >= 2.14.54" + + do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies="tbf" + stack_trap "do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies=fifo" + + for i in {1..50}; do + local pid1 pid2 + + do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'start rule77q_1 uid={500}&gid={500} rate=100'" & + pid1=$! + do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'start rule77q_2 uid={1000}&gid={1000} rate=100'" & + pid2=$! + wait $pid1 || error "$i: Fail to start TBF rule 'rule77q_1'" + wait $pid2 || error "$i: Fail to start TBF rule 'rule77q_2'" + + do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'stop rule77q_1'" & + pid1=$! + do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'stop rule77q_2'" & + pid2=$! + wait $pid1 || error "$i: Fail to stop TBF rule 'rule77q_1'" + wait $pid2 || error "$i: Fail to stop TBF rule 'rule77q_2'" + done +} +run_test 77q "Parallel TBF rule definitions should not panic" + test_78() { #LU-6673 local rc -- 1.8.3.1