From patchwork Mon Oct 28 14:56:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13853639 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 6E8FFD33992 for ; Mon, 28 Oct 2024 14:57:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1E446B0089; Mon, 28 Oct 2024 10:57:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ECDC26B008C; Mon, 28 Oct 2024 10:57:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBCFE6B0092; Mon, 28 Oct 2024 10:57:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C49716B0089 for ; Mon, 28 Oct 2024 10:57:43 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 419441C55D0 for ; Mon, 28 Oct 2024 14:57:43 +0000 (UTC) X-FDA: 82723314156.19.7B7B18B Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf01.hostedemail.com (Postfix) with ESMTP id 743B640004 for ; Mon, 28 Oct 2024 14:57:20 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730127302; h=from:from:sender:reply-to:subject:subject: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: references; bh=ui5cpwb6Tw8NRzcPOhjmqQaxQOVZGqWX1AuklEuYaPs=; b=usNucMGHtmZlfHUc4VjKe6FRDBpSD7OuHGG8mWVtvDnLqvUkLSjMXHN/1TbhuKxrynG22L edh1nZKu2c7oUHy5sixtfSpNWqBqYbSwyOzGFmTXunKrIBB30XUvfILe+kf6jzOUPD7Nm9 ji2I+cSC0p7DkUYgoq9xt1jD7dJymXw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730127302; a=rsa-sha256; cv=none; b=0TMyrThLNPnD2kpgvAd8A8WhnVOE+3ZoMYlBnDefuIIUQppAyOwHgqsXUBWKjUul4NLgy2 9087BzcW9i29H1GdSQcJheg+1p4BGFGKLd5eknsbbE8XnDw9uH6Hrv7ki7jjiOKtdeihD+ fwwWOT2d9wb73wwPoyrnUtnyjIeASqQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4XcbzJ68bDz10P6k; Mon, 28 Oct 2024 22:55:24 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 940D4140135; Mon, 28 Oct 2024 22:57:33 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 28 Oct 2024 22:57:33 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Matthew Wilcox , Muchun Song , "Huang, Ying" , , Kefeng Wang Subject: [PATCH v3 1/2] mm: use aligned address in clear_gigantic_page() Date: Mon, 28 Oct 2024 22:56:55 +0800 Message-ID: <20241028145656.932941-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemf100008.china.huawei.com (7.185.36.138) X-Stat-Signature: ox3reicprq7k9p96rnfth5owbfbqgmx9 X-Rspamd-Queue-Id: 743B640004 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1730127440-513549 X-HE-Meta: U2FsdGVkX19vIWzisyDUsp6aH0ZXeLM/ek1n1L1GRIR18ukFiqDYcV5Qx39Uxn6N/1qqrFw6AUbGZ3RWjRGomF7wVy/kZargioaj2xhRCKxRNMcpduqhSM3vszs3GWzEWZWismcDjv4h9qMcuEAnq9y9X6typ7FeBa2RvT8Bv1I7QwKicZUExXhYW6YPWPEtyHsFDg9qq/YG4ViA3xckLVP9v78LifhYZKgX2BTN1Jg6YuLXQBwmN9IZU7q11dz92LZeh5fQnsWRpMYl5whTTGHdU8TsyXj1dUSSPQ4jR2dgCfPWfbcfmL8MwEQO3EGDC5M1Wo2vRZg3sj06fARdUP6aRNQ/0c8rYsRaGpxXvIN8aMZb8PoPdW7PeP6m7D1KKQXicIxcGfS1pkEYnHoISmXo/ZAZywwCL2fTsAFbARGLjIEw9dowGpYTcthSM/mlVT6/2zHGXujfPnb8b3mSN19hcj6TWaEKYPafzXGm4pvl7SbQfzGRiDbSG2qAg0hR3IsKpMs3/jzrtI+dXrrvF7i2xmaoXLLSKkE4EdIobexDIC9OYC8gFb0qHLOiG6kY/fC7iyYBlFkl0YdVWZqeQ/3l/UgeSPfjFFNwyB+E0tMmJpSXugNOx9kIken2ZbnhYEhZVPIIH3XE2yGHCuE6x4gJVZzkrMXfo+0jrUBi9ba3mJSss5VMzfJkk0kmaWy4h3TeVHdlOwT9TH3WLKMVPXe7R/Hyd9FA8o6gkUQwaA0WqZX5LnqpCQLxY/J/FURVEW+szPYUuk9YWiX/FKDeicIbL+vAoaVhMqZvWXpWfaKAERjqGHOUSxAfAyiWW2H+o5Us0MZdZ3nT2desOoqlFJpYYD8EcBWIdailsW02u+C094c0Iv1cNcsDdD5PlOeg+fQ6YiNLE23vlVGUN6e+MtZNLqZ/llMt5J3ZBzk4jUHIMXpg2PiSukf+Vjvr8lL1xPjsGISyjUUUXmeEBnK 931kNa7/ RbMZfxI92Lv+hnlBYmMfBY87wGZYCSHQr7TNvi6dVs59UecY487zj5ybXq2WTOvV5BMQLjkkRz1jsXZxd32ystvrLBLUdHQwIGfZc10cOcQhbB8zFJhMB4ob4b0oZj/enc2euHnk6eJnLGyY4iJacBsz+pYa2pvfI/pK26HdWgbvEvx/3v9mfX2ihAIUYq3zJwCbI 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: List-Subscribe: List-Unsubscribe: In current kernel, hugetlb_no_page() calls folio_zero_user() with the fault address. Where the fault address may be not aligned with the huge page size. Then, folio_zero_user() may call clear_gigantic_page() with the address, while clear_gigantic_page() requires the address to be huge page size aligned. So, this may cause memory corruption or information leak, addtional, use more obvious naming 'addr_hint' instead of 'addr' for clear_gigantic_page(). Fixes: 78fefd04c123 ("mm: memory: convert clear_huge_page() to folio_zero_user()") Signed-off-by: Kefeng Wang Reviewed-by: "Huang, Ying" Reviewed-by: David Hildenbrand --- v3: - revise patch description, suggested by Huang Ying - use addr_hint for clear_gigantic_page(), suggested by David v2: - update changelog to clarify the impact, per Andrew fs/hugetlbfs/inode.c | 2 +- mm/memory.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index a4441fb77f7c..a5ea006f403e 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -825,7 +825,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, error = PTR_ERR(folio); goto out; } - folio_zero_user(folio, ALIGN_DOWN(addr, hpage_size)); + folio_zero_user(folio, addr); __folio_mark_uptodate(folio); error = hugetlb_add_to_page_cache(folio, mapping, index); if (unlikely(error)) { diff --git a/mm/memory.c b/mm/memory.c index 75c2dfd04f72..84864387f965 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6815,9 +6815,10 @@ static inline int process_huge_page( return 0; } -static void clear_gigantic_page(struct folio *folio, unsigned long addr, +static void clear_gigantic_page(struct folio *folio, unsigned long addr_hint, unsigned int nr_pages) { + unsigned long addr = ALIGN_DOWN(addr_hint, folio_size(folio)); int i; might_sleep();