linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] proc: Provide details on indirect branch speculation
@ 2020-10-30  6:27 Anand K Mistry
  2020-10-31 20:05 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Anand K Mistry @ 2020-10-30  6:27 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: asteinhauser, joelaf, tglx, Anand K Mistry, Alexey Dobriyan,
	Alexey Gladkov, Andrew Morton, Jonathan Corbet, Kees Cook,
	Mauro Carvalho Chehab, Michal Hocko, Mike Rapoport, NeilBrown,
	Peter Zijlstra, linux-doc, linux-kernel

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

Signed-off-by: Anand K Mistry <amistry@google.com>
---

 Documentation/filesystems/proc.rst |  2 ++
 fs/proc/array.c                    | 28 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
index 533c79e8d2cd..710dd69614b9 100644
--- a/Documentation/filesystems/proc.rst
+++ b/Documentation/filesystems/proc.rst
@@ -210,6 +210,7 @@ read the file /proc/PID/status::
   NoNewPrivs:     0
   Seccomp:        0
   Speculation_Store_Bypass:       thread vulnerable
+  Speculation_Indirect_Branch:    conditional enabled
   voluntary_ctxt_switches:        0
   nonvoluntary_ctxt_switches:     1
 
@@ -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
+ Speculation_Indirect_Branch 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
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 65ec2029fa80..ce4fa948c9dd 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -368,6 +368,34 @@ static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
 		seq_puts(m, "vulnerable");
 		break;
 	}
+
+	seq_puts(m, "\nSpeculation_Indirect_Branch:\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');
 }
 
-- 
2.29.1.341.ge80a0c044ae-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] proc: Provide details on indirect branch speculation
  2020-10-30  6:27 [PATCH] proc: Provide details on indirect branch speculation Anand K Mistry
@ 2020-10-31 20:05 ` Andrew Morton
  2020-11-05  5:57   ` Anand K. Mistry
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2020-10-31 20:05 UTC (permalink / raw)
  To: Anand K Mistry
  Cc: linux-fsdevel, asteinhauser, joelaf, tglx, Alexey Dobriyan,
	Alexey Gladkov, Jonathan Corbet, Kees Cook,
	Mauro Carvalho Chehab, Michal Hocko, Mike Rapoport, NeilBrown,
	Peter Zijlstra, linux-doc, linux-kernel

On Fri, 30 Oct 2020 17:27:54 +1100 Anand K Mistry <amistry@google.com> wrote:

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

Why is this considered useful?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] proc: Provide details on indirect branch speculation
  2020-10-31 20:05 ` Andrew Morton
@ 2020-11-05  5:57   ` Anand K. Mistry
  0 siblings, 0 replies; 3+ messages in thread
From: Anand K. Mistry @ 2020-11-05  5:57 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-fsdevel, Anthony Steinhauser, Joel Fernandes, tglx,
	Alexey Dobriyan, Alexey Gladkov, Jonathan Corbet, Kees Cook,
	Mauro Carvalho Chehab, Michal Hocko, Mike Rapoport, NeilBrown,
	Peter Zijlstra, linux-doc, linux-kernel

On Sun, 1 Nov 2020 at 07:05, Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Fri, 30 Oct 2020 17:27:54 +1100 Anand K Mistry <amistry@google.com> wrote:
>
> > Similar to speculation store bypass, show information about the indirect
> > branch speculation mode of a task in /proc/$pid/status.
>
> Why is this considered useful?

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 precedence for adding this one.

-- 
Anand K. Mistry
Software Engineer
Google Australia

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-05  5:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-30  6:27 [PATCH] proc: Provide details on indirect branch speculation Anand K Mistry
2020-10-31 20:05 ` Andrew Morton
2020-11-05  5:57   ` Anand K. Mistry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).