diff mbox series

[30/40] lnet: memory leak in copy_ioc_udsp_descr

Message ID 1681042400-15491-31-git-send-email-jsimmons@infradead.org (mailing list archive)
State New, archived
Headers show
Series lustre: backport OpenSFS changes from March XX, 2023 | expand

Commit Message

James Simmons April 9, 2023, 12:13 p.m. UTC
From: Chris Horn <chris.horn@hpe.com>

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.

WC-bug-id: https://jira.whamcloud.com/browse/LU-16575
Lustre-commit: f8e129198b002589d ("LU-16575 lnet: memory leak in copy_ioc_udsp_descr")
Signed-off-by: Chris Horn <chris.horn@hpe.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50081
Reviewed-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Reviewed-by: Frank Sehr <fsehr@whamcloud.com>
Reviewed-by: Cyril Bordage <cbordage@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 net/lnet/lnet/udsp.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/net/lnet/lnet/udsp.c b/net/lnet/lnet/udsp.c
index 2594df1..deaca51 100644
--- a/net/lnet/lnet/udsp.c
+++ b/net/lnet/lnet/udsp.c
@@ -1485,8 +1485,19 @@  struct lnet_udsp *
 	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));
+	}
+
 	buf = kzalloc(alloc_size, GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;