Gentoo Archives: gentoo-user

From: Martin Vaeth <martin@×××××.de>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: gcc 7.3 + kernel 4.15 = spectre_v2 fixed
Date: Wed, 31 Jan 2018 13:26:23
Message-Id: p4sg18$mj7$1@blaine.gmane.org
In Reply to: [gentoo-user] Re: gcc 7.3 + kernel 4.15 = spectre_v2 fixed by Nikos Chantziaras
1 Nikos Chantziaras <realnc@×××××.com> wrote:
2 >
3 > For example, if you don't trust Firefox, don't install Firefox. But you
4 > *do* trust Firefox. What you don't trust is the JS code Firefox is
5 > executing.
6
7 That's an artificial distinction, because it is actually firefox
8 which is executing the code during the interpretation of JS.
9
10 > So Firefox needs protection.
11
12 The only "protection" firefox could be giving is that interpreted
13 JS is not able to do anything (not access any file or any program
14 outside of a well-defined sandbox). For various reasons, this is
15 not the case and will not be the case in any foreseeable future.
16
17 What does need protection is all the programs which can be accessed
18 (almost no matter how indirectly) by JS code - which is almost everything
19 running on a typical desktop.
20
21 Admittedly, firefox can help by e.g. making it harder to use timers
22 for the precise time measurement needed for "simple" spectre exploits.
23 This is already happening, but this is independent of the mitigations
24 provided by the compiler.
25
26 > I was under the impression that it's the function that performs the call
27 > that needs protection. The called function doesn't need protection,
28 > because if it ends up being actually called, then it's too late already.
29
30 The opposite is true. There should be no problem for any code (even
31 untrusted) to query gnupg to verify the validity of the signature.
32 But with the spectre exploits, this query might be used to get the
33 secret key which gnupg must access. So it is gnupg which needs the
34 protection (unless you want to make it much harder to use gnupg).
35
36 > For example, if sandboxed, untrusted code wants to speculatively execute
37 > a memcpy(), then the sandbox would need to call it on behalf of the
38 > untrusted code.
39
40 In my above example, it is gnupg which speculatively executes some code
41 if queried e.g. to verify a signature. The "attacking" program then might
42 use this fact (under some conditions) to understand which secret key was
43 used.
44 Everything which untrusted code can influence (no matter how indirectly)
45 is possible subject to be exploited if it uses speculative execution.
46 Therefore, the only way to be on the safe side is to avoid speculative
47 execution altogether.
48
49 > But if the sandbox is protected, the memcpy() call would
50 > never be made speculatively, since retpoline will trap it.
51
52 This means that the sandbox-code itself is protected from being
53 "read" by other code. But already if e.g. a webpage uses libjpeg to
54 render a picture (even if it would do it inside of an otherwise
55 protected sandbox), and libjpeg uses speculative execution (which
56 it does if you do not have compiled it with the new compiler switches),
57 javascript might (theoretically) be used to get image data it normally
58 has no access to.
59
60 Admittedly, this is all very theoretical and whether it is
61 actually possible to write working exploits is a different story
62 (that's why I wrote "(under some conditions)" and "(theoretically)"):
63 Not every speculative execution actually _can_ be exploited,
64 but there is always a certain probability (the more direct the
65 victim program can be accessed by the thief code, the higher the
66 probability is).