From: Michal Hocko <mhocko@suse.com>
To: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@suse.cz>,
Jonathan Corbet <corbet@lwn.net>, Mike Rapoport <rppt@kernel.org>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, kernel-team@meta.com
Subject: Re: [PATCH v2 1/2] mm/mm_init: Introduce a boot parameter for check_pages
Date: Tue, 25 Nov 2025 09:44:18 +0100 [thread overview]
Message-ID: <aSVsYvQUm_xnoRxC@tiehlicka> (raw)
In-Reply-To: <20251124225408.2243564-1-joshua.hahnjy@gmail.com>
On Mon 24-11-25 14:54:06, Joshua Hahn wrote:
> Use-after-free and double-free bugs can be very difficult to track down.
> The kernel is good at tracking these and preventing bad pages from being
> used/created through simple checks gated behind "check_pages_enabled".
>
> Currently, the only ways to enable this flag is by building with
> CONFIG_DEBUG_VM, or as a side effect of other checks such as
> init_on_{alloc, free}, page_poisoning, or debug_pagealloc among others.
> These solutions are powerful, but may often be too coarse in balancing
> the performance vs. safety that a user may want, particularly in
> latency-sensitive production environments.
>
> Introduce a new boot parameter "check_pages", which enables page checking
> with no other side effects. It takes kstrbool-able inputs as an argument
> (i.e. 0/1, true/false, on/off, ...). This patch is backwards-compatible;
> setting CONFIG_DEBUG_VM still enables page checking.
Arguing with performance without any performance numbers is not really
convincing but the change makes some sense to me even without that.
DEBUG_VM is just everything-in-one-bag thing which is not suitable for
production use and bad_page checks might still be valuable for such a
use.
> Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Acked-by: Michal Hocko <mhocko@suse.com>
> ---
> v1 --> v2:
> - Changed check_pages from a build config into a boot config, as suggested
> by Vlastimil.
> - Introduced the second patch, which decouples page checking from
> init_on_page_alloc and init_on_page_free.
> ---
>
> Documentation/admin-guide/kernel-parameters.txt | 8 ++++++++
> mm/mm_init.c | 11 ++++++++++-
> 2 files changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index 6c42061ca20e..0ba9561440a7 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -669,6 +669,14 @@
> nokmem -- Disable kernel memory accounting.
> nobpf -- Disable BPF memory accounting.
>
> + check_pages= [MM,EARLY] Enable sanity checking of pages after
> + allocations / before freeing. This adds checks to catch
> + double-frees, use-after-frees, and other sources of
> + page corruption by inspecting page internals (flags,
> + mapcount/refcount, memcg_data, etc.).
> + Format: { "0" | "1" }
> + Default: 0 (1 if CONFIG_DEBUG_VM is set)
> +
> checkreqprot= [SELINUX] Set initial checkreqprot flag value.
> Format: { "0" | "1" }
> See security/selinux/Kconfig help text.
> diff --git a/mm/mm_init.c b/mm/mm_init.c
> index c6812b4dbb2e..01d46efc42b4 100644
> --- a/mm/mm_init.c
> +++ b/mm/mm_init.c
> @@ -2525,6 +2525,14 @@ early_param("init_on_free", early_init_on_free);
>
> DEFINE_STATIC_KEY_MAYBE(CONFIG_DEBUG_VM, check_pages_enabled);
>
> +static bool _check_pages_enabled_early __initdata;
> +
> +static int __init early_check_pages(char *buf)
> +{
> + return kstrtobool(buf, &_check_pages_enabled_early);
> +}
> +early_param("check_pages", early_check_pages);
> +
> /*
> * Enable static keys related to various memory debugging and hardening options.
> * Some override others, and depend on early params that are evaluated in the
> @@ -2591,7 +2599,8 @@ static void __init mem_debugging_and_hardening_init(void)
> * of struct pages being allocated or freed. With CONFIG_DEBUG_VM it's
> * enabled already.
> */
> - if (!IS_ENABLED(CONFIG_DEBUG_VM) && want_check_pages)
> + if (!IS_ENABLED(CONFIG_DEBUG_VM) && (_check_pages_enabled_early ||
> + want_check_pages))
> static_branch_enable(&check_pages_enabled);
> }
>
> --
> 2.47.3
--
Michal Hocko
SUSE Labs
next prev parent reply other threads:[~2025-11-25 8:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-24 22:54 [PATCH v2 1/2] mm/mm_init: Introduce a boot parameter for check_pages Joshua Hahn
2025-11-24 22:54 ` [PATCH v2 2/2] mm/mm_init: decouple page checking and init_on_{alloc, free} Joshua Hahn
2025-11-25 1:18 ` SeongJae Park
2025-11-25 18:59 ` Joshua Hahn
2025-11-25 8:45 ` Michal Hocko
2025-11-25 18:06 ` Vlastimil Babka
2025-11-25 18:58 ` Joshua Hahn
2025-11-25 1:10 ` [PATCH v2 1/2] mm/mm_init: Introduce a boot parameter for check_pages SeongJae Park
2025-11-25 8:44 ` Michal Hocko [this message]
2025-11-25 10:23 ` Mike Rapoport
2025-11-25 18:44 ` Joshua Hahn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aSVsYvQUm_xnoRxC@tiehlicka \
--to=mhocko@suse.com \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=joshua.hahnjy@gmail.com \
--cc=kernel-team@meta.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rppt@kernel.org \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.