Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1109580BE0 for ; Wed, 17 Apr 2024 10:30:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713349854; cv=none; b=kSYQxKqvEEHnfKBoiDBseRK/3ORxxc8eETRBrA3m7QwE4G8eJZ+xFog3rJgwzkCr2q57kLV6zeNxlIRGkODBYo3GdjVOYEBri/ZQ857L1kQO/ge7Ht6SVen5YC6DlBHV0JRsWtccLlGncv4sb3kOUuRh81WEdb3f5Aua1ko+Ixg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713349854; c=relaxed/simple; bh=xcohU4LmVdSRs0IxMc7fXULXPUK7d80y4Tp6XEpGhT8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Tw2kRFWqXKwKtTvGeEibhERiZ0yhVNmAwWzQ0YmYFtDVvEE3WGdEjsyyX+NyLcVw+ps97ZtS9F4dDcIFjj4V3JPDVkjqftIvnXdk+e4pgoFWBGdXqJohmt504NQ3ZwEdXRQpp0bOU8cr+N6jlYwFa6Emkkd0ZunNbGIX9MnkdmI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vJ4Uhqr6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="vJ4Uhqr6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89059C072AA; Wed, 17 Apr 2024 10:30:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1713349853; bh=xcohU4LmVdSRs0IxMc7fXULXPUK7d80y4Tp6XEpGhT8=; h=From:To:Cc:Subject:Date:Reply-to:From; b=vJ4Uhqr6KX66SN91Jlo0niEDnHZQqlQ8Vwn4gM1Pn0z9W9VI5uGljEYCQa3fIt+Px 23G0XIuxqqgwbywsEeuai9DKsIA2xULuTWPT8Ag0vpPa+r0T+lFSiYbFm5fwcPS2Mn DZ64K6R7fse66XSg/Ljsw7nGJ/ZJnemZLab0pyaY= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-26868: nfs: fix panic when nfs4_ff_layout_prepare_ds() fails Date: Wed, 17 Apr 2024 12:28:43 +0200 Message-ID: <2024041737-CVE-2024-26868-35ff@gregkh> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=4846; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=xcohU4LmVdSRs0IxMc7fXULXPUK7d80y4Tp6XEpGhT8=; b=owGbwMvMwCRo6H6F97bub03G02pJDGnyS0LvlK/7tf530pWnDanm3Sb8d+SN6lkMWldnmtv8m FJYaRXeEcvCIMjEICumyPJlG8/R/RWHFL0MbU/DzGFlAhnCwMUpABPJDGOYH9Rtts2IYb710Tun bldXvxd7or5jPsOCjUKPS2Z++7ny8IHudfL8G/NcLwRYAgA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: nfs: fix panic when nfs4_ff_layout_prepare_ds() fails We've been seeing the following panic in production BUG: kernel NULL pointer dereference, address: 0000000000000065 PGD 2f485f067 P4D 2f485f067 PUD 2cc5d8067 PMD 0 RIP: 0010:ff_layout_cancel_io+0x3a/0x90 [nfs_layout_flexfiles] Call Trace: ? __die+0x78/0xc0 ? page_fault_oops+0x286/0x380 ? __rpc_execute+0x2c3/0x470 [sunrpc] ? rpc_new_task+0x42/0x1c0 [sunrpc] ? exc_page_fault+0x5d/0x110 ? asm_exc_page_fault+0x22/0x30 ? ff_layout_free_layoutreturn+0x110/0x110 [nfs_layout_flexfiles] ? ff_layout_cancel_io+0x3a/0x90 [nfs_layout_flexfiles] ? ff_layout_cancel_io+0x6f/0x90 [nfs_layout_flexfiles] pnfs_mark_matching_lsegs_return+0x1b0/0x360 [nfsv4] pnfs_error_mark_layout_for_return+0x9e/0x110 [nfsv4] ? ff_layout_send_layouterror+0x50/0x160 [nfs_layout_flexfiles] nfs4_ff_layout_prepare_ds+0x11f/0x290 [nfs_layout_flexfiles] ff_layout_pg_init_write+0xf0/0x1f0 [nfs_layout_flexfiles] __nfs_pageio_add_request+0x154/0x6c0 [nfs] nfs_pageio_add_request+0x26b/0x380 [nfs] nfs_do_writepage+0x111/0x1e0 [nfs] nfs_writepages_callback+0xf/0x30 [nfs] write_cache_pages+0x17f/0x380 ? nfs_pageio_init_write+0x50/0x50 [nfs] ? nfs_writepages+0x6d/0x210 [nfs] ? nfs_writepages+0x6d/0x210 [nfs] nfs_writepages+0x125/0x210 [nfs] do_writepages+0x67/0x220 ? generic_perform_write+0x14b/0x210 filemap_fdatawrite_wbc+0x5b/0x80 file_write_and_wait_range+0x6d/0xc0 nfs_file_fsync+0x81/0x170 [nfs] ? nfs_file_mmap+0x60/0x60 [nfs] __x64_sys_fsync+0x53/0x90 do_syscall_64+0x3d/0x90 entry_SYSCALL_64_after_hwframe+0x46/0xb0 Inspecting the core with drgn I was able to pull this >>> prog.crashed_thread().stack_trace()[0] #0 at 0xffffffffa079657a (ff_layout_cancel_io+0x3a/0x84) in ff_layout_cancel_io at fs/nfs/flexfilelayout/flexfilelayout.c:2021:27 >>> prog.crashed_thread().stack_trace()[0]['idx'] (u32)1 >>> prog.crashed_thread().stack_trace()[0]['flseg'].mirror_array[1].mirror_ds (struct nfs4_ff_layout_ds *)0xffffffffffffffed This is clear from the stack trace, we call nfs4_ff_layout_prepare_ds() which could error out initializing the mirror_ds, and then we go to clean it all up and our check is only for if (!mirror->mirror_ds). This is inconsistent with the rest of the users of mirror_ds, which have if (IS_ERR_OR_NULL(mirror_ds)) to keep from tripping over this exact scenario. Fix this up in ff_layout_cancel_io() to make sure we don't panic when we get an error. I also spot checked all the other instances of checking mirror_ds and we appear to be doing the correct checks everywhere, only unconditionally dereferencing mirror_ds when we know it would be valid. The Linux kernel CVE team has assigned CVE-2024-26868 to this issue. Affected and fixed versions =========================== Issue introduced in 6.1 with commit b739a5bd9d9f and fixed in 6.1.83 with commit 31db25e3141b Issue introduced in 6.1 with commit b739a5bd9d9f and fixed in 6.6.23 with commit 7ca651b4ec4a Issue introduced in 6.1 with commit b739a5bd9d9f and fixed in 6.7.11 with commit 5ada9016b121 Issue introduced in 6.1 with commit b739a5bd9d9f and fixed in 6.8.2 with commit dac068f164ad Issue introduced in 6.1 with commit b739a5bd9d9f and fixed in 6.9-rc1 with commit 719fcafe07c1 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2024-26868 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: fs/nfs/flexfilelayout/flexfilelayout.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/31db25e3141b20e2a76a9f219eeca52e3cab126c https://git.kernel.org/stable/c/7ca651b4ec4a049f5a46a0e5ff921b86b91c47c5 https://git.kernel.org/stable/c/5ada9016b1217498fad876a3d5b07645cc955608 https://git.kernel.org/stable/c/dac068f164ad05b35e7c0be13f138c3f6adca58f https://git.kernel.org/stable/c/719fcafe07c12646691bd62d7f8d94d657fa0766