From f8e129198b002589daf4acdaf10cb970e9dab44a Mon Sep 17 00:00:00 2001 From: Chris Horn Date: Tue, 21 Feb 2023 10:37:56 -0600 Subject: [PATCH] LU-16575 lnet: memory leak in copy_ioc_udsp_descr copy_ioc_udsp_descr() doesn't correctly handle the case where a net number was not specified. In this case, there isn't any net number range that needs to be copied into the udsp descriptor. Test-Parameters: trivial testlist=sanity-lnet env=ONLY=400 Signed-off-by: Chris Horn Change-Id: Ica900e2b0ec816237a8303d1d9e07cc1f6c5a652 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50081 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Serguei Smirnov Reviewed-by: Frank Sehr Reviewed-by: Cyril Bordage Reviewed-by: Oleg Drokin --- lnet/lnet/udsp.c | 15 +++++++++++++-- lustre/tests/sanity-lnet.sh | 11 +++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lnet/lnet/udsp.c b/lnet/lnet/udsp.c index 185d27f..bd8efda 100644 --- a/lnet/lnet/udsp.c +++ b/lnet/lnet/udsp.c @@ -1486,8 +1486,19 @@ copy_ioc_udsp_descr(struct lnet_ud_nid_descr *nid_descr, char *type, CDEBUG(D_NET, "%u\n", nid_descr->ud_net_id.udn_net_type); /* allocate the total memory required to copy this NID descriptor */ - alloc_size = (sizeof(struct cfs_expr_list) * (expr_count + 1)) + - (sizeof(struct cfs_range_expr) * (range_count)); + if (ioc_nid->iud_net.ud_net_num_expr.le_count) { + if (ioc_nid->iud_net.ud_net_num_expr.le_count != 1) { + CERROR("Unexpected number of net numeric ranges \"%u\". Cannot add UDSP rule.\n", + ioc_nid->iud_net.ud_net_num_expr.le_count); + return -EINVAL; + } + alloc_size = (sizeof(struct cfs_expr_list) * (expr_count + 1)) + + (sizeof(struct cfs_range_expr) * (range_count)); + } else { + alloc_size = (sizeof(struct cfs_expr_list) * (expr_count)) + + (sizeof(struct cfs_range_expr) * (range_count)); + } + LIBCFS_ALLOC(buf, alloc_size); if (!buf) return -ENOMEM; diff --git a/lustre/tests/sanity-lnet.sh b/lustre/tests/sanity-lnet.sh index a1ef920..976e3e1 100755 --- a/lustre/tests/sanity-lnet.sh +++ b/lustre/tests/sanity-lnet.sh @@ -3353,6 +3353,17 @@ test_302() { } run_test 302 "Check that peer debug info can be dumped" +test_400() { + reinit_dlc || return $? + + do_lnetctl udsp add --src tcp --priority 0 || + error "Failed to add udsp rule" + do_lnetctl udsp del --idx 0 || + error "Failed to del udsp rule" + unload_modules +} +run_test 400 "Check for udsp add/delete net rule without net num" + complete $SECONDS cleanup_testsuite -- 1.8.3.1