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 029D9524A5 for ; Fri, 17 May 2024 13:24:56 +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=1715952296; cv=none; b=Dqi7DiijtAWanezZkoX8rfBTA/oro0HtEEtb6hTPJVOtJtZz4uKjl0g+L8m/j9M04xyIdU+8KWo2cFqsMV62aYi/B7TaaUUqzKQJhxcajpu9CD7zPm1Pfih+ch0iBco3GIfe1Y08SU3+4j8dZ6ZTDCYgLab85qdPq80rSOFHeRE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715952296; c=relaxed/simple; bh=226C6xZbD3T4A3A/0yOcw5cjIrKTtw2cppxTA+mwS3M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ZeNbriXsSLlxm3VdVcEfDJMixCZfVXQnyDfHNsO+qlXutw/QR798z15WXpFn092DHz/l91iSDyPwfwwNCy3LK6axsmHlS+hC70lYWuc11oGWy6kPLQc/IMKgy6pSWmoVbJt6ORJgsfrcnI2eiJRa0/IN4CVBOrIJ4UuxtDgRLow= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=U25spyg4; 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="U25spyg4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FF7EC2BD10; Fri, 17 May 2024 13:24:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1715952295; bh=226C6xZbD3T4A3A/0yOcw5cjIrKTtw2cppxTA+mwS3M=; h=From:To:Cc:Subject:Date:Reply-to:From; b=U25spyg4popQFW1a0wDPPjc//wgDsHjCnWVgCIelQYlTvAVHAGDcSRpKKINGgIPu+ Ko3Fsv+51MlKkMA00XtLJB9qQscuV1NTGSX8LH87QmyWr1aq0LVTuxPOnHBtOhY28+ U5WPUwzVT8RIobDtH6peLyJPdH7gDlsUzPuBWmVo= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-35798: btrfs: fix race in read_extent_buffer_pages() Date: Fri, 17 May 2024 15:23:38 +0200 Message-ID: <2024051737-CVE-2024-35798-8d90@gregkh> X-Mailer: git-send-email 2.45.1 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=3810; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=226C6xZbD3T4A3A/0yOcw5cjIrKTtw2cppxTA+mwS3M=; b=owGbwMvMwCRo6H6F97bub03G02pJDGnuUZHhgTeP/PwxMWHHjZlL55/TyeCXO38yWpzR58yMR 4vT8l7xd8SyMAgyMciKKbJ82cZzdH/FIUUvQ9vTMHNYmUCGMHBxCsBEXkUwzFOfcCn4+7tQ/45r hd5RN0+pBpXJZzHMd7vTKO/I6yaz7u33j7t+zTj6p3ddJQA= 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: btrfs: fix race in read_extent_buffer_pages() There are reports from tree-checker that detects corrupted nodes, without any obvious pattern so possibly an overwrite in memory. After some debugging it turns out there's a race when reading an extent buffer the uptodate status can be missed. To prevent concurrent reads for the same extent buffer, read_extent_buffer_pages() performs these checks: /* (1) */ if (test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags)) return 0; /* (2) */ if (test_and_set_bit(EXTENT_BUFFER_READING, &eb->bflags)) goto done; At this point, it seems safe to start the actual read operation. Once that completes, end_bbio_meta_read() does /* (3) */ set_extent_buffer_uptodate(eb); /* (4) */ clear_bit(EXTENT_BUFFER_READING, &eb->bflags); Normally, this is enough to ensure only one read happens, and all other callers wait for it to finish before returning. Unfortunately, there is a racey interleaving: Thread A | Thread B | Thread C ---------+----------+--------- (1) | | | (1) | (2) | | (3) | | (4) | | | (2) | | | (1) When this happens, thread B kicks of an unnecessary read. Worse, thread C will see UPTODATE set and return immediately, while the read from thread B is still in progress. This race could result in tree-checker errors like this as the extent buffer is concurrently modified: BTRFS critical (device dm-0): corrupted node, root=256 block=8550954455682405139 owner mismatch, have 11858205567642294356 expect [256, 18446744073709551360] Fix it by testing UPTODATE again after setting the READING bit, and if it's been set, skip the unnecessary read. [ minor update of changelog ] The Linux kernel CVE team has assigned CVE-2024-35798 to this issue. Affected and fixed versions =========================== Issue introduced in 6.5 with commit d7172f52e993 and fixed in 6.6.24 with commit 0427c8ef8bbb Issue introduced in 6.5 with commit d7172f52e993 and fixed in 6.7.12 with commit 3a25878a3378 Issue introduced in 6.5 with commit d7172f52e993 and fixed in 6.8.3 with commit 2885d54af2c2 Issue introduced in 6.5 with commit d7172f52e993 and fixed in 6.9 with commit ef1e68236b91 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-35798 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/btrfs/extent_io.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/0427c8ef8bbb7f304de42ef51d69c960e165e052 https://git.kernel.org/stable/c/3a25878a3378adce5d846300c9570f15aa7f7a80 https://git.kernel.org/stable/c/2885d54af2c2e1d910e20d5c8045bae40e02fbc1 https://git.kernel.org/stable/c/ef1e68236b9153c27cb7cf29ead0c532870d4215