Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 1 Jan 2018 20:52:24 +0100
From: Markus Wichmann <>
Subject: Re: [PATCH] Add comments to i386 assembly source

On Sun, Dec 31, 2017 at 10:49:26AM -0500, Rich Felker wrote:
> I don't follow your reasoning here. Where are you getting the possible
> range of %gs from? If __clone is called with flags relevant to thread
> creation, %gs is necessarily a GDT entry. The LDT stuff in i386's
> __set_thread_area is only used to provide a working %gs for
> single-threaded processes on ancient kernels that lack thread support;
> in this case pthread_create always fails without calling __clone.

First of all, happy new year everybody.

The range of GS is rather simple: GS is a word in Intel-lingo, i.e. 16
bits, so that sets its range. Nothing else limits it down any way
further. Not the interpretation of it (there are 13 bits for selector
index, so enough for 8192 selector entries), not GDT size (the GDTR can
hold a size of at most 65535 bytes, which is enough for 8192 selector
entries if each entry is 8 bytes), not the ABI (kernel returns GDT index
as int), nor the API (set_thread_area(2) is underdocumented, anyway).

Now, __set_thread_area() for i386 only makes sense if Linux has a
different GDT for each thread: In the entire code, you make sure to only
allocate a single TLS array index for the whole process runtime, which
would be nonsense if the GDT were distributed any further. In that case,
exceeding twenty segments would be quite a feat, never mind two hundred.

Also, the thing about the LDT not being used except on kernels that
don't have threading, that should be documented as well. Solves the
question I had in the OP of this thread nicely.

> Thank you and Markus for reminding me why some comments would help
> here. :-)

You're welcome. :-)


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.