Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aHIHEXOhZRIki4qF@voyager>
Date: Sat, 12 Jul 2025 08:56:17 +0200
From: Markus Wichmann <nullplan@....net>
To: Luca Kellermann <mailto.luca.kellermann@...il.com>
Cc: Rich Felker <dalias@...c.org>, musl@...ts.openwall.com
Subject: Re: [PATCH 3/4] scandir: fix leaks caused by cancellation

Am Sat, Jul 12, 2025 at 07:48:53AM +0200 schrieb Luca Kellermann:
> So should I update the patch to disable cancellation? It would
> definitely simplify the code. If so, should it be disabled before or
> after the call to opendir()? There is no need for a cancellation
> cleanup handler if opendir() acts upon a cancellation request.
> 

I would put the calls as far to the outside of that function as
possible. I don't really see a reason to do otherwise; every other
function that disables cancellation does so.

For the application, the question is "is scandir() a cancel point?", and
I would think that an unequivocal "no" is better than "sometimes" (if
the cancellation happens early enough).

> Would I use pthread_setcancelstate() or __pthread_setcancelstate() to
> disable cancellation? Some functions in musl use
> pthread_setcancelstate() (e.g. sem_open()), others use
> __pthread_setcancelstate() (e.g. pthread_join()). I think I don't
> really understand hidden and weak_alias and how/why musl uses them.
> 

That's for namespacing. The implementations of ISO-C functions must not
pull in POSIX functions, since the POSIX names aren't reserved in ISO-C,
so the application may be using them (this would cause linking errors,
or unwanted interposition in some cases). So all ISO-C functions must be
implemented only in terms of other ISO-C functions or double-underscore
functions. And that of course applies recursively.

In the case of pthread_join(), the ISO-C functions thrd_detach() and
thrd_join() reference it using the double-underscore name. Therefore it
must not use POSIX names itself, and so all functions it calls must use
double-underscores ore be ISO-C functions.

No such requirement exists for scandir(), so you should just use the
POSIX names.

Ciao,
Markus

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.