From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: libc-alpha@sourceware.org,
John Ogness <john.ogness@linutronix.de>,
linux-rt-devel@lists.linux.dev,
Thomas Gleixner <tglx@linutronix.de>,
Carlos O'Donell <carlos@redhat.com>
Subject: Re: [PATCH] nptl: Use a PI-aware lock for internal pthread_cond-related locking
Date: Tue, 9 Sep 2025 16:14:11 -0300 [thread overview]
Message-ID: <437ea968-d726-40c9-a833-08d94c5fe105@linaro.org> (raw)
In-Reply-To: <lhubjnja8ng.fsf@oldenburg.str.redhat.com>
On 09/09/25 13:32, Florian Weimer wrote:
> * Sebastian Andrzej Siewior:
>
>>> Are there seccomp filters for PI futexes? I wouldn't be surprised if
>>> people added them after some of the high-profile futex vulnerabilities.
>>> I think we should not support such seccomp filters, but we need to know
>>> what we are up against.
>>
>> I don't know. But don't you allow a syscall such a sys_futex and don't
>> filter additional arguments? Unless one would filter the op argument, it
>> shouldn't be an issue.
>
> There's this historic example:
>
> Remove priority inheritance support for Futex in all Chrome policies,
> including NaCl NonSFI
> <https://issues.chromium.org/issues/40381864>
>
> Some applications are exactly doing that, though, particularly for
> FUTEX_CMP_REQUEUE_PI.
>
> Given how widely the Chromium sandbox code is used, I wonder if this is
> still an issue.
>
>>>> There shouldn't be any error. There might be the case where the lock
>>>> owner is gone (ESRCH I believe) or the theoretical ENOMEM. ESRCH isn't
>>>> handled now but it can't be recognized either. It would require to kill
>>>> the thread owning the lock.
>>>> So either abort the operation if the futex-op returns an error because
>>>> "this shouldn't happen" or I don't know.
>>>
>>> ENOMEM needs to be reported to the caller because the application may
>>> want to react to it.
>>
>> Well. Right now it only checks ESRCH and EDEADLK. Everything else is
>> considered success.
>> So do want to update this + man-page?
>
> The man page already mentions ENOMEM, it's just glibc that is buggy.
>
>> But what should be done this pthread_cond_.*() functions? I guess we
>> can't forward that possible -ENOMEM to the caller?
>
> Is this about the wait operation? POSIX allows spurious wakeups, so we
> could technically return without an error.
>
>> Also if we are in good mood, there pthread_mutex_lock() has this comment
>> | /* ESRCH can happen only for non-robust PI mutexes where
>> | the owner of the lock died. */
>>
>> This is simply not true as far as the kernel goes. If the futex uaddr
>> contains a pid of a non-existing task then LOCK_PI will return ESRCH. A
>> simple testcase would be
>>
>> | #include <stdio.h>
>> | #include <pthread.h>
>> |
>> | static pthread_mutex_t l;
>> |
>> | static void *thread_code(void *arg)
>> | {
>> | pthread_mutex_lock(&l);
>> | return NULL;
>> | }
>> |
>> | int main(void)
>> | {
>> | pthread_mutexattr_t attr;
>> | pthread_t thread;
>> | int ret;
>> |
>> | ret = pthread_mutexattr_init(&attr);
>> | ret |= pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
>> | ret |= pthread_mutex_init(&l, &attr);
>> | ret |= pthread_create(&thread, NULL, thread_code, NULL);
>> | if (ret) {
>> | printf("->[%d] %d\n", __LINE__, ret);
>> | return 1;
>> | }
>> | pthread_join(thread, NULL);
>> | ret = pthread_mutex_lock(&l);
>> | printf("-> %d %m\n", ret);
>> |
>> | return 0;
>> | }
>>
>> and strace says:
>> | futex(0x55afb0ceb080, FUTEX_LOCK_PI_PRIVATE, NULL) = -1 ESRCH (No such process)
>> | futex(0x7ffe73216f24, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY
>>
>> the second futex() is the __futex_abstimed_wait64() that follows.
>
> Does POSIX define what happens if a non-robust mutex is accessed again
> if a thread terminates without unlocking it first? If yes, then this is
> indeed a problem.
Afaik this is UB for non-robust mutexes, although the resolution for Austin
Issue 755 [1] is not clear IMHO.
[1] https://www.austingroupbugs.net/view.php?id=755#c1875
next prev parent reply other threads:[~2025-09-09 19:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-08 16:33 [PATCH] nptl: Use a PI-aware lock for internal pthread_cond-related locking Sebastian Andrzej Siewior
2025-09-08 17:46 ` Adhemerval Zanella Netto
2025-09-09 7:32 ` Sebastian Andrzej Siewior
2025-09-09 12:22 ` Florian Weimer
2025-09-09 15:37 ` Sebastian Andrzej Siewior
2025-09-09 16:32 ` Florian Weimer
2025-09-09 19:14 ` Adhemerval Zanella Netto [this message]
2025-09-10 5:57 ` Florian Weimer
2025-09-09 13:09 ` Adhemerval Zanella Netto
2025-09-09 15:52 ` Sebastian Andrzej Siewior
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=437ea968-d726-40c9-a833-08d94c5fe105@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=bigeasy@linutronix.de \
--cc=carlos@redhat.com \
--cc=fweimer@redhat.com \
--cc=john.ogness@linutronix.de \
--cc=libc-alpha@sourceware.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=tglx@linutronix.de \
/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 NNTP newsgroup(s).