Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Row, row, row your bits, gently down the stream...


devel / comp.lang.c / A Famous Security Bug

SubjectAuthor
* A Famous Security BugStefan Ram
+* Re: A Famous Security BugKaz Kylheku
|+* Re: A Famous Security BugScott Lurndal
||`* Re: A Famous Security BugKeith Thompson
|| `- Re: A Famous Security BugKeith Thompson
|+* Re: A Famous Security BugDavid Brown
||`* Re: A Famous Security BugKaz Kylheku
|| +* Re: A Famous Security BugChris M. Thomasson
|| |`* Re: A Famous Security BugScott Lurndal
|| | `* Re: A Famous Security BugChris M. Thomasson
|| |  `* Re: A Famous Security BugScott Lurndal
|| |   `* Re: A Famous Security BugChris M. Thomasson
|| |    `- Re: A Famous Security BugChris M. Thomasson
|| +* Re: A Famous Security BugKeith Thompson
|| |+* Re: A Famous Security BugKaz Kylheku
|| ||+* Re: A Famous Security BugKeith Thompson
|| |||`* Re: A Famous Security BugKaz Kylheku
|| ||| +* Re: A Famous Security BugJames Kuyper
|| ||| |`- Re: A Famous Security BugKaz Kylheku
|| ||| +- Re: A Famous Security BugDavid Brown
|| ||| `* Re: A Famous Security BugKeith Thompson
|| |||  `* Re: A Famous Security BugKaz Kylheku
|| |||   `* Re: A Famous Security BugDavid Brown
|| |||    `* Re: A Famous Security BugKaz Kylheku
|| |||     +* Re: A Famous Security BugDavid Brown
|| |||     |`- Re: A Famous Security BugKaz Kylheku
|| |||     `* Re: A Famous Security BugJames Kuyper
|| |||      `* Re: A Famous Security BugKaz Kylheku
|| |||       `* Re: A Famous Security BugDavid Brown
|| |||        `* Re: A Famous Security BugKaz Kylheku
|| |||         +* Re: A Famous Security BugDavid Brown
|| |||         |`* Re: A Famous Security BugKaz Kylheku
|| |||         | `- Re: A Famous Security BugDavid Brown
|| |||         `- Re: A Famous Security BugChris M. Thomasson
|| ||+- Re: A Famous Security BugJames Kuyper
|| ||`* Re: A Famous Security BugDavid Brown
|| || `* Re: A Famous Security BugKaz Kylheku
|| ||  `- Re: A Famous Security BugDavid Brown
|| |`* Re: A Famous Security BugJames Kuyper
|| | `* Re: A Famous Security BugKaz Kylheku
|| |  `- Re: A Famous Security BugJames Kuyper
|| `- Re: A Famous Security BugDavid Brown
|`* Re: A Famous Security BugAnton Shepelev
| +- Re: A Famous Security BugKeith Thompson
| +* Re: A Famous Security BugKaz Kylheku
| |+* Re: A Famous Security BugDavid Brown
| ||`* Re: A Famous Security BugKaz Kylheku
| || +- Re: A Famous Security BugJames Kuyper
| || `* Re: A Famous Security BugDavid Brown
| ||  `* Re: A Famous Security BugRichard Kettlewell
| ||   +- Re: A Famous Security BugKaz Kylheku
| ||   +* Re: A Famous Security BugDavid Brown
| ||   |`- Re: A Famous Security BugKaz Kylheku
| ||   `* Re: A Famous Security BugTim Rentsch
| ||    `* Re: A Famous Security BugMalcolm McLean
| ||     `* Re: A Famous Security BugTim Rentsch
| ||      +- Re: A Famous Security BugDavid Brown
| ||      `- Re: A Famous Security BugKeith Thompson
| |`* Re: A Famous Security BugAnton Shepelev
| | `- Re: A Famous Security BugScott Lurndal
| +- Re: A Famous Security BugTim Rentsch
| `* Re: A Famous Security BugJames Kuyper
|  `* Re: A Famous Security Bugbart
|   +* Re: A Famous Security BugKeith Thompson
|   |`* Re: A Famous Security BugKaz Kylheku
|   | `* Re: A Famous Security BugDavid Brown
|   |  +- Re: A Famous Security BugScott Lurndal
|   |  `* Re: A Famous Security Bugbart
|   |   `- Re: A Famous Security BugDavid Brown
|   `* Re: A Famous Security BugJames Kuyper
|    `* Re: A Famous Security Bugbart
|     +* Re: A Famous Security BugDavid Brown
|     |`* Re: A Famous Security Bugbart
|     | +* Re: A Famous Security BugDavid Brown
|     | |`* Re: A Famous Security Bugbart
|     | | +* Re: A Famous Security BugKeith Thompson
|     | | |+- Re: A Famous Security BugDavid Brown
|     | | |+* Re: A Famous Security BugMichael S
|     | | ||+- Re: A Famous Security BugDavid Brown
|     | | ||`- Re: A Famous Security BugKeith Thompson
|     | | |`* Re: A Famous Security Bugbart
|     | | | `* Re: A Famous Security BugMichael S
|     | | |  +* Re: A Famous Security Bugbart
|     | | |  |+* Re: A Famous Security BugDavid Brown
|     | | |  ||`* Re: A Famous Security BugMalcolm McLean
|     | | |  || `- Re: A Famous Security BugMichael S
|     | | |  |`- Re: A Famous Security BugScott Lurndal
|     | | |  `* Re: A Famous Security BugDavid Brown
|     | | |   `- Re: A Famous Security BugScott Lurndal
|     | | `* Re: A Famous Security BugDavid Brown
|     | |  `* Re: A Famous Security BugMichael S
|     | |   `* Re: A Famous Security BugDavid Brown
|     | |    +* Re: A Famous Security BugMichael S
|     | |    |+- Re: A Famous Security BugDavid Brown
|     | |    |`- Re: A Famous Security Bugbart
|     | |    `* Re: A Famous Security Bugbart
|     | |     +* Re: A Famous Security BugMichael S
|     | |     |`* Re: A Famous Security Bugbart
|     | |     | +* Re: A Famous Security BugDavid Brown
|     | |     | |`- Re: A Famous Security BugScott Lurndal
|     | |     | `* Re: A Famous Security BugMichael S
|     | |     `- Re: A Famous Security BugDavid Brown
|     | `* Re: A Famous Security BugMichael S
|     +- Re: A Famous Security BugTim Rentsch
|     +- Re: A Famous Security BugMichael S
|     +* Re: A Famous Security BugMichael S
|     `- Re: A Famous Security BugJames Kuyper
+- Re: A Famous Security BugJoerg Mertens
+* Re: A Famous Security BugChris M. Thomasson
`* Re: A Famous Security BugStefan Ram

Pages:123456
A Famous Security Bug

<bug-20240320191736@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34568&group=comp.lang.c#34568

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: A Famous Security Bug
Date: 20 Mar 2024 18:18:37 GMT
Organization: Stefan Ram
Lines: 10
Expires: 1 Feb 2025 11:59:58 GMT
Message-ID: <bug-20240320191736@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de I9JOY+2UYzWi+eC9rGl6qw8ujl8wymBYs9D1NCznUxEe7x
Cancel-Lock: sha1:xQ8tCdvLLcfG9UbtFZgkwMDqhqc= sha256:PBw0eW5LlXFR1UIZF9Ieyopw2OOO89oSpNC7x0tToMQ=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE-1901, en-US, it, fr-FR
 by: Stefan Ram - Wed, 20 Mar 2024 18:18 UTC

