Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8099765ybi; Thu, 6 Jun 2019 06:44:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEWUk3ICLjWx9gRV0pAVkb+ZE73jlTYgN7t6e7xWQ8nXMPvQ9+uyI7XSdkwZCumR2LaG1X X-Received: by 2002:a17:902:ba8c:: with SMTP id k12mr48162730pls.229.1559828668562; Thu, 06 Jun 2019 06:44:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559828668; cv=none; d=google.com; s=arc-20160816; b=OP+mQePFa51Hqb/noiKEf1Km2cgqkkX19BL6iycjGb/B7RZbESvpaW8YuBI8oRb9Wq ckd55BU19Qg+d4VQJUvfJp5chTPg9T215WCmlehEXoVZmrytC1glaldCkxPu0F6BznLY Me0SYSdrQ45H7ckHwRYdx1fMhyENOrdnnNDGNAIq0lnBymIBt1XClGR0p2qLU1QAdV2N SO82xV1INKnFd5nzWtZR2nyoDQ49A5Q+ocW6HNuwxwgllUkR5kGg2v5I7Xy46YDQry3m UZedX3lngw+R0Er9y7/yTsQUDKi4lyMbfqYtsgAxBLtrPcWxkKfCvLfSffNLGMGEqbYq SdPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=vm4btAOsyOUR0oYjzNf92pqRfluADuwslifIy4VqXiM=; b=UOQl3pAEM2O1hePHDY5VFmsTIWnDS01hqxyMD8PlVNVmxPoCyP1I+lh+9lninbzmkL TcOonEZWKZKoYXVBJAqXE1p5qOW7XlMZxcTyxyFYFA1K9EoRPhULbmbHJgH/yZSz7Qh4 dg7NRJMarTGzHXRNlsk0fwdj6eQla3YDKrMZ5OZI+p5yQW6Pm0Uca8Dt4WuWZalSs8hA wiYrUrB2GhjqTcifygUs2khJpsVe1MoU2HHLjqcamX1cVGXsw9eziulUyV/BCq3qKjoC dxfTEDFDqMQIdka1jwYzfMPF7yrcW8I8e2cwNE/ZJHXgSw22sTNZgTs33YdVfUqCNpWY l1aA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i95si1836206plb.106.2019.06.06.06.44.08; Thu, 06 Jun 2019 06:44:28 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727009AbfFFNoD (ORCPT + 99 others); Thu, 6 Jun 2019 09:44:03 -0400 Received: from relay.sw.ru ([185.231.240.75]:33160 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726092AbfFFNoD (ORCPT ); Thu, 6 Jun 2019 09:44:03 -0400 Received: from [172.16.25.169] by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hYsgC-0008Uh-Hh; Thu, 06 Jun 2019 16:43:44 +0300 Subject: Re: KASAN: use-after-free Read in unregister_shrinker To: "J. Bruce Fields" 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 References: <0000000000005a4b99058a97f42e@google.com> <20190606131334.GA24822@fieldses.org> From: Kirill Tkhai Message-ID: <275f77ad-1962-6a60-e60b-6b8845f12c34@virtuozzo.com> Date: Thu, 6 Jun 2019 16:43:44 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190606131334.GA24822@fieldses.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On 06.06.2019 16:13, J. Bruce Fields wrote: > 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. Yes, it's had to bump into this in real life. AFAIU, syzbot triggers such the problem by using fault-injections on allocation places should_failslab()->should_fail(). It's possible to configure a specific slab, so the allocations will fail with requested probability. > 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; Looks OK for me. Feel free to add my reviewed-by if you want. Reviewed-by: Kirill Tkhai