From patchwork Mon Oct 23 08:32:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyesoo Yu X-Patchwork-Id: 13432532 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 543FCCDB474 for ; Mon, 23 Oct 2023 08:43:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 761E66B00B7; Mon, 23 Oct 2023 04:43:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 710B26B00B8; Mon, 23 Oct 2023 04:43:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58AC76B00B9; Mon, 23 Oct 2023 04:43:11 -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 4604D6B00B7 for ; Mon, 23 Oct 2023 04:43:11 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 12500B57E7 for ; Mon, 23 Oct 2023 08:43:11 +0000 (UTC) X-FDA: 81376086582.05.893A4C4 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by imf15.hostedemail.com (Postfix) with ESMTP id 0DA14A001C for ; Mon, 23 Oct 2023 08:43:05 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=Hd0SUHr6; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf15.hostedemail.com: domain of hyesoo.yu@samsung.com designates 203.254.224.33 as permitted sender) smtp.mailfrom=hyesoo.yu@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698050587; 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:references:dkim-signature; bh=HTJwEqe2gL+M6uZuKwI49ZiZ+DBMP7gSkZ2LxpURipU=; b=pWCW4VtgIcozWs5JZatIRwCygeJuzsnH4/uDPytCtCGjxMuZkF/dsfKhI/D+WQ3b/K2is3 qAXfW3wkJ/oKNl1pdZpaF200HxVWRTiNV3V1mFSj2wvA0OMHFFfRdA5spx2ZTQtYU3sicI 9LXM15XCm/h5bNtX5hLBKcdWDLNlw1w= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=Hd0SUHr6; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf15.hostedemail.com: domain of hyesoo.yu@samsung.com designates 203.254.224.33 as permitted sender) smtp.mailfrom=hyesoo.yu@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698050587; a=rsa-sha256; cv=none; b=S1fyXjPnr40IpjX9JX5g4h0STKtQPURdy6l8oIoswiTi9AM6F6BpEhl+LUVuH1maNsKx3V k2d7myiDQNp1+ZyPilHT1BY+yjm3FMECEY9f6ZyKbzLmMWbc0LbnBaG0C1BlhToaeNM0T/ rKetpWiausoLfW0Sxxz5AAIGvsoB1k4= Received: from epcas2p1.samsung.com (unknown [182.195.41.53]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20231023084302epoutp03ab57d187781c20383d8ff05c5b97a093~QsAIWpVio2395423954epoutp03Q for ; Mon, 23 Oct 2023 08:43:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20231023084302epoutp03ab57d187781c20383d8ff05c5b97a093~QsAIWpVio2395423954epoutp03Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698050582; bh=HTJwEqe2gL+M6uZuKwI49ZiZ+DBMP7gSkZ2LxpURipU=; h=From:To:Cc:Subject:Date:References:From; b=Hd0SUHr6wVX0Dois7KaMSgUBKsyKxJ8q0rQLT9jfy0KBk4N4i/+mFExdFkqqN+o7J L4e893gr+nPnc5oLDH60BWfalYUK4E2fxZfDTkFhwUCfkNS5+msAVRC6nYKA4hyCtQ 6JxPnUQWJYtWOCuGxkwECSjCJG9eKmLMTLap6Rv8= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas2p1.samsung.com (KnoxPortal) with ESMTP id 20231023084302epcas2p1525086f205cda4b707e9d5d8afba8ac2~QsAH826_52662426624epcas2p1U; Mon, 23 Oct 2023 08:43:02 +0000 (GMT) Received: from epsmges2p4.samsung.com (unknown [182.195.36.99]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4SDTGs42wGz4x9Q6; Mon, 23 Oct 2023 08:43:01 +0000 (GMT) Received: from epcas2p2.samsung.com ( [182.195.41.54]) by epsmges2p4.samsung.com (Symantec Messaging Gateway) with SMTP id 1A.A6.09607.51236356; Mon, 23 Oct 2023 17:43:01 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas2p2.samsung.com (KnoxPortal) with ESMTPA id 20231023084301epcas2p2de7cdc5cb6795d409a183aae43ce8c13~QsAHG-zXP1999019990epcas2p2l; Mon, 23 Oct 2023 08:43:01 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231023084301epsmtrp286dacf3e1b1a53d82a1b1f0f23d36aa8~QsAHGXSiX0893008930epsmtrp2c; Mon, 23 Oct 2023 08:43:01 +0000 (GMT) X-AuditID: b6c32a48-bcdfd70000002587-d4-65363215ff17 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 1E.72.08817.51236356; Mon, 23 Oct 2023 17:43:01 +0900 (KST) Received: from localhost.localdomain (unknown [10.229.95.142]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231023084300epsmtip1b2e9f35749e34d07523d745dff1ff595~QsAG6UvES1225612256epsmtip12; Mon, 23 Oct 2023 08:43:00 +0000 (GMT) From: Hyesoo Yu To: Cc: Hyesoo Yu , Vishal Moola , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mm: page_alloc: check the order of compound page even when the order is zero Date: Mon, 23 Oct 2023 17:32:16 +0900 Message-Id: <20231023083217.1866451-1-hyesoo.yu@samsung.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrCKsWRmVeSWpSXmKPExsWy7bCmma6okVmqwdx3chZz1q9hs/jbeYHV 4vKuOWwW99b8Z7VYv+8GqwOrx85Zd9k9Nn2axO5xYsZvFo++LasYPT5vkgtgjcq2yUhNTEkt UkjNS85PycxLt1XyDo53jjc1MzDUNbS0MFdSyEvMTbVVcvEJ0HXLzAFarqRQlphTChQKSCwu VtK3synKLy1JVcjILy6xVUotSMkpMC/QK07MLS7NS9fLSy2xMjQwMDIFKkzIzmjrXMFW0MFb 0fPqFHsD42muLkZODgkBE4nmS0uYuxi5OIQEdjBK3DlymBXC+cQosfbtMTYI5xujxOsTy9m7 GDnAWu7f1IaI72WUmHX5DxPIKCGBz4wSG98kgdhsAuoSJ7YsYwSxRQRYJFZ+/84C0sAssJZR YsuEfewgCWGBJIkvyz4xg9gsAqoSB7qnsoDYvAI2Eo/fr2WGuE9eYual7+wQcUGJkzOfgNUw A8Wbt84Gu1tC4Bi7xMTOZ1ANLhKtr3ayQtjCEq+Ob2GHsKUkPr/bywZhZ0vc/TgByi6RWHem AarGWGLWs3ZGkC+ZBTQl1u/Sh3hYWeLILai1fBIdh/9Cw4FXoqNNCKJRWWL/snksELakxKO1 7VAHeEh8eXgNGjyxEkdXvGKcwCg/C8kzs5A8Mwth7wJG5lWMYqkF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CyTBycUg1MzgLl91hnFHmfjxbzWbrn4Sc+tY03Fu6U/zeRsf+U5G3nzfPM/29cGs6/yr7k 0cZVjE1zP+RMeDhJh+Xful/5nA9XHZJbNdVt8Xl+sbAtNW7miuHaBytW+X35+c5VyT/UffeJ uHvyZudnTNc8cOVVXfjH4Bv+27IvsH07lCpwb+nRX+ftV8nnt10xWTW37bz8jI2JT0Ur355u jdmb/YR10qFD6vcjIjbslJa+2/JGf1fwwsePtkid60xYvkAx6vq64q8LG934FZ33hX/46Zq1 tnzJ9CS9nKwFal8jpuzw0tIWWvFI5fCHiSnqG4tri5cu+Scaxslx4bfN9fkXY1wykrbITvz2 lUXX+egDX0GVHdFKLMUZiYZazEXFiQCY7gK8uAIAAA== X-CMS-MailID: 20231023084301epcas2p2de7cdc5cb6795d409a183aae43ce8c13 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231023084301epcas2p2de7cdc5cb6795d409a183aae43ce8c13 References: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 0DA14A001C X-Stat-Signature: qrs5ws7j4i4zey6deegi9cw6hk3ztp4z X-Rspam-User: X-HE-Tag: 1698050585-466389 X-HE-Meta: U2FsdGVkX18fe5HlRRH6IWZGJFO/h4FJ7QOwvPzdEGXnUgu1X4M0a92i+/9l29YIIemcI6CHBNMgfASGoIONT8eQjEdqxeQwoCEgGokqvitJOe3cfN2cTrSBGuxSbNus5TZCkMvw4DjbRTccX58dQb5gTEw/wwVGcyz1UsvKKhS4l9oC83tLc96DmTYUVWnjDVJJkTCLGLUN6+lXzB8tSP6K32onXAMwGN80nT/m7Nojmy69b57c/gcf6eU2JbKvDMDhFWMJAq0O7EiWKIWtbk8rUioJnXSRwJVbhDWoMvR89RI64SbhqyqnU/Scavdc521FJGuMXh4/umOj1FgYQlywZOTzEk3IxHgu+ZCWw0d4khpMbn05BGqOVRWnwsOawPS/RJe/UlZLLicOCiL1otAaUAdIvigK3Q3Zaavg67VYsrx5h26SdqyzwmkgHr8upH6JWlqDpIhZMQTTgFjQltT85Xc246gDKC4CuKCk8PZ5lNYOMejaHtVAJUn/DRvdDcm+8zppcJ+/CLaDzOsNbFVMGSOZ7pIE/BsGE+mMxZ7SBw/EHEMJYiyPribqcD+nkijyBkvWnkb4rIIh0RdzghENNUQ7twopJKANYDBFOhYRlSOIDCCK3YDYXZXfxr2r7z65+bMWHNDkv4Lu4J9Cpz+/HxkOz807wjpUtzomhXruCUb+5Y2PupjJPwLDxP9nrbZ0XHnwUooXaDQL6tmDRtw6RmV7G9nFVeuoXlc9zZJ2BVzQGfycfh1wqcdO0HDcP5iGM3FXvP9sdQOpFFxsY6WgnncFtPMJgKGEYL42MetSOU5+HE5PsDi9c8AdhkhzveXqqil74xtNiyHIXm0rMI7W0Z5hDlKOj0l20dbpxtu4j8o3IwNbVR4jhZEPHbbPog03hD8u5W4a+y3FqlzcSCFJMYYV4HI+KyRsa9CFNpChM4cAPm3JqZp/aTR9cj5ramUYtU6haj0yGLVprFX A76TAq4q ihYAuI4g0VA7n8/CUUA3iimswzNykP0qaXjmIoBa3P2MxzrclK9jqacTzYuLS4vX3DX/3PxSFoMzp8xI7pPUxRc/p2RVmOWxJ4Qj9nx2DCl35tX+jEg84fDGrphTeA9xYX0YNA08AOBKWMcijNzS3IMVV9k8rMoNIN0Ogwy/uQjdapbyjQabjmJtyyuGft23Qtzu6x3S2ysIACTs= 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: For compound pages, the head sets the PG_head flag and the tail sets the compound_head to indicate the head page. If a user allocates a compound page and frees it with a different order, the compound page information will not be properly initialized. To detect this problem, compound_order(page) and the order argument are compared, but this is not checked when the order argument is zero. That error should be checked regardless of the order. Reviewed-by: Vishal Moola (Oracle) Signed-off-by: Hyesoo Yu --- mm/page_alloc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 95546f376302..fc92ac93c7c8 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1078,6 +1078,7 @@ static __always_inline bool free_pages_prepare(struct page *page, int bad = 0; bool skip_kasan_poison = should_skip_kasan_poison(page, fpi_flags); bool init = want_init_on_free(); + bool compound = PageCompound(page); VM_BUG_ON_PAGE(PageTail(page), page); @@ -1096,16 +1097,15 @@ static __always_inline bool free_pages_prepare(struct page *page, return false; } + VM_BUG_ON_PAGE(compound && compound_order(page) != order, page); + /* * Check tail pages before head page information is cleared to * avoid checking PageCompound for order-0 pages. */ if (unlikely(order)) { - bool compound = PageCompound(page); int i; - VM_BUG_ON_PAGE(compound && compound_order(page) != order, page); - if (compound) page[1].flags &= ~PAGE_FLAGS_SECOND; for (i = 1; i < (1 << order); i++) {