Whamcloud - gitweb
LU-17000 lnet: lnet_inet_enumerate krealloc and kfree 50/56150/6
authorShaun Tancheff <shaun.tancheff@hpe.com>
Mon, 26 Aug 2024 04:02:17 +0000 (11:02 +0700)
committerOleg Drokin <green@whamcloud.com>
Sun, 24 Nov 2024 06:05:01 +0000 (06:05 +0000)
CoverityID: 442369  ("Memory - corruptions, double free")
On realloc() failure free 'ifaces' which may already differ from
*dev_list due to a previous realloc(). Also nalloc is now zero.

CoverityID: 442378 ("Resource Leak")
Ensure lnet_inet_enumerate() ifaces are freed.

Signed-off-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Change-Id: I2d2762d86fcf070387b100115ad3a50bd2b2840b
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56150
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Frank Sehr <fsehr@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
lnet/lnet/config.c
lnet/lnet/lib-socket.c

index f166755..501d7c0 100644 (file)
@@ -1583,7 +1583,8 @@ lnet_parse_ip2nets(const char **networksp, const char *ip2nets)
                } else {
                        LCONSOLE_ERROR("No local IP interfaces for ip2nets to match\n");
                }
-               return nip;
+               rc = nip;
+               goto out_free_addrs;
        }
 
        CFS_ALLOC_PTR_ARRAY(ipaddrs, nip);
index d9fa38b..ed00356 100644 (file)
@@ -462,7 +462,8 @@ static int lnet_inet4_enumerate(struct net_device *dev, int flags,
                        tmp = krealloc(ifaces, *nalloc * sizeof(*tmp),
                                       GFP_KERNEL);
                        if (!tmp) {
-                               kfree(*dev_list);
+                               kfree(ifaces);
+                               *nalloc = 0;
                                *dev_list = NULL;
                                return -ENOMEM;
                        }
@@ -516,7 +517,8 @@ static int lnet_inet6_enumerate(struct net_device *dev, int flags,
                        tmp = krealloc(ifaces, *nalloc * sizeof(*tmp),
                                       GFP_KERNEL);
                        if (!tmp) {
-                               kfree(*dev_list);
+                               kfree(ifaces);
+                               *nalloc = 0;
                                *dev_list = NULL;
                                return -ENOMEM;
                        }