Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3550211ybf; Tue, 3 Mar 2020 07:59:43 -0800 (PST) X-Google-Smtp-Source: ADFU+vuprX08PgNVzVe1eS87nPr5uB83/jYiTiBywpQEy8DPjD5qzR/RdaP8H08rpA/cKmQ5gd2N X-Received: by 2002:a9d:6b12:: with SMTP id g18mr3747452otp.211.1583251183049; Tue, 03 Mar 2020 07:59:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583251183; cv=none; d=google.com; s=arc-20160816; b=hNVNrtXkYxwbzGR0pNGSLxEYcnQ1XMBmrM/w0De1dPXILqHvf7lYmfYBYYnl2VVAjO TQxAV6S42Ub0MDcXCbaxoA/7rLS9LCbxqbHKnj6mu0WLWOtkKyP14pN93JGxdWPcHar1 SS0hwynS6/ZPeEloKp8a7CNDO7k7XivOcsLj/1fkO6/K6exi+iFuUAJTbnvL9s2lfvaK fgeRFBQnkBEo3tVhslteOR1mdwKo3E0289bbXe3kTlBnfCbUUYST4XCK95R2p7IzJYc/ qzcDkczXxSWmxWXSKZExBil7gvECwA5KRDIHHmMZgzBrLMwxB9OkxqXnOvUxO4yKFntC 9c/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=O5UeeS46MKDPj1TSFD4lV3QEGuK4/wM5Jx3AII0/4ak=; b=yay4pLwFN1OAWUSJf8vWrH7PEnN0+PtJ8ReKtgsih2Hz2J0cC5oFydUYCOCIJg1kRK QhSMaVBMygqk9jILxVs6oCC0xF8wJsjDiPUJwPtQ6vkvavbbMuHODX9caRtTyeVA+0OY gBmucq2/RMn2FKzamUx2BUSISoMJ+D7fcXkw1UePEpeGFsAuo50DrWlrdVKWiuKDohOo 8XWYu/AjFOVzTtcJD3yZJxhvqIf0r3GIJm0WObFEAmQVpNaQvbR4S3HSf6YJNa+54b6z oOpO700cmO7qWyPyermRdmgYF/c4b03Ty56qrBREWBmMEv7tmF93Wlsc46/KCZYemyKe uvcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u14si8529550otg.10.2020.03.03.07.59.26; Tue, 03 Mar 2020 07:59:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730261AbgCCPzr (ORCPT + 99 others); Tue, 3 Mar 2020 10:55:47 -0500 Received: from fieldses.org ([173.255.197.46]:37226 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730214AbgCCPzr (ORCPT ); Tue, 3 Mar 2020 10:55:47 -0500 Received: by fieldses.org (Postfix, from userid 2815) id 4A90489A; Tue, 3 Mar 2020 10:55:47 -0500 (EST) Date: Tue, 3 Mar 2020 10:55:47 -0500 From: "J. Bruce Fields" To: Stephen Hemminger Cc: trond.myklebust@hammerspace.com, chuck.lever@oracle.com, linux-nfs@vger.kernel.org Subject: Re: Fw: [Bug 206651] New: kmemleak in rpcsec_gss_krb5 Message-ID: <20200303155547.GD17257@fieldses.org> References: <20200223195520.0afdad4a@hermes.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200223195520.0afdad4a@hermes.lan> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Sun, Feb 23, 2020 at 07:55:20PM -0800, Stephen Hemminger wrote: > During the loading and unloading of the kernel module, kmemleak discovered a > leak problem. To reproduce this problem, you only need to enable the kmemleak > option. > CONFIG_DEBUG_KMEMLEAK=y > CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=10000: > Then, load and unload the module. > modprobe rpcsec_gss_krb5 > modprobe -r rpcsec_gss_krb5: > Repeat this process every 1000 cycles to obtain the leaked information. > Repeat the preceding operations for 115 times. The SUnreclaim memory will > increase by 85 MB. > > After checking the loading source code of rpcsec_gss_krb5, we find that the > svcauth_gss_register_pseudoflavor function in the svcauth_gss.c file contains > the following code segment: > > ... > test = auth_domain_lookup(name, &new->h); > if (test != &new->h) { /* Duplicate registration */ > auth_domain_put(test); > kfree(new->h.name); > goto out_free_dom; > } > return 0; > > out_free_dom: > kfree(new); > out: > return stat; > ... > > The structure of new->h.name is dynamically applied by kstrdup. When > auth_domain_lookup cannot find new->h.name in the hash table, it is added to > the hash table. > > When the module is unloaded, the structure in the hash table is not released > accordingly. As a result, the module is leaked. I modified the gss_mech_free > function to forcibly release the structure in the hash table. > > ... > for (i = 0; i < gm->gm_pf_num; i++) { > pf = &gm->gm_pfs[i]; > + struct auth_domain *test; > + test = auth_domain_find(pf->auth_domain_name); > + if (test != NULL) { > + test->flavour->domain_release(test); > + } > kfree(pf->auth_domain_name); > ... > > Perform the leakage test again. The memory usage of SUnreclaim does not > increase. > > I want a complete destructor to free the hash table, not by force. Thanks! I'm not sure what the right solution is. Honestly, maybe just preventing unloading of these modules--I'm not sure why it's really needed. --b.