Re: [PATCH v5 2/3] man/man2/prctl.2, PR_FUTEX_HASH_SET_SLOTS.2const: Document PR_FUTEX_HASH_SET_SLOTS

From: Sebastian Andrzej Siewior
Date: Thu Aug 21 2025 - 10:18:34 EST


On 2025-08-19 13:19:15 [+0200], Alejandro Colomar wrote:
> Hi Sebastian,
Hi Alejandro,

> > > +.B int prctl(PR_FUTEX_HASH, PR_FUTEX_HASH_SET_SLOTS,
> > > +.BI " unsigned long " hash_size ", unsigned long " hash_flags ");
>
> I see that it is implemented in the kernel as
>
> static int
> futex_hash_allocate(unsigned int hash_slots, unsigned int flags)
> {
> ...
> }
>
> But PR_FUTEX_HASH is implemented as
>
> int
> futex_hash_prctl(unsigned long arg2, unsigned long arg3,
> unsigned long arg4)
> {
> ...
> }
>
> Should we document is as a u_int, or a u_long? Is that mismatch a bug,
> or is it on purpose?

The prctl() interface is long so I started with that. Internally we keep
it as an int since we don't need it that big and it avoids a hole
otherwise (but then there is a hole towards the end of the structure).
Realistically speaking 1 << 31 is the largest value that can be
specified (atm) and it will very likely lead to ENOMEM. If the user
tries the next higher value, 1 << 32, then the upper bits will be
truncated and the global hash will be requested and this will succeed.

The bug could be based on the argument type 1 << 32 will succeed but
it should not. Using 1 << 25 will request ~2GiB of memory and is a bit
far from sane.
I am bit forth and back between forcing an error for anything > 1 << 30,
or updating the docs to int. But this will be the easiest ;)
Any recommendations based on similar cases?

> Cheers,
> Alex

Sebastian