Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8067229ybi; Thu, 6 Jun 2019 06:13:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjzfz9A+qKWCrRXNb7Hn3Ibw8Ox8AoD1PaeKUVDLtXAhU5pAODtCpdENcgi+cWRnumJMIg X-Received: by 2002:a17:902:7297:: with SMTP id d23mr36500703pll.254.1559826835769; Thu, 06 Jun 2019 06:13:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559826835; cv=none; d=google.com; s=arc-20160816; b=w4PPZxHrNc3BlnOxtByD1ZugV1Jk5xzJsRc2usZncUkeHkpNqmmyBGLROueL3UhbG6 8MVxGw6R+U1XMMZbyIa/sr9yxFme9v/qWBA4cvyGLKF+gKLKbe8z/1sQ9iFrgqROSk29 l9apLjggks9Te2E4ncSZN0BLD+zrX4/ifdV8ml8sIAFj5gbEHw4wQE110QUWIEy8P0oG eDpdIWwfg91MCyTzdXhavcLlszl8aqI2XgFnYbLZp5HCCaWR1w3Uqe/0taJ37TOYReYW 6pa8RTNmeuPdL62iYQhZbZnTVsT/oLMsAYUO80QNUHKFq2AkAWAFcP64wDCZhxGWUZeN jroQ== 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=JAErcRwTm4Fxv7hc/ipsQuGC8OwztSmhtOobDqFAvak=; b=ZMNkUtE+2myJNOz/XyXlwwcMsQE2ulvakLGd2kwjKAn7qs0tYTrWnXsNZKscQNWO7X SdF1EZDaOsJfE6qM6qfKKv4ukoOrYyJ3SVbdrZi9QfrUqhUZBHcyc36hJOA8jDplCWkA IvduaG9GjxhxGjjxrt+A/2gF0RWa8jhPspCWvglcIjJ9zy8qCy+Yj3C9/M8WGvVg/arQ nl+JT2K+2gAKgQQUaKvBIeXG5fdBsZ1a05vDODYZ7ZsDlMY0PG7fWwS+AjJ1mkP4rc5N w5SkivxE33idBsX/WRq9YcvjF5eiZNvgSdbbf+PIJY2XyucNJU/Nl0Mokq6EQaFk9xZC BXxQ== 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 v9si1941218pfm.50.2019.06.06.06.13.39; Thu, 06 Jun 2019 06:13:55 -0700 (PDT) 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 S1727068AbfFFNNf (ORCPT + 99 others); Thu, 6 Jun 2019 09:13:35 -0400 Received: from fieldses.org ([173.255.197.46]:36386 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725782AbfFFNNf (ORCPT ); Thu, 6 Jun 2019 09:13:35 -0400 Received: by fieldses.org (Postfix, from userid 2815) id 8384214DB; Thu, 6 Jun 2019 09:13:34 -0400 (EDT) Date: Thu, 6 Jun 2019 09:13:34 -0400 From: "J. Bruce Fields" To: Kirill Tkhai Cc: syzbot , akpm@linux-foundation.org, bfields@redhat.com, chris@chrisdown.name, daniel.m.jordan@oracle.com, guro@fb.com, hannes@cmpxchg.org, jlayton@kernel.org, laoar.shao@gmail.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, mgorman@techsingularity.net, mhocko@suse.com, sfr@canb.auug.org.au, syzkaller-bugs@googlegroups.com, yang.shi@linux.alibaba.com Subject: Re: KASAN: use-after-free Read in unregister_shrinker Message-ID: <20190606131334.GA24822@fieldses.org> References: <0000000000005a4b99058a97f42e@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Thu, Jun 06, 2019 at 10:47:43AM +0300, Kirill Tkhai wrote: > This may be connected with that shrinker unregistering is forgotten on error path. I was wondering about that too. Seems like it would be hard to hit reproduceably though: one of the later allocations would have to fail, then later you'd have to create another namespace and this time have a later module's init fail. This is the patch I have, which also fixes a (probably less important) failure to free the slab cache. --b. commit 17c869b35dc9 Author: J. Bruce Fields Date: Wed Jun 5 18:03:52 2019 -0400 nfsd: fix cleanup of nfsd_reply_cache_init on failure Make sure everything is cleaned up on failure. Especially important for the shrinker, which will otherwise eventually be freed while still referred to by global data structures. Signed-off-by: J. Bruce Fields diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index ea39497205f0..3dcac164e010 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -157,12 +157,12 @@ int nfsd_reply_cache_init(struct nfsd_net *nn) nn->nfsd_reply_cache_shrinker.seeks = 1; status = register_shrinker(&nn->nfsd_reply_cache_shrinker); if (status) - return status; + goto out_nomem; nn->drc_slab = kmem_cache_create("nfsd_drc", sizeof(struct svc_cacherep), 0, 0, NULL); if (!nn->drc_slab) - goto out_nomem; + goto out_shrinker; nn->drc_hashtbl = kcalloc(hashsize, sizeof(*nn->drc_hashtbl), GFP_KERNEL); @@ -170,7 +170,7 @@ int nfsd_reply_cache_init(struct nfsd_net *nn) nn->drc_hashtbl = vzalloc(array_size(hashsize, sizeof(*nn->drc_hashtbl))); if (!nn->drc_hashtbl) - goto out_nomem; + goto out_slab; } for (i = 0; i < hashsize; i++) { @@ -180,6 +180,10 @@ int nfsd_reply_cache_init(struct nfsd_net *nn) nn->drc_hashsize = hashsize; return 0; +out_slab: + kmem_cache_destroy(nn->drc_slab); +out_shrinker: + unregister_shrinker(&nn->nfsd_reply_cache_shrinker); out_nomem: printk(KERN_ERR "nfsd: failed to allocate reply cache\n"); return -ENOMEM;