Skip to contentSkip to conversation

LSM: Support ptrace sidechannel access checks

PATCH Superseded Casey Schaufler 7 participants 28 messages Sep 26, 2018 – Oct 16, 2018

Subsystems (6)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover LSM: Support ptrace sidechannel access checks

v5: Revamped to match Jiri Kosina <[email protected]>
Harden spectrev2 userspace-userspace protection v7 Fixed locking issues in the LSM code.
Dropped the new LSM hook and use a ptrace hook instead.
v4: select namespace checks if user namespaces are enabled
and credential checks are request.
v3: get_task_cred wasn't a good choice due to refcounts.
Use lower level protection instead
v2: SELinux access policy corrected.
Use real_cred instead of cred.

This patchset provide a mechanism by which a security module can advise the system about potential side-channel vulnerabilities. The existing security modules have been updated to avoid locking issues in the face of PTRACE_MODE_SCHED. A new security module is provided to make determinations regarding task attributes including namespaces.

---
 include/linux/lsm_hooks.h          |  5 +++
 kernel/ptrace.c                    |  2 -
 security/Kconfig                   |  1 +
 security/Makefile                  |  2 +
 security/apparmor/domain.c         |  2 +-
 security/apparmor/include/ipc.h    |  2 +-
 security/apparmor/ipc.c            |  8 ++--
 security/apparmor/lsm.c            |  5 ++-
 security/commoncap.c               |  2 +
 security/security.c                |  1 +
 security/selinux/hooks.c           |  2 +
 security/sidechannel/Kconfig       | 13 ++++++
 security/sidechannel/Makefile      |  1 +
 security/sidechannel/sidechannel.c | 88 ++++++++++++++++++++++++++++++++++++++
 security/smack/smack_lsm.c         |  3 +-
 15 files changed, 127 insertions(+), 10 deletions(-)
#1 lore raw

PATCH v5 1/5 AppArmor: Prepare for PTRACE_MODE_SCHED

From: Casey Schaufler <[email protected]>

A ptrace access check with mode PTRACE_MODE_SCHED gets called from process switching code. This precludes the use of audit, as the locking is incompatible. Don't do audit in the PTRACE_MODE_SCHED case.

---
 security/apparmor/domain.c      | 2 +-
 security/apparmor/include/ipc.h | 2 +-
 security/apparmor/ipc.c         | 8 +++++---
 security/apparmor/lsm.c         | 5 +++--
 4 files changed, 10 insertions(+), 7 deletions(-)
security/apparmor/domain.c +1 -1
index 08c88de0ffda..28300f4c3ef9 100644
@@ -77,7 +77,7 @@ static int may_change_ptraced_domain(struct aa_label *to_label,
 	if (!tracer || unconfined(tracerl))
 		goto out;
 
-	error = aa_may_ptrace(tracerl, to_label, PTRACE_MODE_ATTACH);
+	error = aa_may_ptrace(tracerl, to_label, PTRACE_MODE_ATTACH, true);
 
 out:
 	rcu_read_unlock();
security/apparmor/include/ipc.h +1 -1
index 5ffc218d1e74..299d1c45fef0 100644
@@ -34,7 +34,7 @@ struct aa_profile;
 	"xcpu xfsz vtalrm prof winch io pwr sys emt lost"
 
 int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
-		  u32 request);
+		  u32 request, bool audit);
 int aa_may_signal(struct aa_label *sender, struct aa_label *target, int sig);
 
 #endif /* __AA_IPC_H */
security/apparmor/ipc.c +5 -3
index 527ea1557120..9ed110afc822 100644
@@ -121,15 +121,17 @@ static int profile_tracer_perm(struct aa_profile *tracer,
  * Returns: %0 else error code if permission denied or error
  */
 int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
-		  u32 request)
+		  u32 request, bool audit)
 {
 	struct aa_profile *profile;
 	u32 xrequest = request << PTRACE_PERM_SHIFT;
 	DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_PTRACE);
 
 	return xcheck_labels(tracer, tracee, profile,
-			profile_tracer_perm(profile, tracee, request, &sa),
-			profile_tracee_perm(profile, tracer, xrequest, &sa));
+			profile_tracer_perm(profile, tracee, request,
+					    audit ? &sa : NULL),
+			profile_tracee_perm(profile, tracer, xrequest,
+					    audit ? &sa : NULL));
 }
 
 
security/apparmor/lsm.c +3 -2
index 8b8b70620bbe..da9d0b228857 100644
@@ -118,7 +118,8 @@ static int apparmor_ptrace_access_check(struct task_struct *child,
 	tracee = aa_get_task_label(child);
 	error = aa_may_ptrace(tracer, tracee,
 			(mode & PTRACE_MODE_READ) ? AA_PTRACE_READ
-						  : AA_PTRACE_TRACE);
+						  : AA_PTRACE_TRACE,
+			!(mode & PTRACE_MODE_SCHED));
 	aa_put_label(tracee);
 	end_current_label_crit_section(tracer);
 
@@ -132,7 +133,7 @@ static int apparmor_ptrace_traceme(struct task_struct *parent)
 
 	tracee = begin_current_label_crit_section();
 	tracer = aa_get_task_label(parent);
-	error = aa_may_ptrace(tracer, tracee, AA_PTRACE_TRACE);
+	error = aa_may_ptrace(tracer, tracee, AA_PTRACE_TRACE, true);
 	aa_put_label(tracer);
 	end_current_label_crit_section(tracee);
 
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v5 1/5] AppArmor: Prepare for PTRACE_MODE_SCHED

Quoted 4 lines · Casey Schaufler

A ptrace access check with mode PTRACE_MODE_SCHED gets called from process switching code. This precludes the use of audit, as the locking is incompatible. Don't do audit in the PTRACE_MODE_SCHED case.

Why is this separate from PTRACE_MODE_NOAUDIT? It looks like apparmor_ptrace_access_check() currently ignores PTRACE_MODE_NOAUDIT. Could you, instead of adding a new flag, fix the handling of PTRACE_MODE_NOAUDIT?

Quoted 85 lines
---
 security/apparmor/domain.c      | 2 +-
 security/apparmor/include/ipc.h | 2 +-
 security/apparmor/ipc.c         | 8 +++++---
 security/apparmor/lsm.c         | 5 +++--
 4 files changed, 10 insertions(+), 7 deletions(-)
security/apparmor/domain.c +1 -1
index 08c88de0ffda..28300f4c3ef9 100644
@@ -77,7 +77,7 @@ static int may_change_ptraced_domain(struct aa_label *to_label,
        if (!tracer || unconfined(tracerl))
                goto out;
 
-       error = aa_may_ptrace(tracerl, to_label, PTRACE_MODE_ATTACH);
+       error = aa_may_ptrace(tracerl, to_label, PTRACE_MODE_ATTACH, true);
 
 out:
        rcu_read_unlock();
security/apparmor/include/ipc.h +1 -1
index 5ffc218d1e74..299d1c45fef0 100644
@@ -34,7 +34,7 @@ struct aa_profile;
        "xcpu xfsz vtalrm prof winch io pwr sys emt lost"
 
 int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
-                 u32 request);
+                 u32 request, bool audit);
 int aa_may_signal(struct aa_label *sender, struct aa_label *target, int sig);
 
 #endif /* __AA_IPC_H */
security/apparmor/ipc.c +5 -3
index 527ea1557120..9ed110afc822 100644
@@ -121,15 +121,17 @@ static int profile_tracer_perm(struct aa_profile *tracer,
  * Returns: %0 else error code if permission denied or error
  */
 int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
-                 u32 request)
+                 u32 request, bool audit)
 {
        struct aa_profile *profile;
        u32 xrequest = request << PTRACE_PERM_SHIFT;
        DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_PTRACE);
 
        return xcheck_labels(tracer, tracee, profile,
-                       profile_tracer_perm(profile, tracee, request, &sa),
-                       profile_tracee_perm(profile, tracer, xrequest, &sa));
+                       profile_tracer_perm(profile, tracee, request,
+                                           audit ? &sa : NULL),
+                       profile_tracee_perm(profile, tracer, xrequest,
+                                           audit ? &sa : NULL));
 }
 
 
