Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3079629rwe; Mon, 29 Aug 2022 05:36:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR7nVzzLSoJwkmYH1d0tfzgdSWj4fMeBNten6Qg6Qzr+A7vK55iDwWWXhWRwkZlCUQr3rU8i X-Received: by 2002:a17:90b:4a10:b0:1fb:2e77:a33 with SMTP id kk16-20020a17090b4a1000b001fb2e770a33mr18235031pjb.67.1661776583904; Mon, 29 Aug 2022 05:36:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661776583; cv=none; d=google.com; s=arc-20160816; b=cmJd8MbRloRNknT2mg26V1htdhXOa711mqG13gkdK6YRGiLmbec/nYyPK4WrVQpyBQ 2Y4zw6oVKxj4ujYl+wpd5hoBQVo/qSZ234qWzPeCYSWJzvoBFIAt5JsjKRiWQeixJMVZ kBIc1/xcO3kewVMOq4Z6eLzhJDCntWSL6cKufVjpsv9QUKZqq5arYqHxR3xhgUUQI+lM ejzuL+pqUaqefSN3qcxNWwOdrEQmxJHCIqoiTR6X7DxmuBsPCxj/cLfeEMIiR9J6A8FF 3ysovfVoysq5B5Gc5LTPfKHp9vgY/Y/DzAgvMXGR1Fx0tzXDTjO0l1lU46ztReN+/nSM //yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2+no3VSninfAySX+gZqg4UjDoZaLn0V23CvB12KEJ6E=; b=VMEwYny8T9X/faeuE5GHnNWFe8NeZ0+Stn4akTsL051FJHZCd2W99tOa5wC+d16H2m b6qOXMHjMcvJgKypi8KAkuowDbpeVUldclnyKCGzwYr4I+bAUSY2EIRtq65Wltm46IjI y0J9dzyiEtkS577iZDKGBQp5jH3eIMYhoiNGNw1ZTGZG5qUlDJUs6QbU5Y1IwPoGLrBv D9+teHGxI5RULN6wBEVv+hb+3nZdIrOX8K+w8JLSJvans2C364+viVEeeQ/KjGJF5wDZ 2qzac0C7bEsj4W58txGDs9vNleBjsnYgmPq71eDmanAu00uMPWVzEMO7mDaEkqJvwV+q YwtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y21Qnk3E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h9-20020a17090a710900b001fab0eae126si8882885pjk.114.2022.08.29.05.36.13; Mon, 29 Aug 2022 05:36:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y21Qnk3E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232951AbiH2LiK (ORCPT + 99 others); Mon, 29 Aug 2022 07:38:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232868AbiH2LhD (ORCPT ); Mon, 29 Aug 2022 07:37:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD36461B3C; Mon, 29 Aug 2022 04:21:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7F0E561185; Mon, 29 Aug 2022 11:19:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 771CAC433C1; Mon, 29 Aug 2022 11:19:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771966; bh=9TpFLjXDWWPGSkUHylnED8xi99Am0soBk1z8T1wdQ/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y21Qnk3E//3apmt8RiGP/5U+uWMfhdeGIQJJbzpKU1ZCNgo50Lk1faCmvr6/44Gkr GhtHIf7W9/+AkQo5clbL/2MXCVRKMAeKIpJkzHiptRzPc+VB9IvjELKui1+2jmBojl VbUxq1wgoNrM//Y1PyCLNHpziuh8H/CYsiaQOX2I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Matthew Wilcox (Oracle)" , William Kucharski , Hugh Dickins , Andrew Morton Subject: [PATCH 5.19 123/158] shmem: update folio if shmem_replace_page() updates the page Date: Mon, 29 Aug 2022 12:59:33 +0200 Message-Id: <20220829105814.269068045@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox (Oracle) commit 9dfb3b8d655022760ca68af11821f1c63aa547c3 upstream. If we allocate a new page, we need to make sure that our folio matches that new page. If we do end up in this code path, we store the wrong page in the shmem inode's page cache, and I would rather imagine that data corruption ensues. This will be solved by changing shmem_replace_page() to shmem_replace_folio(), but this is the minimal fix. Link: https://lkml.kernel.org/r/20220730042518.1264767-1-willy@infradead.org Fixes: da08e9b79323 ("mm/shmem: convert shmem_swapin_page() to shmem_swapin_folio()") Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: William Kucharski Cc: Hugh Dickins Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/shmem.c | 1 + 1 file changed, 1 insertion(+) --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1771,6 +1771,7 @@ static int shmem_swapin_folio(struct ino if (shmem_should_replace_folio(folio, gfp)) { error = shmem_replace_page(&page, gfp, info, index); + folio = page_folio(page); if (error) goto failed; }