From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACC6E606A338 for ; Mon, 30 Nov 2026 07:01:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J8AFburO Received: by kanga.kvack.org (Postfix) id D22696B05B4; Mon, 30 Nov 2026 02:01:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CD2F26B05B5; Mon, 30 Nov 2026 02:01:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE9B86B05B6; Mon, 30 Nov 2026 02:01:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 556506B05B4 for ; Mon, 30 Nov 2026 02:01:29 -0500 (EST) Received: from smtpin06.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D76CDC09A6 for ; Mon, 30 Nov 2026 07:01:28 +0000 (UTC) X-FDA: 85490889456.06.21B796F Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf05.hostedemail.com (Postfix) with ESMTP id 2D58110000C for ; Mon, 30 Nov 2026 07:01:27 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=J8AFburO; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796022087; b=oUMj+oCr1oXQ3BbMcCC24YhZRt04833HAzWwHLB5MtVShIBdhDg/3fnfi+RzaWnrDO1897 86cmV4t0t83/N1FRuynUF5qrNbIqPw4K0OYb9FB6Dr4o0Lk3DivvRxpygXsO6RrfcwgrQ/ KjqE2af5xH2kKV9aP9JTHQfvcynmEc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796022087; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6yZcd0bNMXQz0/NXCFEgSPCo6SAMGnP2aHeTKB/htJM=; b=ffxBqVrHCpS7tgZTCkBZWxdh+pwKk7wKpDCuoqbxYiEtM82gde8CWmd0V+TzzcpUMg5gAB KLT3jY1nJnA6ieS6OPxsTuFVH2prZr90t9TqSrE9RBy8pTr2nXYafuEf8kcirN5N3UKCuD ANpXaiYsA7Wu+/QsR01re75ICJAk2Ow= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=J8AFburO; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 972CA61CE0; Mon, 30 Nov 2026 07:01:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A89311F00897; Mon, 30 Nov 2026 07:01:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796022086; bh=6yZcd0bNMXQz0/NXCFEgSPCo6SAMGnP2aHeTKB/htJM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=J8AFburOWD6Tq5Vzhjal4y3R8TJ89mruvRGcM3ZVpMMvEhwgUonxS3P9B8SXM+lAU 0rvm95GOQo3kc+cwF/vKlWHjRvvXzai+V1GkjJc2yudcKEKpiXPUeR3yw8uP/CjQ2C Vi0iI7jcCG6fh0DW9llEvnNkmIs1K3u+6hozHWJb5wTNnUqyVvxplL0W4WNGe9WYAL LZS/LaPBdhcz09/MoBYpowAuCClsxf6xOgY1xSpQ4kZ8yH+iwtW7OZBnYUJ2fwWsjk 3VRsvdJKj3245yKJ4djdn+uZNmQQhYkcN4bTYmB4WN75wr7MsBntdLXvNabR+KYaPI OYLkpyfFl4vQg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] xarray: add READ_ONCE() in xas_find_chunk() Reply-To: sashiko-reviews@lists.linux.dev To: "Shuai Liu" <847807867@qq.com>, willy@infradead.org Cc: linux-mm@kvack.org, elver@google.com, syzbot+cc64b6bdf649b54047e0@syzkaller.appspotmail.com In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 07:01:25 +0000 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 2D58110000C X-Rspam-User: X-Stat-Signature: 78w7sfiahs3s9j1wawzqocc3sws9pwu4 X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796022087-516161 X-HE-Meta: U2FsdGVkX1/PCIrmNoBThapEeiBkdCTZP+IvQRn61FYgYYtEUmwzqpWNYveJi5l8kLDMahjsHuarHvgHBTFT12U43Ri9+iDKZqmqE70UfngCIldPLWbs8ISiQORoIZ87pNHDuFGYmPULLXp8dAV/pISYMfghbWXq8QBwS1AiXHSxksxG80otl8RWYSXEt5vADoXuu9rxWkeHQOOaZwAlvWK5bDk5bI2xEJwN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acOfAfwNhwWR9ZhAg7SIpD5w+wcnH5A/W8z00HgHVy01ljGzJKQm9FMT0ztrrz2NvcCwmCtxsPHK/JaIfyt9eqngcFEgmzJ5047Ro5BjQ5ZABPAZn9c7j9lT5jr4FBaehDiU4C12AaQJAPAHPCatcigaJGihwJE6yjVhY+s5ncDGRaI7uqMnI3DqpdumdD0KOHH/hhg7MFHubEyeUSUa+eN20vj3cNVxoZf4FqXYhzxxNNHw3/6T39d6pELexYDkxUR3n3+3naz+Wy+cZYVO6gRQaNhFlJC32cLuuIdJYXc6GzI4t3wsKHwPN9AP6gCPjqrm6FOGQIp8kBoZELy/1kEHJYcPEj7BR/msok7kS5o4ri9Vm8LDK14zx2dgWRieU7aH7pFcvY1SUBxSIEzAHkAhzZ3Z/Cs00/vyb1jIxZuRv98d13CMRXZGeN5PlQXWxUbmARvBPAy8FmuhqZIFs0yMLhzrGCIkFNwI40KpxviKje3M4Bd28BYKUTLM59TpgdbGD6TzwI6mE9a2gk6M+tLPthYsc8NJzPzKnK/M8qPOpx8jcEFG7QhVZ/3flYzBsR/tbKtuB8rwNu+vK/FQEIi+jIrsrdxfDzd9ZTBwIpSxvp2acdmcUlg2l5qWf/G4FiY86passVBjGyPKnekhV+Q9wzqTu u3bLWQ7K o5wqArp0fOwW2UK15c6JDJUtrd+yiL4uiWvS1mu4ULNHQF1xitXg6zv6oLs14Xq7XpMdIdi6PXQ= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Critical] xarray: stack out-of-bounds read and broken 32-bit mark search in xas_find_chunk() - [Low] xarray: missing Fixes: trailer for xas_find_chunk() data race fix -- commit c0ac2830e45356e29b88c9ec8263075b4152d250 Author: Shuai Liu <847807867@qq.com> > xarray: add READ_ONCE() in xas_find_chunk() > > xas_find_chunk() reads xa_node->marks with a plain dereference while > concurrent xa_set_mark()/xa_clear_mark() writers use non-atomic > __test_and_set_bit()/__test_and_clear_bit() under xa_lock. RCU readers > in xa_find() -> xas_find_marked() -> xas_find_chunk() call this without > xa_lock, so the plain read races with the locked non-atomic write. > > KCSAN flags this as a data race, and Marco Elver notes the failure > scenario is worse than benign: the compiler can hoist *addr into a > register on the reader. When a concurrent writer later clears a mark > bit, the cached stale value causes xas_find_chunk() to keep returning > the cleared offset. xas_find_marked() then loops forever looking for > an entry at that offset under rcu_read_lock(). > > Load the marks word once via READ_ONCE(*addr) into a local variable, > then do all bit operations on that snapshot. This silences KCSAN, > forces a fresh load on each call, and prevents the compiler from > caching the stale value across iterations. > > Reported-by: syzbot+cc64b6bdf649b54047e0@syzkaller.appspotmail.com > Signed-off-by: Shuai Liu <847807867@qq.com> [Severity: Low] Should this bug fix include a Fixes: tag for commit b803b42823d0 ("xarray: Add XArray iterators"), which introduced xas_find_chunk()? > diff --git a/include/linux/xarray.h b/include/linux/xarray.h > index be850174e802e..8c898b846bde8 100644 > --- a/include/linux/xarray.h > +++ b/include/linux/xarray.h > @@ -1744,19 +1744,21 @@ static inline unsigned int xas_find_chunk(struct = xa_state *xas, bool advance, > { > unsigned long *addr =3D xas->xa_node->marks[(__force unsigned)mark]; > unsigned int offset =3D xas->xa_offset; > + unsigned long marks; > =20 > if (advance) > offset++; > + marks =3D READ_ONCE(*addr); > if (XA_CHUNK_SIZE =3D=3D BITS_PER_LONG) { > if (offset < XA_CHUNK_SIZE) { > - unsigned long data =3D *addr & (~0UL << offset); > + unsigned long data =3D marks & (~0UL << offset); > if (data) > return __ffs(data); > } > return XA_CHUNK_SIZE; > } > =20 > - return find_next_bit(addr, XA_CHUNK_SIZE, offset); > + return find_next_bit(&marks, XA_CHUNK_SIZE, offset); > } [Severity: Critical] Does passing &marks to find_next_bit() read out-of-bounds from the stack on 32-bit architectures? When CONFIG_BASE_SMALL is disabled, XA_CHUNK_SIZE is 64, so on 32-bit systems XA_MARK_LONGS is 2 and xas->xa_node->marks[mark] spans two 32-bit words. Because marks is a single unsigned long initialized with only READ_ONCE(*addr), find_next_bit(&marks, 64, offset) reads (&marks)[1] four bytes past the stack variable and never inspects addr[1] (slots 32..63). Besides missing marked entries in slots 32..63, if (&marks)[1] on the stack has a bit set at an offset where node->slots[offset] is NULL, xas_find_marked() sets advance =3D false and xas->xa_offset =3D offset, see= s no entry, and loops forever under rcu_read_lock() because xas_find_chunk() keeps returning the same offset from stack memory. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_26261313EE1= 4D2462CBFF2E64D2AB8226208@qq.com?part=3D1