security/apparmor/lsm.c +3 -3
index 8b8b70620bbe..da9d0b228857 100644
@@ -118,7 +118,8 @@ static int apparmor_ptrace_access_check(struct task_struct *child,
        tracee = aa_get_task_label(child);
        error = aa_may_ptrace(tracer, tracee,
                        (mode & PTRACE_MODE_READ) ? AA_PTRACE_READ
-                                                 : AA_PTRACE_TRACE);
+                                                 : AA_PTRACE_TRACE,
+                       !(mode & PTRACE_MODE_SCHED));
        aa_put_label(tracee);
        end_current_label_crit_section(tracer);
 
@@ -132,7 +133,7 @@ static int apparmor_ptrace_traceme(struct task_struct *parent)
 
        tracee = begin_current_label_crit_section();
        tracer = aa_get_task_label(parent);
-       error = aa_may_ptrace(tracer, tracee, AA_PTRACE_TRACE);
+       error = aa_may_ptrace(tracer, tracee, AA_PTRACE_TRACE, true);
        aa_put_label(tracer);
        end_current_label_crit_section(tracee);
 
--

2.17.1

#3 lore raw

Re: [PATCH v5 1/5] AppArmor: Prepare for PTRACE_MODE_SCHED

Quoted 8 lines · Jann Horn
Quoted 4 lines · Casey Schaufler

A ptrace access check with mode PTRACE_MODE_SCHED gets called from process switching code. This precludes the use of audit, as the locking is incompatible. Don't do audit in the PTRACE_MODE_SCHED case.

Quoted 4 lines

Why is this separate from PTRACE_MODE_NOAUDIT? It looks like apparmor_ptrace_access_check() currently ignores PTRACE_MODE_NOAUDIT. Could you, instead of adding a new flag, fix the handling of PTRACE_MODE_NOAUDIT?

Er, after looking at more of the series, I see that PTRACE_MODE_SCHED is necessary; but could you handle the "don't audit" part for AppArmor using PTRACE_MODE_NOAUDIT instead?

Quoted 85 lines
Quoted 85 lines
---
 security/apparmor/domain.c      | 2 +-
 security/apparmor/include/ipc.h | 2 +-
 security/apparmor/ipc.c         | 8 +++++---
 security/apparmor/lsm.c         | 5 +++--
 4 files changed, 10 insertions(+), 7 deletions(-)
security/apparmor/domain.c +1 -1
index 08c88de0ffda..28300f4c3ef9 100644
@@ -77,7 +77,7 @@ static int may_change_ptraced_domain(struct aa_label *to_label,
        if (!tracer || unconfined(tracerl))
                goto out;
 
-       error = aa_may_ptrace(tracerl, to_label, PTRACE_MODE_ATTACH);
+       error = aa_may_ptrace(tracerl, to_label, PTRACE_MODE_ATTACH, true);
 
 out:
        rcu_read_unlock();
security/apparmor/include/ipc.h +1 -1
index 5ffc218d1e74..299d1c45fef0 100644
@@ -34,7 +34,7 @@ struct aa_profile;
        "xcpu xfsz vtalrm prof winch io pwr sys emt lost"
 
 int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
-                 u32 request);
+                 u32 request, bool audit);
 int aa_may_signal(struct aa_label *sender, struct aa_label *target, int sig);
 
 #endif /* __AA_IPC_H */
security/apparmor/ipc.c +5 -3
index 527ea1557120..9ed110afc822 100644
@@ -121,15 +121,17 @@ static int profile_tracer_perm(struct aa_profile *tracer,
  * Returns: %0 else error code if permission denied or error
  */
 int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
-                 u32 request)
+                 u32 request, bool audit)
 {
        struct aa_profile *profile;
        u32 xrequest = request << PTRACE_PERM_SHIFT;
        DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_PTRACE);
 
        return xcheck_labels(tracer, tracee, profile,
-                       profile_tracer_perm(profile, tracee, request, &sa),
-                       profile_tracee_perm(profile, tracer, xrequest, &sa));
+                       profile_tracer_perm(profile, tracee, request,
+                                           audit ? &sa : NULL),
+                       profile_tracee_perm(profile, tracer, xrequest,
+                                           audit ? &sa : NULL));
 }
 
 
security/apparmor/lsm.c +3 -3
index 8b8b70620bbe..da9d0b228857 100644
@@ -118,7 +118,8 @@ static int apparmor_ptrace_access_check(struct task_struct *child,
        tracee = aa_get_task_label(child);
        error = aa_may_ptrace(tracer, tracee,
                        (mode & PTRACE_MODE_READ) ? AA_PTRACE_READ
-                                                 : AA_PTRACE_TRACE);
+                                                 : AA_PTRACE_TRACE,
+                       !(mode & PTRACE_MODE_SCHED));
        aa_put_label(tracee);
        end_current_label_crit_section(tracer);
 
@@ -132,7 +133,7 @@ static int apparmor_ptrace_traceme(struct task_struct *parent)
 
        tracee = begin_current_label_crit_section();
        tracer = aa_get_task_label(parent);
-       error = aa_may_ptrace(tracer, tracee, AA_PTRACE_TRACE);
+       error = aa_may_ptrace(tracer, tracee, AA_PTRACE_TRACE, true);
        aa_put_label(tracer);
        end_current_label_crit_section(tracee);
 
--

2.17.1

#4 lore raw

RE: [PATCH v5 1/5] AppArmor: Prepare for PTRACE_MODE_SCHED

Quoted 22 lines

-----Original Message-----
From: Jann Horn [mailto:[email protected]]
Sent: Wednesday, September 26, 2018 2:19 PM
To: Schaufler, Casey <[email protected]>
Cc: Kernel Hardening <[email protected]>; kernel list <[email protected]>; linux-security-module <linux-security- [email protected]>; [email protected]; Hansen, Dave <[email protected]>; Dock, Deneen T <[email protected]>; [email protected]; Arjan van de Ven <[email protected]>
Subject: Re: [PATCH v5 1/5] AppArmor: Prepare for PTRACE_MODE_SCHED

Quoted 10 lines · Jann Horn
Quoted 4 lines · Casey Schaufler

A ptrace access check with mode PTRACE_MODE_SCHED gets called from process switching code. This precludes the use of audit, as the locking is incompatible. Don't do audit in the PTRACE_MODE_SCHED case.

Why is this separate from PTRACE_MODE_NOAUDIT? It looks like apparmor_ptrace_access_check() currently ignores

Quoted 7 lines

PTRACE_MODE_NOAUDIT.

Quoted 2 lines

Could you, instead of adding a new flag, fix the handling of PTRACE_MODE_NOAUDIT?

Er, after looking at more of the series, I see that PTRACE_MODE_SCHED is necessary; but could you handle the "don't audit" part for AppArmor using PTRACE_MODE_NOAUDIT instead?

I could have done it a number of ways, but this seemed to maintain the apparmor AA_PTRACE abstraction the best. If aa_may_ptrace didn't eschew PTRACE_MODE in favor of AA_PTRACE no change to the interface would have been required. I'm reluctant to change something like that.

Quoted 91 lines
Quoted 8 lines
Quoted 8 lines
---
 security/apparmor/domain.c      | 2 +-
 security/apparmor/include/ipc.h | 2 +-
 security/apparmor/ipc.c         | 8 +++++---
 security/apparmor/lsm.c         | 5 +++--
 4 files changed, 10 insertions(+), 7 deletions(-)
