From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF428C4332F for ; Wed, 23 Feb 2022 17:05:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E29828D002A; Wed, 23 Feb 2022 12:05:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DDBB38D0011; Wed, 23 Feb 2022 12:05:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA0258D002A; Wed, 23 Feb 2022 12:05:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id A76C78D0011 for ; Wed, 23 Feb 2022 12:05:42 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 47F59121210 for ; Wed, 23 Feb 2022 17:05:42 +0000 (UTC) X-FDA: 79174671324.08.620DFAC Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf07.hostedemail.com (Postfix) with ESMTP id 56B7740016 for ; Wed, 23 Feb 2022 17:05:41 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9E91C1F43D; Wed, 23 Feb 2022 17:05:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1645635939; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2GJrbL5GtZBvRuSJ9SW+6RjiwuvjkEo2u5aLhU0R+R4=; b=q/VB8Brw02rDOO+atLW8Cv3HziC+gcHX7RMqdtFFLAToVBJslZdrKkzmEJsfsj39468iSy REhTEPK5jkiPfzo1CInnMbD3bv0fhFlJQdSDQlu1b390kGemVBpQohzHxwvviJpOSInPw7 SFzv2Yn54+xFrwVESma49x+c8RKFTlo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1645635939; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2GJrbL5GtZBvRuSJ9SW+6RjiwuvjkEo2u5aLhU0R+R4=; b=ooHQ4jwNnLyDlWUM+RRrdvtNGohWztZR/KFhUJWfe3D41UBdhvj4ogq0eLgPpFQbWoTfx5 wltTiTmCW/jzaYBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 35D5E13C94; Wed, 23 Feb 2022 17:05:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Ta9jDGNpFmIjGQAAMHmgww (envelope-from ); Wed, 23 Feb 2022 17:05:39 +0000 Message-ID: <7ec07580-8430-c4ba-69e1-004de161584e@suse.cz> Date: Wed, 23 Feb 2022 18:05:38 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH] mm/filemap: Fix handling of THPs in generic_file_buffered_read() Content-Language: en-US To: "Matthew Wilcox (Oracle)" , stable@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, Song Liu Cc: Adam Majer , Dirk Mueller , Takashi Iwai References: <20220223155918.927140-1-willy@infradead.org> From: Vlastimil Babka In-Reply-To: <20220223155918.927140-1-willy@infradead.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 56B7740016 X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="q/VB8Brw"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=ooHQ4jwN; spf=pass (imf07.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Stat-Signature: rtkmm3mdahtze34u7jxp7h3bqqyi4xiw X-HE-Tag: 1645635941-108942 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2/23/22 16:59, Matthew Wilcox (Oracle) wrote: > 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_read") > Cc: stable@vger.kernel.org # v5.15, v5.16 > Link: https://lore.kernel.org/r/df3b5d1c-a36b-2c73-3e27-99e74983de3a@suse.cz/ > Analyzed-by: Adam Majer > Analyzed-by: Dirk Mueller > Bisected-by: Takashi Iwai > Reported-by: Vlastimil Babka Replace with: Reported-and-tested-by: Vlastimil Babka Thanks! > 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_space *mapping, > break; > if (PageReadahead(head)) > break; > - xas.xa_index = head->index + thp_nr_pages(head) - 1; > - xas.xa_offset = (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 >= max) > + break; > + } > continue; > put_page: > put_page(head);