A "famous security bug":

void f( void )
{ char buffer[ MAX ];
/* . . . */
memset( buffer, 0, sizeof( buffer )); }

. Can you see what the bug is?

(I have already read the answer; I post it as a pastime.)

Re: A Famous Security Bug

<20240320114218.151@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34569&group=comp.lang.c#34569

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Wed, 20 Mar 2024 18:54:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <20240320114218.151@kylheku.com>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
Injection-Date: Wed, 20 Mar 2024 18:54:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="722e78c67748d1849c972971dd333b29";
logging-data="1746824"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Yz8IxQJJUC+kymQ6uePN9KkR9mdQsO70="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:F0hlTaJnE4+qE8a4199L7cKLqcU=
 by: Kaz Kylheku - Wed, 20 Mar 2024 18:54 UTC

On 2024-03-20, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
> A "famous security bug":
>
> void f( void )
> { char buffer[ MAX ];
> /* . . . */
> memset( buffer, 0, sizeof( buffer )); }
>
> . Can you see what the bug is?

I don't know about "the bug", but conditions can be identified under
which that would have a problem executing, like MAX being in excess
of available automatic storage.

If the /*...*/ comment represents the elision of some security sensitive
code, where the memset is intended to obliterate secret information,
of course, that obliteration is not required to work.

After the memset, the buffer has no next use, so the all the assignments
performed by memset to the bytes of buffer are dead assignments that can
be elided.

To securely clear memory, you have to use a function for that purpose
that is not susceptible to optimization.

If you're not doing anything stupid, like link time optimization, an
external function in another translation unit (a function that the
compiler doesn't recognize as being an alias or wrapper for memset)
ought to suffice.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: A Famous Security Bug

<87ttl0pw4n.fsf@jmertens.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34570&group=comp.lang.c#34570

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!jmertens.eternal-september.org!.POSTED!not-for-mail
From: joerg-me...@t-online.de (Joerg Mertens)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Wed, 20 Mar 2024 19:59:36 +0100
Organization: privat
Lines: 15
Message-ID: <87ttl0pw4n.fsf@jmertens.eternal-september.org>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: jmertens.eternal-september.org; posting-host="93220d0a9bfe326c1e31a6e4f5afab60";
logging-data="1746594"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zCf/XN+wjUiWhatmJa2sVmQJiz5E8iQ4="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:H2GmYbpIpbb2ooaegGdV7FWzdNo=
sha1:UX4L/0cpl8pEKypd1ZRYdWi00G0=
 by: Joerg Mertens - Wed, 20 Mar 2024 18:59 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:

> A "famous security bug":
>
> void f( void )
> { char buffer[ MAX ];
> /* . . . */
> memset( buffer, 0, sizeof( buffer )); }
>
> . Can you see what the bug is?
>
> (I have already read the answer; I post it as a pastime.)

The optimizer deletes the memset statement because buffer is not
accessed after it?

Re: A Famous Security Bug

<utfdte$1lou1$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34571&group=comp.lang.c#34571

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Wed, 20 Mar 2024 12:37:17 -0700
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <utfdte$1lou1$1@dont-email.me>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 20 Mar 2024 19:37:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="52d051050d0f5afbf153f83776a931b4";
logging-data="1762241"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19eK/+8Dv4XlPd5Fbf9mN7xc4z03OVxtd4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Ni2quesqp+bfx2ePhhSaGTDkHvU=
Content-Language: en-US
In-Reply-To: <bug-20240320191736@ram.dialup.fu-berlin.de>
 by: Chris M. Thomasson - Wed, 20 Mar 2024 19:37 UTC

On 3/20/2024 11:18 AM, Stefan Ram wrote:
> A "famous security bug":
>
> void f( void )
> { char buffer[ MAX ];
> /* . . . */
> memset( buffer, 0, sizeof( buffer )); }
>
> . Can you see what the bug is?
>
> (I have already read the answer; I post it as a pastime.)

Add in a volatile? ;^)

Re: A Famous Security Bug

<lXGKN.156286$t8cc.2924@fx06.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34572&group=comp.lang.c#34572

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.niel.me!news.gegeweb.eu!gegeweb.org!usenet-fr.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx06.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: A Famous Security Bug
Newsgroups: comp.lang.c
References: <bug-20240320191736@ram.dialup.fu-berlin.de> <20240320114218.151@kylheku.com>
Lines: 18
Message-ID: <lXGKN.156286$t8cc.2924@fx06.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 20 Mar 2024 19:38:57 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 20 Mar 2024 19:38:57 GMT
X-Received-Bytes: 1293
 by: Scott Lurndal - Wed, 20 Mar 2024 19:38 UTC

Kaz Kylheku <433-929-6894@kylheku.com> writes:
>On 2024-03-20, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>> A "famous security bug":
>>
>> void f( void )
>> { char buffer[ MAX ];
>> /* . . . */
>> memset( buffer, 0, sizeof( buffer )); }
>>
>> . Can you see what the bug is?
>
>I don't know about "the bug", but conditions can be identified under
>which that would have a problem executing, like MAX being in excess
>of available automatic storage.

Perhaps Stephan is under the mistaken assumption that
'buffer' devolves to a type of 'char *' when used
with the sizeof operator.

Re: A Famous Security Bug

<utfecl$1lou2$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34573&group=comp.lang.c#34573

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Wed, 20 Mar 2024 12:45:25 -0700
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <utfecl$1lou2$1@dont-email.me>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<utfdte$1lou1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 20 Mar 2024 19:45:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="52d051050d0f5afbf153f83776a931b4";
logging-data="1762242"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Yfe70mdP4/Q3KgbgOl2KJuJ2fn0gZNlw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:RvWB59bSEQif6hCMYNy22Sxd8Bc=
Content-Language: en-US
In-Reply-To: <utfdte$1lou1$1@dont-email.me>
 by: Chris M. Thomasson - Wed, 20 Mar 2024 19:45 UTC

On 3/20/2024 12:37 PM, Chris M. Thomasson wrote:
> On 3/20/2024 11:18 AM, Stefan Ram wrote:
>>    A "famous security bug":
>>
>> void f( void )
>> { char buffer[ MAX ];
>>    /* . . . */
>>    memset( buffer, 0, sizeof( buffer )); }
>>
>>    . Can you see what the bug is?
>>
>>    (I have already read the answer; I post it as a pastime.)
>
> Add in a volatile? ;^)

Also, show us the definition of MAX...

Re: A Famous Security Bug

<87zfus1txp.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34579&group=comp.lang.c#34579

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.chmurka.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Wed, 20 Mar 2024 14:20:50 -0700
Organization: None to speak of
Lines: 33
Message-ID: <87zfus1txp.fsf@nosuchdomain.example.com>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<20240320114218.151@kylheku.com> <lXGKN.156286$t8cc.2924@fx06.iad>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="5d6dd62c05ea9ae13c7053cd9c4c457b";
logging-data="1815152"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196NRTxR7HVtsqt7DwnZF4D"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:ri0jQKTo9IDw1PRDMb+YPVerzd8=
sha1:PolEQWvgKU/bMSoffH4IY3iYIwA=
 by: Keith Thompson - Wed, 20 Mar 2024 21:20 UTC

