Skip to content

Commit

Permalink
proc: provide details on indirect branch speculation
Browse files Browse the repository at this point in the history
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.

[[email protected]: 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 <[email protected]>
Cc: Anthony Steinhauser <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Anand K Mistry <[email protected]>
Cc: Alexey Dobriyan <[email protected]>
Cc: Alexey Gladkov <[email protected]>
Cc: Jonathan Corbet <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Mike Rapoport <[email protected]>
Cc: NeilBrown <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
akmistry authored and torvalds committed Dec 16, 2020
1 parent d2928e8 commit fe71988
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Documentation/filesystems/proc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ read the file /proc/PID/status::
NoNewPrivs: 0
Seccomp: 0
Speculation_Store_Bypass: thread vulnerable
SpeculationIndirectBranch: conditional enabled
voluntary_ctxt_switches: 0
nonvoluntary_ctxt_switches: 1

Expand Down Expand Up @@ -292,6 +293,7 @@ It's slow but very precise.
NoNewPrivs no_new_privs, like prctl(PR_GET_NO_NEW_PRIV, ...)
Seccomp seccomp mode, like prctl(PR_GET_SECCOMP, ...)
Speculation_Store_Bypass speculative store bypass mitigation status
SpeculationIndirectBranch indirect branch speculation mode
Cpus_allowed mask of CPUs on which this process may run
Cpus_allowed_list Same as previous, but in "list format"
Mems_allowed mask of memory nodes allowed to this process
Expand Down
28 changes: 28 additions & 0 deletions fs/proc/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,34 @@ static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
seq_puts(m, "vulnerable");
break;
}

seq_puts(m, "\nSpeculationIndirectBranch:\t");
switch (arch_prctl_spec_ctrl_get(p, PR_SPEC_INDIRECT_BRANCH)) {
case -EINVAL:
seq_puts(m, "unsupported");
break;
case PR_SPEC_NOT_AFFECTED:
seq_puts(m, "not affected");
break;
case PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE:
seq_puts(m, "conditional force disabled");
break;
case PR_SPEC_PRCTL | PR_SPEC_DISABLE:
seq_puts(m, "conditional disabled");
break;
case PR_SPEC_PRCTL | PR_SPEC_ENABLE:
seq_puts(m, "conditional enabled");
break;
case PR_SPEC_ENABLE:
seq_puts(m, "always enabled");
break;
case PR_SPEC_DISABLE:
seq_puts(m, "always disabled");
break;
default:
seq_puts(m, "unknown");
break;
}
seq_putc(m, '\n');
}

Expand Down

0 comments on commit fe71988

Please sign in to comment.