Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

proc: provide details on indirect branch speculation

Similar to speculation store bypass, show information about the indirect
branch speculation mode of a task in /proc/$pid/status.

For testing/benchmarking, I needed to see whether IB (Indirect Branch)
speculation (see Spectre-v2) is enabled on a task, to see whether an
IBPB instruction should be executed on an address space switch.
Unfortunately, this information isn't available anywhere else and
currently the only way to get it is to hack the kernel to expose it
(like this change). It also helped expose a bug with conditional IB
speculation on certain CPUs.

Another place this could be useful is to audit the system when using
sanboxing. With this change, I can confirm that seccomp-enabled
process have IB speculation force disabled as expected when the kernel
command line parameter `spectre_v2_user=seccomp`.

Since there's already a 'Speculation_Store_Bypass' field, I used that
as precedent for adding this one.

[amistry@google.com: remove underscores from field name to workaround documentation issue]
Link: https://lkml.kernel.org/r/20201106131015.v2.1.I7782b0cedb705384a634cfd8898eb7523562da99@changeid

Link: https://lkml.kernel.org/r/20201030172731.1.I7782b0cedb705384a634cfd8898eb7523562da99@changeid
Signed-off-by: Anand K Mistry <amistry@google.com>
Cc: Anthony Steinhauser <asteinhauser@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Anand K Mistry <amistry@google.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Alexey Gladkov <gladkov.alexey@gmail.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Kees Cook <keescook@chromium.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: NeilBrown <neilb@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Anand K Mistry and committed by
Linus Torvalds
fe719888 d2928e85

+30
+2
Documentation/filesystems/proc.rst
··· 210 210 NoNewPrivs: 0 211 211 Seccomp: 0 212 212 Speculation_Store_Bypass: thread vulnerable 213 + SpeculationIndirectBranch: conditional enabled 213 214 voluntary_ctxt_switches: 0 214 215 nonvoluntary_ctxt_switches: 1 215 216 ··· 293 292 NoNewPrivs no_new_privs, like prctl(PR_GET_NO_NEW_PRIV, ...) 294 293 Seccomp seccomp mode, like prctl(PR_GET_SECCOMP, ...) 295 294 Speculation_Store_Bypass speculative store bypass mitigation status 295 + SpeculationIndirectBranch indirect branch speculation mode 296 296 Cpus_allowed mask of CPUs on which this process may run 297 297 Cpus_allowed_list Same as previous, but in "list format" 298 298 Mems_allowed mask of memory nodes allowed to this process
+28
fs/proc/array.c
··· 369 369 seq_puts(m, "vulnerable"); 370 370 break; 371 371 } 372 + 373 + seq_puts(m, "\nSpeculationIndirectBranch:\t"); 374 + switch (arch_prctl_spec_ctrl_get(p, PR_SPEC_INDIRECT_BRANCH)) { 375 + case -EINVAL: 376 + seq_puts(m, "unsupported"); 377 + break; 378 + case PR_SPEC_NOT_AFFECTED: 379 + seq_puts(m, "not affected"); 380 + break; 381 + case PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE: 382 + seq_puts(m, "conditional force disabled"); 383 + break; 384 + case PR_SPEC_PRCTL | PR_SPEC_DISABLE: 385 + seq_puts(m, "conditional disabled"); 386 + break; 387 + case PR_SPEC_PRCTL | PR_SPEC_ENABLE: 388 + seq_puts(m, "conditional enabled"); 389 + break; 390 + case PR_SPEC_ENABLE: 391 + seq_puts(m, "always enabled"); 392 + break; 393 + case PR_SPEC_DISABLE: 394 + seq_puts(m, "always disabled"); 395 + break; 396 + default: 397 + seq_puts(m, "unknown"); 398 + break; 399 + } 372 400 seq_putc(m, '\n'); 373 401 } 374 402