Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp773863imw; Fri, 8 Jul 2022 11:25:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1skXc53bgW/luXwg2yCbfML1WkZRbmM7g0XPkPQdxTrbh+9dEqLVp36zlme3D0vBXDWbdTn X-Received: by 2002:a65:6b94:0:b0:3fb:16f4:3620 with SMTP id d20-20020a656b94000000b003fb16f43620mr4405199pgw.464.1657304749172; Fri, 08 Jul 2022 11:25:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657304749; cv=none; d=google.com; s=arc-20160816; b=f9el2/cRjOoWeJNYeyZiOvTmDaUuvCkr4/eGh+lf8V/7OwwHD72rSrZN/kjudf9RsF yU9lcbfq8oNDs03dC1sC6mSqmcmHogAVdzUZIvM0hDADMBjFRvLM4v/vXfc+h05q+2KT 3qzt5BahEF4U3TzVHhp/Eb7S2x9wyXqKz19d7+qDQ6gUA8tzlgfsuVj6esfOXzDVXxX7 vtyljyJQjKsvr9xzeDc/VGIInr5iR88PCk5v7OASuFIFhln5yOPmLuJgzpfIzPUpOg2+ O6nN8CF/Ru3yuIaH6hIDPZVxj//kipYKmK3zO8bIAOeRv1E0D76x7ftFTX//HI45Kd5G 5r1Q== 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=o97Gd4DXS9Hm9UMtIAYcjfa3p5iPbCQE4h8fX4LKwI81wogKsFKtVrrHIJ0dI5J+ez MCEH9H7P/jyc5PMfOUYafnL2jDB48WD6seEEpjN/9nl7xEBRv8woOFlY0MqGYf+ntgDs H4P/Q2kl/WZbSb1lXHyVJsFLRkIAJ/D+evz2RyR+ECcabuC3fAT8EasqsTgUrwacC6tJ cwIZovowoShbqZl2ZvCSwJT1Ogdml1xVXHVAq/DMDnM/FHO7EFBMVPnW4ObaE2ntwEwm PeGHI0w8sVVHuKdOzIqBVh8DQ16RgRaCnPcTVYM6snvs/ppMqaM1b6gIHBUtPewWd3Bd Q6Fw== 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 z13-20020aa79e4d000000b00528b9bb5d32si294287pfq.30.2022.07.08.11.25.36; Fri, 08 Jul 2022 11:25:49 -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 S239456AbiGHSZN (ORCPT + 99 others); Fri, 8 Jul 2022 14:25:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239465AbiGHSZI (ORCPT ); Fri, 8 Jul 2022 14:25:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E28E984EC2; Fri, 8 Jul 2022 11:25:06 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 7FCA562610; Fri, 8 Jul 2022 18:25:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95BB8C341C0; Fri, 8 Jul 2022 18:25:05 +0000 (UTC) Subject: [PATCH v3 13/32] 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: Fri, 08 Jul 2022 14:25:04 -0400 Message-ID: <165730470467.28142.1460484670621105058.stgit@klimt.1015granger.net> In-Reply-To: <165730437087.28142.6731645688073512500.stgit@klimt.1015granger.net> References: <165730437087.28142.6731645688073512500.stgit@klimt.1015granger.net> User-Agent: StGit/1.5.dev3+g9561319 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;