Gentoo Archives: gentoo-user

From: Ian Zimmerman <itz@××××××××××××.org>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: Spectre-NG
Date: Thu, 10 May 2018 16:53:12
Message-Id: 20180510165253.nkqtyysshn6f4ibh@matica.foolinux.mooo.com
In Reply to: Re: [gentoo-user] Re: Spectre-NG by Wol's lists
1 On 2018-05-10 14:35, Wol's lists wrote:
2
3 > > Code may be "security-sensitive" but buggy. Is the compiler writer
4 > > really responsible for guessing what the programmer meant to
5 > > accomplish with buggy code?
6 >
7 > What do you mean by "buggy"?
8
9 Relying on UB, or not telling the compiler the whole truth. You have a
10 point in that I should have been more specific.
11
12 > So if the compiler can't detect undefined behaviour, how the hell do
13 > you expect the programmer to?
14
15 Number one reason is that UB is at least in part a run-time concept.
16 Clearly the compiler cannot try all possible inputs to a function and
17 run a simulation on them. The programmer _can_ insert guard code at the
18 calling site to prevent the undefined cases from happening.
19
20 A "whole program" compiler (ie. one that analyzes code across source
21 modules) may be able to detect the _possibility_ of UB. But if you put
22 such a compiler to work on the kernel (for example), you can probably
23 take a short vacation while you await the result ;-)
24
25 > Oh - and please explain - what is buggy about wanting the following
26 > program to compile and actually *do* what the code is asking, rather
27 > than compiling to a no-op ... and 0x00ff is the address of your
28 > network adaptor? Do you want THAT to be optimised away "because it
29 > doesn't do anything"?
30
31 > int main () {
32 > int a, b, c;
33 > a = 2;
34 > b = 4;
35 > c = 6;
36 > }
37
38 > int main () {
39 > void *a;
40 > a = 0x00ff;
41 > *a = 6;
42 > }
43
44 This is actually not UB, but a different problem. Yes, if I write it
45 like this, I want it eliminated. When I want to keep it, I will use
46 the "volatile" keyword which is in the language precisely for this
47 purpose.
48
49 --
50 Please don't Cc: me privately on mailing lists and Usenet,
51 if you also post the followup to the list or newsgroup.
52 To reply privately _only_ on Usenet and on broken lists
53 which rewrite From, fetch the TXT record for no-use.mooo.com.