fs/exec: "always_unprivileged" patch
Subsystems (8)
Will Drewry
reviewerPATCH 1/3 fs/exec: "always_unprivileged" patch
This patch is a placeholder until Andy's ([email protected]) patch arrives implementing Linus's proposal for applying a "this is a process that has *no* extra privileges at all, and can never get them".
It adds the "always_unprivileged" member to the task_struct and the ability for a process to set it to 1 via prctl. Fixup is then done alongside MNT_NOSUID in fs/exec.c and security/commoncap.c (as Eric Paris suggested).
selinux/hooks.c have not been touched but need a similar one line change. That said, this is just a placeholder and is not meant to be authoritative: I look forward to Andy's patches!
--- fs/exec.c | 3 ++- include/linux/prctl.h | 6 ++++++ include/linux/sched.h | 1 + kernel/sys.c | 4 +++- security/commoncap.c | 3 ++- 5 files changed, 14 insertions(+), 3 deletions(-)
fs/exec.c +2 -1
@@ -1281,7 +1281,8 @@ int prepare_binprm(struct linux_binprm *bprm) bprm->cred->euid =current_euid (); bprm->cred->egid =current_egid (); -if (!(bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID )) { +if (!(bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID ) && + !current->always_unprivileged) {/* Set-uid? */ if (mode &S_ISUID ) { bprm->per_clear |=PER_CLEAR_ON_SETID ;
include/linux/prctl.h +6 -0
@@ -102,4 +102,10 @@#define PR_MCE_KILL_GET 34 +/* +* Set this to ensure that a process and any of its descendents may never +* escalate privileges (only reduce them). +*/ +#define PR_SET_ALWAYS_UNPRIVILEGED 35 +#endif /* _LINUX_PRCTL_H */
include/linux/sched.h +1 -0
@@ -1402,6 +1402,7 @@ struct task_struct {unsigned int sessionid;#endif seccomp_t seccomp; +int always_unprivileged;/* Thread group tracking */ u32 parent_exec_id;
kernel/sys.c +3 -1
@@ -1776,7 +1776,6 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,case PR_SET_ENDIAN : error =SET_ENDIAN (me, arg2);break ; -case PR_GET_SECCOMP : error =prctl_get_seccomp ();break ;
@@ -1841,6 +1840,9 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,else error =PR_MCE_KILL_DEFAULT ;break ; +case PR_SET_ALWAYS_UNPRIVILEGED : + current->always_unprivileged =1 ; +break ;default : error = -EINVAL ;break ;
security/commoncap.c +2 -1
@@ -439,7 +439,8 @@ static int get_file_caps(struct linux_binprm *bprm, bool *effective, bool *has_cif (!file_caps_enabled)return 0 ; -if (bprm->file->f_vfsmnt->mnt_flags &MNT_NOSUID ) +if ((bprm->file->f_vfsmnt->mnt_flags &MNT_NOSUID ) || + current->always_unprivileged)return 0 ; dentry =dget (bprm->file->f_dentry);
Signature · 1 line
1.7.5.4
Will Drewry
reviewerPATCH v3 2/3 seccomp_filters: system call filtering using BPF
This patch adds support for seccomp mode 2. This mode enables dynamic enforcement of system call filtering policy in the kernel as specified by a userland task. The policy is expressed in terms of a BPF program, as is used for userland-exposed socket filtering. Instead of network data, the BPF program is evaluated over struct user_regs_struct at the time of the system call (as retrieved using regviews).
A filter program may be installed by a userland task by calling
prctl(PR_ATTACH_SECCOMP_FILTER, &fprog);
where fprog is of type struct sock_fprog.
If the first filter program allows subsequent prctl(2) calls, then additional filter programs may be attached. All attached programs must be evaluated before a system call will be allowed to proceed.
To avoid CONFIG_COMPAT related landmines, once a filter program is installed using specific is_compat_task() and current->personality, it is not allowed to make system calls or attach additional filters which use a different combination of is_compat_task() and current->personality.
Filter programs are inherited across fork, clone, and execve, but if a filter is attached by an unprivileged process (!CAP_SYS_ADMIN), the "always unprivileged" process bit will be set. This ensures that unprivileged processes may not enact unexpected system call filters on processes that are run as different users or with different capabilities unless the process already had that ability.
There are a number of benefits to this approach. A few of which are as follows:
- BPF has been exposed to userland for a long time.
- Userland already knows its ABI: expected register layout and system call numbers.
- Full register information is provided which may be relevant for certain syscalls (fork, rt_sigreturn) or for other userland filtering tactics (checking the PC).
- No time-of-check-time-of-use vulnerable data accesses are possible.
This patch includes its own BPF evaluator, but relies on the net/core/filter.c BPF checking code. It is possible to share evaluators, but the performance sensitive nature of the network filtering path makes it an iterative optimization which (I think :) can be tackled separately via separate patchsets. (And at some point sharing BPF JIT code!)
v3: - macros to inline ([email protected])
- init_task behavior fixed ([email protected])
- drop creator entry and extra NULL check ([email protected])
- alloc returns -EINVAL on bad sizing ([email protected])
- (!) adds tentative use of "always_unprivileged" as per [email protected] and [email protected]
v2: - n/a
--- include/linux/prctl.h | 3 + include/linux/seccomp.h | 68 +++++- kernel/Makefile | 1 + kernel/fork.c | 4 + kernel/seccomp.c | 8 + kernel/seccomp_filter.c | 620 +++++++++++++++++++++++++++++++++++++++++++++++ kernel/sys.c | 4 + security/Kconfig | 12 + 8 files changed, 717 insertions(+), 3 deletions(-) create mode 100644 kernel/seccomp_filter.c
include/linux/prctl.h +3 -0
@@ -64,6 +64,9 @@#define PR_GET_SECCOMP 21#define PR_SET_SECCOMP 22 +/* Set process seccomp filters */ +#define PR_ATTACH_SECCOMP_FILTER 36 +/* Get/set the capability bounding set (as per security/commoncap.c) */ #define PR_CAPBSET_READ 23#define PR_CAPBSET_DROP 24
include/linux/seccomp.h +65 -3
86 lines not on this page · raw message
kernel/Makefile +1 -0
@@ -79,6 +79,7 @@ obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o obj-$(CONFIG_LOCKUP_DETECTOR) += watchdog.o obj-$(CONFIG_GENERIC_HARDIRQS) += irq/ obj-$(CONFIG_SECCOMP) += seccomp.o +obj-$(CONFIG_SECCOMP_FILTER) += seccomp_filter.o obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o obj-$(CONFIG_TREE_RCU) += rcutree.o obj-$(CONFIG_TREE_PREEMPT_RCU) += rcutree.o
kernel/fork.c +4 -0
@@ -34,6 +34,7 @@#include <linux/cgroup.h> #include <linux/security.h> #include <linux/hugetlb.h> +#include <linux/seccomp.h> #include <linux/swap.h> #include <linux/syscalls.h> #include <linux/jiffies.h>
@@ -166,6 +167,7 @@ void free_task(struct task_struct *tsk)free_thread_info (tsk->stack);rt_mutex_debug_task_free (tsk);ftrace_graph_exit_task (tsk); +seccomp_struct_free_task (&tsk->seccomp);free_task_struct (tsk); }EXPORT_SYMBOL (free_task);
@@ -1089,6 +1091,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, goto fork_out;ftrace_graph_init_task (p); +seccomp_struct_init_task (&p->seccomp);rt_mutex_init_task (p);
@@ -1375,6 +1378,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,if (clone_flags &CLONE_THREAD )threadgroup_fork_read_unlock (current);perf_event_fork (p); +seccomp_struct_fork (&p->seccomp, ¤t->seccomp);return p; bad_fork_free_pid:
kernel/seccomp.c +8 -0
@@ -47,6 +47,14 @@ void __secure_computing(int this_syscall)return ; }while (*++syscall);break ; +#ifdef CONFIG_SECCOMP_FILTER +case 2 : +if (seccomp_test_filters (this_syscall) ==0 ) +return ; + +seccomp_filter_log_failure (this_syscall); +break ; +#endif default :BUG (); }
kernel/seccomp_filter.c new file +620 -0
620 lines not on this page · raw message
kernel/sys.c +4 -0
@@ -1782,6 +1782,10 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,case PR_SET_SECCOMP : error =prctl_set_seccomp (arg2);break ; +case PR_ATTACH_SECCOMP_FILTER : + error =prctl_attach_seccomp_filter ((char __user *) + arg2); +break ;case PR_GET_TSC : error =GET_TSC_CTL (arg2);break ;
security/Kconfig +12 -0
@@ -84,6 +84,18 @@ config SECURITY_DMESG_RESTRICT If you are unsure how to answer this question, answer N. +config SECCOMP_FILTER + bool "Enable seccomp-based system call filtering" + select SECCOMP + depends on EXPERIMENTAL + help + This kernel feature expands CONFIG_SECCOMP to allow computing + in environments with reduced kernel access dictated by a system + call filter, expressed in BPF, installed by the application itself + through prctl(2). + + See Documentation/prctl/seccomp_filter.txt for more detail. + config SECURITY bool "Enable different security models" depends on SYSFS
Signature · 1 line
1.7.5.4
Re: [PATCH v3 2/3] seccomp_filters: system call filtering using BPF
Quoted 71 lines · Will Drewry
include/linux/prctl.h | 3 + include/linux/seccomp.h | 68 +++++- kernel/Makefile | 1 + kernel/fork.c | 4 + kernel/seccomp.c | 8 + kernel/seccomp_filter.c | 620 +++++++++++++++++++++++++++++++++++++++++++++++ kernel/sys.c | 4 + security/Kconfig | 12 + 8 files changed, 717 insertions(+), 3 deletions(-) create mode 100644 kernel/seccomp_filter.cinclude/linux/seccomp.h +33
-3@@ -5,9 +5,28 @@#ifdef CONFIG_SECCOMP #include <linux/thread_info.h> +#include <linux/types.h> #include <asm/seccomp.h> -typedef struct {int mode; }seccomp_t ; +struct seccomp_filter ; +/** +* struct seccomp_struct - the state of a seccomp'ed process +* +* @mode: +* if this is 0, seccomp is not in use. +* is 1, the process is under standard seccomp rules. +* is 2, the process is only allowed to make system calls where +* associated filters evaluate successfully. +* @filter: Metadata for filter if using CONFIG_SECCOMP_FILTER. +* @filter must only be accessed from the context of current as there +* is no guard. +*/ +typedef struct seccomp_struct { +int mode; +#ifdef CONFIG_SECCOMP_FILTER +struct seccomp_filter *filter; +#endif +}seccomp_t ;extern void __secure_computing (int );static inline void secure_computing (int this_syscall)@@ -28,8 +47,7 @@ static inline int seccomp_mode(seccomp_t *s)#include <linux/errno.h> -typedef struct { }seccomp_t ; - +typedef struct seccomp_struct { }seccomp_t ;#define secure_computing (x) do { } while (0)static inline long prctl_get_seccomp (void )@@ -49,4 +67,48 @@ static inline int seccomp_mode(seccomp_t *s)#endif /* CONFIG_SECCOMP */ +#ifdef CONFIG_SECCOMP_FILTER + + +extern long prctl_attach_seccomp_filter (char __user *); + +extern struct seccomp_filter *get_seccomp_filter (struct seccomp_filter *); +extern void put_seccomp_filter (struct seccomp_filter *); + +extern int seccomp_test_filters (int ); +extern void seccomp_filter_log_failure (int ); +extern void seccomp_struct_fork (struct seccomp_struct *child, +const struct seccomp_struct *parent);
include/linux/seccomp.h static inline int seccomp_mode(seccomp_t *s) · line 91
Quoted 10 lines
include/linux/seccomp.h +10
-0+ +static inline void seccomp_struct_init_task (struct seccomp_struct *seccomp) +{ + seccomp->mode =0 ; + seccomp->filter =NULL ; +} + +/* No locking is needed here because the task_struct will +* have no parallel consumers. +*/
(in multiple places:) Kernel multi-line comment style is:
/*
* first line of text
* more stuff
*/
Quoted 30 lines
include/linux/seccomp.h +22
-0+static inline void seccomp_struct_free_task (struct seccomp_struct *seccomp) +{ +put_seccomp_filter (seccomp->filter); + seccomp->filter =NULL ; +} + +#else /* CONFIG_SECCOMP_FILTER */ + +#include <linux/errno.h> + +struct seccomp_filter { }; +/* Macros consume the unused dereference by the caller. */ +#define seccomp_struct_init_task (_seccomp) do { } while (0); +#define seccomp_struct_fork (_tsk, _orig) do { } while (0); +#define seccomp_struct_free_task (_seccomp) do { } while (0); + +static inline long prctl_attach_seccomp_filter (char __user *a2) +{ +return -ENOSYS ; +} + +#endif /* CONFIG_SECCOMP_FILTER */ #endif /* _LINUX_SECCOMP_H */ kernel/seccomp.c +0
-0
kernel/seccomp.c void __secure_computing(int this_syscall) · line 51
Quoted 5 lines
kernel/seccomp.c +2
-0@@ -47,6 +47,14 @@ void __secure_computing(int this_syscall)return ; }while (*++syscall);break ; +#ifdef CONFIG_SECCOMP_FILTER +case 2 :
Can we get macros (defines) for these @modes instead of using inline constants?
Quoted 34 lines
kernel/seccomp.c +6
-0+if (seccomp_test_filters (this_syscall) ==0 ) +return ; + +seccomp_filter_log_failure (this_syscall); +break ; +#endif default :BUG (); }kernel/seccomp_filter.c new file +19
-0@@ -0,0 +1,620 @@ +/* bpf program-based system call filtering +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +* Copyright (C) 2011 The Chromium OS Authors <[email protected]> +*/ +
...
Quoted 1 line
+/*
seccomp_struct_fork: manages inheritance on fork
/**
* seccomp_struct_fork - manages inheritance on fork
Quoted 7 lines
+ * @child: forkee's
seccomp_struct
+ * @parent: forker'sseccomp_struct
+ * Ensures that @child inherit aseccomp_filteriff seccomp is enabled
+ * and the set of filters is marked as 'enabled'.
+ */kernel/seccomp_filter.c new file +2
-0+void seccomp_struct_fork (struct seccomp_struct *child, +const struct seccomp_struct *parent)
kernel/seccomp_filter.c line 378
Quoted 10 lines
kernel/seccomp_filter.c new file +10
-0+{ +if (!parent->mode) +return ; + child->mode = parent->mode; + child->filter =get_seccomp_filter (parent->filter); +} + +/* Returns a pointer to the BPF evaluator after checking the offset and size +* boundaries. The signature almost matches the signature from +* net/core/filter.c with the hopes of sharing code in the future.
Use kernel multi-line comment style.
Quoted 24 lines
+ */
kernel/seccomp_filter.c new file +15
-0+static const void *load_pointer (const u8 *buf,size_t buflen, +int offset,size_t size, +void *unused) +{ +if (offset >= buflen) + goto fail; +if (offset <0 ) + goto fail; +if (size > buflen - offset) + goto fail; +return buf + offset; +fail: +return NULL ; +} +security/Kconfig +0
-0@@ -84,6 +84,18 @@ config SECURITY_DMESG_RESTRICT If you are unsure how to answer this question, answer N.
security/Kconfig config SECURITY_DMESG_RESTRICT · line 95
Quoted 10 lines
security/Kconfig +9
-0+config SECCOMP_FILTER + bool "Enable seccomp-based system call filtering" + select SECCOMP + depends on EXPERIMENTAL + help + This kernel feature expands CONFIG_SECCOMP to allow computing + in environments with reduced kernel access dictated by a system + call filter, expressed in BPF, installed by the application itself + through prctl(2).
This help text is only useful to someone who already knows what it does/means IMO.
security/Kconfig config SECURITY_DMESG_RESTRICT · line 97
Quoted 2 lines
security/Kconfig +2
-0+ + See Documentation/prctl/seccomp_filter.txt for more detail.
Yes, I'll look at that..
Quoted 4 lines
security/Kconfig +1
-0+ config SECURITY bool "Enable different security models" depends on SYSFS
Signature · 2 lines
~Randy *** Remember to use Documentation/SubmitChecklist when testing your code ***
Will Drewry
reviewerRe: [PATCH v3 2/3] seccomp_filters: system call filtering using BPF
Quoted 85 lines · Randy Dunlap
Quoted 71 lines · Will Drewry
include/linux/prctl.h | 3 +
include/linux/seccomp.h | 68 +++++-
kernel/Makefile | 1 +
kernel/fork.c | 4 +
kernel/seccomp.c | 8 +
kernel/seccomp_filter.c | 620 +++++++++++++++++++++++++++++++++++++++++++++++kernel/sys.c| 4 +
security/Kconfig | 12 +8 files changed, 717 insertions(+), 3 deletions(-)create mode 100644
kernel/seccomp_filter.cinclude/linux/seccomp.h +33
-3@@ -5,9 +5,28 @@ #ifdef CONFIG_SECCOMP #include <linux/thread_info.h> +#include <linux/types.h> #include <asm/seccomp.h> -typedef struct {int mode; }seccomp_t ; +struct seccomp_filter ; +/** +* struct seccomp_struct - the state of a seccomp'ed process +* +* @mode: +* if this is 0, seccomp is not in use. +* is 1, the process is under standard seccomp rules. +* is 2, the process is only allowed to make system calls where +* associated filters evaluate successfully. +* @filter: Metadata for filter if using CONFIG_SECCOMP_FILTER. +* @filter must only be accessed from the context of current as there +* is no guard. +*/ +typedef struct seccomp_struct { + int mode; +#ifdef CONFIG_SECCOMP_FILTER + struct seccomp_filter *filter; +#endif +}seccomp_t ; extern void __secure_computing(int); static inline void secure_computing(int this_syscall)@@ -28,8 +47,7 @@ static inline int seccomp_mode(seccomp_t *s) #include <linux/errno.h> -typedef struct { }seccomp_t ; - +typedef struct seccomp_struct { }seccomp_t ; #define secure_computing(x) do { } while (0) static inline long prctl_get_seccomp(void)@@ -49,4 +67,48 @@ static inline int seccomp_mode(seccomp_t *s) #endif /* CONFIG_SECCOMP */ +#ifdef CONFIG_SECCOMP_FILTER + + +extern long prctl_attach_seccomp_filter (char __user *); + +extern struct seccomp_filter *get_seccomp_filter (struct seccomp_filter *); +extern void put_seccomp_filter (struct seccomp_filter *); + +extern int seccomp_test_filters (int ); +extern void seccomp_filter_log_failure (int ); +extern void seccomp_struct_fork (struct seccomp_struct *child, + const struct seccomp_struct *parent);include/linux/seccomp.h static inline int seccomp_mode(seccomp_t *s) · line 91
Quoted 10 lines
include/linux/seccomp.h +10
-0+ +static inline void seccomp_struct_init_task (struct seccomp_struct *seccomp) +{ + seccomp->mode = 0; + seccomp->filter = NULL; +} + +/* No locking is needed here because the task_struct will +* have no parallel consumers. +*/ (in multiple places:) Kernel multi-line comment style is:
Quoted 4 lines
/*
* first line of text
* more stuff
*/
Thanks! I'll roll through and clean them all up. My apologies!
Quoted 25 lines
Quoted 23 lines
include/linux/seccomp.h +22
-0+static inline void seccomp_struct_free_task (struct seccomp_struct *seccomp) +{ + put_seccomp_filter(seccomp->filter); + seccomp->filter = NULL; +} + +#else /* CONFIG_SECCOMP_FILTER */ + +#include <linux/errno.h> + +struct seccomp_filter { }; +/* Macros consume the unused dereference by the caller. */ +#define seccomp_struct_init_task (_seccomp) do { } while (0); +#define seccomp_struct_fork (_tsk, _orig) do { } while (0); +#define seccomp_struct_free_task (_seccomp) do { } while (0); + +static inline long prctl_attach_seccomp_filter (char __user *a2) +{ + return -ENOSYS; +} + +#endif /* CONFIG_SECCOMP_FILTER */ #endif /* _LINUX_SECCOMP_H */
Quoted 13 lines
kernel/seccomp.c void __secure_computing(int this_syscall) · line 51
Quoted 10 lines
kernel/seccomp.c +2
-0@@ -47,6 +47,14 @@ void __secure_computing(int this_syscall) return; } while (*++syscall); break; +#ifdef CONFIG_SECCOMP_FILTER + case 2:Can we get macros (defines) for these @modes instead of using inline constants?
Certainly!
Quoted 26 lines
Quoted 26 lines
kernel/seccomp.c +6
-0+ if (seccomp_test_filters(this_syscall) == 0) + return; + + seccomp_filter_log_failure(this_syscall); + break; +#endif default:
BUG();
}kernel/seccomp_filter.c new file +11
-0@@ -0,0 +1,620 @@ +/* bpf program-based system call filtering +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details.
Quoted 8 lines
kernel/seccomp_filter.c line 19
Quoted 8 lines
kernel/seccomp_filter.c new file +8
-0+* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +* Copyright (C) 2011 The Chromium OS Authors <[email protected]> +*/ +
Aside from being a year off, is there a current style? I just went off of an existing file.
Quoted 5 lines
kernel/seccomp_filter.c line 361
Quoted 2 lines
kernel/seccomp_filter.c new file +1
-0+/* seccomp_struct_fork: manages inheritance on fork /**
*seccomp_struct_fork- manages inheritance on fork
Thanks - sorry!
Quoted 11 lines
Quoted 11 lines
kernel/seccomp_filter.c new file +11
-0+* @child: forkee's seccomp_struct +* @parent: forker's seccomp_struct +* Ensures that @child inherit a seccomp_filter iff seccomp is enabled +* and the set of filters is marked as 'enabled'. +*/ +void seccomp_struct_fork (struct seccomp_struct *child, + const struct seccomp_struct *parent) +{ + if (!parent->mode) + return; + child->mode = parent->mode;
Quoted 8 lines
kernel/seccomp_filter.c line 378
Quoted 6 lines
kernel/seccomp_filter.c new file +6
-0+ child->filter = get_seccomp_filter(parent->filter); +} + +/* Returns a pointer to the BPF evaluator after checking the offset and size +* boundaries. The signature almost matches the signature from +* net/core/filter.c with the hopes of sharing code in the future. Use kernel multi-line comment style.
Of course.
Quoted 25 lines
Quoted 25 lines
kernel/seccomp_filter.c new file +16
-0+*/ +static const void *load_pointer (const u8 *buf,size_t buflen, + int offset, size_t size, + void *unused) +{ + if (offset >= buflen) + goto fail; + if (offset < 0) + goto fail; + if (size > buflen - offset) + goto fail; + return buf + offset; +fail: + return NULL; +} +security/Kconfig +0
-0@@ -84,6 +84,18 @@ config SECURITY_DMESG_RESTRICTIf you are unsure how to answer this question, answer N.
Quoted 12 lines
Quoted 9 lines
+config
SECCOMP_FILTER
+ bool "Enable seccomp-based system call filtering"
+ select SECCOMP
+ depends on EXPERIMENTAL
+ help
+ This kernel feature expandsCONFIG_SECCOMPto allow computing
+ in environments with reduced kernel access dictated by a system
+ call filter, expressed in BPF, installed by the application itself
+ through prctl(2).This help text is only useful to someone who already knows what it does/means IMO.
I'll attempt to clean that up so it makes actual sense to those without context!
Quoted 4 lines
Quoted 2 lines
+
+ SeeDocumentation/prctl/seccomp_filter.txtfor more detail.Yes, I'll look at that..
Awesome - thanks!
Quoted 9 lines
Quoted 4 lines
+
config SECURITY
bool "Enable different security models"
depends on SYSFS--
~Randy
*** Remember to useDocumentation/SubmitChecklistwhen testing your code ***
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 2/3] seccomp_filters: system call filtering using BPF
Quoted 20 lines · Will Drewry
Quoted 20 lines
Quoted 20 lines
kernel/seccomp_filter.c new file +14
-0@@ -0,0 +1,620 @@ +/* bpf program-based system call filtering +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software
Quoted 8 lines
Quoted 5 lines
kernel/seccomp_filter.c line 19
Quoted 5 lines
kernel/seccomp_filter.c new file +5
-0+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +* Copyright (C) 2011 The Chromium OS Authors <[email protected]> +*/ +Aside from being a year off, is there a current style? I just went off of an existing file.
Sorry, I wasn't making a comment about that header. Guess I should have deleted it.
thanks,
Signature · 2 lines
~Randy *** Remember to use Documentation/SubmitChecklist when testing your code ***
Re: [PATCH v3 2/3] seccomp_filters: system call filtering using BPF
In reply to Will DrewryQuoted 18 lines · Will Drewry
include/linux/seccomp.h +12
-1-typedef struct {int mode; }seccomp_t ; +struct seccomp_filter ; +/** +* struct seccomp_struct - the state of a seccomp'ed process +* +* @mode: +* if this is 0, seccomp is not in use. +* is 1, the process is under standard seccomp rules. +* is 2, the process is only allowed to make system calls where +* associated filters evaluate successfully. +* @filter: Metadata for filter if using CONFIG_SECCOMP_FILTER. +* @filter must only be accessed from the context of current as there +* is no guard.
include/linux/seccomp.h line 32
Quoted 10 lines
include/linux/seccomp.h +7
-0+*/ +typedef struct seccomp_struct { +int mode; +#ifdef CONFIG_SECCOMP_FILTER +struct seccomp_filter *filter; +#endif +}seccomp_t ;extern void __secure_computing (int );static inline void secure_computing (int this_syscall)
Can we get rid of all of the typedef stuff? I know you didn't add it but now seems like a good time to follow typical kernel semantics if you have to re-rev for some other reason.
-Eric
Will Drewry
reviewerRe: [PATCH v3 2/3] seccomp_filters: system call filtering using BPF
Quoted 28 lines · Eric Paris
Quoted 26 lines · Will Drewry
include/linux/seccomp.h +19
-1-typedef struct {int mode; }seccomp_t ; +struct seccomp_filter ; +/** +* struct seccomp_struct - the state of a seccomp'ed process +* +* @mode: +* if this is 0, seccomp is not in use. +* is 1, the process is under standard seccomp rules. +* is 2, the process is only allowed to make system calls where +* associated filters evaluate successfully. +* @filter: Metadata for filter if using CONFIG_SECCOMP_FILTER. +* @filter must only be accessed from the context of current as there +* is no guard. +*/ +typedef struct seccomp_struct { + int mode; +#ifdef CONFIG_SECCOMP_FILTER + struct seccomp_filter *filter; +#endif +}seccomp_t ;
Quoted 6 lines
Quoted 2 lines
extern void
__secure_computing(int);
static inline voidsecure_computing(int this_syscall)Can we get rid of all of the typedef stuff? I know you didn't add it but now seems like a good time to follow typical kernel semantics if you have to re-rev for some other reason.
Yup - I was hoping to do that separately since it touches extra files.
I'll make a prereq patch that enacts the change (so it can be picked
up even if the seccomp-bpf is less successful).
cheers!
will
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Will Drewry
reviewerPATCH v3 3/3 Documentation: prctl/seccomp_filter
In reply to Will DrewryDocuments how system call filtering using Berkeley Packet Filter programs works and how it may be used. Includes an example for x86 (32-bit).
v3: - call out BPF <-> Berkeley Packet Filter ([email protected])
- document use of tentative always-unprivileged
- guard sample compilation for i386 and x86_64
v2: - move code to samples ([email protected])
--- Documentation/prctl/seccomp_filter.txt | 94 ++++++++++++++++++++++++++++++++ samples/Makefile | 2 +- samples/seccomp/Makefile | 18 ++++++ samples/seccomp/bpf-example.c | 74 +++++++++++++++++++++++++ 4 files changed, 187 insertions(+), 1 deletions(-) create mode 100644 Documentation/prctl/seccomp_filter.txt create mode 100644 samples/seccomp/Makefile create mode 100644 samples/seccomp/bpf-example.c
Documentation/prctl/seccomp_filter.txt new file +94 -0
@@ -0,0 +1,94 @@ + Seccomp filtering + ================= + +Introduction +------------ + +A large number of system calls are exposed to every userland process +with many of them going unused for the entire lifetime of the process. +As system calls change and mature, bugs are found and eradicated. A +certain subset of userland applications benefit by having a reduced set +of available system calls. The resulting set reduces the total kernel +surface exposed to the application. System call filtering is meant for +use with those applications. + +Seccomp filtering provides a means for a process to specify a filter +for incoming system calls. The filter is expressed as a Berkeley Packet +Filter (BPF) program, as with socket filters, except that the data +operated on is the current user_regs_struct. This allows for expressive +filtering of system calls using the pre-existing system call ABI and +using a filter program language with a long history of being exposed to +userland. Additionally, BPF makes it impossible for users of seccomp to +fall prey to time-of-check-time-of-use (TOCTOU) attacks that are common +in system call interposition frameworks because the evaluated data is +solely register state just after system call entry. + +What it isn't +------------- + +System call filtering isn't a sandbox. It provides a clearly defined +mechanism for minimizing the exposed kernel surface. Beyond that, +policy for logical behavior and information flow should be managed with +a combinations of other system hardening techniques and, potentially, a +LSM of your choosing. Expressive, dynamic filters provide further options down +this path (avoiding pathological sizes or selecting which of the multiplexed +system calls in socketcall() is allowed, for instance) which could be +construed, incorrectly, as a more complete sandboxing solution. + +Usage +----- + +An additional seccomp mode is added, but they are not directly set by the +consuming process. The new mode, '2', is only available if +CONFIG_SECCOMP_FILTER is set and enabled using prctl with the +PR_ATTACH_SECCOMP_FILTER argument. + +Interacting with seccomp filters is done using one prctl(2) call. + +PR_ATTACH_SECCOMP_FILTER: + Allows the specification of a new filter using a BPF program. + The BPF program will be executed over a user_regs_struct data + reflecting system call time except with the system call number + resident in orig_[register]. To allow a system call, the size + of the data must be returned. At present, all other return values + result in the system call being blocked, but it is recommended to + return 0 in those cases. This will allow for future custom return + values to be introduced, if ever desired. + + Usage: + prctl(PR_ATTACH_SECCOMP_FILTER, prog); + + The 'prog' argument is a pointer to a struct sock_fprog which will + contain the filter program. If the program is invalid, the call + will return -1 and set errno to -EINVAL. + + The struct user_regs_struct the @prog will see is based on the + personality of the task at the time of this prctl call. Additionally, + is_compat_task is also tracked for the @prog. This means that once set + the calling task will have all of its system calls blocked if it + switches its system call ABI (via personality or other means). + + If fork/clone and execve are allowed by @prog, any child processes will + be constrained to the same filters and syscal call ABI as the parent. + + When called from an unprivileged process (lacking CAP_SYS_ADMIN), the + "always_unprivileged" bit is enabled for the process. + + Additionally, if prctl(2) is allowed by the attached filter, + additional filters may be layered on which will increase evaluation + time, but allow for further decreasing the attack surface during + execution of a process. + +The above call returns 0 on success and non-zero on error. + +Example +------- + +samples/seccomp-bpf-example.c shows an example process that allows read from stdin, +write to stdout/err, exit and signal returns for 32-bit x86. + +Adding architecture support +----------------------- + +Any platform with seccomp support will support seccomp filters +as long as CONFIG_SECCOMP_FILTER is enabled.
samples/Makefile +1 -1
@@ -1,4 +1,4 @@ # Makefile for Linux samples code obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ tracepoints/ trace_events/ \ - hw_breakpoint/ kfifo/ kdb/ hidraw/ + hw_breakpoint/ kfifo/ kdb/ hidraw/ seccomp/
samples/seccomp/Makefile new file +18 -0
@@ -0,0 +1,18 @@ +# This sample is x86-only. +ifeq ($(filter-out x86_64 i386,$(KBUILD_BUILDHOST)),) +# kbuild trick to avoid linker error. Can be omitted if a module is built. +obj- := dummy.o + +# List of programs to build +hostprogs-y := bpf-example +bpf-example-objs := bpf-example.o + +# Tell kbuild to always build the programs +always := $(hostprogs-y) + +HOSTCFLAGS_bpf-example.o += -I$(objtree)/usr/include +ifeq ($(KBUILD_BUILDHOST),x86_64) +HOSTCFLAGS_bpf-example.o += -m32 +HOSTLOADLIBES_bpf-example += -m32 +endif +endif # host arch is x86
samples/seccomp/bpf-example.c new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Re: [PATCH v3 3/3] Documentation: prctl/seccomp_filter
Quoted 48 lines · Will Drewry
Documents how system call filtering using Berkeley Packet Filter programs works and how it may be used. Includes an example for x86 (32-bit).
v3: - call out BPF <-> Berkeley Packet Filter ([email protected])
- document use of tentative always-unprivileged
- guard sample compilation for i386 andx86_64
v2: - move code to samples ([email protected])Signed-off-by Will Drewry <[email protected]>--- Documentation/prctl/seccomp_filter.txt | 94 ++++++++++++++++++++++++++++++++ samples/Makefile | 2 +- samples/seccomp/Makefile | 18 ++++++ samples/seccomp/bpf-example.c | 74 +++++++++++++++++++++++++ 4 files changed, 187 insertions(+), 1 deletions(-) create mode 100644 Documentation/prctl/seccomp_filter.txt create mode 100644 samples/seccomp/Makefile create mode 100644 samples/seccomp/bpf-example.cDocumentation/prctl/seccomp_filter.txt new file +22
-0@@ -0,0 +1,94 @@ + Seccomp filtering + ================= + +Introduction +------------ + +A large number of system calls are exposed to every userland process +with many of them going unused for the entire lifetime of the process. +As system calls change and mature, bugs are found and eradicated. A +certain subset of userland applications benefit by having a reduced set +of available system calls. The resulting set reduces the total kernel +surface exposed to the application. System call filtering is meant for +use with those applications. + +Seccomp filtering provides a means for a process to specify a filter +for incoming system calls. The filter is expressed as a Berkeley Packet +Filter (BPF) program, as with socket filters, except that the data +operated on is the current user_regs_struct. This allows for expressive +filtering of system calls using the pre-existing system call ABI and +using a filter program language with a long history of being exposed to +userland. Additionally, BPF makes it impossible for users of seccomp to +fall prey to time-of-check-time-of-use (TOCTOU) attacks that are common
Documentation/prctl/seccomp_filter.txt line 32
Quoted 10 lines
Documentation/prctl/seccomp_filter.txt new file +10
-0+in system call interposition frameworks because the evaluated data is +solely register state just after system call entry. + +What it isn't +------------- + +System call filtering isn't a sandbox. It provides a clearly defined +mechanism for minimizing the exposed kernel surface. Beyond that, +policy for logical behavior and information flow should be managed with +a combinations of other system hardening techniques and, potentially, a
combination an
Quoted 21 lines
Documentation/prctl/seccomp_filter.txt new file +21
-0+LSM of your choosing. Expressive, dynamic filters provide further options down +this path (avoiding pathological sizes or selecting which of the multiplexed +system calls in socketcall() is allowed, for instance) which could be +construed, incorrectly, as a more complete sandboxing solution. + +Usage +----- + +An additional seccomp mode is added, but they are not directly set by the +consuming process. The new mode, '2', is only available if +CONFIG_SECCOMP_FILTER is set and enabled using prctl with the +PR_ATTACH_SECCOMP_FILTER argument. + +Interacting with seccomp filters is done using one prctl(2) call. + +PR_ATTACH_SECCOMP_FILTER: + Allows the specification of a new filter using a BPF program. + The BPF program will be executed over a user_regs_struct data + reflecting system call time except with the system call number + resident in orig_[register]. To allow a system call, the size + of the data must be returned. At present, all other return values
Documentation/prctl/seccomp_filter.txt line 63
Quoted 10 lines
Documentation/prctl/seccomp_filter.txt new file +10
-0+ result in the system call being blocked, but it is recommended to + return 0 in those cases. This will allow for future custom return + values to be introduced, if ever desired. + + Usage: + prctl(PR_ATTACH_SECCOMP_FILTER, prog); + + The 'prog' argument is a pointer to a struct sock_fprog which will + contain the filter program. If the program is invalid, the call + will return -1 and set errno to -EINVAL.
EINVAL.
(I think)
Documentation/prctl/seccomp_filter.txt line 72
Quoted 9 lines
Documentation/prctl/seccomp_filter.txt new file +9
-0+ + The struct user_regs_struct the @prog will see is based on the + personality of the task at the time of this prctl call. Additionally, + is_compat_task is also tracked for the @prog. This means that once set + the calling task will have all of its system calls blocked if it + switches its system call ABI (via personality or other means). + + If fork/clone and execve are allowed by @prog, any child processes will + be constrained to the same filters and syscal call ABI as the parent.
syscall
Quoted 5 lines
Documentation/prctl/seccomp_filter.txt new file +5
-0+ + When called from an unprivileged process (lacking CAP_SYS_ADMIN), the + "always_unprivileged" bit is enabled for the process. + + Additionally, if prctl(2) is allowed by the attached filter,
Documentation/prctl/seccomp_filter.txt line 87
Quoted 10 lines
Documentation/prctl/seccomp_filter.txt new file +10
-0+ additional filters may be layered on which will increase evaluation + time, but allow for further decreasing the attack surface during + execution of a process. + +The above call returns 0 on success and non-zero on error. + +Example +------- + +samples/seccomp-bpf-example.c shows an example process that allows read from stdin,
samples/seccomp/bpf-example.c
Documentation/prctl/seccomp_filter.txt line 88
Quoted 1 line
Documentation/prctl/seccomp_filter.txt new file +1
-0+write to stdout/err, exit and signal returns for 32-bit x86.
/stderr,
Quoted 6 lines
Documentation/prctl/seccomp_filter.txt new file +6
-0+ +Adding architecture support +----------------------- + +Any platform with seccomp support will support seccomp filters +as long as CONFIG_SECCOMP_FILTER is enabled.
Signature · 2 lines
~Randy *** Remember to use Documentation/SubmitChecklist when testing your code ***
Will Drewry
reviewerRe: [PATCH v3 3/3] Documentation: prctl/seccomp_filter
Quoted 127 lines · Randy Dunlap
Quoted 48 lines · Will Drewry
Documents how system call filtering using Berkeley Packet Filter programs works and how it may be used. Includes an example for x86 (32-bit).
v3: - call out BPF <-> Berkeley Packet Filter ([email protected])
- document use of tentative always-unprivileged
- guard sample compilation for i386 andx86_64
v2: - move code to samples ([email protected])Signed-off-by Will Drewry <[email protected]>---
Documentation/prctl/seccomp_filter.txt | 94 ++++++++++++++++++++++++++++++++samples/Makefile| 2 +-samples/seccomp/Makefile| 18 ++++++samples/seccomp/bpf-example.c| 74 +++++++++++++++++++++++++4 files changed, 187 insertions(+), 1 deletions(-)create mode 100644
Documentation/prctl/seccomp_filter.txtcreate mode 100644samples/seccomp/Makefilecreate mode 100644samples/seccomp/bpf-example.cDocumentation/prctl/seccomp_filter.txt new file +22
-0@@ -0,0 +1,94 @@ + Seccomp filtering + ================= + +Introduction +------------ + +A large number of system calls are exposed to every userland process +with many of them going unused for the entire lifetime of the process. +As system calls change and mature, bugs are found and eradicated. A +certain subset of userland applications benefit by having a reduced set +of available system calls. The resulting set reduces the total kernel +surface exposed to the application. System call filtering is meant for +use with those applications. + +Seccomp filtering provides a means for a process to specify a filter +for incoming system calls. The filter is expressed as a Berkeley Packet +Filter (BPF) program, as with socket filters, except that the data +operated on is the current user_regs_struct. This allows for expressive +filtering of system calls using the pre-existing system call ABI and +using a filter program language with a long history of being exposed to +userland. Additionally, BPF makes it impossible for users of seccomp to +fall prey to time-of-check-time-of-use (TOCTOU) attacks that are commonDocumentation/prctl/seccomp_filter.txt line 32
Quoted 10 lines
Documentation/prctl/seccomp_filter.txt new file +10
-0+in system call interposition frameworks because the evaluated data is +solely register state just after system call entry. + +What it isn't +------------- + +System call filtering isn't a sandbox. It provides a clearly defined +mechanism for minimizing the exposed kernel surface. Beyond that, +policy for logical behavior and information flow should be managed with +a combinations of other system hardening techniques and, potentially, acombination an
Quoted 21 lines
Documentation/prctl/seccomp_filter.txt new file +21
-0+LSM of your choosing. Expressive, dynamic filters provide further options down +this path (avoiding pathological sizes or selecting which of the multiplexed +system calls in socketcall() is allowed, for instance) which could be +construed, incorrectly, as a more complete sandboxing solution. + +Usage +----- + +An additional seccomp mode is added, but they are not directly set by the +consuming process. The new mode, '2', is only available if +CONFIG_SECCOMP_FILTER is set and enabled using prctl with the +PR_ATTACH_SECCOMP_FILTER argument. + +Interacting with seccomp filters is done using one prctl(2) call. + +PR_ATTACH_SECCOMP_FILTER: + Allows the specification of a new filter using a BPF program. + The BPF program will be executed over a user_regs_struct data + reflecting system call time except with the system call number + resident in orig_[register]. To allow a system call, the size + of the data must be returned. At present, all other return valuesDocumentation/prctl/seccomp_filter.txt line 63
Quoted 10 lines
Documentation/prctl/seccomp_filter.txt new file +10
-0+ result in the system call being blocked, but it is recommended to + return 0 in those cases. This will allow for future custom return + values to be introduced, if ever desired. + + Usage: + prctl(PR_ATTACH_SECCOMP_FILTER, prog); + + The 'prog' argument is a pointer to a struct sock_fprog which will + contain the filter program. If the program is invalid, the call + will return -1 and set errno to -EINVAL.EINVAL.
(I think)Documentation/prctl/seccomp_filter.txt line 72
Quoted 9 lines
Documentation/prctl/seccomp_filter.txt new file +9
-0+ + The struct user_regs_struct the @prog will see is based on the + personality of the task at the time of this prctl call. Additionally, + is_compat_task is also tracked for the @prog. This means that once set + the calling task will have all of its system calls blocked if it + switches its system call ABI (via personality or other means). + + If fork/clone and execve are allowed by @prog, any child processes will + be constrained to the same filters and syscal call ABI as the parent.syscall
Quoted 5 lines
Documentation/prctl/seccomp_filter.txt new file +5
-0+ + When called from an unprivileged process (lacking CAP_SYS_ADMIN), the + "always_unprivileged" bit is enabled for the process. + + Additionally, if prctl(2) is allowed by the attached filter,Documentation/prctl/seccomp_filter.txt line 87
Quoted 10 lines
Documentation/prctl/seccomp_filter.txt new file +10
-0+ additional filters may be layered on which will increase evaluation + time, but allow for further decreasing the attack surface during + execution of a process. + +The above call returns 0 on success and non-zero on error. + +Example +------- + +samples/seccomp-bpf-example.c shows an example process that allows read from stdin,
samples/seccomp/bpf-example.c
Quoted 4 lines
Documentation/prctl/seccomp_filter.txt line 88
Quoted 1 line
Documentation/prctl/seccomp_filter.txt new file +1
-0+write to stdout/err, exit and signal returns for 32-bit x86./stderr,
Thanks for the close reading! I've got another patchset mostly rolled and I'll pull these in too.
will
Re: [PATCH v3 3/3] Documentation: prctl/seccomp_filter
In reply to Will Drewrysamples/seccomp/bpf-example.c line 22
Quoted 3 lines · Will Drewry
samples/seccomp/bpf-example.c new file +3
-0+#ifndef PR_ATTACH_SECCOMP_FILTER +# define PR_ATTACH_SECCOMP_FILTER 36 +#endif
The example code here uses 36, but the real code I believe uses 37. Can we get these in sync? Thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Will Drewry
reviewerRe: [PATCH v3 3/3] Documentation: prctl/seccomp_filter
Quoted 9 lines · Eric Paris
samples/seccomp/bpf-example.c line 22
Quoted 3 lines · Will Drewry
samples/seccomp/bpf-example.c new file +3
-0+#ifndef PR_ATTACH_SECCOMP_FILTER +# define PR_ATTACH_SECCOMP_FILTER 36 +#endif The example code here uses 36, but the real code I believe uses 37. Can we get these in sync? Thanks!
Nice - of course! [That is from before the PR_NO_NEW_PRIVS patch.]
thanks!
Quoted 3 lines · Will Drewry
This patch is a placeholder until Andy's ([email protected]) patch arrives implementing Linus's proposal for applying a "this is a process that has *no* extra privileges at all, and can never get them".
I think we can simplify and improve the naming/logic by just saying "can't change privileges".
I'd argue that that even includes "can't drop them", just to make it really clear what the rules are.
So the usage model would be to first simply set the privileges to whatever you want the sandbox to be, and then enter the restricted mode.
Linus
Will Drewry
reviewerQuoted 8 lines · Linus Torvalds
Quoted 3 lines · Will Drewry
This patch is a placeholder until Andy's ([email protected]) patch arrives implementing Linus's proposal for applying a "this is a process that has *no* extra privileges at all, and can never get them".
I think we can simplify and improve the naming/logic by just saying "can't change privileges".
Quoted 6 lines
I'd argue that that even includes "can't drop them", just to make it really clear what the rules are.
So the usage model would be to first simply set the privileges to whatever you want the sandbox to be, and then enter the restricted mode.
That sounds ideal to me. This placeholder is certainly insufficient then. I'll keep tweaking this patch then until its successor emerges.
Thanks!
will
Quoted 10 lines · Linus Torvalds
Quoted 3 lines · Will Drewry
This patch is a placeholder until Andy's ([email protected]) patch arrives implementing Linus's proposal for applying a "this is a process that has *no* extra privileges at all, and can never get them".
I think we can simplify and improve the naming/logic by just saying "can't change privileges".
I'd argue that that even includes "can't drop them", just to make it really clear what the rules are.
That may prevent another use: set this new flag, chroot, drop privileges, accept network connections. (The idea being that chroot might work unprivileged if this flag is set.)
--Andy
Quoted 4 lines · Andrew Lutomirski
That may prevent another use: set this new flag, chroot, drop privileges, accept network connections. (The idea being that chroot might work unprivileged if this flag is set.)
Well, if you have privileges, then just do
chroot(); drop privileges
and if you depend on the new flag, then you do
drop privileges
set new flag
chroot
and if you want to work either way then you just do
error = chroot
drop privileges
set new flag
if error
chroot
which does the right thing regardless of whether you had privileges and/or a new kernel or not.
In any of the three cases I don't see why you'd ever want to drop privileges *after* setting the new flag.
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 25 lines · Linus Torvalds
Quoted 4 lines · Andrew Lutomirski
That may prevent another use: set this new flag, chroot, drop privileges, accept network connections. (The idea being that chroot might work unprivileged if this flag is set.)
Well, if you have privileges, then just do
chroot();
drop privilegesand if you depend on the new flag, then you do
drop privileges
set new flag
chrootand if you want to work either way then you just do
error = chroot
drop privileges
set new flag
if error
chroot
Quoted 5 lines
which does the right thing regardless of whether you had privileges and/or a new kernel or not.
In any of the three cases I don't see why you'd ever want to drop privileges *after* setting the new flag.
Hmm...
What if you're a daemon that needs something like CAP_NET_BIND but also wants to be able to run other helpers without CAP_NET_BIND?
(Also, preventing dropping of privileges will probably make a patch more complicted -- I'll have to find and update all the places that allow dropping privileges.)
--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 7 lines · Andrew Lutomirski
What if you're a daemon that needs something like
CAP_NET_BINDbut also wants to be able to run other helpers withoutCAP_NET_BIND?(Also, preventing dropping of privileges will probably make a patch more complicted -- I'll have to find and update all the places that allow dropping privileges.)
Hey, if it actually makes it more complicated to say "don't change privileges", then I guess my argument that it should be simpler is wrong.
That said, the thing you bring up is *not* the actual use-case for the suggestion. The use-case is a "run untrusted code". So the use-case would be to set the flag after you've dropped CAP_NET_BIND, and *before* you actually run the other helpers. You clearly must have a fork() or something like that there, since you want to keep the NET_BIND in the original daemon.
So I don't t think your example is actually the expected situation. The obvious approach for your example is
- run deamon with CAP_NET_BIND
- per connection, fork, drop privileges in child, then set
"restricted" flag, and run the untrusted code.
(where the restricted mode setting may well obviously also do other things - like limit allowed system calls etc)
Linus
Quoted 13 lines · Linus Torvalds
Quoted 7 lines · Andrew Lutomirski
What if you're a daemon that needs something like
CAP_NET_BINDbut also wants to be able to run other helpers withoutCAP_NET_BIND?(Also, preventing dropping of privileges will probably make a patch more complicted -- I'll have to find and update all the places that allow dropping privileges.)
Hey, if it actually makes it more complicated to say "don't change privileges", then I guess my argument that it should be simpler is wrong.
Quoted 6 lines
That said, the thing you bring up is *not* the actual use-case for the suggestion. The use-case is a "run untrusted code". So the use-case would be to set the flag after you've dropped
CAP_NET_BIND, and *before* you actually run the other helpers. You clearly must have afork()or something like that there, since you want to keep theNET_BINDin the original daemon.
Well suppose you don't trust the daemon either. It might be running in a network namespace where it's safe for untrusted code to bind to low ports.
Or maybe you just need to let it bind willy-nilly among a restricted subset of low ports - which of course you would like to restrict with the seccomp filter.
(This can't happen right now because the filter can only look at arguments, not memory pointed to - so it can't look at the port number. Can it even see when sys_bind is called on archs like x86 that use sys_socketcall?!)
Anyway the principle is there - CAP_NET_BIND doesn't necessarily mean the daemon code is trusted.
-- Jamie
Will Drewry
reviewerQuoted 21 lines · Jamie Lokier
Quoted 13 lines · Linus Torvalds
Quoted 7 lines · Andrew Lutomirski
What if you're a daemon that needs something like
CAP_NET_BINDbut also wants to be able to run other helpers withoutCAP_NET_BIND?(Also, preventing dropping of privileges will probably make a patch more complicted -- I'll have to find and update all the places that allow dropping privileges.)
Hey, if it actually makes it more complicated to say "don't change privileges", then I guess my argument that it should be simpler is wrong.
Quoted 6 lines
That said, the thing you bring up is *not* the actual use-case for the suggestion. The use-case is a "run untrusted code". So the use-case would be to set the flag after you've dropped
CAP_NET_BIND, and *before* you actually run the other helpers. You clearly must have afork()or something like that there, since you want to keep theNET_BINDin the original daemon.
Quoted 7 lines
Well suppose you don't trust the daemon either. It might be running in a network namespace where it's safe for untrusted code to bind to low ports.
Or maybe you just need to let it bind willy-nilly among a restricted subset of low ports - which of course you would like to restrict with the seccomp filter.
Unless the port values are the register arguments, seccomp filter won't help. It can be used to incrementally drop available system calls (like socketcall(SYS_LISTEN) or whatever).
Quoted 4 lines
(This can't happen right now because the filter can only look at arguments, not memory pointed to - so it can't look at the port number. Can it even see when
sys_bindis called on archs like x86 that usesys_socketcall?!)
Yeah - multiplexed system calls like ipc and socketcall can be filtered based on the argument value in the register. (socketcall's first argument is "call".)
Quoted 2 lines
Anyway the principle is there -
CAP_NET_BINDdoesn't necessarily mean the daemon code is trusted.
I think we're comparing apples to oranges. I believe the current proposal is a
bit that says "hey! I'm sandboxed!". Defensive programming that is often
achieved through continued reduction of capabilities is important, but orthogonal. In that model, only once the last vestige of "privilege" is dropped would the process set the no_new_privs bit. Until then, you rely on the other access contol pieces you've put in place: namespacing, etc.
While I am a fan of capabilities systems, it would be very cool to have a bottom floor, privilege-freezer which could help against some classes of sandbox escapes.
cheers!
will
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines · Jamie Lokier
Anyway the principle is there -
CAP_NET_BINDdoesn't necessarily mean the daemon code is trusted.
I really think all these arguments are *COMPLETELY* missing the point.
You don't have to use the new flag if you don't want to. Just let it go.
The point of the flag is to not allow security changes. It's that easy. If you want something else, don't use it.
Because even "dropping capabilities" is quite often the wrong thing to do. To one person it's "dropping capabilities", to another it is "no longer running with the capabilities I need".
We've had security bugs that were *due* to dropped capabilities - people dropped one capability but not another, and fooled code into doing things they weren't expecting it to do. So quite frankly, I believe that from a security standpoint it's a hell of a lot safer to just keep the rules really simple.
Think of the "restrict" bit as "my universe will now run with this *known* set of permissions".
And if you don't like it, don't use it. It really is that simple. But don't make the model more complicated. Don't confuse it with "but but capabilites" crap. The point of the patch is that it makes all of that go away. There are no capabilities. There only is what you can do.
And yes, I really seriously do believe that is both safer and simpler than some model that says "you can drop stuff", and then you have to start making up rules for what "dropping" means.
Does "dropping" mean allowing setuid(geteuid()) for example? That *is* dropping the uid in a _POSIX_SAVED_IDS environment. And I'm saying that no, we should not even allow that. It's simply all too "subtle".
(I don't think Andrew's patch actually touched any of those paths, but I didn't check)
Linus
Quoted 7 lines · Linus Torvalds
We've had security bugs that were *due* to dropped capabilities - people dropped one capability but not another, and fooled code into doing things they weren't expecting it to do. So quite frankly, I believe that from a security standpoint it's a hell of a lot safer to just keep the rules really simple.
Which is the point of this patch. If suid/sgid/file caps/LSM transitions are disabled, you can't exploit thinks like sendmail because they don't have any special privileges to exploit.
Quoted 7 lines
Does "dropping" mean allowing setuid(geteuid()) for example? That *is* dropping the uid in a
_POSIX_SAVED_IDSenvironment. And I'm saying that no, we should not even allow that. It's simply all too "subtle".(I don't think Andrew's patch actually touched any of those paths, but I didn't check)
Correct. I did not touch any of these paths. I think that's the right choice for at least three reasons:
1. If there's an exploit that does PR_SET_NO_NEW_CAPS, then setuid/capset/whatever, then runs something and exploits it, it is likely to work just as will if setuid/capset is called before PR_SET_NO_NEW_CAPS.
2. Even if I made that change, it wouldn't help. You can always simulate dropping capabilities with LD_PRELOAD or something like seccomp mode 2. The secure exec stuff that happens when you execve something with the setuid bit set won't prevent it because the setuid bit is *disabled* in this mode. (Again, there is no exploit here -- there are no new privileges to steal.)
3. Simplicity. It would be easy to miss something subtle. There's the dumpable bit and however it interacts with ptrace (especially on Ubuntu, which seems to have a patched kernel with different rules), there's capset, there's file capabilities (which can, I think, drop capabilities as well as adding them), there's cap_bset, securebits, etc. Leaving them all alone means I don't need to worry about bitrot or about missing one.
I'm tempted to submit a followup patch to allow unprivileged users to use some of the sys_unshare modes if no_new_privs is set so we can have an example use case. CLONE_NEWIPC, CLONE_SYSVSEM, and CLONE_NEWUTS would be a decent start, I think, and the patch would be trivial.
--Andy
Quoted 28 lines · Linus Torvalds
Quoted 2 lines · Jamie Lokier
Anyway the principle is there -
CAP_NET_BINDdoesn't necessarily mean the daemon code is trusted.I really think all these arguments are *COMPLETELY* missing the point.
You don't have to use the new flag if you don't want to. Just let it go.
The point of the flag is to not allow security changes. It's that easy. If you want something else, don't use it.
Because even "dropping capabilities" is quite often the wrong thing to do. To one person it's "dropping capabilities", to another it is "no longer running with the capabilities I need".
We've had security bugs that were *due* to dropped capabilities - people dropped one capability but not another, and fooled code into doing things they weren't expecting it to do. So quite frankly, I believe that from a security standpoint it's a hell of a lot safer to just keep the rules really simple.
Think of the "restrict" bit as "my universe will now run with this *known* set of permissions".
And if you don't like it, don't use it. It really is that simple. But don't make the model more complicated. Don't confuse it with "but but capabilites" crap. The point of the patch is that it makes all of that go away. There are no capabilities. There only is what you can do.
Quoted 7 lines
And yes, I really seriously do believe that is both safer and simpler than some model that says "you can drop stuff", and then you have to start making up rules for what "dropping" means.
Does "dropping" mean allowing setuid(geteuid()) for example? That *is* dropping the uid in a
_POSIX_SAVED_IDSenvironment. And I'm saying that no, we should not even allow that. It's simply all too "subtle".
I am casting my two cents worth behind Linus. Dropping privilege can be every bit as dangerous as granting privilege in the real world of atrocious user land code. Especially in the case of security policy enforcing user land code.
This even more important in environments that support fine granularity of privilege, including capabilities and SELinux. Under SELinux a domain transition can increase, decrease or completely change a process' access rights and there is really no way for the kernel to tell which it is because that's all encoded in the arbitrary SELinux policy. Smack does not try to maintain a notion of hierarchy of privilege, so the notion of any change being equivalent to any other is in line with the Smack philosophy.
Quoted 11 lines
(I don't think Andrew's patch actually touched any of those paths, but I didn't check)
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 11 lines · Casey Schaufler
Quoted 8 lines · Linus Torvalds
And yes, I really seriously do believe that is both safer and simpler than some model that says "you can drop stuff", and then you have to start making up rules for what "dropping" means.
Does "dropping" mean allowing setuid(geteuid()) for example? That *is* dropping the uid in a
_POSIX_SAVED_IDSenvironment. And I'm saying that no, we should not even allow that. It's simply all too "subtle".
Quoted 4 lines
I am casting my two cents worth behind Linus. Dropping privilege can be every bit as dangerous as granting privilege in the real world of atrocious user land code. Especially in the case of security policy enforcing user land code.
Can you think of *any* plausible attack that is possible with my patch (i.e. no_new_privs allows setuid, setresuid, and capset) that would be prevented or even mitigated if I blocked those syscalls? I can't. (The sendmail-style attack is impossible with no_new_privs.)
Also, how would you even block setuid(2) in a non-confusing manner? The semantics and error returns are already such a disaster than it's barely worth it for anything to check the return value.
Quoted 11 lines
This even more important in environments that support fine granularity of privilege, including capabilities and SELinux. Under SELinux a domain transition can increase, decrease or completely change a process' access rights and there is really no way for the kernel to tell which it is because that's all encoded in the arbitrary SELinux policy. Smack does not try to maintain a notion of hierarchy of privilege, so the notion of any change being equivalent to any other is in line with the Smack philosophy.
My patch does not (barring bugs) allow selinux domain transitions. I certainly think that all security transitions that vary across distributions should be blocked by no_new_privs.
--Andy
Quoted 11 lines · Andrew Lutomirski
Quoted 9 lines · Casey Schaufler
Quoted 7 lines · Linus Torvalds
And yes, I really seriously do believe that is both safer and simpler than some model that says "you can drop stuff", and then you have to start making up rules for what "dropping" means.
Does "dropping" mean allowing setuid(geteuid()) for example? That *is* dropping the uid in a
_POSIX_SAVED_IDSenvironment. And I'm saying that no, we should not even allow that. It's simply all too "subtle".
Quoted 8 lines
Quoted 4 lines
I am casting my two cents worth behind Linus. Dropping privilege can be every bit as dangerous as granting privilege in the real world of atrocious user land code. Especially in the case of security policy enforcing user land code.
Can you think of *any* plausible attack that is possible with my patch (i.e.
no_new_privsallows setuid, setresuid, and capset) that would be prevented or even mitigated if I blocked those syscalls? I can't. (The sendmail-style attack is impossible withno_new_privs.)
I am notoriously bad at coming up with this sort of example. I will try, I may not hit the mark, but it should be close.
The application is running with saved uid != euid when no-new-privs is set. It execs a new binary, which keeps the saved and effective uids. The program calls setreuid, which succeeds. It opens the saved userid's files.
Some people reading this will say this is expected and appropriate behavior, and others will say it's an exploit under sandbox conditions. Those in the latter group can point out that blocking setreuid() would prevent what they consider an exploit. Those in the former group will say blocking the setreuid would introduce a denial of service that could lead to an exploit if the program is poorly written.
Because the correctness of the behavior is ambiguous (to me at least) when no_new_privs is set I argue that we shouldn't have it. If we are going to have it my feeling is that it should be as draconian as possible. Because you can't always tell if state A is "more" privileged than state B, any change between A and B has to be treated as an escalation.
Quoted 21 lines
Also, how would you even block setuid(2) in a non-confusing manner? The semantics and error returns are already such a disaster than it's barely worth it for anything to check the return value.
Quoted 10 lines
This even more important in environments that support fine granularity of privilege, including capabilities and SELinux. Under SELinux a domain transition can increase, decrease or completely change a process' access rights and there is really no way for the kernel to tell which it is because that's all encoded in the arbitrary SELinux policy. Smack does not try to maintain a notion of hierarchy of privilege, so the notion of any change being equivalent to any other is in line with the Smack philosophy.
My patch does not (barring bugs) allow selinux domain transitions. I certainly think that all security transitions that vary across distributions should be blocked by
no_new_privs.--Andy
Quoted 27 lines · Casey Schaufler
Quoted 20 lines · Andrew Lutomirski
Quoted 12 lines · Casey Schaufler
Quoted 8 lines · Linus Torvalds
And yes, I really seriously do believe that is both safer and simpler than some model that says "you can drop stuff", and then you have to start making up rules for what "dropping" means.
Does "dropping" mean allowing setuid(geteuid()) for example? That *is* dropping the uid in a
_POSIX_SAVED_IDSenvironment. And I'm saying that no, we should not even allow that. It's simply all too "subtle".Quoted 4 lines
I am casting my two cents worth behind Linus. Dropping privilege can be every bit as dangerous as granting privilege in the real world of atrocious user land code. Especially in the case of security policy enforcing user land code.
Quoted 4 lines
Can you think of *any* plausible attack that is possible with my patch (i.e.
no_new_privsallows setuid, setresuid, and capset) that would be prevented or even mitigated if I blocked those syscalls? I can't. (The sendmail-style attack is impossible withno_new_privs.)
Quoted 7 lines
I am notoriously bad at coming up with this sort of example. I will try, I may not hit the mark, but it should be close.
The application is running with saved uid != euid when no-new-privs is set. It execs a new binary, which keeps the saved and effective uids. The program calls setreuid, which succeeds. It opens the saved userid's files.
If you don't trust that binary, then why are you execing it with saved uid != euid in the first place? If you are setting no_new_privs, then you are new code and should have at least some basic awareness of the semantics. The exact same "exploit" is possible if you have CAP_DAC_OVERRIDE with either no_new_privs semantics -- if you have a privilege and you run untrusted code, then you had better remove that privilege somehow for the untrusted code.
IOW, *drop privileges if you are a sandbox*. Otherwise you're screwed with or without no_new_privs.
Another way of saying this is: no_new_privs is not a sandbox. It's just a way to make it safe for sandboxes and other such weird things processes can do to themselves safe across execve. If you want a sandbox, use seccomp mode 2, which will require you to set no_new_privs.
--Andy
Will Drewry
reviewerQuoted 44 lines · Andrew Lutomirski
Quoted 27 lines · Casey Schaufler
Quoted 20 lines · Andrew Lutomirski
Quoted 12 lines · Casey Schaufler
Quoted 8 lines · Linus Torvalds
And yes, I really seriously do believe that is both safer and simpler than some model that says "you can drop stuff", and then you have to start making up rules for what "dropping" means.
Does "dropping" mean allowing setuid(geteuid()) for example? That *is* dropping the uid in a
_POSIX_SAVED_IDSenvironment. And I'm saying that no, we should not even allow that. It's simply all too "subtle".Quoted 4 lines
I am casting my two cents worth behind Linus. Dropping privilege can be every bit as dangerous as granting privilege in the real world of atrocious user land code. Especially in the case of security policy enforcing user land code.
Quoted 4 lines
Can you think of *any* plausible attack that is possible with my patch (i.e.
no_new_privsallows setuid, setresuid, and capset) that would be prevented or even mitigated if I blocked those syscalls? I can't. (The sendmail-style attack is impossible withno_new_privs.)Quoted 7 lines
I am notoriously bad at coming up with this sort of example. I will try, I may not hit the mark, but it should be close.
The application is running with saved uid != euid when no-new-privs is set. It execs a new binary, which keeps the saved and effective uids. The program calls setreuid, which succeeds. It opens the saved userid's files.
If you don't trust that binary, then why are you execing it with saved uid != euid in the first place? If you are setting
no_new_privs, then you are new code and should have at least some basic awareness of the semantics. The exact same "exploit" is possible if you haveCAP_DAC_OVERRIDEwith eitherno_new_privssemantics -- if you have a privilege and you run untrusted code, then you had better remove that privilege somehow for the untrusted code.
Quoted 2 lines
IOW, *drop privileges if you are a sandbox*. Otherwise you're screwed with or without
no_new_privs.
One consideration could be to add do_exit()s at known DAC transitions (set*id, fcaps). I don't know if that'd be wise, but it would remove some described ambiguity. The same could be done with exec when the (e)uid/gid/fcaps change. However, none of that helps with the opaque LSM data, so that'd have to be left up to the LSMs and the LSM_* flag you've added.
This does seem subject to bitrot though, and your current approach certainly suits the needs of the general don't-do-something-stupid-on-exec that seccomp filter, unprivileged chroot, unshare, etc all need (which is really nice).
Quoted 5 lines
Another way of saying this is:
no_new_privsis not a sandbox. It's just a way to make it safe for sandboxes and other such weird things processes can do to themselves safe across execve. If you want a sandbox, use seccomp mode 2, which will require you to setno_new_privs.
And even with system call filtering, you'll need to have appropriately set up accessible files, file descriptors, memory maps, etc if you want a proper sandbox. There's no single sandbox-equivalent kernel feature. no_new_privs would be an excellent addition to the sandbox toolkit. (I've tried to synthesize it in userspace with an empty capability bounding set, SECURE_NOROOT, and MNT_NOSUID. Having this in a future-proof task_struct bit form would be amazing.)
cheers!
will
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Will Drewry
One consideration could be to add do_exit()s at known DAC transitions (set*id, fcaps). I don't know if that'd be wise, but it would remove some described ambiguity. The same could be done with exec when the (e)uid/gid/fcaps change. However, none of that helps with the opaque LSM data, so that'd have to be left up to the LSMs and the LSM_* flag you've added.
I went through and audited userspace recently and I could not find anything that did not handle setuid failing. It looks like kernel developers are not the only ones who learned from the sendmail/capabilities problem.
Eric
Quoted 25 lines · Andrew Lutomirski
Quoted 24 lines · Casey Schaufler
Quoted 11 lines · Andrew Lutomirski
Quoted 9 lines · Casey Schaufler
Quoted 7 lines · Linus Torvalds
And yes, I really seriously do believe that is both safer and simpler than some model that says "you can drop stuff", and then you have to start making up rules for what "dropping" means.
Does "dropping" mean allowing setuid(geteuid()) for example? That *is* dropping the uid in a
_POSIX_SAVED_IDSenvironment. And I'm saying that no, we should not even allow that. It's simply all too "subtle".Quoted 8 lines
Quoted 4 lines
I am casting my two cents worth behind Linus. Dropping privilege can be every bit as dangerous as granting privilege in the real world of atrocious user land code. Especially in the case of security policy enforcing user land code.
Can you think of *any* plausible attack that is possible with my patch (i.e.
no_new_privsallows setuid, setresuid, and capset) that would be prevented or even mitigated if I blocked those syscalls? I can't. (The sendmail-style attack is impossible withno_new_privs.)I am notoriously bad at coming up with this sort of example. I will try, I may not hit the mark, but it should be close.
Quoted 6 lines
Quoted 4 lines
The application is running with saved uid != euid when no-new-privs is set. It execs a new binary, which keeps the saved and effective uids. The program calls setreuid, which succeeds. It opens the saved userid's files.
If you don't trust that binary, then why are you execing it with saved uid != euid in the first place?
If I could trust the binary I wouldn't need your no_new_privs semantics in the first place. Do you have any idea how big the chrome browser binary is? You can't link it on a 32bit machine it uses so much address space. On top of that, most modern applications are compositions of scripts and interpreters built on top of multiple layers of middleware. Of course I don't trust the binary!
Quoted 3 lines
If you are setting
no_new_privs, then
you are new code and should have at least some basic awareness of the semantics.
It's not the program setting no_new_privs that I'm worried about. It's the nth descendant of that program and its ancestors that are going to do screwy things.
Quoted 4 lines
The exact same "exploit" is possible if you have
CAP_DAC_OVERRIDEwith eitherno_new_privssemantics -- if you have a privilege and you run untrusted code, then you had better remove that privilege somehow for the untrusted code.
Yes, and my very own name is engraved on the security wall of shame for the classic sendmail capabilities exploit. Don't think for a minute that something won't get done just because its obviously inappropriate.
Quoted 18 lines
IOW, *drop privileges if you are a sandbox*. Otherwise you're screwed with or without
no_new_privs.Another way of saying this is:
no_new_privsis not a sandbox. It's just a way to make it safe for sandboxes and other such weird things processes can do to themselves safe across execve. If you want a sandbox, use seccomp mode 2, which will require you to setno_new_privs.--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 8 lines · Casey Schaufler
Quoted 5 lines · Andrew Lutomirski
On Sun, Jan 15, 2012 at 1:32 PM, Casey Schaufler<[email protected]>
If you don't trust that binary, then why are you execing it with saved uid != euid in the first place?
Quoted 8 lines
If I could trust the binary I wouldn't need your
no_new_privssemantics in the first place. Do you have any idea how big the chrome browser binary is? You can't link it on a 32bit machine it uses so much address space. On top of that, most modern applications are compositions of scripts and interpreters built on top of multiple layers of middleware. Of course I don't trust the binary!
I'm not sure we're really talking about the same thing here. I agree that, if you are trying to sandbox untrusted code, then you probably don't want that code messing with setuid, capset, or any other privilege-changing operation.
no_new_privs is not intended to be that sandbox. It is, by itself, at best a small reduction in attack surface.
The attack surface accessible to a program (e.g. chrome) that you run normally is huge. There is filesystem access, ptrace, unix sockets, any available privileges, setuid programs, /proc, etc. LSMs try to characterize and control that whole attack surface. seccomp mode 2 allows a whitelisting approach in which everything is denied except that which is explicitly allowed (and I think that's a much better approach to sandboxing things). The problem is that seccomp mode 2, as well as anything else that changes the behavior of syscalls in a nonstandard way (chroot, unshare, etc), can cause existing code to malfunction. That's how the sendmail bug came to be -- dropping a privilege made sendmail do the wrong thing. This type of attack works by changing something that persists across a *gain* of privilege and then attacking the code that gains that privilege. If new things like seccomp mode 2 require no_new_privs, then that entire class of attacks is prevented.
In answer to your specific example, if you are trying to sandbox chrome or anything else and you forget to drop your privileged saved uid, I really don't think it's no_new_privs's job to rescue you.
--Andy
Quoted 15 lines · Andrew Lutomirski
Quoted 6 lines · Casey Schaufler
Quoted 4 lines · Andrew Lutomirski
On Sun, Jan 15, 2012 at 1:32 PM, Casey Schaufler<[email protected]>
If you don't trust that binary, then why are you execing it with saved uid != euid in the first place?
Quoted 8 lines
If I could trust the binary I wouldn't need your
no_new_privssemantics in the first place. Do you have any idea how big the chrome browser binary is? You can't link it on a 32bit machine it uses so much address space. On top of that, most modern applications are compositions of scripts and interpreters built on top of multiple layers of middleware. Of course I don't trust the binary!
Quoted 4 lines
I'm not sure we're really talking about the same thing here. I agree that, if you are trying to sandbox untrusted code, then you probably don't want that code messing with setuid, capset, or any other privilege-changing operation.
My point is that if you're interacting with untrusted code it's somewhat dangerous to change system call behavior and if you're dealing strictly with trusted code you don't need to change system call behavior.
Quoted 2 lines
no_new_privsis not intended to be that sandbox. It is, by itself, at best a small reduction in attack surface.
My preference is that we not complicate an environment that has already proven too difficult for many programmers to use effectively.
Quoted 7 lines
The attack surface accessible to a program (e.g. chrome) that you run normally is huge. There is filesystem access, ptrace, unix sockets, any available privileges, setuid programs, /proc, etc. LSMs try to characterize and control that whole attack surface. seccomp mode 2 allows a whitelisting approach in which everything is denied except that which is explicitly allowed (and I think that's a much better approach to sandboxing things). The problem is that seccomp mode 2,
Quoted 8 lines
as well as anything else that changes the behavior of syscalls in a nonstandard way (chroot, unshare, etc), can cause existing code to malfunction. That's how the sendmail bug came to be -- dropping a privilege made sendmail do the wrong thing. This type of attack works by changing something that persists across a *gain* of privilege and then attacking the code that gains that privilege. If new things like seccomp mode 2 require
no_new_privs, then that entire class of attacks is prevented.
Believe me, I am familiar with programs, trusted and otherwise, that go wonky when there are little changes in the behavior of syscalls. My take is that making security decisions based on the system call used rather than on the thing being accessed leads the programmer to expect behavior that does not always match the underlying implementation. Yes, system call based controls are easier to use and understand. That does not make them correct.
Quoted 3 lines
In answer to your specific example, if you are trying to sandbox chrome or anything else and you forget to drop your privileged saved uid, I really don't think it's no_new_privs's job to rescue you.
As much as I dislike the modern application paradigms, I don't see a lot of point in investing in new security facilities that are not of value in that arena. And I really mean of value, not just something that some "architect" threw onto a spreadsheet for the PM to track. I expect that we're overdue for a mindset changing sort of facility to address the issues that really matter.
Patches for that to follow, but not any time soon. :-)
Quoted 3 lines
--Andy
Will Drewry
reviewerQuoted 3 lines · Andrew Lutomirski
(Also, preventing dropping of privileges will probably make a patch more complicted -- I'll have to find and update all the places that allow dropping privileges.)
An alternative approach might be that the restricted bit drops all privileges that allows privilege changes in either direction. E.g.,
- set restricted bit
-- adds a check anywhere MNT_NOSUID is
-- sets securebit to SECURE_NOROOT|..LOCKED
-- drops CAP_SETUID, CAP_DAC_OVERRIDE, ...
-- set the caps bounding set to the minimum the restricted bit allows
That may deviate from the intent (by re-using caps), but it could keep some of the privilege transition checking code the same.
Just a thought,
will
Quoted 13 lines · Will Drewry
Quoted 3 lines · Andrew Lutomirski
(Also, preventing dropping of privileges will probably make a patch more complicted -- I'll have to find and update all the places that allow dropping privileges.)
An alternative approach might be that the restricted bit drops all privileges that allows privilege changes in either direction. E.g.,
- set restricted bit
-- adds a check anywhereMNT_NOSUIDis
-- sets securebit to SECURE_NOROOT|..LOCKED
-- dropsCAP_SETUID,CAP_DAC_OVERRIDE, ...
-- set the caps bounding set to the minimum the restricted bit allows
Quoted 2 lines
That may deviate from the intent (by re-using caps), but it could keep some of the privilege transition checking code the same.
I'm not sure it'll be much of a simplification. The entire patch is 45 lines right now :) I'll test it and send it out.
FWIW, though, it breaks apparmor (intentionally). Can any of you either explain what *should* happen or (better) volunteer to fix it? It should be about three lines of code for someone who understands what's going on. I don't have an apparmor system, so I can't really test it.
--Andy
Quoted 3 lines
Just a thought,
will
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 17 lines · Andrew Lutomirski
Quoted 13 lines · Will Drewry
Quoted 3 lines · Andrew Lutomirski
(Also, preventing dropping of privileges will probably make a patch more complicted -- I'll have to find and update all the places that allow dropping privileges.)
An alternative approach might be that the restricted bit drops all privileges that allows privilege changes in either direction. E.g.,
- set restricted bit
-- adds a check anywhereMNT_NOSUIDis
-- sets securebit to SECURE_NOROOT|..LOCKED
-- dropsCAP_SETUID,CAP_DAC_OVERRIDE, ...
-- set the caps bounding set to the minimum the restricted bit allowsQuoted 2 lines
That may deviate from the intent (by re-using caps), but it could keep some of the privilege transition checking code the same.
Quoted 8 lines
I'm not sure it'll be much of a simplification. The entire patch is 45 lines right now :) I'll test it and send it out.
FWIW, though, it breaks apparmor (intentionally). Can any of you either explain what *should* happen or (better) volunteer to fix it? It should be about three lines of code for someone who understands what's going on. I don't have an apparmor system, so I can't really test it.
I'm happy to take a look at the AppArmor breakage. What's happening with it at the moment?
Signature · 6 lines
Kees Cook ChromeOS Security -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html