mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: ak@suse.de, alan@lxorguk.ukuu.org.uk, arjan@infradead.org,
	bunk@stusta.de, rlrevell@joe-job.com,
	linux-kernel@vger.kernel.org, alan@redhat.com, torvalds@osdl.org
Subject: Re: [patch] let CONFIG_SECCOMP default to n
Date: Wed, 12 Jul 2006 18:51:03 -0700	[thread overview]
Message-ID: <20060712185103.f41b51d2.akpm@osdl.org> (raw)
In-Reply-To: <20060712210732.GA10182@elte.hu>

On Wed, 12 Jul 2006 23:07:32 +0200
Ingo Molnar <mingo@elte.hu> wrote:

> Despite good resons to apply the patch, it has not been applied yet, 
> with no explanation.

I queued the below.  Andrea claims that it'll reduce seccomp overhead to
literally zero.

But looking at it, I think it's a bit confused.  The patch needs
s/DISABLE_TSC/ENABLE_TSC/ to make it right.





From: Andrea Arcangeli <andrea@cpushare.com>

Make the TSC disable purely paranoid feature optional, so by default seccomp
returns absolutely zerocost.

Signed-off-by: Andrea Arcangeli <andrea@cpushare.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 arch/i386/Kconfig            |   12 ++++++++++++
 arch/i386/kernel/process.c   |    2 ++
 arch/x86_64/Kconfig          |   12 ++++++++++++
 arch/x86_64/kernel/process.c |   31 +++++++++++++++++++++++++++++++
 4 files changed, 57 insertions(+)

diff -puN arch/i386/Kconfig~add-seccomp_disable_tsc-config-option arch/i386/Kconfig
--- a/arch/i386/Kconfig~add-seccomp_disable_tsc-config-option
+++ a/arch/i386/Kconfig
@@ -737,6 +737,18 @@ config SECCOMP
 
 	  If unsure, say Y. Only embedded should say N here.
 
+config SECCOMP_DISABLE_TSC
+	bool "Disable the TSC for seccomp tasks"
+	depends on SECCOMP
+	default n
+	help
+	  This feature mathematically prevents covert channels
+	  for tasks running under SECCOMP. This can generate
+	  a minuscule overhead in the scheduler.
+
+	  If you care most about performance say N. Say Y only if you're
+	  paranoid about covert channels.
+
 config VGA_NOPROBE
        bool "Don't probe VGA at boot" if EMBEDDED
        default n