scott@slp53.sl.home (Scott Lurndal) writes:
> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>>On 2024-03-20, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>>> A "famous security bug":
>>>
>>> void f( void )
>>> { char buffer[ MAX ];
>>> /* . . . */
>>> memset( buffer, 0, sizeof( buffer )); }
>>>
>>> . Can you see what the bug is?
>>
>>I don't know about "the bug", but conditions can be identified under
>>which that would have a problem executing, like MAX being in excess
>>of available automatic storage.
>
> Perhaps Stephan is under the mistaken assumption that
> 'buffer' devolves to a type of 'char *' when used
> with the sizeof operator.

That was my first thought, but I think the idea (not clearly stated) is
that the /* . . . */ code stores sensitive information in buffer, and
the memset call is intended to clobber that information, but may be
elided since buffer is not explicitly used later. A malicious process
with access to the program's memory might be able to read that
information after f() has returned.

C23 adds memset_explicit() for this purpose.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: A Famous Security Bug

<87v85g1tsn.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34580&group=comp.lang.c#34580

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Wed, 20 Mar 2024 14:23:52 -0700
Organization: None to speak of
Lines: 36
Message-ID: <87v85g1tsn.fsf@nosuchdomain.example.com>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<20240320114218.151@kylheku.com> <lXGKN.156286$t8cc.2924@fx06.iad>
<87zfus1txp.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="5d6dd62c05ea9ae13c7053cd9c4c457b";
logging-data="1815152"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2m39vwk8qvztkC2lhX+ZF"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:UCz3GPEZI3qgxygOih3Ml3kLc0s=
sha1:CYhy/Se1fqmMU8FECJ1Z6DM3ABM=
 by: Keith Thompson - Wed, 20 Mar 2024 21:23 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> scott@slp53.sl.home (Scott Lurndal) writes:
>> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>>>On 2024-03-20, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>>>> A "famous security bug":
>>>>
>>>> void f( void )
>>>> { char buffer[ MAX ];
>>>> /* . . . */
>>>> memset( buffer, 0, sizeof( buffer )); }
>>>>
>>>> . Can you see what the bug is?
>>>
>>>I don't know about "the bug", but conditions can be identified under
>>>which that would have a problem executing, like MAX being in excess
>>>of available automatic storage.
>>
>> Perhaps Stephan is under the mistaken assumption that
>> 'buffer' devolves to a type of 'char *' when used
>> with the sizeof operator.
>
> That was my first thought, but I think the idea (not clearly stated) is
> that the /* . . . */ code stores sensitive information in buffer, and
> the memset call is intended to clobber that information, but may be
> elided since buffer is not explicitly used later. A malicious process
> with access to the program's memory might be able to read that
> information after f() has returned.

And I should acknowledge that Kaz mentioned that before I did.

> C23 adds memset_explicit() for this purpose.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: A Famous Security Bug

<utfmd6$1nv2m$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34582&group=comp.lang.c#34582

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Wed, 20 Mar 2024 15:02:14 -0700
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <utfmd6$1nv2m$1@dont-email.me>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<utfdte$1lou1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 20 Mar 2024 22:02:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="52d051050d0f5afbf153f83776a931b4";
logging-data="1834070"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//f9aoXbx7j9Ej1hA9m0mkL7UxD9GVZ+U="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:m6O4HlE4Qe44SaAMcu/Jk/iYOlQ=
Content-Language: en-US
In-Reply-To: <utfdte$1lou1$1@dont-email.me>
 by: Chris M. Thomasson - Wed, 20 Mar 2024 22:02 UTC

On 3/20/2024 12:37 PM, Chris M. Thomasson wrote:
> On 3/20/2024 11:18 AM, Stefan Ram wrote:
>>    A "famous security bug":
>>
>> void f( void )
>> { char buffer[ MAX ];
>>    /* . . . */
>>    memset( buffer, 0, sizeof( buffer )); }
>>
>>    . Can you see what the bug is?
>>
>>    (I have already read the answer; I post it as a pastime.)
>
> Add in a volatile? ;^)

Instead of zeroing, what about filling it with random bytes reaped from
a TRNG?

Re: A Famous Security Bug

<87r0g41ofh.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34583&group=comp.lang.c#34583

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Wed, 20 Mar 2024 16:19:46 -0700
Organization: None to speak of
Lines: 24
Message-ID: <87r0g41ofh.fsf@nosuchdomain.example.com>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<utfdte$1lou1$1@dont-email.me> <utfmd6$1nv2m$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="0bf58c5e3e50115de10475b5e7b86fc1";
logging-data="1869328"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4KCf8n/PgZ0qz3RblXh58"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:7aTzL8ms29Vv/yGTXwIhpZJBHts=
sha1:Rd7e1G5oMjJ/J+jp647FoJTlZlg=
 by: Keith Thompson - Wed, 20 Mar 2024 23:19 UTC

"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
> On 3/20/2024 12:37 PM, Chris M. Thomasson wrote:
>> On 3/20/2024 11:18 AM, Stefan Ram wrote:
>>>    A "famous security bug":
>>>
>>> void f( void )
>>> { char buffer[ MAX ];
>>>    /* . . . */
>>>    memset( buffer, 0, sizeof( buffer )); }
>>>
>>>    . Can you see what the bug is?
>>>
>>>    (I have already read the answer; I post it as a pastime.)
>> Add in a volatile? ;^)
>
> Instead of zeroing, what about filling it with random bytes reaped
> from a TRNG?

Why?

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: A Famous Security Bug

<utg6vq$1vdv8$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34584&group=comp.lang.c#34584

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Wed, 20 Mar 2024 19:45:14 -0700
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <utg6vq$1vdv8$1@dont-email.me>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<utfdte$1lou1$1@dont-email.me> <utfmd6$1nv2m$1@dont-email.me>
<87r0g41ofh.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 21 Mar 2024 02:45:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2ab8e2f24273ba6122fc526819eafbc5";
logging-data="2078696"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7/1jr7QjMPR0emyuigAQ7Zp6xAGek5lc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:n4u9gkBNkMTVxizLkqDEG9IkAqY=
In-Reply-To: <87r0g41ofh.fsf@nosuchdomain.example.com>
Content-Language: en-US
 by: Chris M. Thomasson - Thu, 21 Mar 2024 02:45 UTC

On 3/20/2024 4:19 PM, Keith Thompson wrote:
> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>> On 3/20/2024 12:37 PM, Chris M. Thomasson wrote:
>>> On 3/20/2024 11:18 AM, Stefan Ram wrote:
>>>>    A "famous security bug":
>>>>
>>>> void f( void )
>>>> { char buffer[ MAX ];
>>>>    /* . . . */
>>>>    memset( buffer, 0, sizeof( buffer )); }
>>>>
>>>>    . Can you see what the bug is?
>>>>
>>>>    (I have already read the answer; I post it as a pastime.)
>>> Add in a volatile? ;^)
>>
>> Instead of zeroing, what about filling it with random bytes reaped
>> from a TRNG?
>
> Why?
>

Those zeros might be "targets" for a nefarious program?

Re: A Famous Security Bug

<uthirj$29aoc$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34595&group=comp.lang.c#34595

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Thu, 21 Mar 2024 16:13:54 +0100
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <uthirj$29aoc$1@dont-email.me>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<20240320114218.151@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 21 Mar 2024 15:13:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9083fc13632a11f6b0fc246dd1fa196c";
logging-data="2403084"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180k+29a8qKSF+SmmUIfNye8keaWQFqIUk="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:VKhQPVSA+91Z4bjBp9coiPmtKWY=
Content-Language: en-GB
In-Reply-To: <20240320114218.151@kylheku.com>
 by: David Brown - Thu, 21 Mar 2024 15:13 UTC

