Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4206953iog; Tue, 28 Jun 2022 11:07:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ubvgyH4ZoXiLBvBlpGUPo/XOdctsHTJrHNNa+JNRQ+xb3ajmf0rEeeWeUNBDps08RmSiZp X-Received: by 2002:a17:90a:eace:b0:1ec:b2a6:c9cf with SMTP id ev14-20020a17090aeace00b001ecb2a6c9cfmr963384pjb.26.1656439679243; Tue, 28 Jun 2022 11:07:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656439679; cv=none; d=google.com; s=arc-20160816; b=WQj45tcKGcEBR+e71miq6cryQ5cS/nYd86dWzuVeLKIq2erecRFSxjSD89NIXaVsN5 aZsyrXTAe9UnO/FyJwXocQwuNJ2p9uhuKAttjiQTitFF7nkpXRQGIWdy31M1f2pmiMe2 aRqY9+FPLbwrJvoTiKqdRP11Kk+Peqb294zgPbL6Wqj3HSdwksNlElufo0HMJKtElVav gS/6U6IH3aq/jj53/DprXqDGHTXmpDQ2xQEQB23qWm9wKokf0/A9wz/9+Rzekm2WaAX/ NJ1a6uWHbvKTkrDdF8j2dfaznaAYDuxPdyPq8np2s3n8r2lNWP+AIeK/wGYvtZuVxiwj UcpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject; bh=w0GIWjaL7HcNl5zwr2DSnKZ6GPKdibkoJ1oayJ4JPPE=; b=lJbTk2IggFntisndJm9koY5rw13naSK2EAd/3Cs+jZznE5u8pshiofmgsKjAnaXEXp HGe3PrKDvbBgi01hk49ezkQouMtOEe6IS/1DFIrAV3LeXkDmjhqCLSfYHB64W5KQTf8K hZ2O3Us5ryPqSxVh43ZQljtlNEUuP29j677sS/PblH3Hp/PH7lWiF5CuVzD9M8KiPQ/0 LFJl1lHPNznwQzKHcIqwYcVr1bOwzomNgUIkvTr5jWItZDmLvBoy11+dVfaXhxzz6mB/ lmmriFWLcVBCOUoWrnPv7YFfrmBXI9TvFmRBo6l8vU9VdgLqQnEnpD7VlWZ95obqrSCW nVYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ng8-20020a17090b1a8800b001d1ad44a667si415927pjb.6.2022.06.28.11.07.46; Tue, 28 Jun 2022 11:07:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232798AbiF1SHR (ORCPT + 99 others); Tue, 28 Jun 2022 14:07:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233856AbiF1SHQ (ORCPT ); Tue, 28 Jun 2022 14:07:16 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41D211EACC; Tue, 28 Jun 2022 11:07:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id A4FBACE21BF; Tue, 28 Jun 2022 18:07:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D353C3411D; Tue, 28 Jun 2022 18:07:11 +0000 (UTC) Subject: [PATCH v2 13/31] NFSD: WARN when freeing an item still linked via nf_lru From: Chuck Lever To: linux-nfs@vger.kernel.org, netdev@vger.kernel.org Cc: david@fromorbit.com, jlayton@redhat.com, tgraf@suug.ch Date: Tue, 28 Jun 2022 14:07:10 -0400 Message-ID: <165643963066.84360.17047678502830993413.stgit@manet.1015granger.net> In-Reply-To: <165643915086.84360.2809940286726976517.stgit@manet.1015granger.net> References: <165643915086.84360.2809940286726976517.stgit@manet.1015granger.net> User-Agent: StGit/1.5.dev2+g9ce680a5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add a guardrail to prevent freeing memory that is still on a list. This includes either a dispose list or the LRU list. This is the sign of a bug, but this class of bugs can be detected so that they don't endanger system stability, especially while debugging. Signed-off-by: Chuck Lever --- fs/nfsd/filecache.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 3055a04eeabe..8ade3699664c 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -220,6 +220,14 @@ nfsd_file_free(struct nfsd_file *nf) fput(nf->nf_file); flush = true; } + + /* + * If this item is still linked via nf_lru, that's a bug. + * WARN and leak it to preserve system stability. + */ + if (WARN_ON_ONCE(!list_empty(&nf->nf_lru))) + return flush; + call_rcu(&nf->nf_rcu, nfsd_file_slab_free); return flush; } @@ -349,7 +357,7 @@ nfsd_file_dispose_list(struct list_head *dispose) while(!list_empty(dispose)) { nf = list_first_entry(dispose, struct nfsd_file, nf_lru); - list_del(&nf->nf_lru); + list_del_init(&nf->nf_lru); nfsd_file_flush(nf); nfsd_file_put_noref(nf); } @@ -363,7 +371,7 @@ nfsd_file_dispose_list_sync(struct list_head *dispose) while(!list_empty(dispose)) { nf = list_first_entry(dispose, struct nfsd_file, nf_lru); - list_del(&nf->nf_lru); + list_del_init(&nf->nf_lru); nfsd_file_flush(nf); if (!refcount_dec_and_test(&nf->nf_ref)) continue;