Quoted 5 lines

security/apparmor/domain.c static int may_change_ptraced_domain(struct

Quoted 5 lines
security/apparmor/domain.c +0 -0
index 08c88de0ffda..28300f4c3ef9 100644
@@ -77,7 +77,7 @@ static int may_change_ptraced_domain(struct

aa_label *to_label,

Quoted 5 lines

security/apparmor/domain.c static int may_change_ptraced_domain(struct aa_label *to_label,

Quoted 5 lines
security/apparmor/domain.c +1 -1
        if (!tracer || unconfined(tracerl))
                goto out;
 
-       error = aa_may_ptrace(tracerl, to_label, PTRACE_MODE_ATTACH);
+       error = aa_may_ptrace(tracerl, to_label, PTRACE_MODE_ATTACH,

true);

Quoted 4 lines

Review

Quoted 4 lines
security/apparmor/domain.c +0 -0
 out:
        rcu_read_unlock();
(quoted diff) +0 -0

b/security/apparmor/include/ipc.h

Quoted 11 lines
Quoted 11 lines

index 5ffc218d1e74..299d1c45fef0 100644

security/apparmor/include/ipc.h +1 -1
@@ -34,7 +34,7 @@ struct aa_profile;
        "xcpu xfsz vtalrm prof winch io pwr sys emt lost"
 
 int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
-                 u32 request);
+                 u32 request, bool audit);
 int aa_may_signal(struct aa_label *sender, struct aa_label *target, int sig);
 
Quoted 6 lines

security/apparmor/ipc.c static int profile_tracer_perm(struct aa_profile

Quoted 6 lines
security/apparmor/include/ipc.h +0 -0
 #endif /* __AA_IPC_H */
security/apparmor/ipc.c +0 -0
index 527ea1557120..9ed110afc822 100644
@@ -121,15 +121,17 @@ static int profile_tracer_perm(struct aa_profile

*tracer,

Quoted 20 lines
Quoted 20 lines
security/apparmor/ipc.c +5 -3
  * Returns: %0 else error code if permission denied or error
  */
 int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
-                 u32 request)
+                 u32 request, bool audit)
 {
        struct aa_profile *profile;
        u32 xrequest = request << PTRACE_PERM_SHIFT;
        DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_PTRACE);
 
        return xcheck_labels(tracer, tracee, profile,
-                       profile_tracer_perm(profile, tracee, request, &sa),
-                       profile_tracee_perm(profile, tracer, xrequest, &sa));
+                       profile_tracer_perm(profile, tracee, request,
+                                           audit ? &sa : NULL),
+                       profile_tracee_perm(profile, tracer, xrequest,
+                                           audit ? &sa : NULL));
 }
 
 
Quoted 5 lines

