From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19810 invoked from network); 8 Apr 2021 17:17:50 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 8 Apr 2021 17:17:50 -0000 Received: (qmail 11756 invoked by uid 550); 8 Apr 2021 17:17:48 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 11734 invoked from network); 8 Apr 2021 17:17:47 -0000 Date: Thu, 8 Apr 2021 13:17:35 -0400 From: Rich Felker To: Florian Weimer Cc: Andrey Bugaevskiy , musl@lists.openwall.com Message-ID: <20210408171734.GA2546@brightrain.aerifal.cx> References: <00bc01d72c91$bdedb030$39c91090$@yandex-team.ru> <87wntc1zee.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87wntc1zee.fsf@oldenburg.str.redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] errno and swapcontext in a multithreaded setup On Thu, Apr 08, 2021 at 07:04:09PM +0200, Florian Weimer wrote: > * Andrey Bugaevskiy: > > > I'm using makecontext/swapcontext to migrate contexts between threads > > and this sometimes leads to getting incorrect errno values. > > > > Investigating further I've noticed that __errno_location > > is marked __attribute__((const)). > > This causes optimizers to assume that errno address never changes > > in the scope of the function which is not the case in my scenario. > > The optimizers make the same assumption for actual thread-local > variables, not just __errno_location. Migrating contexts between > threads results in undefined behavior. Indeed, this is not functionality that has ever been defined on any implementation I'm aware of. There are a lot of other things that could go wrong. Even if you don't explicitly use TLS, if your code is built with stack protector it may access the canary value from TLS, and the value may be individual to each thread (musl doesn't currently do this, but could in the future as further hardening). Rich