Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240321115806.511a81cc@inria.fr>
Date: Thu, 21 Mar 2024 11:58:06 +0100
From: Jₑₙₛ Gustedt <jens.gustedt@...ia.fr>
To: Thorsten Glaser <tg@...bsd.de>
Cc: musl@...ts.openwall.com
Subject: Re: Potential bug in __res_msend_rc() wrt to union
 initialization.

Hi,

on Tue, 19 Mar 2024 20:47:00 +0000 (UTC) you (Thorsten Glaser
<tg@...bsd.de>) wrote:

> Jₑₙₛ Gustedt dixit:
> 
> >seems to be to always put the biggest union member first, or to even
> >add an artificial first one `char [size-of-the-union] __dummy;`, such
> >that this is always 0-byte initialized if there is any
> >initialization  
> 
> But then you can just memset the union and then initialise any
> known pointer members to NULL/nullptr manually afterwards in the
> union’s member you actually need.
> 
> (IIRC, POSIX actively specifies the possible pointer members in
> these structs for that reason.)

no, that is actually not a full solution, I think. As soon as you store
to any member, padding bytes may change to arbitrary values. I don't
know if compilers really do that, but for example writing a wide
register that has garbage in the upper half could be valid in some
cases.

Also, I think that up-thread there was the idea that a statically
initialized object could be used to initialize an automatic object,
and that this would guarantee that the padding is transferred. There
is no such guarantee.

So if you have known places where the pointer members are situated,
you could try to ensure that you have an artificial union member as
first, that has pointers at these places and otherwise fills the gaps
with `unsigned char[something]`. That would guarantee that
initialization does the right thing for pointer members, that all other
bytes are zero-initialized, *and* that these values would be properly
transferred on union assignment.

Thanks
Jₑₙₛ

-- 
:: ICube :::::::::::::::::::::::::::::: deputy director ::
:: Université de Strasbourg :::::::::::::::::::::: ICPS ::
:: INRIA Nancy Grand Est :::::::::::::::::::::::: Camus ::
:: :::::::::::::::::::::::::::::::::::: ☎ +33 368854536 ::
:: https://icube-icps.unistra.fr/index.php/Jens_Gustedt ::

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.