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 B46BDC433F5 for ; Mon, 4 Apr 2022 14:12:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 051928D0001; Mon, 4 Apr 2022 10:11:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F1BDB6B0074; Mon, 4 Apr 2022 10:11:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBDB38D0001; Mon, 4 Apr 2022 10:11:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id C9A336B0072 for ; Mon, 4 Apr 2022 10:11:56 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8E9EFA8354 for ; Mon, 4 Apr 2022 14:11:46 +0000 (UTC) X-FDA: 79319385012.21.C025B08 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf24.hostedemail.com (Postfix) with ESMTP id AAB25180015 for ; Mon, 4 Apr 2022 14:11:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=OSGhNgcMSZj8i4ui18pS1xGCuT1ZlpXgVLZj9Bopt84=; b=CkKP9rJ+cJQFQAODpAw8lKuD17 SGHViuvdVuqCHLFm6jCtMjHfyWrUEGQ/+ET+pyJvDp3sRa8oLPOtBpHuKT3xpANdfr70g9uOGj8z8 /4NrXOEhjSUM2YMHflgqy5YI7ZgNEtYjGyVTHomde346KQF+dFcI6ufJhwJaws0AHZTX9t0CD0wwT kmGqZQqM7qGdAWR0UqzvvilYS0KjciAgg3z1l610TJYvQgOOHp5Vp7urL52tk1BYWB6hJ+S2e+23C RUpnWXbVSUu81CjRn55YWafn4WQaWmV73COnVXeSaYiqHtfHH6JSGsBRMh1u63w+j1TyybRsDBW4Z OlTgNYWA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbNQd-005mwQ-1U; Mon, 04 Apr 2022 14:11:35 +0000 Date: Mon, 4 Apr 2022 15:11:35 +0100 From: Matthew Wilcox To: David Hildenbrand Cc: Miaohe Lin , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/swapfile: unuse_pte can map random data if swap read fails Message-ID: References: <20220401072926.45051-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: cz9hugyaf61996zyz7xugr9hr1fq9cec X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: AAB25180015 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=CkKP9rJ+; dmarc=none; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspam-User: X-HE-Tag: 1649081505-687543 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 Mon, Apr 04, 2022 at 03:37:36PM +0200, David Hildenbrand wrote: > On 01.04.22 09:29, Miaohe Lin wrote: > > There is a bug in unuse_pte(): when swap page happens to be unreadable, > > page filled with random data is mapped into user address space. The fix > > is to check for PageUptodate and fail swapoff in case of error. > > > > Signed-off-by: Miaohe Lin > > --- > > mm/swapfile.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/mm/swapfile.c b/mm/swapfile.c > > index 63c61f8b2611..e72a35de7a0f 100644 > > --- a/mm/swapfile.c > > +++ b/mm/swapfile.c > > @@ -1795,6 +1795,10 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, > > ret = 0; > > goto out; > > } > > + if (unlikely(!PageUptodate(page))) { > > + ret = -EIO; > > + goto out; > > + } > > Yeah, we have the same handling in do_swap_page(), whereby we send a > SIGBUS because we're dealing with an actual access. > > Interestingly, folio_test_uptodate() states: > > "Anonymous and CoW folios are always uptodate." > > @Willy, is that true or is the swapin case not documented there? Why do we keep a !Uptodate page in the swap cache? If it can't be read in from swap, I thought we just freed the page. Since Miaohe has observed that not happening, I guess it doesn't work that way, but why not make it work that way?