Whamcloud - gitweb
LU-16081 lnet: Memory leak on adding existing interface 73/48173/7
authorFrank Sehr <fsehr@whamcloud.com>
Tue, 9 Aug 2022 17:10:54 +0000 (10:10 -0700)
committerOleg Drokin <green@whamcloud.com>
Thu, 1 Sep 2022 05:53:59 +0000 (05:53 +0000)
In the function lnet_dyn_add_ni an lnet_ni structure is allocated.
In case of an error the function returns without freeing the memory of
the structure.
Added handling of possible lnet_net structure memory leaks.

Test-parameters: trivial testlist=sanity-lnet
Signed-off-by: Frank Sehr <fsehr@whamcloud.com>
Change-Id: I7544a9379093b99f77aaddb8d021b4a5bf221082
Reviewed-on: https://review.whamcloud.com/48173
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/lnet/api-ni.c
lustre/tests/sanity-lnet.sh

index 67e20b1..d4adae2 100644 (file)
@@ -3641,25 +3641,34 @@ int lnet_dyn_add_ni(struct lnet_ioctl_config_ni *conf)
                return -ENOMEM;
 
        for (i = 0; i < conf->lic_ncpts; i++) {
-               if (conf->lic_cpts[i] >= LNET_CPT_NUMBER)
+               if (conf->lic_cpts[i] >= LNET_CPT_NUMBER) {
+                       lnet_net_free(net);
                        return -EINVAL;
+               }
        }
 
        ni = lnet_ni_alloc_w_cpt_array(net, conf->lic_cpts, conf->lic_ncpts,
                                       conf->lic_ni_intf);
-       if (!ni)
+       if (!ni) {
+               lnet_net_free(net);
                return -ENOMEM;
+       }
 
        lnet_set_tune_defaults(tun);
 
        mutex_lock(&the_lnet.ln_api_mutex);
-       if (the_lnet.ln_state != LNET_STATE_RUNNING)
+       if (the_lnet.ln_state != LNET_STATE_RUNNING) {
+               lnet_net_free(net);
                rc = -ESHUTDOWN;
-       else
+       } else {
                rc = lnet_add_net_common(net, tun);
+       }
 
        mutex_unlock(&the_lnet.ln_api_mutex);
 
+       if (rc)
+               lnet_ni_free(ni);
+
        return rc;
 }
 
index b3c1fa1..28afdfd 100755 (executable)
@@ -3084,6 +3084,20 @@ test_300() {
 }
 run_test 300 "packaged LNet UAPI headers can be compiled"
 
+# LU-16081 lnet: Memory leak on adding existing interface
+
+test_301() {
+       reinit_dlc || return $?
+       do_lnetctl net add --net tcp --if ${INTERFACES[0]} ||
+               error "Failed to add net"
+       do_lnetctl net add --net tcp --if ${INTERFACES[0]} &&
+               error "add net should have failed"
+       do_lnetctl net del --net tcp --if ${INTERFACES[0]} ||
+               error "Failed to del net"
+       unload_modules
+}
+run_test 301 "Check for dynamic adds of same/wrong interface (memory leak)"
+
 complete $SECONDS
 
 cleanup_testsuite