[glibc][PATCHv2] nptl: open threads comm with O_WRONLY|O_CLOEXEC

Florian Weimer fweimer@redhat.com
Mon Jun 15 14:32:51 GMT 2026


* Sana Kazi:

> From: Sana Kazi <Sana.Kazi@bmwtechworks.in>
>
> pthread_setname_np opens the thread's comm file using O_RDWR, but the
> function only ever writes to it.  This causes two distinct problems:
>
> 1. Missing O_CLOEXEC: the file descriptor is not marked close-on-exec,
>    so it remains open across fork+exec.  A child process that audits
>    its inherited file-descriptor set will encounter an unexpected /proc
>    fd it did not open and may treat this as a security violation and
>    abort.
>
> 2. Unnecessary O_RDWR: requesting read+write access when only write
>    access is needed can cause open() to fail under security policies
>    that permit writing to /proc/<tid>/comm but deny reading it.
>
> Fix both issues by replacing O_RDWR with O_WRONLY|O_CLOEXEC
>
> Similarly, updated pthread_getname_np to use O_CLOEXEC.
>
> Bug-Id: 34192[https://sourceware.org/bugzilla/show_bug.cgi?id=34192]
>
> Signed-off-by: Sana Kazi <Sana.Kazi@bmwtechworks.in>

This version looks good to me.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

I'm going to push it for you.

Thanks,
Florian



More information about the Libc-alpha mailing list