lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250714163850.e58dd109d4c9e0d191995405@linux-foundation.org>
Date: Mon, 14 Jul 2025 16:38:50 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Matt Fleming <matt@...dmodwrite.com>
Cc: linux-kernel@...r.kernel.org, kernel-team@...udflare.com, Marco Elver
 <elver@...gle.com>, Alexander Potapenko <glider@...gle.com>, Andrey
 Konovalov <andreyknvl@...il.com>, Dmitry Vyukov <dvyukov@...gle.com>, Oscar
 Salvador <osalvador@...e.de>, Vlastimil Babka <vbabka@...e.cz>, Matt
 Fleming <mfleming@...udflare.com>
Subject: Re: [PATCH] stackdepot: Make max number of pools boot-time
 configurable

On Mon, 14 Jul 2025 15:33:32 +0100 Matt Fleming <matt@...dmodwrite.com> wrote:

> From: Matt Fleming <mfleming@...udflare.com>
> 
> We're hitting the WARN in depot_init_pool() about reaching the stack
> depot limit because we have long stacks that don't dedup very well.
> 
> Introduce a new start-up parameter to allow users to set the number of
> maximum stack depot pools.
> 
> ...
>
> --- a/lib/stackdepot.c
> +++ b/lib/stackdepot.c
> @@ -42,6 +42,8 @@
>  	(((1LL << (DEPOT_POOL_INDEX_BITS)) - 1 < DEPOT_POOLS_CAP) ? \
>  	 (1LL << (DEPOT_POOL_INDEX_BITS)) - 1 : DEPOT_POOLS_CAP)
>  
> +static unsigned int stack_max_pools = DEPOT_MAX_POOLS;

Geeze that was all quite the mouthful.  Can't we just do this?

--- a/lib/stackdepot.c~a
+++ a/lib/stackdepot.c
@@ -36,13 +36,11 @@
 #include <linux/memblock.h>
 #include <linux/kasan-enabled.h>
 
-#define DEPOT_POOLS_CAP 8192
-/* The pool_index is offset by 1 so the first record does not have a 0 handle. */
-#define DEPOT_MAX_POOLS \
-	(((1LL << (DEPOT_POOL_INDEX_BITS)) - 1 < DEPOT_POOLS_CAP) ? \
-	 (1LL << (DEPOT_POOL_INDEX_BITS)) - 1 : DEPOT_POOLS_CAP)
-
-static unsigned int stack_max_pools = DEPOT_MAX_POOLS;
+/*
+ * The pool_index is offset by 1 so the first record does not have a 0 handle.
+ */
+static unsigned int stack_max_pools __read_mostly =
+	MIN((1LL << DEPOT_POOL_INDEX_BITS) - 1, 8192);
 
 static bool stack_depot_disabled;
 static bool __stack_depot_early_init_requested __initdata = IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT);
_

(please add this to the next version)

(but why do we do this min() at all?  Why not simply use (1<<DEPOT_POOL_INDEX_BITS)?)

(shouldn't that 8192 be 8191?  Seems oddly inconsistent)

> @@ -101,6 +103,33 @@ static int __init disable_stack_depot(char *str)
>  }
>  early_param("stack_depot_disable", disable_stack_depot);
>  
> +static int __init parse_max_pools(char *str)
> +{
> +	const long long limit = (1LL << (DEPOT_POOL_INDEX_BITS)) - 1;

Expands to
limit = (1LL << (((sizeof(depot_stack_handle_t) * 8) - (2 + 12 - 4) - 5))) - 1;
which is 131071.

This seems a reasonable limit.  If we are to have any limit at all. 
Why do we have a limit?

> +	unsigned int max_pools;
> +	int rv;
> +
> +	rv = kstrtouint(str, 0, &max_pools);
> +	if (rv)
> +		return rv;
> +
> +	if (max_pools < 1024) {
> +		pr_err("stack_depot_max_pools too low, using default\n");
> +		goto out;
> +	}
> +
> +	if (max_pools > limit) {
> +		pr_err("stack_depot_max_pools too high, using default\n");

If user hits this they're going to tear hair figuring out the actual
limit.  So how about "stack_depot_max_pools exceeds %d, using default
of %d".



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