From patchwork Thu Oct 12 01:11:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyesoo Yu X-Patchwork-Id: 13418103 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 03F03CDB465 for ; Thu, 12 Oct 2023 01:22:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 109716B0253; Wed, 11 Oct 2023 21:22:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BA8C6B0254; Wed, 11 Oct 2023 21:22:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC3EA6B0256; Wed, 11 Oct 2023 21:22:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DD14A6B0253 for ; Wed, 11 Oct 2023 21:22:01 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id AB9F51CADBD for ; Thu, 12 Oct 2023 01:22:01 +0000 (UTC) X-FDA: 81335058042.09.2DEA91A Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by imf16.hostedemail.com (Postfix) with ESMTP id B06DD18000B for ; Thu, 12 Oct 2023 01:21:57 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=YpzJXSWQ; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf16.hostedemail.com: domain of hyesoo.yu@samsung.com designates 203.254.224.24 as permitted sender) smtp.mailfrom=hyesoo.yu@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697073718; a=rsa-sha256; cv=none; b=nKcq6d5TX84dVmUE0OK87hoEMOZmJ1TUSjLhh66dyW95L0W4BzMqf+laHeeOr497bmrPd8 FbjHVxk0KocYHN0H5/ohSF9Gk1Ok9rxwkbVWTVZZ7Ufmwaic11lbnnas8QdCLPE68jJzOj 5NXH8NmB7MtNK/7th/JfyaycIUpDmsA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=YpzJXSWQ; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf16.hostedemail.com: domain of hyesoo.yu@samsung.com designates 203.254.224.24 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=1697073718; 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=7H0v5Ho0xCMOHAlATsQ+2agtg+oJP2k/heeGuFBWmXk=; b=xzDrQK52RV8yYeaTVt9W6EAaeE198BfuQmhARfknpqCuVzyXMmyIPxE0XlSo1wsA4UhsGw sqzYcjANKNacAUwF8phNbFebyOUU1MPj4HIiAv6IKXvHl6HFBJ0SOxVRHzZmZ1MJPRRrhz hPl86Fp3ViZjNon2/Gmc8FUynXy4xYg= Received: from epcas2p3.samsung.com (unknown [182.195.41.55]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20231012012154epoutp014cc08de6fc024a952dfcb7edf18ad951~NN40ybpIh2711327113epoutp01g for ; Thu, 12 Oct 2023 01:21:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20231012012154epoutp014cc08de6fc024a952dfcb7edf18ad951~NN40ybpIh2711327113epoutp01g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1697073714; bh=7H0v5Ho0xCMOHAlATsQ+2agtg+oJP2k/heeGuFBWmXk=; h=From:To:Cc:Subject:Date:References:From; b=YpzJXSWQlcSAeqaeS3irZlUyN6fKeZTrG3YJuSTifoTeqmoRdat93jYnPhDhw5K7+ wns40FaCdZW7Lh1ynaXh97lg8YBQancDEK5E4tpggwRJwyA2zj+r6sR26hlHbq6vPB bnSd+K46kd4AT+3UIPruqCSRPcWadg0qEEv43oQk= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas2p2.samsung.com (KnoxPortal) with ESMTP id 20231012012153epcas2p2544b47305521e527fa664ef08c3a8dbe~NN40ZJaq92121121211epcas2p2z; Thu, 12 Oct 2023 01:21:53 +0000 (GMT) Received: from epsmges2p1.samsung.com (unknown [182.195.36.88]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4S5X0x35WCz4x9Q3; Thu, 12 Oct 2023 01:21:53 +0000 (GMT) Received: from epcas2p2.samsung.com ( [182.195.41.54]) by epsmges2p1.samsung.com (Symantec Messaging Gateway) with SMTP id 23.28.09693.13A47256; Thu, 12 Oct 2023 10:21:53 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas2p3.samsung.com (KnoxPortal) with ESMTPA id 20231012012153epcas2p34b8e9e8a898ace8d50411cadf937ef5d~NN4zuYfw-1690416904epcas2p3I; Thu, 12 Oct 2023 01:21:53 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231012012153epsmtrp2ad75a250d8ac9aba399a830f068c9818~NN4ztra1Q2295322953epsmtrp20; Thu, 12 Oct 2023 01:21:53 +0000 (GMT) X-AuditID: b6c32a45-abbfd700000025dd-b5-65274a31f973 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id D7.4D.18916.03A47256; Thu, 12 Oct 2023 10:21:52 +0900 (KST) Received: from localhost.localdomain (unknown [10.229.95.142]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231012012152epsmtip1d3663edb6846e000ef6ca2fdbc07e4b1~NN4zmAgks0828408284epsmtip1f; Thu, 12 Oct 2023 01:21:52 +0000 (GMT) From: Hyesoo Yu To: Cc: Hyesoo Yu , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: page_alloc: check the order of compound page event when the order is 0 Date: Thu, 12 Oct 2023 10:11:06 +0900 Message-Id: <20231012011106.2425309-1-hyesoo.yu@samsung.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBKsWRmVeSWpSXmKPExsWy7bCmma6hl3qqweU34hZz1q9hs/jbeYHV 4vKuOWwW99b8Z3Vg8dj0aRK7x4kZv1k8+rasYvT4vEkugCUq2yYjNTEltUghNS85PyUzL91W yTs43jne1MzAUNfQ0sJcSSEvMTfVVsnFJ0DXLTMHaKWSQlliTilQKCCxuFhJ386mKL+0JFUh I7+4xFYptSAlp8C8QK84Mbe4NC9dLy+1xMrQwMDIFKgwITvjxcZ/jAWbeCr+vZ/D1MD4j7OL kZNDQsBEYsXB6+xdjFwcQgI7GCUmHJ7EDOF8YpT4+HE+E5xzbtF3FpiWWd/PQrXsZJT48OAT I0hCSOAzo8Sd6TogNpuAusSJLcvA4iICLBIrv4M0c3EwC7QxSkx+excsISwQK9He9AFoEgcH i4CqxLT5CiBhXgEbiTcLzrJBLJOXmHnpOztEXFDi5MwnYEcwA8Wbt84GO1VCYB27xOslrWwg cyQEXCQ+96dA9ApLvDq+hR3ClpL4/G4v1MxsibsfJ0DZJRLrzjRA1RhLzHrWzggyhllAU2L9 Ln2IicoSR25BbeWT6Dj8lx0izCvR0SYE0agssX/ZPGjoSEo8WtvOClHiIdG1Jx4SNrESt2+d YJzAKD8LySuzkLwyC2HtAkbmVYxiqQXFuempxUYFhvAYTc7P3cQITnJarjsYJ7/9oHeIkYmD 8RCjBAezkg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5vQ/rLT nS8CZugt2HFBtuCIixqnQ3ir386Wp18aHRfP25QaJOPzu2y94a59RbY3WStLZn3NUN3NvlPu n0CAz0LezDnTO9iFPbOevfujFKcfG+KQJHlcZmqW6S0fWRtxibgk7v+98lqHMl13b1p5MVB6 Vk0Sk27V/GZdj6z/QS8a1Er/JP/wPyuyYrIcu2lR5YbH8vpacv8Pf3212ufxrqop2QtlMpXb s6u1pqptMXIxFJ6Zt3jl3ZfbzWOj1QzLpq1dsjF13pr0j+/LzqonzZCp/RvCcfm5EktxRqKh FnNRcSIAzyK6T6oCAAA= X-CMS-MailID: 20231012012153epcas2p34b8e9e8a898ace8d50411cadf937ef5d X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231012012153epcas2p34b8e9e8a898ace8d50411cadf937ef5d References: X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B06DD18000B X-Stat-Signature: rz1sohmbg88rme5qqj7jjy4tok6iogq3 X-HE-Tag: 1697073717-7605 X-HE-Meta: U2FsdGVkX1/qua/GPuoTz1cLN29WaTPsbRqcYNywYIURxk75rFdK4ZKchdbKQSi1swXQ18aKSA75Bwzw93dORVR7q9PmbXsizhxqaTGoa0RJ93xsJ3PCyYCtI9X+gAG5eze2b4poXWvrL9cvg5xpc2xhMdx3pXKwM2yUDKKnR62uKQWAoDNgKQwZvTLag0yXPbS8S6Pp6SZXDvQrIQWyWerK6lBl/PtJU8HmViiyA4Owe/n5i4Q8OpAvSfVSbhP/I9kZBTZ8Wlky7Yu4t7BdyyrTaOeUWipOM+XIDvIj5w2EgrkQ6ifIgB83eh+af802llr/Yj1BVwnVtYxd81S/jdVDWscKTIe9roOA4abW8WMbbOMtpE4Rjs8izfPxrAjrUMr4B+vsktHKH1ufW+zfCAnQ/d4JdDMUu+WE0UqbAi+TjD0n2o3GiCPMuvHTpfnctxVXizGx2keRIUpJWXpIdHx5KAxr3JPn1VlyAGYSJCVJZ371xU0daOa1WlMRmrtED11IKD0A4IorxLF5Dmlg4U7faOAmdRGoMXc07tEJ7GGiT3xwDyFxfjRGstoaHGtubY5+6A5nr5OzzErWiGmMirF14ahKZcttk0bHa1wGgM/i8VfiPaNZlqsi3M6tYWGDOByDkqol4a+PKAXPSp48CsG/5Zir6cudaTs9ZZdUtOzG8crhFhp0grhPrP1gm31RJIHyeFPAAPRGezlNCU9fVE3RXe32/mXktB2n/yvRGW5qWY9K2lCdodlvg34UxH/ZfkCImf2AQOpGVYI7jzBAjKtXyJU31uNp9BfSFVQceVLyF70Ew1B8B8fARE+OIQRbySWcw+HqU4smwLR64tfvbeyBoLrOd4d015mhoLOtvLNMJVSoQp1miNk44na7QycPbf/Zkd4zeBu2Hway0SPGIbh8Pg2ydSmUVV8q9cY1hMDni2UVgfoOY1uDQrnC7aOVxrDlApRkAAtNympnFe7 mt2rPSie 7uoDrQJ+hmpDyg7se7e6ys7KhDMOfH5LwEQuDiZcPw3fg8O1t59zOcQa+/WjxnWf3ByFF4/+wzu4xoEj0Rmus8ZiFkmLVBXcVJ7IdjptyXBgXVJPszHa7tvWpShoBCGlGoWZMVtcgiW+aSOQ= 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: 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_page(page) and the order are compared, but it is not checked when the order is 0. That error should be checked regardless of the order. Signed-off-by: Hyesoo Yu Reviewed-by: Vishal Moola (Oracle) --- 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++) {