diff -puN arch/i386/kernel/process.c~add-seccomp_disable_tsc-config-option arch/i386/kernel/process.c
--- a/arch/i386/kernel/process.c~add-seccomp_disable_tsc-config-option
+++ a/arch/i386/kernel/process.c
@@ -572,6 +572,7 @@ handle_io_bitmap(struct thread_struct *n
 static inline void disable_tsc(struct task_struct *prev_p,
 			       struct task_struct *next_p)
 {
+#ifdef CONFIG_SECCOMP_DISABLE_TSC
 	struct thread_info *prev, *next;
 
 	/*
@@ -590,6 +591,7 @@ static inline void disable_tsc(struct ta
 			   has_secure_computing(next))
 			write_cr4(read_cr4() | X86_CR4_TSD);
 	}
+#endif
 }
 
 /*
diff -puN arch/x86_64/Kconfig~add-seccomp_disable_tsc-config-option arch/x86_64/Kconfig
--- a/arch/x86_64/Kconfig~add-seccomp_disable_tsc-config-option
+++ a/arch/x86_64/Kconfig
@@ -526,6 +526,18 @@ config SECCOMP
 
 	  If unsure, say Y. Only embedded should say N here.
 
+config SECCOMP_DISABLE_TSC
+	bool "Disable the TSC for seccomp tasks"
+	depends on SECCOMP
+	default n
+	help
+	  This feature mathematically prevents covert channels
+	  for tasks running under SECCOMP. This can generate
+	  a minuscule overhead in the scheduler.
+
+	  If you care most about performance say N. Say Y only if you're
+	  paranoid about covert channels.
+
 source kernel/Kconfig.hz
 
 config REORDER
diff -puN arch/x86_64/kernel/process.c~add-seccomp_disable_tsc-config-option arch/x86_64/kernel/process.c
--- a/arch/x86_64/kernel/process.c~add-seccomp_disable_tsc-config-option
+++ a/arch/x86_64/kernel/process.c
@@ -494,6 +494,35 @@ out:
 }
 
 /*
+ * This function selects if the context switch from prev to next
+ * has to tweak the TSC disable bit in the cr4.
+ */
+static inline void disable_tsc(struct task_struct *prev_p,
+			       struct task_struct *next_p)
+{
+#ifdef CONFIG_SECCOMP_DISABLE_TSC
+	struct thread_info *prev, *next;
+
+	/*
+	 * gcc should eliminate the ->thread_info dereference if
+	 * has_secure_computing returns 0 at compile time (SECCOMP=n).
+	 */
+	prev = prev_p->thread_info;
+	next = next_p->thread_info;
+
+	if (has_secure_computing(prev) || has_secure_computing(next)) {
+		/* slow path here */
+		if (has_secure_computing(prev) &&
+		    !has_secure_computing(next)) {
+			write_cr4(read_cr4() & ~X86_CR4_TSD);
+		} else if (!has_secure_computing(prev) &&
+			   has_secure_computing(next))
+			write_cr4((read_cr4() | X86_CR4_TSD) & ~X86_CR4_PCE);
+	}
+#endif
+}
+
+/*
  * This special macro can be used to load a debugging register
  */
 #define loaddebug(thread,r) set_debugreg(thread->debugreg ## r, r)
@@ -622,6 +651,8 @@ __switch_to(struct task_struct *prev_p, 
 		}
 	}
 
+	disable_tsc(prev_p, next_p);
+
 	/* If the task has used fpu the last 5 timeslices, just do a full
 	 * restore of the math state immediately to avoid the trap; the
 	 * chances of needing FPU soon are obviously high now
_


  parent reply	other threads:[~2006-07-13  1:54 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-29 19:21 [2.6 patch] " Adrian Bunk
2006-06-30  0:44 ` Lee Revell
2006-06-30  1:07   ` Andrew Morton
2006-06-30  1:40     ` Adrian Bunk
2006-06-30  4:52       ` Andrea Arcangeli
2006-06-30  9:47         ` Ingo Molnar
2006-06-30 14:58           ` andrea
2006-07-11  7:36             ` [patch] " Ingo Molnar
2006-07-11 14:17               ` andrea
2006-07-11 14:32                 ` Arjan van de Ven
2006-07-11 15:31                   ` andrea
2006-07-11 15:54                     ` Arjan van de Ven
2006-07-11 16:13                       ` andrea
2006-07-11 16:23                         ` Arjan van de Ven
2006-07-11 16:57                         ` Alan Cox
2006-07-11 16:25                       ` Alan Cox
2006-07-11 16:02                     ` Adrian Bunk
2006-07-11 16:16                       ` andrea
2006-07-11 16:24                     ` Alan Cox
2006-07-12 15:43                       ` Andi Kleen
2006-07-12 21:07                         ` Ingo Molnar
2006-07-12 22:06                           ` Andi Kleen
2006-07-12 22:19                             ` Ingo Molnar
2006-07-12 22:33                               ` Andi Kleen
2006-07-12 22:49                                 ` Ingo Molnar
2006-07-13  3:16                               ` Andrea Arcangeli
2006-07-13 11:23                                 ` Jeff Dike
2006-07-13 11:35                                   ` Ingo Molnar
2006-07-13  3:04                             ` Andrea Arcangeli
2006-07-13  3:12                               ` Linus Torvalds
2006-07-13  4:40                                 ` Andrea Arcangeli
2006-07-13  4:51                                   ` andrea
2006-07-13  5:12                                   ` Linus Torvalds
2006-07-13  6:22                                     ` andrea
2006-07-13  1:51                           ` Andrew Morton [this message]
2006-07-13  2:00                             ` Linus Torvalds
2006-07-13  7:44                             ` James Bruce
2006-07-13  8:34                               ` andrea
2006-07-13  9:18                                 ` Andrew Morton
2006-07-14  6:09                                   ` [PATCH] TIF_NOTSC and SECCOMP prctl andrea
2006-07-14  6:27                                     ` Andrew Morton
2006-07-14  6:33                                       ` andrea
2006-07-13 12:13                             ` [patch] let CONFIG_SECCOMP default to n Andi Kleen
2006-07-12 21:22                         ` Ingo Molnar
2006-07-12 22:11                           ` Andi Kleen
2006-07-11 15:54                 ` Pavel Machek
2006-06-30 12:39       ` [2.6 patch] " Alan Cox
2006-06-30  2:35     ` Randy.Dunlap
2006-06-30 15:03       ` Lee Revell
2006-07-08  9:23         ` Andrea Arcangeli
2006-07-11  1:59           ` Andrew James Wade
2006-07-11  4:16             ` andrea
2006-07-11 20:19               ` Andrew James Wade
2006-07-12 21:05                 ` andrea
2006-07-12 22:02                   ` Alan Cox
2006-07-12 23:44                     ` andrea
2006-07-13 21:29                       ` Pavel Machek
2006-07-13 23:11                         ` andrea
2006-07-13 23:20                           ` Pavel Machek
2006-07-14  0:34                             ` andrea
2006-07-15  2:55                           ` Valdis.Kletnieks
2006-07-16  0:51                             ` andrea
2006-07-16  1:54                               ` Pavel Machek
2006-07-16 15:36                                 ` andrea
2006-07-13  2:56                     ` Andrew James Wade
2006-07-12 21:13                 ` Ingo Molnar
2006-07-13  1:16                   ` andrea
2006-07-13  1:37                   ` Andrew James Wade
2006-07-12 21:37 [patch] " Chuck Ebbert
2006-07-12 21:55 ` Linus Torvalds
2006-07-12 22:48   ` andrea
2006-07-12 21:57 ` Andi Kleen
2006-07-13  5:43 Albert Cahalan
2006-07-13  7:07 ` andrea
     [not found] <6tgj0-8ip-19@gated-at.bofh.it>
     [not found] ` <6xP8s-5mc-9@gated-at.bofh.it>
     [not found]   ` <6xUhQ-4Wx-33@gated-at.bofh.it>
     [not found]     ` <6xVdX-6oH-53@gated-at.bofh.it>
     [not found]       ` <6xVnz-6AI-21@gated-at.bofh.it>
     [not found]         ` <6xZUd-4Es-13@gated-at.bofh.it>
     [not found]           ` <6y7yy-7ws-13@gated-at.bofh.it>
     [not found]             ` <6y7RK-7TX-9@gated-at.bofh.it>
2006-07-17 11:37               ` Bodo Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060712185103.f41b51d2.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=ak@suse.de \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=alan@redhat.com \
    --cc=arjan@infradead.org \
    --cc=bunk@stusta.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rlrevell@joe-job.com \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome