Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp5365rdg; Wed, 11 Oct 2023 18:22:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBgr8l3HLeS5aiYz8Z5MiglIcC0KYE1gVSQ27ZiAI4v7yI5bCCdio6tD6OXyOt1q3/o6pT X-Received: by 2002:a05:6a00:2e90:b0:690:3b59:cc7a with SMTP id fd16-20020a056a002e9000b006903b59cc7amr29442044pfb.23.1697073755089; Wed, 11 Oct 2023 18:22:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697073755; cv=none; d=google.com; s=arc-20160816; b=VfHwolEmJ77jN+N029BTeddvZ0uYcQYFJV9/u4pEFrwxvHL5XYejaQY+JJQqZu+AHa BbChrSjIEx+0+sn0PxnV5oJTeh8H/lI/JHzOt1oKjneKdZ/DGw/CtVUrck2oKyvHeWcs wjG143TFfdUojWoCmcjDVxjkowjFj+i2sc+PN7QGMA8KYe48tABRq+2jbeYJQcdG/L2l 4lwl9y+8KCxeozj8Yj7R7RLMHTWT7oP+tgaQ/J7qsbr3ByJ3eoHnzGhwHJaPnWuru5Rd EGxXGgy9KAHxztQUNgZ8Tf+uqUDqAdGv1+PalDYh3+WbmHZLAgqQlqe5R5lp2os9G7KQ zO4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:dlp-filter:cms-type :content-transfer-encoding:mime-version:message-id:date:subject:cc :from:dkim-signature:dkim-filter; bh=7H0v5Ho0xCMOHAlATsQ+2agtg+oJP2k/heeGuFBWmXk=; fh=HadQFIcPJNEv8UrrfFmkNlrnF8CsP0O0cBesvrnzPBc=; b=HnbR9mQcwGvvlwxaA9hXBMVTIcX5ESytftvaCkSjyWtQHE2qmCip0ZsBM+Gd/J6WwV fMK47WgokHQ9Lxxf9GCTa9gqn5gWD1ply72T0LIMSjchIbafQrdUp0v+sOB3mN2UsLYF lWMXcGyE3kgw0KM+ERWj8/Blv5MbLNYQzb6Qe34B3bFqx43SrLpFgGWBKdaZ6Dfx314s L0bNY/bP9Ewp0xIb/2rGgOSIWZ199OumGrn6jNO9z8aUrDKqJZzWh5Zy9peWQHxY7Q5C rzfAdyyOz0O/BhwS8WA41w8kIY32nDf1GTutZoMRVEH5bYOEidDt81o6kGn8pFPyGGKU am5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@samsung.com header.s=mail20170921 header.b=YpzJXSWQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id bv7-20020a056a00414700b00690c75e54e1si10197688pfb.402.2023.10.11.18.22.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 18:22:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=fail header.i=@samsung.com header.s=mail20170921 header.b=YpzJXSWQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 46D8E80B81E3; Wed, 11 Oct 2023 18:22:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376637AbjJLBWC (ORCPT + 99 others); Wed, 11 Oct 2023 21:22:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233901AbjJLBWB (ORCPT ); Wed, 11 Oct 2023 21:22:01 -0400 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C97D98 for ; Wed, 11 Oct 2023 18:21:59 -0700 (PDT) Received: from epcas2p3.samsung.com (unknown [182.195.41.55]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20231012012154epoutp03efaf986c6f9cd57cc51374d2c062020a~NN40yx3dF0057900579epoutp03H for ; Thu, 12 Oct 2023 01:21:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20231012012154epoutp03efaf986c6f9cd57cc51374d2c062020a~NN40yx3dF0057900579epoutp03H 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 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 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBKsWRmVeSWpSXmKPExsWy7bCmma6hl3qqweU34hZz1q9hs/jbeYHV 4vKuOWwW99b8Z3Vg8dj0aRK7x4kZv1k8+rasYvT4vEkugCUq2yYjNTEltUghNS85PyUzL91W yTs43jne1MzAUNfQ0sJcSSEvMTfVVsnFJ0DXLTMHaKWSQlliTilQKCCxu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SXmKPExsWy7bCSnK6Bl3qqwbIfVhZz1q9hs/jbeYHV 4vKuOWwW99b8Z3Vg8dj0aRK7x4kZv1k8+rasYvT4vEkugCWKyyYlNSezLLVI3y6BK+PFxn+M BZt4Kv69n8PUwPiPs4uRk0NCwERi1vez7F2MXBxCAtsZJRZ1P2CBSEhKzPp8kgnCFpa433KE FaLoI6PEi1vX2UASbALqEie2LGMEsUUEWCRWfv/OAlLELNDBKLHzxgmwhLBAtMSv+eeBVnBw sAioSkybrwAS5hWwkXiz4CwbxAJ5iZmXvrNDxAUlTs58AnYEM1C8eets5gmMfLOQpGYhSS1g ZFrFKJpaUJybnptcYKhXnJhbXJqXrpecn7uJERx2WkE7GJet/6t3iJGJg/EQowQHs5II76NM lVQh3pTEyqrUovz4otKc1OJDjNIcLErivMo5nSlCAumJJanZqakFqUUwWSYOTqkGpo5LNnP0 J/6dvKexbEKU0LotzBcOTlQVfaqjk+4s9d/LbZpxW8mZsq60q0uWGtyw9f4WfvSbx5vQ/rLT nS8CZugt2HFBtuCIixqnQ3ir386Wp18aHRfP25QaJOPzu2y94a59RbY3WStLZn3NUN3NvlPu n0CAz0LezDnTO9iFPbOevfujFKcfG+KQJHlcZmqW6S0fWRtxibgk7v+98lqHMl13b1p5MVB6 Vk0Sk27V/GZdj6z/QS8a1Er/JP/wPyuyYrIcu2lR5YbH8vpacv8Pf3212ufxrqop2QtlMpXb s6u1pqptMXIxFJ6Zt3jl3ZfbzWOj1QzLpq1dsjF13pr0j+/LzqonzZCp/RvCcfm5EktxRqKh FnNRcSIAzyK6T6oCAAA= X-CMS-MailID: 20231012012153epcas2p34b8e9e8a898ace8d50411cadf937ef5d X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231012012153epcas2p34b8e9e8a898ace8d50411cadf937ef5d References: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 11 Oct 2023 18:22:32 -0700 (PDT) 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 --- 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++) { -- 2.25.1