From nobody Thu Jun 25 03:46:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B900C433EF for ; Wed, 23 Feb 2022 15:59:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242552AbiBWQAM (ORCPT ); Wed, 23 Feb 2022 11:00:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234105AbiBWQAI (ORCPT ); Wed, 23 Feb 2022 11:00:08 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 518FDC2E4B; Wed, 23 Feb 2022 07:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=U1NJLx2hNGzn0cF6hu7XUgutHeB7KzSAS3+ZL8eXD0c=; b=sI/6jm4ANMJu2XxEFZa6wo+hHy TuR5xBR9lM5xrobaeW8u9ebzG577X2PORDlb5LJkqggX8lWqoBhEgF0o39ZZMq3znekbvNdLJYxdF aLDJ0lR5Q+qaq3N29TO+vZvDmZ8Qb0Uv8aW65L5cHjNCiYxbcKgnlr3I36994zBhTe3DdUOTwAwVl 7oiGWpcAkw1Az8BiFa5vCHVpuMAsBmoV82WmFaCmcgB0EIszgU6y/PBIqC1A0ylGXnsSQDcd3lnAf u090fogA7nsPBAqX6xPvctNvg60gd0j1vy0AA9lxezzKMzHhwAiTd6WeDSxNEgi8KiK3dqPzl0gk0 L2LAg8Yg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMu3D-003tMu-EB; Wed, 23 Feb 2022 15:59:35 +0000 From: "Matthew Wilcox (Oracle)" To: stable@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, Song Liu Cc: "Matthew Wilcox (Oracle)" , Adam Majer , Dirk Mueller , Takashi Iwai , Vlastimil Babka Subject: [PATCH] mm/filemap: Fix handling of THPs in generic_file_buffered_read() Date: Wed, 23 Feb 2022 15:59:18 +0000 Message-Id: <20220223155918.927140-1-willy@infradead.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When a THP is present in the page cache, we can return it several times, leading to userspace seeing the same data repeatedly if doing a read() that crosses a 64-page boundary. This is probably not a security issue (since the data all comes from the same file), but it can be interpreted as a transient data corruption issue. Fortunately, it is very rare as it can only occur when CONFIG_READ_ONLY_THP_FOR_FS is enabled, and it can only happen to executables. We don't often call read() on executables. This bug is fixed differently in v5.17 by commit 6b24ca4a1a8d ("mm: Use multi-index entries in the page cache"). That commit is unsuitable for backporting, so fix this in the clearest way. It sacrifices a little performance for clarity, but this should never be a performance path in these kernel versions. Fixes: cbd59c48ae2b ("mm/filemap: use head pages in generic_file_buffered_r= ead") Cc: stable@vger.kernel.org # v5.15, v5.16 Link: https://lore.kernel.org/r/df3b5d1c-a36b-2c73-3e27-99e74983de3a@suse.c= z/ Analyzed-by: Adam Majer Analyzed-by: Dirk Mueller Bisected-by: Takashi Iwai Reported-by: Vlastimil Babka Signed-off-by: Matthew Wilcox (Oracle) --- mm/filemap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 82a17c35eb96..1293c3409e42 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2354,8 +2354,12 @@ static void filemap_get_read_batch(struct address_sp= ace *mapping, break; if (PageReadahead(head)) break; - xas.xa_index =3D head->index + thp_nr_pages(head) - 1; - xas.xa_offset =3D (xas.xa_index >> xas.xa_shift) & XA_CHUNK_MASK; + if (PageHead(head)) { + xas_set(&xas, head->index + thp_nr_pages(head)); + /* Handle wrap correctly */ + if (xas.xa_index - 1 >=3D max) + break; + } continue; put_page: put_page(head); --=20 2.34.1