Linux-api Archive mirror
 help / color / mirror / Atom feed
From: "André Almeida" <andrealmeid@igalia.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, mingo@redhat.com,
	dvhart@infradead.org, dave@stgolabs.net, tglx@linutronix.de,
	axboe@kernel.dk, Andrew Morton <akpm@linux-foundation.org>,
	urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com,
	Arnd Bergmann <arnd@arndb.de>,
	linux-api@vger.kernel.org, linux-mm@kvack.org,
	linux-arch@vger.kernel.org, malteskarupke@web.de,
	Geert Uytterhoeven <geert@linux-m68k.org>
Subject: Re: [PATCH v2 05/14] futex: Add sys_futex_wake()
Date: Thu, 10 Aug 2023 14:01:20 -0300	[thread overview]
Message-ID: <3bcdb026-8558-43ca-80c1-776216dcd86c@igalia.com> (raw)
In-Reply-To: <20230810121341.GX212435@hirez.programming.kicks-ass.net>



Em 10/08/2023 09:13, Peter Zijlstra escreveu:
> On Wed, Aug 09, 2023 at 07:25:19PM -0300, André Almeida wrote:
>> Hi Peter,
>>
>> Em 07/08/2023 09:18, Peter Zijlstra escreveu:
>>> To complement sys_futex_waitv() add sys_futex_wake(). This syscall
>>> implements what was previously known as FUTEX_WAKE_BITSET except it
>>> uses 'unsigned long' for the bitmask and takes FUTEX2 flags.
>>>
>>> The 'unsigned long' allows FUTEX2_SIZE_U64 on 64bit platforms.
>>>
>>> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
>>> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
>>> ---
>>
>> [...]
>>
>>> +/*
>>> + * sys_futex_wake - Wake a number of futexes
>>> + * @uaddr:	Address of the futex(es) to wake
>>> + * @mask:	bitmask
>>> + * @nr:		Number of the futexes to wake
>>> + * @flags:	FUTEX2 flags
>>> + *
>>> + * Identical to the traditional FUTEX_WAKE_BITSET op, except it is part of the
>>> + * futex2 family of calls.
>>> + */
>>> +
>>> +SYSCALL_DEFINE4(futex_wake,
>>> +		void __user *, uaddr,
>>> +		unsigned long, mask,
>>> +		int, nr,
>>> +		unsigned int, flags)
>>> +{
>>
>> Do you think we could have a
>>
>> 	if (!nr)
>> 		return 0;
>>
>> here? Otherwise, calling futex_wake(&f, 0, flags) will wake 1 futex (if
>> available), which is a strange undocumented behavior in my opinion.
> 
> Oh 'cute' that.. yeah, but how about I put it ...
> 
>>> +	if (flags & ~FUTEX2_VALID_MASK)
>>> +		return -EINVAL;
>>> +
>>> +	flags = futex2_to_flags(flags);
>>> +	if (!futex_flags_valid(flags))
>>> +		return -EINVAL;
>>> +
>>> +	if (!futex_validate_input(flags, mask))
>>> +		return -EINVAL;
> 
> here, because otherwise we get:
> 
> 	sys_futex_wake(&f, 0xFFFF, 0, FUTEX2_SIZE_U8)
> 
> to return 0, even though that is 'obviously' nonsensical and should
> return -EINVAL. Or even garbage flags would be 'accepted'.
> 
> (because 0xFFFF is larger than U8 can accomodate)
> 

That make sense to me, but we would also want to validate the value of 
f, if it's NULL or something strange to return -EINVAL... but this 
happens only inside get_futex_key()...

To make this right, I think we would need to move this verification to 
the syscall validation part:

	if (unlikely((address % sizeof(u32)) != 0))
		return -EINVAL;

	if (unlikely(!access_ok(uaddr, sizeof(u32))))
		return -EFAULT;

And have u32 replaced with the proper size being used.

>>> +
>>> +	return futex_wake(uaddr, flags, nr, mask);
>>> +}

  reply	other threads:[~2023-08-10 17:01 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07 12:18 [PATCH v2 00/14] futex: More futex2 bits Peter Zijlstra
2023-08-07 12:18 ` [PATCH v2 01/14] futex: Clarify FUTEX2 flags Peter Zijlstra
2023-08-07 23:51   ` André Almeida
2023-08-07 12:18 ` [PATCH v2 02/14] futex: Extend the " Peter Zijlstra
2023-08-07 18:56   ` Thomas Gleixner
2023-08-08  0:02   ` André Almeida
2023-08-07 12:18 ` [PATCH v2 03/14] futex: Flag conversion Peter Zijlstra
2023-08-07 18:58   ` Thomas Gleixner
2023-08-08  0:52   ` André Almeida
2023-08-07 12:18 ` [PATCH v2 04/14] futex: Validate futex value against futex size Peter Zijlstra
2023-08-07 12:18 ` [PATCH v2 05/14] futex: Add sys_futex_wake() Peter Zijlstra
2023-08-07 19:00   ` Thomas Gleixner
2023-08-09 22:25   ` André Almeida
2023-08-10 12:13     ` Peter Zijlstra
2023-08-10 17:01       ` André Almeida [this message]
2023-08-07 12:18 ` [PATCH v2 06/14] futex: Add sys_futex_wait() Peter Zijlstra
2023-08-07 12:18 ` [PATCH v2 07/14] futex: Propagate flags into get_futex_key() Peter Zijlstra
2023-08-07 12:18 ` [PATCH v2 08/14] futex: Add flags2 argument to futex_requeue() Peter Zijlstra
2023-08-07 19:01   ` Thomas Gleixner
2023-08-07 12:18 ` [PATCH v2 09/14] futex: Add sys_futex_requeue() Peter Zijlstra
2023-08-07 19:05   ` Thomas Gleixner
2023-08-07 12:18 ` [PATCH v2 10/14] mm: Add vmalloc_huge_node() Peter Zijlstra
2023-08-07 12:18 ` [PATCH v2 11/14] futex: Implement FUTEX2_NUMA Peter Zijlstra
2023-08-07 21:11   ` Thomas Gleixner
2023-08-08  8:54     ` Peter Zijlstra
2023-08-08  9:12       ` Thomas Gleixner
2023-08-07 12:18 ` [PATCH v2 12/14] futex: Propagate flags into futex_get_value_locked() Peter Zijlstra
2023-08-07 21:12   ` Thomas Gleixner
2023-08-07 12:18 ` [PATCH v2 13/14] futex: Enable FUTEX2_{8,16} Peter Zijlstra
2023-08-07 21:15   ` Thomas Gleixner
2023-08-07 12:18 ` [PATCH v2 14/14] futex,selftests: Extend the futex selftests Peter Zijlstra
2023-08-08 20:32 ` [PATCH v2 00/14] futex: More futex2 bits Jens Axboe

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=3bcdb026-8558-43ca-80c1-776216dcd86c@igalia.com \
    --to=andrealmeid@igalia.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=axboe@kernel.dk \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=geert@linux-m68k.org \
    --cc=hch@infradead.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    --cc=malteskarupke@web.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=urezki@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).