[PATCH] pthread_getcpuclockid: Add descriptive comment to smoke test
Florian Weimer
fweimer@redhat.com
Thu Nov 28 13:49:08 GMT 2024
* Siddhesh Poyarekar:
> On 2024-11-28 07:00, Florian Weimer wrote:
>> * Siddhesh Poyarekar:
>>
>>> +/* The input thread descriptor to pthread_getcpuclockid needs to be valid when
>>> + the function is called. For the purposes of this test, this means that the
>>> + thread should not be detached, have exited, but not joined. There is also a
>>> + tiny window where the TCB has been allocated but the target thread itself
>>> + not created, where pthread_getcpuclockid could return ESRCH, but it's not
>>> + possible to tap into that window to reliably test it. It's not necessary
>>> + anyway, since the window this test exploits is good enough to complete
>>> + coverage for pthread_getcpuclockid alongside tst-clock2. */
>> The kernel stores the TID to the TCB before the system call returns
>> (according to the clone manual page).
>> So the only race is for thread exit, not thread creation, and the
>> comment is misleading.
>
> I was thinking of a situation where the thread descriptor points to a
> TCB and the syscall has not been invoked yet; this would be
> exploitable when the thread descriptor itself is in memory shared with
> another thread. But now that I'm saying it out loud, it doesn't sound
> like behaviour that ought to be relied upon, just something that the
> internals currently happen to allow.
>
> How about this then:
>
> /* The input thread descriptor to pthread_getcpuclockid needs to be
> valid when
> the function is called. For the purposes of this test, this means
> that the
> thread should not be detached, have exited, but not joined. This
> should be
> good enough to complete coverage for pthread_getcpuclockid alongside
> tst-clock2. */
This looks reasonable to me (except for the line breaks).
Thanks,
Florian
More information about the Libc-alpha
mailing list