Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp868424rdg; Wed, 11 Oct 2023 07:44:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhIMI7oc9FwFmyTSSWzVxPtp+zbfwtaTHrjYCqtGjP2v+O45CtFIR7C3zw2FLSTqPcr2zF X-Received: by 2002:a05:6a20:1e57:b0:14c:d0c0:dd27 with SMTP id cy23-20020a056a201e5700b0014cd0c0dd27mr15427973pzb.44.1697035463831; Wed, 11 Oct 2023 07:44:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697035463; cv=none; d=google.com; s=arc-20160816; b=uKbhngcPLDbbq+7AYeQZR8RXQByz1VVB2ibKis289FnJ8zS6QmIJYi/Ea7EbUyxQvg FBjDXeMLDJU6L3xduGY1NAw0AeLyxdaoY570ABqyIYkoOL771+R33vPO5RLQOOZgUcIf URSHfEZ+HRQaviRTAG3j/9BGi56xqn8cSRPEQ7jAZQSnpgB2shhUzyOQNS5FdOLG/CpX qsLlbdrXX6P2CqZVf7RrRA1oygvf/OxB+OMj/Go0LY9zpUu9tbasTgE4/6l1SyQuqLN3 dmwSiXcmSt6bTnCGQqE2u0mfyhF7gZTHWLepuuraxxR/l3ICisnJ2UghLSDIU+PxlEjw qAhA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VuWI80C20i7PJV6KMNwxtQYzd52tczI2bNhvyMzQlMM=; fh=tp0JmB7nlJNp/GT7FI6DcBs98ziHTxt0IXA0AAv8iNA=; b=aw5FrI+qh5fkbCy8o2iYqVnmfOq1P4bUbDEcM/RQUIWSI4rIzPBptejBIQoSMd5ppV S8eTCn2r6v6cSCAW7C1ZBlOStzHz8ATirQjvw2yDEM2OIyNT6f+mwKeBtfsL7ER1jI1Q Oq1gBW8U/8e6TlcWTmyaOK7rId5QkKCm68zihJxBlTh4xomsqcL4JiiQEwSXllzl381m 8qJmJc7ILXx04+gLhSj4OFQjB+py+XMNH/nPqcdxgHMA9FTu9C0y7hwqbbAA5nQeIYUo y1m7Rm4s1DP4zWJG9BUt28H6/gzI/6JIwb+ohc9k871gcicco+5w0Kgm/jhPDXbqp8vT Ug7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=g5FS36pi; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id a4-20020a170902ecc400b001b829a32f2dsi6067504plh.457.2023.10.11.07.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 07:44:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=g5FS36pi; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 05BC281142CF; Wed, 11 Oct 2023 07:44:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232323AbjJKOoT (ORCPT + 99 others); Wed, 11 Oct 2023 10:44:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232246AbjJKOoT (ORCPT ); Wed, 11 Oct 2023 10:44:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E376A4 for ; Wed, 11 Oct 2023 07:43:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697035416; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VuWI80C20i7PJV6KMNwxtQYzd52tczI2bNhvyMzQlMM=; b=g5FS36pinbAMQG2CjnPEYq+lYC+2cVuWdiXLig+can+BQVNhm9XoPje/U/yxIQdYFDKStQ Vvh7GJQmlVAysVhjvPmkdBeaX9bVtk07nJ/mcUyFJ1mzENl1yitomLmh7DR18/0jS0SOCx O9qtDYZ81UNxERuANA/butz+zqhnub4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-226-hkhF-BtWMvaU2WCQnQXDuQ-1; Wed, 11 Oct 2023 10:43:28 -0400 X-MC-Unique: hkhF-BtWMvaU2WCQnQXDuQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 690A23822E8A; Wed, 11 Oct 2023 14:43:27 +0000 (UTC) Received: from bcodding.csb.redhat.com (unknown [10.22.9.172]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21D8A9A; Wed, 11 Oct 2023 14:43:27 +0000 (UTC) From: Benjamin Coddington To: Anna Schumaker Cc: Jeff Layton , linux-nfs@vger.kernel.org, Dai Ngo , Scott Mayhew , Trond Myklebust Subject: [PATCH] NFS: Fix potential oops in nfs_inode_remove_request() Date: Wed, 11 Oct 2023 10:43:26 -0400 Message-ID: <9ce2991a161ce2bd9c5c7f5f8eb39b6d05c0b0b2.1697034691.git.bcodding@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 11 Oct 2023 07:44:21 -0700 (PDT) X-Spam-Level: ** From: Scott Mayhew Once a folio's private data has been cleared, it's possible for another process to clear the folio->mapping (e.g. via invalidate_complete_folio2 or evict_mapping_folio), so it wouldn't be safe to call nfs_page_to_inode() after that. Fixes: 0c493b5cf16e ("NFS: Convert buffered writes to use folios") Signed-off-by: Scott Mayhew Reviewed-by: Benjamin Coddington Tested-by: Benjamin Coddington Reviewed-by: Jeff Layton --- fs/nfs/write.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 7720b5e43014..9d82d50ce0b1 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -788,6 +788,8 @@ static void nfs_inode_add_request(struct nfs_page *req) */ static void nfs_inode_remove_request(struct nfs_page *req) { + struct nfs_inode *nfsi = NFS_I(nfs_page_to_inode(req)); + if (nfs_page_group_sync_on_bit(req, PG_REMOVE)) { struct folio *folio = nfs_page_to_folio(req->wb_head); struct address_space *mapping = folio_file_mapping(folio); @@ -802,7 +804,7 @@ static void nfs_inode_remove_request(struct nfs_page *req) } if (test_and_clear_bit(PG_INODE_REF, &req->wb_flags)) { - atomic_long_dec(&NFS_I(nfs_page_to_inode(req))->nrequests); + atomic_long_dec(&nfsi->nrequests); nfs_release_request(req); } } -- 2.41.0