security/apparmor/lsm.c static int apparmor_ptrace_access_check(struct

Quoted 5 lines
security/apparmor/lsm.c +0 -0
index 8b8b70620bbe..da9d0b228857 100644
@@ -118,7 +118,8 @@ static int apparmor_ptrace_access_check(struct

task_struct *child,

Quoted 10 lines

security/apparmor/lsm.c static int apparmor_ptrace_traceme(struct

Quoted 10 lines
security/apparmor/lsm.c +2 -1
        tracee = aa_get_task_label(child);
        error = aa_may_ptrace(tracer, tracee,
                        (mode & PTRACE_MODE_READ) ? AA_PTRACE_READ
-                                                 : AA_PTRACE_TRACE);
+                                                 : AA_PTRACE_TRACE,
+                       !(mode & PTRACE_MODE_SCHED));
        aa_put_label(tracee);
        end_current_label_crit_section(tracer);
 
@@ -132,7 +133,7 @@ static int apparmor_ptrace_traceme(struct

task_struct *parent)

Quoted 11 lines
Quoted 11 lines
security/apparmor/lsm.c +1 -2
        tracee = begin_current_label_crit_section();
        tracer = aa_get_task_label(parent);
-       error = aa_may_ptrace(tracer, tracee, AA_PTRACE_TRACE);
+       error = aa_may_ptrace(tracer, tracee, AA_PTRACE_TRACE, true);
        aa_put_label(tracer);
        end_current_label_crit_section(tracee);
 
--

2.17.1

#5 lore raw

PATCH v5 2/5 Smack: Prepare for PTRACE_MODE_SCHED

In reply to Casey Schaufler

From: Casey Schaufler <[email protected]>

A ptrace access check with mode PTRACE_MODE_SCHED gets called from process switching code. This precludes the use of audit, as the locking is incompatible. Don't do audit in the PTRACE_MODE_SCHED case.

---
 security/smack/smack_lsm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/smack/smack_lsm.c +2 -1
index 340fc30ad85d..ffa95bcab599 100644
@@ -422,7 +422,8 @@ static int smk_ptrace_rule_check(struct task_struct *tracer,
 	struct task_smack *tsp;
 	struct smack_known *tracer_known;
 
-	if ((mode & PTRACE_MODE_NOAUDIT) == 0) {
+	if ((mode & PTRACE_MODE_NOAUDIT) == 0 &&
+	    (mode & PTRACE_MODE_SCHED) == 0) {
 		smk_ad_init(&ad, func, LSM_AUDIT_DATA_TASK);
 		smk_ad_setfield_u_tsk(&ad, tracer);
 		saip = &ad;
Signature · 1 line
2.17.1
#6 lore raw

Re: [PATCH v5 2/5] Smack: Prepare for PTRACE_MODE_SCHED

Quoted 15 lines · Casey Schaufler

A ptrace access check with mode PTRACE_MODE_SCHED gets called from process switching code. This precludes the use of audit, as the locking is incompatible. Don't do audit in the PTRACE_MODE_SCHED case.

---
 security/smack/smack_lsm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/smack/smack_lsm.c +0 -0
index 340fc30ad85d..ffa95bcab599 100644

security/smack/smack_lsm.c static int smk_ptrace_rule_check(struct task_struct *tracer, · line 426

Quoted 6 lines
security/smack/smack_lsm.c +2 -1
@@ -422,7 +422,8 @@ static int smk_ptrace_rule_check(struct task_struct *tracer,
        struct task_smack *tsp;
        struct smack_known *tracer_known;
 
-       if ((mode & PTRACE_MODE_NOAUDIT) == 0) {
+       if ((mode & PTRACE_MODE_NOAUDIT) == 0 &&
+           (mode & PTRACE_MODE_SCHED) == 0) {

If you ORed PTRACE_MODE_NOAUDIT into the flags when calling the security hook, you could drop this patch, right?

#7 lore raw

RE: [PATCH v5 2/5] Smack: Prepare for PTRACE_MODE_SCHED

Quoted 32 lines

-----Original Message-----
From: Jann Horn [mailto:[email protected]]
Sent: Wednesday, September 26, 2018 2:31 PM
To: Schaufler, Casey <[email protected]>
Cc: Kernel Hardening <[email protected]>; kernel list <[email protected]>; linux-security-module <linux-security- [email protected]>; [email protected]; Hansen, Dave <[email protected]>; Dock, Deneen T <[email protected]>; [email protected]; Arjan van de Ven <[email protected]>
Subject: Re: [PATCH v5 2/5] Smack: Prepare for PTRACE_MODE_SCHED

security/smack/smack_lsm.c static int smk_ptrace_rule_check(struct task_struct

Quoted 15 lines · Casey Schaufler

A ptrace access check with mode PTRACE_MODE_SCHED gets called from process switching code. This precludes the use of audit, as the locking is incompatible. Don't do audit in the PTRACE_MODE_SCHED case.

---
 security/smack/smack_lsm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/smack/smack_lsm.c +0 -0
index 340fc30ad85d..ffa95bcab599 100644
@@ -422,7 +422,8 @@ static int smk_ptrace_rule_check(struct task_struct

*tracer,

Quoted 3 lines
security/smack/smack_lsm.c +0 -0
        struct task_smack *tsp;
        struct smack_known *tracer_known;
 
Quoted 6 lines

security/smack/smack_lsm.c static int smk_ptrace_rule_check(struct task_struct *tracer, · line 426

Quoted 3 lines
security/smack/smack_lsm.c +2 -1
-       if ((mode & PTRACE_MODE_NOAUDIT) == 0) {
+       if ((mode & PTRACE_MODE_NOAUDIT) == 0 &&
+           (mode & PTRACE_MODE_SCHED) == 0) {

If you ORed PTRACE_MODE_NOAUDIT into the flags when calling the security hook, you could drop this patch, right?

Yes. Since the PTRACE_MODE_NOAUDIT was in PTRACE_MODE_IBPB in Jiri's previous patch set and not in PTRACE_MODE_SCHED in this one I assumed that there was a good reason for it.

#8 lore raw

Re: [PATCH v5 2/5] Smack: Prepare for PTRACE_MODE_SCHED

+Jiri

Quoted 36 lines · Casey
Quoted 36 lines

-----Original Message-----
From: Jann Horn [mailto:[email protected]]
Sent: Wednesday, September 26, 2018 2:31 PM
To: Schaufler, Casey <[email protected]>
Cc: Kernel Hardening <[email protected]>; kernel list <[email protected]>; linux-security-module <linux-security- [email protected]>; [email protected]; Hansen, Dave <[email protected]>; Dock, Deneen T <[email protected]>; [email protected]; Arjan van de Ven <[email protected]>
Subject: Re: [PATCH v5 2/5] Smack: Prepare for PTRACE_MODE_SCHED

security/smack/smack_lsm.c static int smk_ptrace_rule_check(struct task_struct

Quoted 15 lines · Casey Schaufler

A ptrace access check with mode PTRACE_MODE_SCHED gets called from process switching code. This precludes the use of audit, as the locking is incompatible. Don't do audit in the PTRACE_MODE_SCHED case.

---
 security/smack/smack_lsm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/smack/smack_lsm.c +0 -0
index 340fc30ad85d..ffa95bcab599 100644
@@ -422,7 +422,8 @@ static int smk_ptrace_rule_check(struct task_struct

*tracer,

Quoted 6 lines
security/smack/smack_lsm.c +2 -1
        struct task_smack *tsp;
        struct smack_known *tracer_known;
 
-       if ((mode & PTRACE_MODE_NOAUDIT) == 0) {
+       if ((mode & PTRACE_MODE_NOAUDIT) == 0 &&
+           (mode & PTRACE_MODE_SCHED) == 0) {
Quoted 6 lines
Quoted 2 lines

If you ORed PTRACE_MODE_NOAUDIT into the flags when calling the security hook, you could drop this patch, right?

Yes. Since the PTRACE_MODE_NOAUDIT was in PTRACE_MODE_IBPB in Jiri's previous patch set and not in PTRACE_MODE_SCHED in this one I assumed that there was a good reason for it.

Jiri, was there a good reason for it, and if so, what was it?

#9 lore raw

Re: [PATCH v5 2/5] Smack: Prepare for PTRACE_MODE_SCHED

Quoted 5 lines · Jann Horn
Quoted 3 lines

Yes. Since the PTRACE_MODE_NOAUDIT was in PTRACE_MODE_IBPB in Jiri's previous patch set and not in PTRACE_MODE_SCHED in this one I assumed that there was a good reason for it.

Jiri, was there a good reason for it, and if so, what was it?

[ FWIW PTRACE_MODE_NOAUDIT being in PTRACE_MODE_IBPB goes back to original
Tim's pre-CRD patchset ]

Well, we can't really call out into audit from scheduler code, and the previous versions of the patchsets didn't have PTRACE_MODE_SCHED, so it had to be included in PTRACE_MODE_IBPB in order to make sure we're not calling into audit from context switch code.

Or did I misunderstand the question?

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#10 lore raw

Re: [PATCH v5 2/5] Smack: Prepare for PTRACE_MODE_SCHED

Quoted 10 lines · Jiri Kosina
Quoted 5 lines · Jann Horn
Quoted 3 lines

Yes. Since the PTRACE_MODE_NOAUDIT was in PTRACE_MODE_IBPB in Jiri's previous patch set and not in PTRACE_MODE_SCHED in this one I assumed that there was a good reason for it.

Jiri, was there a good reason for it, and if so, what was it?

[ FWIW PTRACE_MODE_NOAUDIT being in PTRACE_MODE_IBPB goes back to original
Tim's pre-CRD patchset ]

Quoted 6 lines

Well, we can't really call out into audit from scheduler code, and the previous versions of the patchsets didn't have PTRACE_MODE_SCHED, so it had to be included in PTRACE_MODE_IBPB in order to make sure we're not calling into audit from context switch code.

Or did I misunderstand the question?

If I understand Casey correctly, he is saying that your patch
(https://lore.kernel.org/lkml/[email protected]/)
doesn't include PTRACE_MODE_NOAUDIT for IBPB, but the previous v6 of
your patch (https://lore.kernel.org/lkml/[email protected]/)
did include it, and therefore Casey thinks that there is a specific
reason why you removed PTRACE_MODE_NOAUDIT, and therefore Casey is
adding special-case logic for PTRACE_MODE_SCHED to Smack when simply
using PTRACE_MODE_NOAUDIT would also work.

I think that Casey should change ptrace_may_access_sched() to use "mode | PTRACE_MODE_SCHED | PTRACE_MODE_NOAUDIT".

#11 lore raw

Re: [PATCH v5 2/5] Smack: Prepare for PTRACE_MODE_SCHED

Quoted 5 lines · Jann Horn
Quoted 5 lines

Well, we can't really call out into audit from scheduler code, and the previous versions of the patchsets didn't have PTRACE_MODE_SCHED, so it had to be included in PTRACE_MODE_IBPB in order to make sure we're not calling into audit from context switch code.

Quoted 8 lines
Quoted 1 line

Or did I misunderstand the question?

If I understand Casey correctly, he is saying that your patch
(https://lore.kernel.org/lkml/[email protected]/)
doesn't include PTRACE_MODE_NOAUDIT for IBPB, but the previous v6 of
your patch (https://lore.kernel.org/lkml/[email protected]/)
did include it, and therefore Casey thinks that there is a specific
reason why you removed PTRACE_MODE_NOAUDIT,

Quite honestly, I don't remember. I dont't think there is any deadlock that'd be triggered by this.

Quoted 5 lines

and therefore Casey is adding special-case logic for PTRACE_MODE_SCHED to Smack when simply using PTRACE_MODE_NOAUDIT would also work.

I think that Casey should change ptrace_may_access_sched() to use "mode | PTRACE_MODE_SCHED | PTRACE_MODE_NOAUDIT".

Agreed, that should work.

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#12 lore raw

PATCH v5 3/5 SELinux: Prepare for PTRACE_MODE_SCHED

In reply to Casey Schaufler

From: Casey Schaufler <[email protected]>

A ptrace access check with mode PTRACE_MODE_SCHED gets called from process switching code. This precludes the use of audit or avc, as the locking is incompatible. The only available check that can be made without using avc is a comparison of the secids. This is not very satisfactory as it will indicate possible vulnerabilies much too aggressively.

---
 security/selinux/hooks.c | 2 ++
 1 file changed, 2 insertions(+)
security/selinux/hooks.c +2 -0
index ad9a9b8e9979..160239791007 100644
@@ -2267,6 +2267,8 @@ static int selinux_ptrace_access_check(struct task_struct *child,
 	u32 sid = current_sid();
 	u32 csid = task_sid(child);
 
+	if (mode & PTRACE_MODE_SCHED)
+		return sid == csid ? 0 : -EACCES;
 	if (mode & PTRACE_MODE_READ)
 		return avc_has_perm(&selinux_state,
 				    sid, csid, SECCLASS_FILE, FILE__READ, NULL);
Signature · 1 line
2.17.1
#13 lore raw

Re: [PATCH v5 3/5] SELinux: Prepare for PTRACE_MODE_SCHED

Quoted 9 lines · Casey Schaufler

From: Casey Schaufler <[email protected]>

A ptrace access check with mode PTRACE_MODE_SCHED gets called from process switching code. This precludes the use of audit or avc, as the locking is incompatible. The only available check that can be made without using avc is a comparison of the secids. This is not very satisfactory as it will indicate possible vulnerabilies much too aggressively.

We already have a flag to disable audit. What locking conflict is presented by the avc, which uses rcu?

Quoted 24 lines
---
 security/selinux/hooks.c | 2 ++
 1 file changed, 2 insertions(+)
security/selinux/hooks.c +2 -0
index ad9a9b8e9979..160239791007 100644
@@ -2267,6 +2267,8 @@ static int selinux_ptrace_access_check(struct
 task_struct *child,
        u32 sid = current_sid();
        u32 csid = task_sid(child);
 
+       if (mode & PTRACE_MODE_SCHED)
+               return sid == csid ? 0 : -EACCES;
        if (mode & PTRACE_MODE_READ)
                return avc_has_perm(&selinux_state,

sid, csid, SECCLASS_FILE, FILE__READ,
NULL);
--
2.17.1

#14 lore raw

Re: [PATCH v5 3/5] SELinux: Prepare for PTRACE_MODE_SCHED

In reply to Casey Schaufler
Quoted 8 lines · Casey Schaufler

From: Casey Schaufler <[email protected]>

A ptrace access check with mode PTRACE_MODE_SCHED gets called from process switching code. This precludes the use of audit or avc, as the locking is incompatible. The only available check that can be made without using avc is a comparison of the secids. This is not very satisfactory as it will indicate possible vulnerabilies much too aggressively.

Can you document (in the patch description and/or in the inline documentation in lsm_hooks.h) what locks can be safely used when this hook is called with PTRACE_MODE_SCHED? rcu_read_lock() seemingly must be safe since it is being called by task_sid() below. Are any other locking primitives safe?

Does the PTRACE_MODE_SCHED check have to occur while holding the scheduler lock, or could it be performed before taking the lock?

Can you cite the commit or patch posting (e.g. from lore or patchwork) that defines PTRACE_MODE_SCHED and its usage as part of the patch description for context? Is this based on the v7 patchset, e.g.
https://lore.kernel.org/lkml/[email protected]/

Quoted 11 lines
---
  security/selinux/hooks.c | 2 ++
  1 file changed, 2 insertions(+)
security/selinux/hooks.c +0 -0
index ad9a9b8e9979..160239791007 100644

security/selinux/hooks.c static int selinux_ptrace_access_check(struct task_struct *child, · line 2271

Quoted 5 lines
security/selinux/hooks.c +2 -0
@@ -2267,6 +2267,8 @@ static int selinux_ptrace_access_check(struct task_struct *child,
  	u32 sid = current_sid();
  	u32 csid = task_sid(child);
 
+	if (mode & PTRACE_MODE_SCHED)
+		return sid == csid ? 0 : -EACCES;

IIUC, this logic is essentially the same as the uid-based check, including the fact that even a "privileged" process is not given any special handling since they always return false from ptrace_has_cap() for PTRACE_MODE_SCHED. If they are ok with applying IBPB whenever uids differ, then doing so whenever sids/contexts differ does not seem like an onerous thing.

Quoted 4 lines
security/selinux/hooks.c +0 -0
  	if (mode & PTRACE_MODE_READ)
  		return avc_has_perm(&selinux_state,
  				    sid, csid, SECCLASS_FILE, FILE__READ, NULL);
#15 lore raw

RE: [PATCH v5 3/5] SELinux: Prepare for PTRACE_MODE_SCHED

Quoted 20 lines

-----Original Message-----
From: Stephen Smalley [mailto:[email protected]]
Sent: Thursday, September 27, 2018 8:50 AM
To: Schaufler, Casey <[email protected]>; kernel- [email protected]; [email protected]; linux-security- [email protected]; [email protected]; Hansen, Dave <[email protected]>; Dock, Deneen T <[email protected]>; [email protected]; [email protected]; Paul Moore <paul@paul- moore.com>
Subject: Re: [PATCH v5 3/5] SELinux: Prepare for PTRACE_MODE_SCHED

Quoted 8 lines · Casey Schaufler

From: Casey Schaufler <[email protected]>

A ptrace access check with mode PTRACE_MODE_SCHED gets called from process switching code. This precludes the use of audit or avc, as the locking is incompatible. The only available check that can be made without using avc is a comparison of the secids. This is not very satisfactory as it will indicate possible vulnerabilies much too aggressively.

Quoted 5 lines

Can you document (in the patch description and/or in the inline documentation in lsm_hooks.h) what locks can be safely used when this hook is called with PTRACE_MODE_SCHED? rcu_read_lock() seemingly must be safe since it is being called by task_sid() below. Are any other locking primitives safe?

Peter Zijlstra <[email protected]> had this comment on locking in the SELinux ptrace path.

avc_has_perm_noaudit()

	  security_compute_av()
	    read_lock(&state->ss->policy_rwlock);
	  avc_insert()
	    spin_lock_irqsave();
	  avc_denied()
	    avc_update_node()
	      spin_lock_irqsave();

under the scheduler's raw_spinlock_t, which are invalid lock nestings.

I don't know that it would be impossible to address these issues, but as many people have noted over the years I am not now nor have ever been an expert on locking.

Quoted 3 lines

Does the PTRACE_MODE_SCHED check have to occur while holding the scheduler lock, or could it be performed before taking the lock?

My understanding is that the lock is required.

Quoted 5 lines

Can you cite the commit or patch posting (e.g. from lore or patchwork) that defines PTRACE_MODE_SCHED and its usage as part of the patch description for context? Is this based on the v7 patchset, e.g.
https://lore.kernel.org/lkml/[email protected]
r.pm/

Yes, that's the one. Sorry, I should have identified that.

Quoted 31 lines

security/selinux/hooks.c static int selinux_ptrace_access_check(struct

Quoted 12 lines
---
  security/selinux/hooks.c | 2 ++
  1 file changed, 2 insertions(+)
security/selinux/hooks.c +0 -0
index ad9a9b8e9979..160239791007 100644
@@ -2267,6 +2267,8 @@ static int selinux_ptrace_access_check(struct

task_struct *child,

security/selinux/hooks.c static int selinux_ptrace_access_check(struct task_struct *child, · line 2271

Quoted 5 lines
security/selinux/hooks.c +2 -0
  	u32 sid = current_sid();
  	u32 csid = task_sid(child);
 
+	if (mode & PTRACE_MODE_SCHED)
+		return sid == csid ? 0 : -EACCES;

IIUC, this logic is essentially the same as the uid-based check, including the fact that even a "privileged" process is not given any special handling since they always return false from ptrace_has_cap() for PTRACE_MODE_SCHED. If they are ok with applying IBPB whenever uids differ, then doing so whenever sids/contexts differ does not seem like an onerous thing.

security/selinux/hooks.c static int selinux_ptrace_access_check(struct task_struct *child,

Quoted 3 lines
security/selinux/hooks.c +0 -0
  	if (mode & PTRACE_MODE_READ)
  		return avc_has_perm(&selinux_state,
  				    sid, csid, SECCLASS_FILE, FILE__READ,

NULL);

Quoted 1 line
#16 lore raw

PATCH v5 4/5 Capability: Complete PTRACE_MODE_SCHED

In reply to Casey Schaufler

From: Casey Schaufler <[email protected]>

Allow a complete ptrace access check with mode PTRACE_MODE_SCHED. Disable the inappropriate privilege check in the capability code that does incompatible locking.

---
 kernel/ptrace.c      | 2 --
 security/commoncap.c | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/ptrace.c +0 -2
index 99cfddde6a55..0b6a9df51c3b 100644
@@ -331,8 +331,6 @@ static int __ptrace_may_access(struct task_struct *task, unsigned int mode)
 	     !ptrace_has_cap(mm->user_ns, mode)))
 	    return -EPERM;
 
-	if (mode & PTRACE_MODE_SCHED)
-		return 0;
 	return security_ptrace_access_check(task, mode);
 }
 
security/commoncap.c +2 -0
index 2e489d6a3ac8..e77457110d05 100644
@@ -152,6 +152,8 @@ int cap_ptrace_access_check(struct task_struct *child, unsigned int mode)
 	if (cred->user_ns == child_cred->user_ns &&
 	    cap_issubset(child_cred->cap_permitted, *caller_caps))
 		goto out;
+	if (mode & PTRACE_MODE_SCHED)
+		goto out;
 	if (ns_capable(child_cred->user_ns, CAP_SYS_PTRACE))
 		goto out;
 	ret = -EPERM;
Signature · 1 line
2.17.1
#17 lore raw

Re: [PATCH v5 4/5] Capability: Complete PTRACE_MODE_SCHED

Quoted 3 lines · Casey Schaufler

Allow a complete ptrace access check with mode PTRACE_MODE_SCHED. Disable the inappropriate privilege check in the capability code that does incompatible locking.

What's that locking you're talking about?

Quoted 24 lines
---
 kernel/ptrace.c      | 2 --
 security/commoncap.c | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/ptrace.c +0 -2
index 99cfddde6a55..0b6a9df51c3b 100644
@@ -331,8 +331,6 @@ static int __ptrace_may_access(struct task_struct *task, unsigned int mode)
             !ptrace_has_cap(mm->user_ns, mode)))
            return -EPERM;
 
-       if (mode & PTRACE_MODE_SCHED)
-               return 0;
        return security_ptrace_access_check(task, mode);
 }
 
security/commoncap.c +0 -0
index 2e489d6a3ac8..e77457110d05 100644

security/commoncap.c int cap_ptrace_access_check(struct task_struct *child, unsigned int mode) · line 156

Quoted 5 lines
security/commoncap.c +2 -0
@@ -152,6 +152,8 @@ int cap_ptrace_access_check(struct task_struct *child, unsigned int mode)
        if (cred->user_ns == child_cred->user_ns &&
            cap_issubset(child_cred->cap_permitted, *caller_caps))
                goto out;
+       if (mode & PTRACE_MODE_SCHED)
+               goto out;

So for PTRACE_MODE_SCHED, this function always returns 0, right? If that's intentional, perhaps you should instead just put "if (mode & PTRACE_MODE_SCHED) return 0;" at the start of the function, to avoid taking the RCU read lock in this case.

Quoted 3 lines
security/commoncap.c +0 -0
        if (ns_capable(child_cred->user_ns, CAP_SYS_PTRACE))
                goto out;
        ret = -EPERM;
#18 lore raw

RE: [PATCH v5 4/5] Capability: Complete PTRACE_MODE_SCHED

Quoted 11 lines

-----Original Message-----
From: Jann Horn [mailto:[email protected]]
Sent: Wednesday, September 26, 2018 2:26 PM
To: Schaufler, Casey <[email protected]>
Cc: Kernel Hardening <[email protected]>; kernel list <[email protected]>; linux-security-module <linux-security- [email protected]>; [email protected]; Hansen, Dave <[email protected]>; Dock, Deneen T <[email protected]>; [email protected]; Arjan van de Ven <[email protected]>
Subject: Re: [PATCH v5 4/5] Capability: Complete PTRACE_MODE_SCHED

Quoted 7 lines
Quoted 3 lines · Casey Schaufler

Allow a complete ptrace access check with mode PTRACE_MODE_SCHED. Disable the inappropriate privilege check in the capability code that does incompatible locking.

What's that locking you're talking about?

ns_capable() eventually gets you to an audit call. The audit code is going to do the locking. Fortunately, the preceding cap_issubset() is the check that we really need here.

Quoted 27 lines

kernel/ptrace.c static int __ptrace_may_access(struct task_struct

Quoted 12 lines
---
 kernel/ptrace.c      | 2 --
 security/commoncap.c | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/ptrace.c +0 -0
index 99cfddde6a55..0b6a9df51c3b 100644
@@ -331,8 +331,6 @@ static int __ptrace_may_access(struct task_struct

*task, unsigned int mode)

security/commoncap.c int cap_ptrace_access_check(struct task_struct

Quoted 13 lines
kernel/ptrace.c +0 -2
             !ptrace_has_cap(mm->user_ns, mode)))
            return -EPERM;
 
-       if (mode & PTRACE_MODE_SCHED)
-               return 0;
        return security_ptrace_access_check(task, mode);
 }
 
security/commoncap.c +0 -0
index 2e489d6a3ac8..e77457110d05 100644
@@ -152,6 +152,8 @@ int cap_ptrace_access_check(struct task_struct

*child, unsigned int mode)

Quoted 7 lines

security/commoncap.c int cap_ptrace_access_check(struct task_struct *child, unsigned int mode) · line 156

Quoted 5 lines
security/commoncap.c +2 -0
        if (cred->user_ns == child_cred->user_ns &&
            cap_issubset(child_cred->cap_permitted, *caller_caps))
                goto out;
+       if (mode & PTRACE_MODE_SCHED)
+               goto out;

So for PTRACE_MODE_SCHED, this function always returns 0, right?

That can't be right, can it? Determining that we have PTRACE_MODE_SCHED at this point should result in -EPERM. I mucked up on the logic flow. The next revision will fix this.

Quoted 7 lines

If that's intentional, perhaps you should instead just put "if (mode & PTRACE_MODE_SCHED) return 0;" at the start of the function, to avoid taking the RCU read lock in this case.

Quoted 3 lines
security/commoncap.c +0 -0
        if (ns_capable(child_cred->user_ns, CAP_SYS_PTRACE))
                goto out;
        ret = -EPERM;
#19 lore raw

PATCH v5 5/5 sidechannel: Linux Security Module for sidechannel

In reply to Casey Schaufler

From: Casey Schaufler <[email protected]>

This is a new Linux Security Module (LSM) that checks for potential sidechannel issues that are not covered in the ptrace PTRACE_MODE_SCHED option. Namespace differences are checked in this intitial version. Additional checks should be added when they are determined to be useful.

---
 include/linux/lsm_hooks.h          |  5 ++
 security/Kconfig                   |  1 +
 security/Makefile                  |  2 +
 security/security.c                |  1 +
 security/sidechannel/Kconfig       | 13 +++++
 security/sidechannel/Makefile      |  1 +
 security/sidechannel/sidechannel.c | 88 ++++++++++++++++++++++++++++++
 7 files changed, 111 insertions(+)
 create mode 100644 security/sidechannel/Kconfig
 create mode 100644 security/sidechannel/Makefile
 create mode 100644 security/sidechannel/sidechannel.c
include/linux/lsm_hooks.h +5 -0
index 97a020c616ad..3cb6516dba3c 100644
@@ -2081,5 +2081,10 @@ void __init loadpin_add_hooks(void);
 #else
 static inline void loadpin_add_hooks(void) { };
 #endif
+#ifdef CONFIG_SECURITY_SIDECHANNEL
+void __init sidechannel_add_hooks(void);
+#else
+static inline void sidechannel_add_hooks(void) { };
+#endif
 
 #endif /* ! __LINUX_LSM_HOOKS_H */
security/Kconfig +1 -0
index d9aa521b5206..6b814a3f93ea 100644
@@ -236,6 +236,7 @@ source security/tomoyo/Kconfig
 source security/apparmor/Kconfig
 source security/loadpin/Kconfig
 source security/yama/Kconfig
+source security/sidechannel/Kconfig
 
 source security/integrity/Kconfig
 
security/Makefile +2 -0
index 4d2d3782ddef..d0c9e1b227f9 100644
@@ -10,6 +10,7 @@ subdir-$(CONFIG_SECURITY_TOMOYO)        += tomoyo
 subdir-$(CONFIG_SECURITY_APPARMOR)	+= apparmor
 subdir-$(CONFIG_SECURITY_YAMA)		+= yama
 subdir-$(CONFIG_SECURITY_LOADPIN)	+= loadpin
+subdir-$(CONFIG_SECURITY_SIDECHANNEL)	+= sidechannel
 
 # always enable default capabilities
 obj-y					+= commoncap.o
@@ -25,6 +26,7 @@ obj-$(CONFIG_SECURITY_TOMOYO)		+= tomoyo/
 obj-$(CONFIG_SECURITY_APPARMOR)		+= apparmor/
 obj-$(CONFIG_SECURITY_YAMA)		+= yama/
 obj-$(CONFIG_SECURITY_LOADPIN)		+= loadpin/
+obj-$(CONFIG_SECURITY_SIDECHANNEL)	+= sidechannel/
 obj-$(CONFIG_CGROUP_DEVICE)		+= device_cgroup.o
 
 # Object integrity file lists
security/security.c +1 -0
index 736e78da1ab9..2129b0e31d7b 100644
@@ -83,6 +83,7 @@ int __init security_init(void)
 	capability_add_hooks();
 	yama_add_hooks();
 	loadpin_add_hooks();
+	sidechannel_add_hooks();
 
 	/*
 	 * Load all the remaining security modules.
security/sidechannel/Kconfig new file +13 -0
new file mode 100644
index 000000000000..653033027415
@@ -0,0 +1,13 @@
+config SECURITY_SIDECHANNEL
+	bool "Sidechannel attack safety extra checks"
+	depends on SECURITY
+	default n
+	help
+	  Look for a variety of cases where a side-channel attack
+	  could potentially be exploited. Instruct the switching
+	  code to use the indirect_branch_prediction_barrier in
+	  cases where the passed task and the current task may be
+	  at risk.
+
+          If you are unsure how to answer this question, answer N.
+
security/sidechannel/Makefile new file +1 -0
new file mode 100644
index 000000000000..f61d83f28035
@@ -0,0 +1 @@
+obj-$(CONFIG_SECURITY_SIDECHANNEL) += sidechannel.o
security/sidechannel/sidechannel.c new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#20 lore raw

Re: [PATCH v5 5/5] sidechannel: Linux Security Module for sidechannel

Quoted 7 lines · Casey Schaufler
security/sidechannel/sidechannel.c new file +7 -0
+	/*
+	 * Namespace checks. Considered safe if:
+	 *	cgroup namespace is the same
+	 *	User namespace is the same
+	 *	PID namespace is the same
+	 */
+	if (current->nsproxy)

security/sidechannel/sidechannel.c line 49

Quoted 10 lines
security/sidechannel/sidechannel.c new file +10 -0
+		ccgn = current->nsproxy->cgroup_ns;
+	if (p->nsproxy)
+		pcgn = p->nsproxy->cgroup_ns;
+	if (ccgn != pcgn)
+		return -EACCES;
+	if (current->cred->user_ns != p->cred->user_ns)
+		return -EACCES;
+	if (task_active_pid_ns(current) != task_active_pid_ns(p))
+		return -EACCES;
+	return 0;

I really don't like the idea of hard-coding namespace security semantics in an LSM. Also, I'm not sure if these semantics make any sense.

It least make it user configurable.

Signature · 2 lines
James Morris
<[email protected]>
maintainer
#21 lore raw

Re: [PATCH v5 5/5] sidechannel: Linux Security Module for sidechannel

Quoted 13 lines · James Morris
Quoted 11 lines · Casey Schaufler
security/sidechannel/sidechannel.c new file +11 -0
+	/*
+	 * Namespace checks. Considered safe if:
+	 *	cgroup namespace is the same
+	 *	User namespace is the same
+	 *	PID namespace is the same
+	 */
+	if (current->nsproxy)
+		ccgn = current->nsproxy->cgroup_ns;
+	if (p->nsproxy)
+		pcgn = p->nsproxy->cgroup_ns;
+	if (ccgn != pcgn)
Quoted 8 lines

security/sidechannel/sidechannel.c line 49

Quoted 6 lines
security/sidechannel/sidechannel.c new file +6 -0
+		return -EACCES;
+	if (current->cred->user_ns != p->cred->user_ns)
+		return -EACCES;
+	if (task_active_pid_ns(current) != task_active_pid_ns(p))
+		return -EACCES;
+	return 0;

I really don't like the idea of hard-coding namespace security semantics in an LSM. Also, I'm not sure if these semantics make any sense.

Checks on namespaces where explicitly requested. I think these are the most sensible, but I'm willing to be educated. I was also requested to check on potential issues between containers, but as there is no kernel concept of containers this is the best I see we can do.

Quoted 1 line

It least make it user configurable.

Would you have a suggested granularity? I could have a configuration option for each of cgroups, user and pid namespaces but that's getting to be a lot of knobs to twist.

maintainer
#22 lore raw

Re: [PATCH v5 5/5] sidechannel: Linux Security Module for sidechannel

Quoted 23 lines · Casey Schaufler
Quoted 13 lines · James Morris
Quoted 11 lines · Casey Schaufler
security/sidechannel/sidechannel.c new file +11 -0
+	/*
+	 * Namespace checks. Considered safe if:
+	 *	cgroup namespace is the same
+	 *	User namespace is the same
+	 *	PID namespace is the same
+	 */
+	if (current->nsproxy)
+		ccgn = current->nsproxy->cgroup_ns;
+	if (p->nsproxy)
+		pcgn = p->nsproxy->cgroup_ns;
+	if (ccgn != pcgn)
Quoted 8 lines

security/sidechannel/sidechannel.c line 49

Quoted 6 lines
security/sidechannel/sidechannel.c new file +6 -0
+		return -EACCES;
+	if (current->cred->user_ns != p->cred->user_ns)
+		return -EACCES;
+	if (task_active_pid_ns(current) != task_active_pid_ns(p))
+		return -EACCES;
+	return 0;

I really don't like the idea of hard-coding namespace security semantics in an LSM. Also, I'm not sure if these semantics make any sense.

Quoted 1 line

Checks on namespaces where explicitly requested.

By whom and what is the rationale?

Signature · 2 lines
James Morris
<[email protected]>
#23 lore raw

RE: [PATCH v5 5/5] sidechannel: Linux Security Module for sidechannel

Quoted 36 lines

-----Original Message-----
From: James Morris [mailto:[email protected]]
Sent: Thursday, September 27, 2018 3:47 PM
To: Casey Schaufler <[email protected]>
Cc: Schaufler, Casey <[email protected]>; [email protected]; [email protected]; Dock, Deneen T <[email protected]>; [email protected]; Hansen, Dave <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 5/5] sidechannel: Linux Security Module for sidechannel

Quoted 23 lines · Casey Schaufler
Quoted 21 lines · James Morris
Quoted 7 lines · Casey Schaufler
security/sidechannel/sidechannel.c new file +7 -0
+	/*
+	 * Namespace checks. Considered safe if:
+	 *	cgroup namespace is the same
+	 *	User namespace is the same
+	 *	PID namespace is the same
+	 */
+	if (current->nsproxy)

security/sidechannel/sidechannel.c line 49

Quoted 10 lines
security/sidechannel/sidechannel.c new file +10 -0
+		ccgn = current->nsproxy->cgroup_ns;
+	if (p->nsproxy)
+		pcgn = p->nsproxy->cgroup_ns;
+	if (ccgn != pcgn)
+		return -EACCES;
+	if (current->cred->user_ns != p->cred->user_ns)
+		return -EACCES;
+	if (task_active_pid_ns(current) != task_active_pid_ns(p))
+		return -EACCES;
+	return 0;

I really don't like the idea of hard-coding namespace security semantics in an LSM. Also, I'm not sure if these semantics make any sense.

Quoted 3 lines
Quoted 1 line

Checks on namespaces where explicitly requested.

By whom and what is the rationale?

The rationale is to protect containers. Since those closest thing there is to a definition of containers is "uses namespaces" that becomes the focus. Separating them out does not make too much sense as I would expect someone concerned with one to be concerned with all.

maintainer
#24 lore raw

RE: [PATCH v5 5/5] sidechannel: Linux Security Module for sidechannel

Quoted 25 lines · Casey
Quoted 25 lines
Quoted 24 lines · James Morris
Quoted 13 lines · Casey Schaufler
Quoted 12 lines
security/sidechannel/sidechannel.c new file +11 -0
+	/*
+	 * Namespace checks. Considered safe if:
+	 *	cgroup namespace is the same
+	 *	User namespace is the same
+	 *	PID namespace is the same
+	 */
+	if (current->nsproxy)
+		ccgn = current->nsproxy->cgroup_ns;
+	if (p->nsproxy)
+		pcgn = p->nsproxy->cgroup_ns;
+	if (ccgn != pcgn)
Quoted 8 lines

security/sidechannel/sidechannel.c line 49

Quoted 6 lines
security/sidechannel/sidechannel.c new file +6 -0
+		return -EACCES;
+	if (current->cred->user_ns != p->cred->user_ns)
+		return -EACCES;
+	if (task_active_pid_ns(current) != task_active_pid_ns(p))
+		return -EACCES;
+	return 0;

I really don't like the idea of hard-coding namespace security semantics in an LSM. Also, I'm not sure if these semantics make any sense.

Checks on namespaces where explicitly requested.

Quoted 7 lines
Quoted 1 line

By whom and what is the rationale?

The rationale is to protect containers. Since those closest thing there is to a definition of containers is "uses namespaces" that becomes the focus. Separating them out does not make too much sense as I would expect someone concerned with one to be concerned with all.

A lot of people will not be using user namespaces due to security concerns, so with this hard-coded logic, you are saying this case is 'safe' in a sidechannel context.

Which hints at the deeper issue that containers are a userland abstraction. Protection of containers needs to be defined by userland policy.

Signature · 2 lines
James Morris
<[email protected]>
#25 lore raw

Re: [PATCH v5 5/5] sidechannel: Linux Security Module for sidechannel

Quoted 28 lines · James Morris
Quoted 27 lines · Casey
Quoted 26 lines
Quoted 20 lines · James Morris
Quoted 19 lines · Casey Schaufler
Quoted 18 lines
security/sidechannel/sidechannel.c new file +17 -0
+      /*
+       * Namespace checks. Considered safe if:
+       *      cgroup namespace is the same
+       *      User namespace is the same
+       *      PID namespace is the same
+       */
+      if (current->nsproxy)
+              ccgn = current->nsproxy->cgroup_ns;
+      if (p->nsproxy)
+              pcgn = p->nsproxy->cgroup_ns;
+      if (ccgn != pcgn)
+              return -EACCES;
+      if (current->cred->user_ns != p->cred->user_ns)
+              return -EACCES;
+      if (task_active_pid_ns(current) != task_active_pid_ns(p))
+              return -EACCES;
+      return 0;
Quoted 4 lines
Quoted 2 lines

I really don't like the idea of hard-coding namespace security semantics in an LSM. Also, I'm not sure if these semantics make any sense.

Checks on namespaces where explicitly requested.

By whom and what is the rationale?

Quoted 8 lines
Quoted 5 lines

The rationale is to protect containers. Since those closest thing there is to a definition of containers is "uses namespaces" that becomes the focus. Separating them out does not make too much sense as I would expect someone concerned with one to be concerned with all.

A lot of people will not be using user namespaces due to security concerns,

Ugh.

Quoted 6 lines

so with this hard-coded logic, you are saying this case is 'safe' in a sidechannel context.

Which hints at the deeper issue that containers are a userland abstraction. Protection of containers needs to be defined by userland policy.

Or just compare mount namespaces additionally/instead. I think that containers will always use those, because AFAIK nobody uses chroot() for containers, given that the kernel makes absolutely no security guarantees about chroot().

maintainer
#26 lore raw

Re: [PATCH v5 5/5] sidechannel: Linux Security Module for sidechannel

Quoted 11 lines · Jann Horn
Quoted 6 lines

so with this hard-coded logic, you are saying this case is 'safe' in a sidechannel context.

Which hints at the deeper issue that containers are a userland abstraction. Protection of containers needs to be defined by userland policy.

Or just compare mount namespaces additionally/instead. I think that containers will always use those, because AFAIK nobody uses chroot() for containers, given that the kernel makes absolutely no security guarantees about chroot().

We can't define this in the kernel. It has no concept of containers.

People utilize some combination of namespaces and cgroups and call them containers, but we can't make assumptions from the kernel on what any of this means from a security point of view, and hard-code kernel policy based on those assumptions.

This is violating the principal of separating mechanism and policy, and also imposing semantics across the kernel/user boundary. The latter creates an ABI which we can then never break.

Signature · 2 lines
James Morris
<[email protected]>
#27 lore raw

RE: [PATCH v5 5/5] sidechannel: Linux Security Module for sidechannel

Quoted 27 lines

-----Original Message-----
From: James Morris [mailto:[email protected]]
Sent: Friday, September 28, 2018 9:33 AM
To: Jann Horn <[email protected]>
Cc: Schaufler, Casey <[email protected]>; Casey Schaufler <[email protected]>; [email protected]; Kernel Hardening <[email protected]>; Dock, Deneen T <[email protected]>; kernel list <[email protected]>; Hansen, Dave <[email protected]>; linux-security-module <linux-security- [email protected]>; [email protected]; Arjan van de Ven <[email protected]>
Subject: Re: [PATCH v5 5/5] sidechannel: Linux Security Module for sidechannel

Quoted 11 lines · Jann Horn
Quoted 6 lines

so with this hard-coded logic, you are saying this case is 'safe' in a sidechannel context.

Which hints at the deeper issue that containers are a userland abstraction. Protection of containers needs to be defined by userland policy.

Or just compare mount namespaces additionally/instead. I think that containers will always use those, because AFAIK nobody uses chroot() for containers, given that the kernel makes absolutely no security guarantees about chroot().

Quoted 4 lines

We can't define this in the kernel. It has no concept of containers.

People utilize some combination of namespaces and cgroups and call them containers,

There is an amazing variety of things called containers out there. I cite them as a use case, not a requirement.

Quoted 3 lines

but we can't make assumptions from the kernel on what any of this means from a security point of view, and hard-code kernel policy based on those assumptions.

We can assume that namespaces are being used as a separation mechanism. That makes processes in different namespaces potentially vulnerable to side-channel attacks. That's true regardless of whether or not someone is using namespaces to implement containers.

Quoted 3 lines

This is violating the principal of separating mechanism and policy, and also imposing semantics across the kernel/user boundary. The latter creates an ABI which we can then never break.

The effects of the sidechannel security module are not API visible. The potential impact is on performance. This implementation of PTRACE_MODE_SCHED does not change what happens, but may affect when it happens. It is intended to aid in optimizing the use of expensive anti-side-channel countermeasures.