Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Wed, 16 Feb 2022 16:02:49 -0500
From: Carlos O'Donell <carlos@...hat.com>
To: Florian Weimer <fweimer@...hat.com>
Cc: musl@...ts.openwall.com, Markus Wichmann <nullplan@....net>
Subject: Re: Is errno signal-safe?

On 2/16/22 16:01, Florian Weimer wrote:
> * Carlos O'Donell:
> 
>> On 2/16/22 14:40, Markus Wichmann wrote:
>>> Hi all,
>>>
>>> today I had a flash of inspiration while staring at some code: errno is
>>> a global variable, right? OK, it is thread-local, but still a global
>>> variable in the context of one thread. And looking at a global variable
>>> while it may (or may not) be modified in a signal handler is not safe to
>>> do.
>>
>> It is required that errno, if changed, must be restored by the signal
>> handler before exit (though note that for glibc the underlying lazy
>> TLS allocation implementation makes errno AS-unsafe for first use in a
>> signal handler because calloc is used to allocate the storage).
> 
> glibc uses initial-exec TLS under the hood for storing the int variable,
> so the variable access itself async-signal-safe (whether it goes
> directly to errno@...BC_PRIVATE or via __errno_location, it doesn't
> matter).

Thanks. I'd forgotten about that quirk. Every *other* use of non-initial-exec TLS is
still AS-unsafe.

-- 
Cheers,
Carlos.

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.