On 20/03/2024 19:54, Kaz Kylheku wrote:
> On 2024-03-20, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>> A "famous security bug":
>>
>> void f( void )
>> { char buffer[ MAX ];
>> /* . . . */
>> memset( buffer, 0, sizeof( buffer )); }
>>
>> . Can you see what the bug is?
>
> I don't know about "the bug", but conditions can be identified under
> which that would have a problem executing, like MAX being in excess
> of available automatic storage.
>
> If the /*...*/ comment represents the elision of some security sensitive
> code, where the memset is intended to obliterate secret information,
> of course, that obliteration is not required to work.
>
> After the memset, the buffer has no next use, so the all the assignments
> performed by memset to the bytes of buffer are dead assignments that can
> be elided.
>
> To securely clear memory, you have to use a function for that purpose
> that is not susceptible to optimization.
>
> If you're not doing anything stupid, like link time optimization, an
> external function in another translation unit (a function that the
> compiler doesn't recognize as being an alias or wrapper for memset)
> ought to suffice.
>

Using LTO is not "stupid". Relying on people /not/ using LTO, or not
using other valid optimisations, is "stupid".

/Really/ dealing with this kind of potential data leakage is a
multi-faceted problem. Does it matter if you zero out this buffer, if
that is just in the cache and the original password data is still in the
ram ready to be read with a Rowhammer attack? Or if there is a copy
somewhere else in code that used it?

Of course it is important to deal with possible security issues at every
practical point, so zeroing out this buffer is part of the solution - as
long as no one thinks that using C23's memset_explicit(), or similar
functions, are somehow complete fixes.

Calling an external function in another translation unit, however, is
not a way to guarantee particular effects. Using volatile accesses is
better (if you don't have a suitable function with the right guarantees
for your target OS and/or C version). There are also compiler-specific
ways, such as adding "__asm__("" : "+m" (buffer));" after the memset.

Re: A Famous Security Bug

<20240321092738.111@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34601&group=comp.lang.c#34601

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Thu, 21 Mar 2024 17:41:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 91
Message-ID: <20240321092738.111@kylheku.com>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<20240320114218.151@kylheku.com> <uthirj$29aoc$1@dont-email.me>
Injection-Date: Thu, 21 Mar 2024 17:41:32 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8a88f4f3d1bb162453330ac9f4d394b5";
logging-data="2473520"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ePqATicfSp4PLNHnpQuKNEWQhZXxXDy4="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:nawoCiL1BtF+SvWsiWxOTEPrz/I=
 by: Kaz Kylheku - Thu, 21 Mar 2024 17:41 UTC

On 2024-03-21, David Brown <david.brown@hesbynett.no> wrote:
> On 20/03/2024 19:54, Kaz Kylheku wrote:
>> On 2024-03-20, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>>> A "famous security bug":
>>>
>>> void f( void )
>>> { char buffer[ MAX ];
>>> /* . . . */
>>> memset( buffer, 0, sizeof( buffer )); }
>>>
>>> . Can you see what the bug is?
>>
>> I don't know about "the bug", but conditions can be identified under
>> which that would have a problem executing, like MAX being in excess
>> of available automatic storage.
>>
>> If the /*...*/ comment represents the elision of some security sensitive
>> code, where the memset is intended to obliterate secret information,
>> of course, that obliteration is not required to work.
>>
>> After the memset, the buffer has no next use, so the all the assignments
>> performed by memset to the bytes of buffer are dead assignments that can
>> be elided.
>>
>> To securely clear memory, you have to use a function for that purpose
>> that is not susceptible to optimization.
>>
>> If you're not doing anything stupid, like link time optimization, an
>> external function in another translation unit (a function that the
>> compiler doesn't recognize as being an alias or wrapper for memset)
>> ought to suffice.
>
> Using LTO is not "stupid". Relying on people /not/ using LTO, or not
> using other valid optimisations, is "stupid".

LTO is a nonconforming optimization. It destroys the concept that
when a translation unit is translated, the semantic analysis is
complete, such that the only remaining activity is resolution of
external references (linkage), and that the semantic analysis of one
translation unit deos not use information about another translation
unit.

This has not yet changed in last April's N3096 draft, where
translation phases 7 and 8 are:

7. White-space characters separating tokens are no longer significant.
Each preprocessing token is converted into a token. The resulting
tokens are syntactically and semantically analyzed and translated
as a translation unit.

8. All external object and function references are resolved. Library
components are linked to satisfy external references to functions
and objects not defined in the current translation. All such
translator output is collected into a program image which contains
information needed for execution in its execution environment.

and before that, the Program Structure section says:

The separate translation units of a program communicate by (for
example) calls to functions whose identifiers have external linkage,
manipulation of objects whose identifiers have external linkage, or
manipulation of data files. Translation units may be separately
translated and then later linked to produce an executable program.

LTO deviates from the the model that translation units are separate,
and the conceptual steps of phases 7 and 8.

The translation unit that is prepared for LTO is not fully cooked. You
have no idea what its code will turn into when the interrupted
compilation is resumed during linkage, under the influence of other
tranlation units it is combined with.

So in fact, the language allows us to take it for granted that, given

my_memset(array, 0, sizeof(array)); }

at the end of a function, and my_memset is an external definition
provided by another translation unit, the call may not be elided.

The one who may be acting recklessly is he who turns on nonconforming
optimizations that are not documented as supported by the code base.

Another example would be something like gcc's -ffast-math.
You wouldn't unleash that on numerical code written by experts,
and expect the same correct results.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: A Famous Security Bug

<20240321211306.779b21d126e122556c34a346@gmail.moc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34603&group=comp.lang.c#34603

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Thu, 21 Mar 2024 21:13:06 +0300
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <20240321211306.779b21d126e122556c34a346@gmail.moc>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<20240320114218.151@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="0089de06f09c3e7028230bfe3077fa53";
logging-data="2488812"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2pw0xKig6TzMvrghFC0vMW2mAXwSP70k="
Cancel-Lock: sha1:x+huX5MiRr+U72XNJpb6TuD/2BM=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Thu, 21 Mar 2024 18:13 UTC

Kaz Kylheku to Stefan Ram:

> > > A "famous security bug":
> > >
> > > void f( void )
> > > { char buffer[ MAX ];
> > > /* . . . */
> > > memset( buffer, 0, sizeof( buffer )); }
> > >
> > > . Can you see what the bug is?
>
> I don't know about "the bug", but conditions can be
> identified under which that would have a problem
> executing, like MAX being in excess of available automatic
> storage.
>
> If the /*...*/ comment represents the elision of some
> security sensitive code, where the memset is intended to
> obliterate secret information, of course, that
> obliteration is not required to work.
>
> After the memset, the buffer has no next use, so the all
> the assignments performed by memset to the bytes of buffer
> are dead assignments that can be elided.
>
> To securely clear memory, you have to use a function for
> that purpose that is not susceptible to optimization.

I think this behavior (of a C compiler) rather stupid. In a
low-level imperative language, the compiled program shall
do whatever the programmer commands it to do. If he
commands it to clear the buffer, it shall clear the buffer.
This optimisation is too high-level, too counter-inituitive,
even deceitful. The optimiser is free to perform the task
in the fastest manner possible, but it shall not ignore the
programmer's order to zero-fill the buffer, especially
without emitting a warning about (potentially!) redundant
code, which it is the programmer's reponsibility to confirm
and remove.

Redundant code shall be dealt with in the source, rather than
in the executable.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: A Famous Security Bug

<uti2am$2d2ts$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34606&group=comp.lang.c#34606

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Thu, 21 Mar 2024 12:37:58 -0700
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <uti2am$2d2ts$1@dont-email.me>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<20240320114218.151@kylheku.com> <uthirj$29aoc$1@dont-email.me>
<20240321092738.111@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 21 Mar 2024 19:37:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2ab8e2f24273ba6122fc526819eafbc5";
logging-data="2526140"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19duyUc1EgzcGgOO8SI1YWHtWB6pkrJaHg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:sfyLmJhc8fg/FoqZT5r6veQDe+o=
In-Reply-To: <20240321092738.111@kylheku.com>
Content-Language: en-US
 by: Chris M. Thomasson - Thu, 21 Mar 2024 19:37 UTC

On 3/21/2024 10:41 AM, Kaz Kylheku wrote:
> On 2024-03-21, David Brown <david.brown@hesbynett.no> wrote:
>> On 20/03/2024 19:54, Kaz Kylheku wrote:
>>> On 2024-03-20, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>>>> A "famous security bug":
>>>>
>>>> void f( void )
>>>> { char buffer[ MAX ];
>>>> /* . . . */
>>>> memset( buffer, 0, sizeof( buffer )); }
>>>>
>>>> . Can you see what the bug is?
>>>
>>> I don't know about "the bug", but conditions can be identified under
>>> which that would have a problem executing, like MAX being in excess
>>> of available automatic storage.
>>>
>>> If the /*...*/ comment represents the elision of some security sensitive
>>> code, where the memset is intended to obliterate secret information,
>>> of course, that obliteration is not required to work.
>>>
>>> After the memset, the buffer has no next use, so the all the assignments
>>> performed by memset to the bytes of buffer are dead assignments that can
>>> be elided.
>>>
>>> To securely clear memory, you have to use a function for that purpose
>>> that is not susceptible to optimization.
>>>
>>> If you're not doing anything stupid, like link time optimization, an
>>> external function in another translation unit (a function that the
>>> compiler doesn't recognize as being an alias or wrapper for memset)
>>> ought to suffice.
>>
>> Using LTO is not "stupid". Relying on people /not/ using LTO, or not
>> using other valid optimisations, is "stupid".
>
> LTO is a nonconforming optimization. It destroys the concept that
> when a translation unit is translated, the semantic analysis is
> complete, such that the only remaining activity is resolution of
> external references (linkage), and that the semantic analysis of one
> translation unit deos not use information about another translation
> unit.
>[...]

Side note:

Actually, way back (pre c/c++ 11), I was worried about LTO messing up my
custom, highly sensitive sync code.

https://web.archive.org/web/20070509044340/http://appcore.home.comcast.net/

Notice the externally assembled functions comment?

"All of its “critical-sequences” are contained in externally assembled
functions ( read all ) in order to prevent a rouge C compiler from
reordering anything that would corrupt the data-structure. The queue
allocates its nodes from a three-level cache"

If a damn "rogue" compiler can mess with my custom ASM then things are
going to be broken...

;^)

Re: A Famous Security Bug

<87il1f1ie2.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34608&group=comp.lang.c#34608

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Thu, 21 Mar 2024 12:42:29 -0700
Organization: None to speak of
Lines: 85
Message-ID: <87il1f1ie2.fsf@nosuchdomain.example.com>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<20240320114218.151@kylheku.com>
<20240321211306.779b21d126e122556c34a346@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="0bf58c5e3e50115de10475b5e7b86fc1";
logging-data="2532317"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19guZPEpbD+tNfuRHCiNdwi"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:UVJTjP+V4zbs4q2eDVKwKfytHBk=
sha1:Qm2e65Z+EfLOLBhy5N59JMALyro=
 by: Keith Thompson - Thu, 21 Mar 2024 19:42 UTC

Anton Shepelev <anton.txt@gmail.moc> writes:
> Kaz Kylheku to Stefan Ram:
>
>> > > A "famous security bug":
>> > >
>> > > void f( void )
>> > > { char buffer[ MAX ];
>> > > /* . . . */
>> > > memset( buffer, 0, sizeof( buffer )); }
>> > >
>> > > . Can you see what the bug is?
>>
>> I don't know about "the bug", but conditions can be
>> identified under which that would have a problem
>> executing, like MAX being in excess of available automatic
>> storage.
>>
>> If the /*...*/ comment represents the elision of some
>> security sensitive code, where the memset is intended to
>> obliterate secret information, of course, that
>> obliteration is not required to work.
>>
>> After the memset, the buffer has no next use, so the all
>> the assignments performed by memset to the bytes of buffer
>> are dead assignments that can be elided.
>>
>> To securely clear memory, you have to use a function for
>> that purpose that is not susceptible to optimization.
>
> I think this behavior (of a C compiler) rather stupid. In a
> low-level imperative language, the compiled program shall
> do whatever the programmer commands it to do. If he
> commands it to clear the buffer, it shall clear the buffer.
> This optimisation is too high-level, too counter-inituitive,
> even deceitful. The optimiser is free to perform the task
> in the fastest manner possible, but it shall not ignore the
> programmer's order to zero-fill the buffer, especially
> without emitting a warning about (potentially!) redundant
> code, which it is the programmer's reponsibility to confirm
> and remove.
>
> Redundant code shall be dealt with in the source, rather than
> in the executable.

Then C is not what you call a "low-level imperative language", and none
of your "shall"s apply to the language defined by the ISO C standard.

C programs define behavior, not generated machine code. If an
implementation can implement the behavior of a C program with a memset()
call without invoking memset(), it's free to do so.

The programmer's intent in the code snippet that started this thread was
for the memset call to erase sensitive data in memory that, after the
function returns, is not part of any object. C (prior to C23) doesn't
provide a way to do that. Any program whose observable behavior differs
depending on whether that memory was cleared has undefined behavior.

Judicious use of "volatile" should avoid the problem.

5.1.2.3p6:

The least requirements on a conforming implementation are:

- Volatile accesses to objects are evaluated strictly according
to the rules of the abstract machine.

- At program termination, all data written into files shall be
identical to the result that execution of the program according
to the abstract semantics would have produced.

- The input and output dynamics of interactive devices shall take
place as specified in 7.23.3. The intent of these requirements
is that unbuffered or line-buffered output appear as soon as
possible, to ensure that prompting messages appear prior to a
program waiting for input.

This is the *observable behavior* of the program.

If you think that's stupid, I won't try to change your mind, but the
meaning is clear.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: A Famous Security Bug

<ZE0LN.84950$_a1e.38190@fx16.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34612&group=comp.lang.c#34612

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx16.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: A Famous Security Bug
Newsgroups: comp.lang.c
References: <bug-20240320191736@ram.dialup.fu-berlin.de> <20240320114218.151@kylheku.com> <uthirj$29aoc$1@dont-email.me> <20240321092738.111@kylheku.com> <uti2am$2d2ts$1@dont-email.me>
Lines: 6
Message-ID: <ZE0LN.84950$_a1e.38190@fx16.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 21 Mar 2024 20:21:13 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 21 Mar 2024 20:21:13 GMT
X-Received-Bytes: 944
 by: Scott Lurndal - Thu, 21 Mar 2024 20:21 UTC

"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:

>"All of its “critical-sequences” are contained in externally assembled
>functions ( read all ) in order to prevent a rouge C compiler from

As opposed to a viridian C compiler?

Re: A Famous Security Bug

<20240321131621.321@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34613&group=comp.lang.c#34613

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Thu, 21 Mar 2024 20:21:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <20240321131621.321@kylheku.com>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<20240320114218.151@kylheku.com>
<20240321211306.779b21d126e122556c34a346@gmail.moc>
Injection-Date: Thu, 21 Mar 2024 20:21:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8a88f4f3d1bb162453330ac9f4d394b5";
logging-data="2546182"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18EWlZNvykcYP4fzip3Yzm7wZiybQRpVF4="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:AZ6UDuabQAurTEXyAezQsAk2b1A=
 by: Kaz Kylheku - Thu, 21 Mar 2024 20:21 UTC

On 2024-03-21, Anton Shepelev <anton.txt@gmail.moc> wrote:
> Kaz Kylheku to Stefan Ram:
>
>> > > A "famous security bug":
>> > >
>> > > void f( void )
>> > > { char buffer[ MAX ];
>> > > /* . . . */
>> > > memset( buffer, 0, sizeof( buffer )); }
>> > >
>> > > . Can you see what the bug is?
>>
>> I don't know about "the bug", but conditions can be
>> identified under which that would have a problem
>> executing, like MAX being in excess of available automatic
>> storage.
>>
>> If the /*...*/ comment represents the elision of some
>> security sensitive code, where the memset is intended to
>> obliterate secret information, of course, that
>> obliteration is not required to work.
>>
>> After the memset, the buffer has no next use, so the all
>> the assignments performed by memset to the bytes of buffer
>> are dead assignments that can be elided.
>>
>> To securely clear memory, you have to use a function for
>> that purpose that is not susceptible to optimization.
>
> I think this behavior (of a C compiler) rather stupid. In a
> low-level imperative language, the compiled program shall
> do whatever the programmer commands it to do. If he
> commands it to clear the buffer, it shall clear the buffer.
> This optimisation is too high-level, too counter-inituitive,
> even deceitful. The optimiser is free to perform the task
> in the fastest manner possible, but it shall not ignore the
> programmer's order to zero-fill the buffer, especially
> without emitting a warning about (potentially!) redundant
> code, which it is the programmer's reponsibility to confirm
> and remove.

If C compilers warned about every piece of dead code that is eliminated,
you'd be up to your ears in diagnostics all day.

Then there is the question of how to silence them on a case-by-case
basis: I did want /that/ code to be eliminated, but not that one.

If you do want the code deleted, that doesn't always mean
you can do it yoruself. What gets eliminated can be target
dependent:

switch (sizeof (long)) {
case 4: ...
case 8: ..
}

Eliminating dead stores is a very basic dataflow-driven optimization.

Because memset is part of the C language, the compiler knows
exactly what effect it has (that it's equivalent to setting
all the bytes to zero, like a sequence of assignments).

If you don't want a call to be optimized away, call your
own function in another translation unit. (And don't turn
on nonconforming cross-translation-unit optimizations.)

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: A Famous Security Bug

<87a5mr1ffp.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34616&group=comp.lang.c#34616

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Thu, 21 Mar 2024 13:46:18 -0700
Organization: None to speak of
Lines: 82
Message-ID: <87a5mr1ffp.fsf@nosuchdomain.example.com>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<20240320114218.151@kylheku.com> <uthirj$29aoc$1@dont-email.me>
<20240321092738.111@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="0bf58c5e3e50115de10475b5e7b86fc1";
logging-data="2555344"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18YJSAMYzAHgY2S/1mquPZQ"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:5IwFfga2XoaNsqclJf60yxWh5xw=
sha1:EVE7EBpS7QvAjLik3VTShMVd0d4=
 by: Keith Thompson - Thu, 21 Mar 2024 20:46 UTC

Kaz Kylheku <433-929-6894@kylheku.com> writes:
> On 2024-03-21, David Brown <david.brown@hesbynett.no> wrote:
>> On 20/03/2024 19:54, Kaz Kylheku wrote:
>>> On 2024-03-20, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>>>> A "famous security bug":
>>>>
>>>> void f( void )
>>>> { char buffer[ MAX ];
>>>> /* . . . */
>>>> memset( buffer, 0, sizeof( buffer )); }
>>>>
>>>> . Can you see what the bug is?
>>>
>>> I don't know about "the bug", but conditions can be identified under
>>> which that would have a problem executing, like MAX being in excess
>>> of available automatic storage.
>>>
>>> If the /*...*/ comment represents the elision of some security sensitive
>>> code, where the memset is intended to obliterate secret information,
>>> of course, that obliteration is not required to work.
>>>
>>> After the memset, the buffer has no next use, so the all the assignments
>>> performed by memset to the bytes of buffer are dead assignments that can
>>> be elided.
>>>
>>> To securely clear memory, you have to use a function for that purpose
>>> that is not susceptible to optimization.
>>>
>>> If you're not doing anything stupid, like link time optimization, an
>>> external function in another translation unit (a function that the
>>> compiler doesn't recognize as being an alias or wrapper for memset)
>>> ought to suffice.
>>
>> Using LTO is not "stupid". Relying on people /not/ using LTO, or not
>> using other valid optimisations, is "stupid".
>
> LTO is a nonconforming optimization. It destroys the concept that
> when a translation unit is translated, the semantic analysis is
> complete, such that the only remaining activity is resolution of
> external references (linkage), and that the semantic analysis of one
> translation unit deos not use information about another translation
> unit.
>
> This has not yet changed in last April's N3096 draft, where
> translation phases 7 and 8 are:
>
> 7. White-space characters separating tokens are no longer significant.
> Each preprocessing token is converted into a token. The resulting
> tokens are syntactically and semantically analyzed and translated
> as a translation unit.
>
> 8. All external object and function references are resolved. Library
> components are linked to satisfy external references to functions
> and objects not defined in the current translation. All such
> translator output is collected into a program image which contains
> information needed for execution in its execution environment.
>
> and before that, the Program Structure section says:
>
> The separate translation units of a program communicate by (for
> example) calls to functions whose identifiers have external linkage,
> manipulation of objects whose identifiers have external linkage, or
> manipulation of data files. Translation units may be separately
> translated and then later linked to produce an executable program.
>
> LTO deviates from the the model that translation units are separate,
> and the conceptual steps of phases 7 and 8.
[...]

Link time optimization is as valid as cross-function optimization *as
long as* it doesn't change the defined behavior of the program.

Say I have a call to foo in main, and the definition of foo is in
another translation unit. In the absence of LTO, the compiler will have
to generate a call to foo. If LTO is able to determine that foo doesn't
do anything, it can remove the code for the function call, and the
resulting behavior of the linked program is unchanged.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: A Famous Security Bug

<uti8ve$2ekbr$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34620&group=comp.lang.c#34620

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Thu, 21 Mar 2024 14:31:26 -0700
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <uti8ve$2ekbr$1@dont-email.me>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<20240320114218.151@kylheku.com> <uthirj$29aoc$1@dont-email.me>
<20240321092738.111@kylheku.com> <uti2am$2d2ts$1@dont-email.me>
<ZE0LN.84950$_a1e.38190@fx16.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 21 Mar 2024 21:31:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2ab8e2f24273ba6122fc526819eafbc5";
logging-data="2576763"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8iw63H+Rn9QGXyXZVA+/yBXi0Km3Ine0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:fj9lO1mkK0XAHpsvy5Meofq0PXQ=
Content-Language: en-US
In-Reply-To: <ZE0LN.84950$_a1e.38190@fx16.iad>
 by: Chris M. Thomasson - Thu, 21 Mar 2024 21:31 UTC

On 3/21/2024 1:21 PM, Scott Lurndal wrote:
> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>
>> "All of its “critical-sequences” are contained in externally assembled
>> functions ( read all ) in order to prevent a rouge C compiler from
>
> As opposed to a viridian C compiler?

I was worried about "overly aggressive" LTO messing around with my ASM.

Re: A Famous Security Bug

<Hf3LN.544352$Ama9.472059@fx12.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34623&group=comp.lang.c#34623

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx12.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: A Famous Security Bug
Newsgroups: comp.lang.c
References: <bug-20240320191736@ram.dialup.fu-berlin.de> <20240320114218.151@kylheku.com> <uthirj$29aoc$1@dont-email.me> <20240321092738.111@kylheku.com> <uti2am$2d2ts$1@dont-email.me> <ZE0LN.84950$_a1e.38190@fx16.iad> <uti8ve$2ekbr$1@dont-email.me>
Lines: 12
Message-ID: <Hf3LN.544352$Ama9.472059@fx12.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 21 Mar 2024 23:19:03 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 21 Mar 2024 23:19:03 GMT
X-Received-Bytes: 1382
 by: Scott Lurndal - Thu, 21 Mar 2024 23:19 UTC

"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>On 3/21/2024 1:21 PM, Scott Lurndal wrote:
>> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>>
>>> "All of its “critical-sequences” are contained in externally assembled
>>> functions ( read all ) in order to prevent a rouge C compiler from
>>
>> As opposed to a viridian C compiler?
>
>I was worried about "overly aggressive" LTO messing around with my ASM.

And you missed the oblique reference to the mispelling of 'rogue' as 'rouge'.

Re: A Famous Security Bug

<utijv2$2h3up$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34624&group=comp.lang.c#34624

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Thu, 21 Mar 2024 17:38:58 -0700
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <utijv2$2h3up$1@dont-email.me>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<20240320114218.151@kylheku.com> <uthirj$29aoc$1@dont-email.me>
<20240321092738.111@kylheku.com> <uti2am$2d2ts$1@dont-email.me>
<ZE0LN.84950$_a1e.38190@fx16.iad> <uti8ve$2ekbr$1@dont-email.me>
<Hf3LN.544352$Ama9.472059@fx12.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Mar 2024 00:38:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1dc3221c1e8ed953d6c9b3654fc414ab";
logging-data="2658265"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wltTDJ3wMJhJb3Tx14iF/IRzXU3vs3hc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:j5COpTTCuLuz1LlZ/3kw3pcxd8c=
In-Reply-To: <Hf3LN.544352$Ama9.472059@fx12.iad>
Content-Language: en-US
 by: Chris M. Thomasson - Fri, 22 Mar 2024 00:38 UTC

On 3/21/2024 4:19 PM, Scott Lurndal wrote:
> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>> On 3/21/2024 1:21 PM, Scott Lurndal wrote:
>>> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>>>
>>>> "All of its “critical-sequences” are contained in externally assembled
>>>> functions ( read all ) in order to prevent a rouge C compiler from
>>>
>>> As opposed to a viridian C compiler?
>>
>> I was worried about "overly aggressive" LTO messing around with my ASM.
>
> And you missed the oblique reference to the mispelling of 'rogue' as 'rouge'.

Yup! I sure did. I have red on my face!

Re: A Famous Security Bug

<utjuta$2u6ah$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34629&group=comp.lang.c#34629

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Fri, 22 Mar 2024 13:51:53 +0100
Organization: A noiseless patient Spider
Lines: 154
Message-ID: <utjuta$2u6ah$1@dont-email.me>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<20240320114218.151@kylheku.com> <uthirj$29aoc$1@dont-email.me>
<20240321092738.111@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Mar 2024 12:51:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="07a44ddb34b47981e78dc5e82c11a0d6";
logging-data="3086673"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+sXe4E/Aa6gD1rsyXcm4KyM9AVuXylm4k="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:wZ2AvimxoKL3tp/VNqntDepFguU=
In-Reply-To: <20240321092738.111@kylheku.com>
Content-Language: en-GB
 by: David Brown - Fri, 22 Mar 2024 12:51 UTC

On 21/03/2024 18:41, Kaz Kylheku wrote:
> On 2024-03-21, David Brown <david.brown@hesbynett.no> wrote:
>> On 20/03/2024 19:54, Kaz Kylheku wrote:
>>> On 2024-03-20, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>>>> A "famous security bug":
>>>>
>>>> void f( void )
>>>> { char buffer[ MAX ];
>>>> /* . . . */
>>>> memset( buffer, 0, sizeof( buffer )); }
>>>>
>>>> . Can you see what the bug is?
>>>
>>> I don't know about "the bug", but conditions can be identified under
>>> which that would have a problem executing, like MAX being in excess
>>> of available automatic storage.
>>>
>>> If the /*...*/ comment represents the elision of some security sensitive
>>> code, where the memset is intended to obliterate secret information,
>>> of course, that obliteration is not required to work.
>>>
>>> After the memset, the buffer has no next use, so the all the assignments
>>> performed by memset to the bytes of buffer are dead assignments that can
>>> be elided.
>>>
>>> To securely clear memory, you have to use a function for that purpose
>>> that is not susceptible to optimization.
>>>
>>> If you're not doing anything stupid, like link time optimization, an
>>> external function in another translation unit (a function that the
>>> compiler doesn't recognize as being an alias or wrapper for memset)
>>> ought to suffice.
>>
>> Using LTO is not "stupid". Relying on people /not/ using LTO, or not
>> using other valid optimisations, is "stupid".
>
> LTO is a nonconforming optimization.

Really? That is news to me, and I suspect to the folks at gcc and
clang/llvm that developed LTO for these compilers. (I have worked with
embedded compilers that have had LTO-type optimisations for decades, but
these are not often concerned with the minutiae of the standards.)

> It destroys the concept that
> when a translation unit is translated, the semantic analysis is
> complete, such that the only remaining activity is resolution of
> external references (linkage), and that the semantic analysis of one
> translation unit deos not use information about another translation
> unit.

Where is it described in the C standards that semantic information from
one translation unit cannot be used (for optimisation, for static error
checking, for other analysis or any other purposes) in another
translation unit?

What makes you think that LTO, as implemented in compilers like gcc and
clang/llvm, do not generate code according to the "as if" rules? (That
is, they can generate code that is more optimal, but produces the same
observable effects "as if" they were strict dumb translators of the
functioning of the C abstract machine.)

I believe there is very little where the behaviour of a C program is
different if parts of the code are in one translation unit, or if they
are in several. There are utilities that merge multiple C files into
single C files (for easier deployment, or for better optimisation).
They have to take into account renaming static objects and functions to
file-local names, and remove duplicate type definitions, but as long as
certain reasonable rules are followed by the programmer, it all goes
fine. (You could, I suppose, hit complications if you relied on
compatibility of struct or union types across translation units where
the identifiers were different and they are compatible across TU's but
not within TU's, according to the 6.2.7p1 rules. But that would be
unlikely, and I expect LTO compilers to handle those cases.)

>
> This has not yet changed in last April's N3096 draft, where
> translation phases 7 and 8 are:
>
> 7. White-space characters separating tokens are no longer significant.
> Each preprocessing token is converted into a token. The resulting
> tokens are syntactically and semantically analyzed and translated
> as a translation unit.
>
> 8. All external object and function references are resolved. Library
> components are linked to satisfy external references to functions
> and objects not defined in the current translation. All such
> translator output is collected into a program image which contains
> information needed for execution in its execution environment.
>
> and before that, the Program Structure section says:
>
> The separate translation units of a program communicate by (for
> example) calls to functions whose identifiers have external linkage,
> manipulation of objects whose identifiers have external linkage, or
> manipulation of data files. Translation units may be separately
> translated and then later linked to produce an executable program.
>

All of that is irrelevant. It says nothing against sharing other
information.

> LTO deviates from the the model that translation units are separate,
> and the conceptual steps of phases 7 and 8.

No, it does not. These paragraphs are requirements, not limitations.

>
> The translation unit that is prepared for LTO is not fully cooked. You
> have no idea what its code will turn into when the interrupted
> compilation is resumed during linkage, under the influence of other
> tranlation units it is combined with.

You have as much and as little idea of what the generated code will be
as you always do during compilation. Compilers can do all kinds of
manipulations of the source code you write - as long as the observable
behaviour of the program is the same as a dumb translation. They can,
and do, use all kinds of inter-procedural optimisations for inlining
code, outlining it, breaking functions into pieces, cloning them, using
constant propagation, and so on. LTO lets them do this across
translation units.

>
> So in fact, the language allows us to take it for granted that, given
>
> my_memset(array, 0, sizeof(array)); }
>
> at the end of a function, and my_memset is an external definition
> provided by another translation unit, the call may not be elided.
>

No, the C language standards make no such guarantee.

> The one who may be acting recklessly is he who turns on nonconforming
> optimizations that are not documented as supported by the code base.
>
> Another example would be something like gcc's -ffast-math.

That is /completely/ different. That option is clearly documented as
potentially violating some of the rules of the ISO C standards. This is
why it is not enabled by default or by any common optimisation levels
(except "-Ofast", which is also documented as potentially violating
standards).

> You wouldn't unleash that on numerical code written by experts,
> and expect the same correct results.
>

I would not expect identical results to floating point calculations, no.

Depending on the code in question, I would still expect correct results.
I use "-ffast-math" in all my code in order to get correct results a
good deal faster (for my targets, and my type of code) than I would get
without it.

Re: A Famous Security Bug

<utk1k9$2uojo$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34632&group=comp.lang.c#34632

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Fri, 22 Mar 2024 14:38:17 +0100
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <utk1k9$2uojo$1@dont-email.me>
References: <bug-20240320191736@ram.dialup.fu-berlin.de>
<20240320114218.151@kylheku.com>
<20240321211306.779b21d126e122556c34a346@gmail.moc>
<20240321131621.321@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Mar 2024 13:38:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="07a44ddb34b47981e78dc5e82c11a0d6";
logging-data="3105400"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+im76wsKM6apC6O75lvyhUx6idWeynQeo="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:4oULhgfiVh1Tzr0IZW4ZLtyU328=
Content-Language: en-GB
In-Reply-To: <20240321131621.321@kylheku.com>
 by: David Brown - Fri, 22 Mar 2024 13:38 UTC

On 21/03/2024 21:21, Kaz Kylheku wrote:

> Eliminating dead stores is a very basic dataflow-driven optimization.
>
> Because memset is part of the C language, the compiler knows
> exactly what effect it has (that it's equivalent to setting
> all the bytes to zero, like a sequence of assignments).
>

Yes.

> If you don't want a call to be optimized away, call your
> own function in another translation unit.

No.

There are several ways that guarantee your code will carry out the
writes here (though none that guarantee the secret data is not also
stored elsewhere). Using a function in a different TU is not one of
these techniques. You do people a disfavour by recommending it.

> (And don't turn
> on nonconforming cross-translation-unit optimizations.)
>

If I knew of any non-conforming cross-translation-unit optimisations in
a compiler, I would avoid using them until the compiler vendor had fixed
the bug in question.

Re: A Famous Security Bug

<86a5mql3ry.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34633&group=comp.lang.c#34633

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: A Famous Security Bug
Date: Fri, 22 Mar 2024 07:50:09 -0700
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <86a5mql3ry.fsf@linuxsc.com>
References: <bug-20240320191736@ram.dialup.fu-berlin.de> <20240320114218.151@kylheku.com> <20240321211306.779b21d126e122556c34a346@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="43a124101bc8549bfa1c6f6d248b1944";
logging-data="3141256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1820LYTj/yTSHX3OWUKPF+l4wR8VICgcHY="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:NNCA3xQMDidJNyDxurVMurgs6WQ=
sha1:uVu21fcn+FBQ9HeJ9f9TqOySLmQ=
 by: Tim Rentsch - Fri, 22 Mar 2024 14:50 UTC

Anton Shepelev <anton.txt@gmail.moc> writes:

> Kaz Kylheku to Stefan Ram:
>
>>>> A "famous security bug":
>>>>
>>>> void f( void )
>>>> { char buffer[ MAX ];
>>>> /* . . . */
>>>> memset( buffer, 0, sizeof( buffer )); }
>>>>
>>>> . Can you see what the bug is?
>>
>> I don't know about "the bug", but conditions can be
>> identified under which that would have a problem
>> executing, like MAX being in excess of available automatic
>> storage.
>>
>> If the /*...*/ comment represents the elision of some
>> security sensitive code, where the memset is intended to
>> obliterate secret information, of course, that
>> obliteration is not required to work.
>>
>> After the memset, the buffer has no next use, so the all
>> the assignments performed by memset to the bytes of buffer
>> are dead assignments that can be elided.
>>
>> To securely clear memory, you have to use a function for
>> that purpose that is not susceptible to optimization.
>
> I think this behavior (of a C compiler) rather stupid. In a
> low-level imperative language, the compiled program shall
> do whatever the programmer commands it to do. If he
> commands it to clear the buffer, it shall clear the buffer.
> This optimisation is too high-level, too counter-inituitive,
> even deceitful. The optimiser is free to perform the task
> in the fastest manner possible, but it shall not ignore the
> programmer's order to zero-fill the buffer, especially
> without emitting a warning about (potentially!) redundant
> code, which it is the programmer's reponsibility to confirm
> and remove.
>
> Redundant code shall be dealt with in the source, rather than
> in the executable.

I have a couple of reactions.

One is that the ship has sailed. Somewhere between 35 and 40
years ago the people who wrote the C standard decided on a
semantic model that allows optimizations like this, and that is
not going to change. Certainly there are people who would prefer
to think of C as being a "low-level imperative language" like
what you describe, but the C community as a whole has accepted
the view taken by the authors of the C standard.

The second reaction is that, to be somewhat blunt, what is being
suggested is naive. I expect you do not yet appreciate the
ramifications of what you are suggesting. It is hard, indeed I
would say very hard, to define a semantic model that faithfully
represents the behaviors you would like to impose. You might
want to look into that, and what has been tried previously along
these lines, before pursuing this advocacy any further.

Pages:123456
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor