Skip to contentSkip to conversation

selinux: clean up cred usage and simplify

PATCH Applied Stephen Smalley 6 participants 48 messages Dec 16, 2016 – Dec 21, 2016

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 selinux: clean up cred usage and simplify

SELinux was sometimes using the task "objective" credentials when it could/should use the "subjective" credentials. This was sometimes hidden by the fact that we were unnecessarily passing around pointers to the current task, making it appear as if the task could be something other than current, so eliminate all such passing of current. Inline various permission checking helper functions that can be reduced to a single avc_has_perm() call.

Since the credentials infrastructure only allows a task to alter its own credentials, we can always assume that current must be the same as the target task in selinux_setprocattr after the check. We likely should move this check from selinux_setprocattr() to proc_pid_attr_write() and drop the task argument to the security hook altogether; it can only serve to confuse things.

---
 security/selinux/hooks.c          | 294 +++++++++++++++-----------------------
 security/selinux/include/objsec.h |  10 ++
 security/selinux/selinuxfs.c      |  73 +++++-----
 3 files changed, 166 insertions(+), 211 deletions(-)
security/selinux/hooks.c +117 -177
index e7c5481..9992626 100644
@@ -210,16 +210,6 @@ static inline u32 task_sid(const struct task_struct *task)
 	return sid;
 }
 
-/*
- * get the subjective security ID of the current task
- */
-static inline u32 current_sid(void)
-{
-	const struct task_security_struct *tsec = current_security();
-
-	return tsec->sid;
-}
-
 /* Allocate and free functions for each kind of security blob. */
 
 static int inode_alloc_security(struct inode *inode)
@@ -1687,55 +1677,6 @@ static inline u32 signal_to_av(int sig)
 	return perm;
 }
 
-/*
- * Check permission between a pair of credentials
- * fork check, ptrace check, etc.
- */
-static int cred_has_perm(const struct cred *actor,
-			 const struct cred *target,
-			 u32 perms)
-{
-	u32 asid = cred_sid(actor), tsid = cred_sid(target);
-
-	return avc_has_perm(asid, tsid, SECCLASS_PROCESS, perms, NULL);
-}
-
-/*
- * Check permission between a pair of tasks, e.g. signal checks,
- * fork check, ptrace check, etc.
- * tsk1 is the actor and tsk2 is the target
- * - this uses the default subjective creds of tsk1
- */
-static int task_has_perm(const struct task_struct *tsk1,
-			 const struct task_struct *tsk2,
-			 u32 perms)
-{
-	const struct task_security_struct *__tsec1, *__tsec2;
-	u32 sid1, sid2;
-
-	rcu_read_lock();
-	__tsec1 = __task_cred(tsk1)->security;	sid1 = __tsec1->sid;
-	__tsec2 = __task_cred(tsk2)->security;	sid2 = __tsec2->sid;
-	rcu_read_unlock();
-	return avc_has_perm(sid1, sid2, SECCLASS_PROCESS, perms, NULL);
-}
-
-/*
- * Check permission between current and another task, e.g. signal checks,
- * fork check, ptrace check, etc.
- * current is the actor and tsk2 is the target
- * - this uses current's subjective creds
- */
-static int current_has_perm(const struct task_struct *tsk,
-			    u32 perms)
-{
-	u32 sid, tsid;
-
-	sid = current_sid();
-	tsid = task_sid(tsk);
-	return avc_has_perm(sid, tsid, SECCLASS_PROCESS, perms, NULL);
-}
-
 #if CAP_LAST_CAP > 63
 #error Fix SELinux to handle capabilities > 63.
 #endif
@@ -1777,16 +1718,6 @@ static int cred_has_capability(const struct cred *cred,
 	return rc;
 }
 
-/* Check whether a task is allowed to use a system operation. */
-static int task_has_system(struct task_struct *tsk,
-			   u32 perms)
-{
-	u32 sid = task_sid(tsk);
-
-	return avc_has_perm(sid, SECINITSID_KERNEL,
-			    SECCLASS_SYSTEM, perms, NULL);
-}
-
 /* Check whether a task has a particular permission to an inode.
    The 'adp' parameter is optional and allows other audit
    data to be passed (e.g. the dentry). */
@@ -1958,15 +1889,6 @@ static int may_create(struct inode *dir,
 			    FILESYSTEM__ASSOCIATE, &ad);
 }
 
-/* Check whether a task can create a key. */
-static int may_create_key(u32 ksid,
-			  struct task_struct *ctx)
-{
-	u32 sid = task_sid(ctx);
-
-	return avc_has_perm(sid, ksid, SECCLASS_KEY, KEY__CREATE, NULL);
-}
-
 #define MAY_LINK	0
 #define MAY_UNLINK	1
 #define MAY_RMDIR	2
@@ -2222,24 +2144,26 @@ static int selinux_binder_transfer_file(struct task_struct *from,
 static int selinux_ptrace_access_check(struct task_struct *child,
 				     unsigned int mode)
 {
-	if (mode & PTRACE_MODE_READ) {
-		u32 sid = current_sid();
-		u32 csid = task_sid(child);
+	u32 sid = current_sid();
+	u32 csid = task_sid(child);
+
+	if (mode & PTRACE_MODE_READ)
 		return avc_has_perm(sid, csid, SECCLASS_FILE, FILE__READ, NULL);
-	}
 
-	return current_has_perm(child, PROCESS__PTRACE);
+	return avc_has_perm(sid, csid, SECCLASS_PROCESS, PROCESS__PTRACE, NULL);
 }
 
 static int selinux_ptrace_traceme(struct task_struct *parent)
 {
-	return task_has_perm(parent, current, PROCESS__PTRACE);
+	return avc_has_perm(task_sid(parent), current_sid(), SECCLASS_PROCESS,
+			    PROCESS__PTRACE, NULL);
 }
 
 static int selinux_capget(struct task_struct *target, kernel_cap_t *effective,
 			  kernel_cap_t *inheritable, kernel_cap_t *permitted)
 {
-	return current_has_perm(target, PROCESS__GETCAP);
+	return avc_has_perm(current_sid(), task_sid(target), SECCLASS_PROCESS,
+			    PROCESS__GETCAP, NULL);
 }
 
 static int selinux_capset(struct cred *new, const struct cred *old,
@@ -2247,7 +2171,8 @@ static int selinux_capset(struct cred *new, const struct cred *old,
 			  const kernel_cap_t *inheritable,
 			  const kernel_cap_t *permitted)
 {
-	return cred_has_perm(old, new, PROCESS__SETCAP);
+	return avc_has_perm(cred_sid(old), cred_sid(new), SECCLASS_PROCESS,
+			    PROCESS__SETCAP, NULL);
 }
 
 /*
@@ -2303,29 +2228,22 @@ static int selinux_quota_on(struct dentry *dentry)
 
 static int selinux_syslog(int type)
 {
-	int rc;
-
 	switch (type) {
 	case SYSLOG_ACTION_READ_ALL:	/* Read last kernel messages */
 	case SYSLOG_ACTION_SIZE_BUFFER:	/* Return size of the log buffer */
-		rc = task_has_system(current, SYSTEM__SYSLOG_READ);
-		break;
+		return avc_has_perm(current_sid(), SECINITSID_KERNEL,
+				    SECCLASS_SYSTEM, SYSTEM__SYSLOG_READ, NULL);
 	case SYSLOG_ACTION_CONSOLE_OFF:	/* Disable logging to console */
 	case SYSLOG_ACTION_CONSOLE_ON:	/* Enable logging to console */
 	/* Set level of messages printed to console */
 	case SYSLOG_ACTION_CONSOLE_LEVEL:
-		rc = task_has_system(current, SYSTEM__SYSLOG_CONSOLE);
-		break;
-	case SYSLOG_ACTION_CLOSE:	/* Close log */
-	case SYSLOG_ACTION_OPEN:	/* Open log */
-	case SYSLOG_ACTION_READ:	/* Read from log */
-	case SYSLOG_ACTION_READ_CLEAR:	/* Read/clear last kernel messages */
-	case SYSLOG_ACTION_CLEAR:	/* Clear ring buffer */
-	default:
-		rc = task_has_system(current, SYSTEM__SYSLOG_MOD);
-		break;
+		return avc_has_perm(current_sid(), SECINITSID_KERNEL,
+				    SECCLASS_SYSTEM, SYSTEM__SYSLOG_CONSOLE,
+				    NULL);
 	}
-	return rc;
+	/* All other syslog types */
+	return avc_has_perm(current_sid(), SECINITSID_KERNEL,
+			    SECCLASS_SYSTEM, SYSTEM__SYSLOG_MOD, NULL);
 }
 
 /*
@@ -2350,13 +2268,13 @@ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages)
 
 /* binprm security operations */
 
-static u32 ptrace_parent_sid(struct task_struct *task)
+static u32 ptrace_parent_sid(void)
 {
 	u32 sid = 0;
 	struct task_struct *tracer;
 
 	rcu_read_lock();
-	tracer = ptrace_parent(task);
+	tracer = ptrace_parent(current);
 	if (tracer)
 		sid = task_sid(tracer);
 	rcu_read_unlock();
@@ -2485,7 +2403,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)
 		 * changes its SID has the appropriate permit */
 		if (bprm->unsafe &
 		    (LSM_UNSAFE_PTRACE | LSM_UNSAFE_PTRACE_CAP)) {
-			u32 ptsid = ptrace_parent_sid(current);
+			u32 ptsid = ptrace_parent_sid();
 			if (ptsid != 0) {
 				rc = avc_has_perm(ptsid, new_tsec->sid,
 						  SECCLASS_PROCESS,
@@ -3579,6 +3497,7 @@ static int default_noexec;
 static int file_map_prot_check(struct file *file, unsigned long prot, int shared)
 {
 	const struct cred *cred = current_cred();
+	u32 sid = cred_sid(cred);
 	int rc = 0;
 
 	if (default_noexec &&
@@ -3589,7 +3508,8 @@ static int file_map_prot_check(struct file *file, unsigned long prot, int shared
 		 * private file mapping that will also be writable.
 		 * This has an additional check.
 		 */
-		rc = cred_has_perm(cred, cred, PROCESS__EXECMEM);
+		rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
+				  PROCESS__EXECMEM, NULL);
 		if (rc)
 			goto error;
 	}
@@ -3640,6 +3560,7 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
 				 unsigned long prot)
 {
 	const struct cred *cred = current_cred();
+	u32 sid = cred_sid(cred);
 
 	if (selinux_checkreqprot)
 		prot = reqprot;
@@ -3649,12 +3570,14 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
 		int rc = 0;
 		if (vma->vm_start >= vma->vm_mm->start_brk &&
 		    vma->vm_end <= vma->vm_mm->brk) {
-			rc = cred_has_perm(cred, cred, PROCESS__EXECHEAP);
+			rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
+					  PROCESS__EXECHEAP, NULL);
 		} else if (!vma->vm_file &&
 			   ((vma->vm_start <= vma->vm_mm->start_stack &&
 			     vma->vm_end >= vma->vm_mm->start_stack) ||
 			    vma_is_stack_for_current(vma))) {
-			rc = current_has_perm(current, PROCESS__EXECSTACK);
+			rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
+					  PROCESS__EXECSTACK, NULL);
 		} else if (vma->vm_file && vma->anon_vma) {
 			/*
 			 * We are making executable a file mapping that has
@@ -3787,7 +3710,9 @@ static int selinux_file_open(struct file *file, const struct cred *cred)
 
 static int selinux_task_create(unsigned long clone_flags)
 {
-	return current_has_perm(current, PROCESS__FORK);
+	u32 sid = current_sid();
+
+	return avc_has_perm(sid, sid, SECCLASS_PROCESS, PROCESS__FORK, NULL);
 }
 
 /*
@@ -3897,15 +3822,12 @@ static int selinux_kernel_create_files_as(struct cred *new, struct inode *inode)
 
 static int selinux_kernel_module_request(char *kmod_name)
 {
-	u32 sid;
 	struct common_audit_data ad;
 
-	sid = task_sid(current);
-
 	ad.type = LSM_AUDIT_DATA_KMOD;
 	ad.u.kmod_name = kmod_name;
 
-	return avc_has_perm(sid, SECINITSID_KERNEL, SECCLASS_SYSTEM,
+	return avc_has_perm(current_sid(), SECINITSID_KERNEL, SECCLASS_SYSTEM,
 			    SYSTEM__MODULE_REQUEST, &ad);
 }
 
@@ -3957,17 +3879,20 @@ static int selinux_kernel_read_file(struct file *file,
 
 static int selinux_task_setpgid(struct task_struct *p, pid_t pgid)
 {
-	return current_has_perm(p, PROCESS__SETPGID);
+	return avc_has_perm(current_sid(), task_sid(p), SECCLASS_PROCESS,
+			    PROCESS__SETPGID, NULL);
 }
 
 static int selinux_task_getpgid(struct task_struct *p)
 {
-	return current_has_perm(p, PROCESS__GETPGID);
+	return avc_has_perm(current_sid(), task_sid(p), SECCLASS_PROCESS,
+			    PROCESS__GETPGID, NULL);
 }
 
 static int selinux_task_getsid(struct task_struct *p)
 {
-	return current_has_perm(p, PROCESS__GETSESSION);
+	return avc_has_perm(current_sid(), task_sid(p), SECCLASS_PROCESS,
+			    PROCESS__GETSESSION, NULL);
 }
 
 static void selinux_task_getsecid(struct task_struct *p, u32 *secid)
@@ -3977,17 +3902,20 @@ static void selinux_task_getsecid(struct task_struct *p, u32 *secid)
 
 static int selinux_task_setnice(struct task_struct *p, int nice)
 {
-	return current_has_perm(p, PROCESS__SETSCHED);
+	return avc_has_perm(current_sid(), task_sid(p), SECCLASS_PROCESS,
+			    PROCESS__SETSCHED, NULL);
 }
 
 static int selinux_task_setioprio(struct task_struct *p, int ioprio)
 {
-	return current_has_perm(p, PROCESS__SETSCHED);
+	return avc_has_perm(current_sid(), task_sid(p), SECCLASS_PROCESS,
+			    PROCESS__SETSCHED, NULL);
 }
 
 static int selinux_task_getioprio(struct task_struct *p)
 {
-	return current_has_perm(p, PROCESS__GETSCHED);
+	return avc_has_perm(current_sid(), task_sid(p), SECCLASS_PROCESS,
+			    PROCESS__GETSCHED, NULL);
 }
 
 static int selinux_task_setrlimit(struct task_struct *p, unsigned int resource,
@@ -4000,47 +3928,48 @@ static int selinux_task_setrlimit(struct task_struct *p, unsigned int resource,
 	   later be used as a safe reset point for the soft limit
 	   upon context transitions.  See selinux_bprm_committing_creds. */
 	if (old_rlim->rlim_max != new_rlim->rlim_max)
-		return current_has_perm(p, PROCESS__SETRLIMIT);
+		return avc_has_perm(current_sid(), task_sid(p),
+				    SECCLASS_PROCESS, PROCESS__SETRLIMIT, NULL);
 
 	return 0;
 }
 
 static int selinux_task_setscheduler(struct task_struct *p)
 {
-	return current_has_perm(p, PROCESS__SETSCHED);
+	return avc_has_perm(current_sid(), task_sid(p), SECCLASS_PROCESS,
+			    PROCESS__SETSCHED, NULL);
 }
 
 static int selinux_task_getscheduler(struct task_struct *p)
 {
-	return current_has_perm(p, PROCESS__GETSCHED);
+	return avc_has_perm(current_sid(), task_sid(p), SECCLASS_PROCESS,
+			    PROCESS__GETSCHED, NULL);
 }
 
 static int selinux_task_movememory(struct task_struct *p)
 {
-	return current_has_perm(p, PROCESS__SETSCHED);
+	return avc_has_perm(current_sid(), task_sid(p), SECCLASS_PROCESS,
+			    PROCESS__SETSCHED, NULL);
 }
 
 static int selinux_task_kill(struct task_struct *p, struct siginfo *info,
 				int sig, u32 secid)
 {
 	u32 perm;
-	int rc;
 
 	if (!sig)
 		perm = PROCESS__SIGNULL; /* null signal; existence test */
 	else
 		perm = signal_to_av(sig);
-	if (secid)
-		rc = avc_has_perm(secid, task_sid(p),
-				  SECCLASS_PROCESS, perm, NULL);
-	else
-		rc = current_has_perm(p, perm);
-	return rc;
+	if (!secid)
+		secid = current_sid();
+	return avc_has_perm(secid, task_sid(p), SECCLASS_PROCESS, perm, NULL);
 }
 
 static int selinux_task_wait(struct task_struct *p)
 {
-	return task_has_perm(p, current, PROCESS__SIGCHLD);
+	return avc_has_perm(task_sid(p), current_sid(), SECCLASS_PROCESS,
+			    PROCESS__SIGCHLD, NULL);
 }
 
 static void selinux_task_to_inode(struct task_struct *p,
@@ -4330,12 +4259,11 @@ static int socket_sockcreate_sid(const struct task_security_struct *tsec,
 				       socksid);
 }
 
-static int sock_has_perm(struct task_struct *task, struct sock *sk, u32 perms)
+static int sock_has_perm(struct sock *sk, u32 perms)
 {
 	struct sk_security_struct *sksec = sk->sk_security;
 	struct common_audit_data ad;
 	struct lsm_network_audit net = {0,};
-	u32 tsid = task_sid(task);
 
 	if (sksec->sid == SECINITSID_KERNEL)
 		return 0;
@@ -4344,7 +4272,8 @@ static int sock_has_perm(struct task_struct *task, struct sock *sk, u32 perms)
 	ad.u.net = &net;
 	ad.u.net->sk = sk;
 
-	return avc_has_perm(tsid, sksec->sid, sksec->sclass, perms, &ad);
+	return avc_has_perm(current_sid(), sksec->sid, sksec->sclass, perms,
+			    &ad);
 }
 
 static int selinux_socket_create(int family, int type,
@@ -4406,7 +4335,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
 	u16 family;
 	int err;
 
-	err = sock_has_perm(current, sk, SOCKET__BIND);
+	err = sock_has_perm(sk, SOCKET__BIND);
 	if (err)
 		goto out;
 
@@ -4505,7 +4434,7 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
 	struct sk_security_struct *sksec = sk->sk_security;
 	int err;
 
-	err = sock_has_perm(current, sk, SOCKET__CONNECT);
+	err = sock_has_perm(sk, SOCKET__CONNECT);
 	if (err)
 		return err;
 
@@ -4557,7 +4486,7 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
 
 static int selinux_socket_listen(struct socket *sock, int backlog)
 {
-	return sock_has_perm(current, sock->sk, SOCKET__LISTEN);
+	return sock_has_perm(sock->sk, SOCKET__LISTEN);
 }
 
 static int selinux_socket_accept(struct socket *sock, struct socket *newsock)
@@ -4568,7 +4497,7 @@ static int selinux_socket_accept(struct socket *sock, struct socket *newsock)
 	u16 sclass;
 	u32 sid;
 
-	err = sock_has_perm(current, sock->sk, SOCKET__ACCEPT);
+	err = sock_has_perm(sock->sk, SOCKET__ACCEPT);
 	if (err)
 		return err;
 
@@ -4589,30 +4518,30 @@ static int selinux_socket_accept(struct socket *sock, struct socket *newsock)
 static int selinux_socket_sendmsg(struct socket *sock, struct msghdr *msg,
 				  int size)
 {
-	return sock_has_perm(current, sock->sk, SOCKET__WRITE);
+	return sock_has_perm(sock->sk, SOCKET__WRITE);
 }
 
 static int selinux_socket_recvmsg(struct socket *sock, struct msghdr *msg,
 				  int size, int flags)
 {
-	return sock_has_perm(current, sock->sk, SOCKET__READ);
+	return sock_has_perm(sock->sk, SOCKET__READ);
 }
 
 static int selinux_socket_getsockname(struct socket *sock)
 {
-	return sock_has_perm(current, sock->sk, SOCKET__GETATTR);
+	return sock_has_perm(sock->sk, SOCKET__GETATTR);
 }
 
 static int selinux_socket_getpeername(struct socket *sock)
 {
-	return sock_has_perm(current, sock->sk, SOCKET__GETATTR);
+	return sock_has_perm(sock->sk, SOCKET__GETATTR);
 }
 
 static int selinux_socket_setsockopt(struct socket *sock, int level, int optname)
 {
 	int err;
 
-	err = sock_has_perm(current, sock->sk, SOCKET__SETOPT);
+	err = sock_has_perm(sock->sk, SOCKET__SETOPT);
 	if (err)
 		return err;
 
@@ -4622,12 +4551,12 @@ static int selinux_socket_setsockopt(struct socket *sock, int level, int optname
 static int selinux_socket_getsockopt(struct socket *sock, int level,
 				     int optname)
 {
-	return sock_has_perm(current, sock->sk, SOCKET__GETOPT);
+	return sock_has_perm(sock->sk, SOCKET__GETOPT);
 }
 
 static int selinux_socket_shutdown(struct socket *sock, int how)
 {
-	return sock_has_perm(current, sock->sk, SOCKET__SHUTDOWN);
+	return sock_has_perm(sock->sk, SOCKET__SHUTDOWN);
 }
 
 static int selinux_socket_unix_stream_connect(struct sock *sock,
@@ -5115,7 +5044,7 @@ static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)
 		goto out;
 	}
 
-	err = sock_has_perm(current, sk, perm);
+	err = sock_has_perm(sk, perm);
 out:
 	return err;
 }
@@ -5446,20 +5375,17 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb)
 	return selinux_nlmsg_perm(sk, skb);
 }
 
-static int ipc_alloc_security(struct task_struct *task,
-			      struct kern_ipc_perm *perm,
+static int ipc_alloc_security(struct kern_ipc_perm *perm,
 			      u16 sclass)
 {
 	struct ipc_security_struct *isec;
-	u32 sid;
 
 	isec = kzalloc(sizeof(struct ipc_security_struct), GFP_KERNEL);
 	if (!isec)
 		return -ENOMEM;
 
-	sid = task_sid(task);
 	isec->sclass = sclass;
-	isec->sid = sid;
+	isec->sid = current_sid();
 	perm->security = isec;
 
 	return 0;
@@ -5527,7 +5453,7 @@ static int selinux_msg_queue_alloc_security(struct msg_queue *msq)
 	u32 sid = current_sid();
 	int rc;
 
-	rc = ipc_alloc_security(current, &msq->q_perm, SECCLASS_MSGQ);
+	rc = ipc_alloc_security(&msq->q_perm, SECCLASS_MSGQ);
 	if (rc)
 		return rc;
 
@@ -5574,7 +5500,8 @@ static int selinux_msg_queue_msgctl(struct msg_queue *msq, int cmd)
 	case IPC_INFO:
 	case MSG_INFO:
 		/* No specific object, just general system-wide information. */
-		return task_has_system(current, SYSTEM__IPC_INFO);
+		return avc_has_perm(current_sid(), SECINITSID_KERNEL,
+				    SECCLASS_SYSTEM, SYSTEM__IPC_INFO, NULL);
 	case IPC_STAT:
 	case MSG_STAT:
 		perms = MSGQ__GETATTR | MSGQ__ASSOCIATE;
@@ -5668,7 +5595,7 @@ static int selinux_shm_alloc_security(struct shmid_kernel *shp)
 	u32 sid = current_sid();
 	int rc;
 
-	rc = ipc_alloc_security(current, &shp->shm_perm, SECCLASS_SHM);
+	rc = ipc_alloc_security(&shp->shm_perm, SECCLASS_SHM);
 	if (rc)
 		return rc;
 
@@ -5716,7 +5643,8 @@ static int selinux_shm_shmctl(struct shmid_kernel *shp, int cmd)
 	case IPC_INFO:
 	case SHM_INFO:
 		/* No specific object, just general system-wide information. */
-		return task_has_system(current, SYSTEM__IPC_INFO);
+		return avc_has_perm(current_sid(), SECINITSID_KERNEL,
+				    SECCLASS_SYSTEM, SYSTEM__IPC_INFO, NULL);
 	case IPC_STAT:
 	case SHM_STAT:
 		perms = SHM__GETATTR | SHM__ASSOCIATE;
@@ -5760,7 +5688,7 @@ static int selinux_sem_alloc_security(struct sem_array *sma)
 	u32 sid = current_sid();
 	int rc;
 
-	rc = ipc_alloc_security(current, &sma->sem_perm, SECCLASS_SEM);
+	rc = ipc_alloc_security(&sma->sem_perm, SECCLASS_SEM);
 	if (rc)
 		return rc;
 
@@ -5808,7 +5736,8 @@ static int selinux_sem_semctl(struct sem_array *sma, int cmd)
 	case IPC_INFO:
 	case SEM_INFO:
 		/* No specific object, just general system-wide information. */
-		return task_has_system(current, SYSTEM__IPC_INFO);
+		return avc_has_perm(current_sid(), SECINITSID_KERNEL,
+				    SECCLASS_SYSTEM, SYSTEM__IPC_INFO, NULL);
 	case GETPID:
 	case GETNCNT:
 	case GETZCNT:
@@ -5889,15 +5818,16 @@ static int selinux_getprocattr(struct task_struct *p,
 	int error;
 	unsigned len;
 
+	rcu_read_lock();
+	__tsec = __task_cred(p)->security;
+
 	if (current != p) {
-		error = current_has_perm(p, PROCESS__GETATTR);
+		error = avc_has_perm(current_sid(), __tsec->sid,
+				     SECCLASS_PROCESS, PROCESS__GETATTR, NULL);
 		if (error)
-			return error;
+			goto bad;
 	}
 
-	rcu_read_lock();
-	__tsec = __task_cred(p)->security;
-
 	if (!strcmp(name, "current"))
 		sid = __tsec->sid;
 	else if (!strcmp(name, "prev"))
@@ -5910,8 +5840,10 @@ static int selinux_getprocattr(struct task_struct *p,
 		sid = __tsec->keycreate_sid;
 	else if (!strcmp(name, "sockcreate"))
 		sid = __tsec->sockcreate_sid;
-	else
-		goto invalid;
+	else {
+		error = -EINVAL;
+		goto bad;
+	}
 	rcu_read_unlock();
 
 	if (!sid)
@@ -5922,9 +5854,9 @@ static int selinux_getprocattr(struct task_struct *p,
 		return error;
 	return len;
 
-invalid:
+bad:
 	rcu_read_unlock();
-	return -EINVAL;
+	return error;
 }
 
 static int selinux_setprocattr(struct task_struct *p,
@@ -5932,31 +5864,38 @@ static int selinux_setprocattr(struct task_struct *p,
 {
 	struct task_security_struct *tsec;
 	struct cred *new;
-	u32 sid = 0, ptsid;
+	u32 mysid = current_sid(), sid = 0, ptsid;
 	int error;
 	char *str = value;
 
 	if (current != p) {
-		/* SELinux only allows a process to change its own
-		   security attributes. */
+		/*
+		 * A task may only alter its own credentials.
+		 * SELinux has always enforced this restriction,
+		 * and it is now mandated by the Linux credentials
+		 * infrastructure; see Documentation/security/credentials.txt.
+		 */
 		return -EACCES;
 	}
 
 	/*
 	 * Basic control over ability to set these attributes at all.
-	 * current == p, but we'll pass them separately in case the
-	 * above restriction is ever removed.
 	 */
 	if (!strcmp(name, "exec"))
-		error = current_has_perm(p, PROCESS__SETEXEC);
+		error = avc_has_perm(mysid, mysid, SECCLASS_PROCESS,
+				     PROCESS__SETEXEC, NULL);
 	else if (!strcmp(name, "fscreate"))
-		error = current_has_perm(p, PROCESS__SETFSCREATE);
+		error = avc_has_perm(mysid, mysid, SECCLASS_PROCESS,
+				     PROCESS__SETFSCREATE, NULL);
 	else if (!strcmp(name, "keycreate"))
-		error = current_has_perm(p, PROCESS__SETKEYCREATE);
+		error = avc_has_perm(mysid, mysid, SECCLASS_PROCESS,
+				     PROCESS__SETKEYCREATE, NULL);
 	else if (!strcmp(name, "sockcreate"))
-		error = current_has_perm(p, PROCESS__SETSOCKCREATE);
+		error = avc_has_perm(mysid, mysid, SECCLASS_PROCESS,
+				     PROCESS__SETSOCKCREATE, NULL);
 	else if (!strcmp(name, "current"))
-		error = current_has_perm(p, PROCESS__SETCURRENT);
+		error = avc_has_perm(mysid, mysid, SECCLASS_PROCESS,
+				     PROCESS__SETCURRENT, NULL);
 	else
 		error = -EINVAL;
 	if (error)
@@ -6010,7 +5949,8 @@ static int selinux_setprocattr(struct task_struct *p,
 	} else if (!strcmp(name, "fscreate")) {
 		tsec->create_sid = sid;
 	} else if (!strcmp(name, "keycreate")) {
-		error = may_create_key(sid, p);
+		error = avc_has_perm(mysid, sid, SECCLASS_KEY, KEY__CREATE,
+				     NULL);
 		if (error)
 			goto abort_change;
 		tsec->keycreate_sid = sid;
@@ -6037,7 +5977,7 @@ static int selinux_setprocattr(struct task_struct *p,
 
 		/* Check for ptracing, and update the task SID if ok.
 		   Otherwise, leave SID unchanged and fail. */
-		ptsid = ptrace_parent_sid(p);
+		ptsid = ptrace_parent_sid();
 		if (ptsid != 0) {
 			error = avc_has_perm(ptsid, sid, SECCLASS_PROCESS,
 					     PROCESS__PTRACE, NULL);
security/selinux/include/objsec.h +10 -0
index e8dab0f..c03cdcd 100644
@@ -37,6 +37,16 @@ struct task_security_struct {
 	u32 sockcreate_sid;	/* fscreate SID */
 };
 
+/*
+ * get the subjective security ID of the current task
+ */
+static inline u32 current_sid(void)
+{
+	const struct task_security_struct *tsec = current_security();
+
+	return tsec->sid;
+}
+
 enum label_initialized {
 	LABEL_INVALID,		/* invalid or not initialized */
 	LABEL_INITIALIZED,	/* initialized */
security/selinux/selinuxfs.c +39 -34

169 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/2 proc, security: move restriction on writing /proc/pid/attr nodes to proc

Processes can only alter their own security attributes via /proc/pid/attr nodes. This is presently enforced by each individual security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials. Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security hook, and drop the unnecessary task argument to the security hook since it can only ever be the current task.

---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------
 7 files changed, 18 insertions(+), 37 deletions(-)
fs/proc/base.c +9 -4
index 6eae4d0..7b228ea 100644
@@ -2485,6 +2485,12 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
 	length = -ESRCH;
 	if (!task)
 		goto out_no_task;
+
+	/* A task may only write its own attributes. */
+	length = -EACCES;
+	if (current != task)
+		goto out;
+
 	if (count > PAGE_SIZE)
 		count = PAGE_SIZE;
 
@@ -2500,14 +2506,13 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
 	}
 
 	/* Guard against adverse ptrace interaction */
-	length = mutex_lock_interruptible(&task->signal->cred_guard_mutex);
+	length = mutex_lock_interruptible(&current->signal->cred_guard_mutex);
 	if (length < 0)
 		goto out_free;
 
-	length = security_setprocattr(task,
-				      (char*)file->f_path.dentry->d_name.name,
+	length = security_setprocattr(file->f_path.dentry->d_name.name,
 				      page, count);
-	mutex_unlock(&task->signal->cred_guard_mutex);
+	mutex_unlock(&current->signal->cred_guard_mutex);
 out_free:
 	kfree(page);
 out:
include/linux/lsm_hooks.h +1 -2
index 558adfa..0dde959 100644
@@ -1547,8 +1547,7 @@ union security_list_options {
 	void (*d_instantiate)(struct dentry *dentry, struct inode *inode);
 
 	int (*getprocattr)(struct task_struct *p, char *name, char **value);
-	int (*setprocattr)(struct task_struct *p, char *name, void *value,
-				size_t size);
+	int (*setprocattr)(const char *name, void *value, size_t size);
 	int (*ismaclabel)(const char *name);
 	int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
 	int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid);
include/linux/security.h +2 -2
index c2125e9..f4ebac1 100644
@@ -361,7 +361,7 @@ int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
 			unsigned nsops, int alter);
 void security_d_instantiate(struct dentry *dentry, struct inode *inode);
 int security_getprocattr(struct task_struct *p, char *name, char **value);
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
+int security_setprocattr(const char *name, void *value, size_t size);
 int security_netlink_send(struct sock *sk, struct sk_buff *skb);
 int security_ismaclabel(const char *name);
 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
@@ -1106,7 +1106,7 @@ static inline int security_getprocattr(struct task_struct *p, char *name, char *
 	return -EINVAL;
 }
 
-static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+static inline int security_setprocattr(char *name, void *value, size_t size)
 {
 	return -EINVAL;
 }
security/apparmor/lsm.c +2 -5
index 41b8cb1..8202e55 100644
@@ -495,8 +495,8 @@ static int apparmor_getprocattr(struct task_struct *task, char *name,
 	return error;
 }
 
-static int apparmor_setprocattr(struct task_struct *task, char *name,
-				void *value, size_t size)
+static int apparmor_setprocattr(const char *name, void *value,
+				size_t size)
 {
 	struct common_audit_data sa;
 	struct apparmor_audit_data aad = {0,};
@@ -506,9 +506,6 @@ static int apparmor_setprocattr(struct task_struct *task, char *name,
 
 	if (size == 0)
 		return -EINVAL;
-	/* task can only write its own attributes */
-	if (current != task)
-		return -EACCES;
 
 	/* AppArmor requires that the buffer must be null terminated atm */
 	if (args[size - 1] != '\0') {
security/security.c +2 -2
index f825304..32052f5 100644
@@ -1170,9 +1170,9 @@ int security_getprocattr(struct task_struct *p, char *name, char **value)
 	return call_int_hook(getprocattr, -EINVAL, p, name, value);
 }
 
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+int security_setprocattr(const char *name, void *value, size_t size)
 {
-	return call_int_hook(setprocattr, -EINVAL, p, name, value, size);
+	return call_int_hook(setprocattr, -EINVAL, name, value, size);
 }
 
 int security_netlink_send(struct sock *sk, struct sk_buff *skb)
security/selinux/hooks.c +1 -12
index 9992626..762276b 100644
@@ -5859,8 +5859,7 @@ static int selinux_getprocattr(struct task_struct *p,
 	return error;
 }
 
-static int selinux_setprocattr(struct task_struct *p,
-			       char *name, void *value, size_t size)
+static int selinux_setprocattr(const char *name, void *value, size_t size)
 {
 	struct task_security_struct *tsec;
 	struct cred *new;
@@ -5868,16 +5867,6 @@ static int selinux_setprocattr(struct task_struct *p,
 	int error;
 	char *str = value;
 
-	if (current != p) {
-		/*
-		 * A task may only alter its own credentials.
-		 * SELinux has always enforced this restriction,
-		 * and it is now mandated by the Linux credentials
-		 * infrastructure; see Documentation/security/credentials.txt.
-		 */
-		return -EACCES;
-	}
-
 	/*
 	 * Basic control over ability to set these attributes at all.
 	 */
security/smack/smack_lsm.c +1 -10
index 4d90257..9bde7f8 100644
@@ -3620,7 +3620,6 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
 
 /**
  * smack_setprocattr - Smack process attribute setting
- * @p: the object task
  * @name: the name of the attribute in /proc/.../attr
  * @value: the value to set
  * @size: the size of the value
@@ -3630,8 +3629,7 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
  *
  * Returns the length of the smack label or an error code
  */
-static int smack_setprocattr(struct task_struct *p, char *name,
-			     void *value, size_t size)
+static int smack_setprocattr(const char *name, void *value, size_t size)
 {
 	struct task_smack *tsp = current_security();
 	struct cred *new;
@@ -3639,13 +3637,6 @@ static int smack_setprocattr(struct task_struct *p, char *name,
 	struct smack_known_list_elem *sklep;
 	int rc;
 
-	/*
-	 * Changing another process' Smack value is too dangerous
-	 * and supports no sane use case.
-	 */
-	if (p != current)
-		return -EPERM;
-
 	if (!smack_privileged(CAP_MAC_ADMIN) && list_empty(&tsp->smk_relabel))
 		return -EPERM;
 
Signature · 1 line
2.7.4
maintainer Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 10 lines · Stephen Smalley

Processes can only alter their own security attributes via /proc/pid/attr nodes. This is presently enforced by each individual security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials. Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security hook, and drop the unnecessary task argument to the security hook since it can only ever be the current task.

Quoted 189 lines
---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------
 7 files changed, 18 insertions(+), 37 deletions(-)
fs/proc/base.c +9 -4
index 6eae4d0..7b228ea 100644
@@ -2485,6 +2485,12 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
 	length = -ESRCH;
 	if (!task)
 		goto out_no_task;
+
+	/* A task may only write its own attributes. */
+	length = -EACCES;
+	if (current != task)
+		goto out;
+
 	if (count > PAGE_SIZE)
 		count = PAGE_SIZE;
 
@@ -2500,14 +2506,13 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
 	}
 
 	/* Guard against adverse ptrace interaction */
-	length = mutex_lock_interruptible(&task->signal->cred_guard_mutex);
+	length = mutex_lock_interruptible(&current->signal->cred_guard_mutex);
 	if (length < 0)
 		goto out_free;
 
-	length = security_setprocattr(task,
-				      (char*)file->f_path.dentry->d_name.name,
+	length = security_setprocattr(file->f_path.dentry->d_name.name,
 				      page, count);
-	mutex_unlock(&task->signal->cred_guard_mutex);
+	mutex_unlock(&current->signal->cred_guard_mutex);
 out_free:
 	kfree(page);
 out:
include/linux/lsm_hooks.h +1 -2
index 558adfa..0dde959 100644
@@ -1547,8 +1547,7 @@ union security_list_options {
 	void (*d_instantiate)(struct dentry *dentry, struct inode *inode);
 
 	int (*getprocattr)(struct task_struct *p, char *name, char **value);
-	int (*setprocattr)(struct task_struct *p, char *name, void *value,
-				size_t size);
+	int (*setprocattr)(const char *name, void *value, size_t size);
 	int (*ismaclabel)(const char *name);
 	int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
 	int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid);
include/linux/security.h +2 -2
index c2125e9..f4ebac1 100644
@@ -361,7 +361,7 @@ int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
 			unsigned nsops, int alter);
 void security_d_instantiate(struct dentry *dentry, struct inode *inode);
 int security_getprocattr(struct task_struct *p, char *name, char **value);
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
+int security_setprocattr(const char *name, void *value, size_t size);
 int security_netlink_send(struct sock *sk, struct sk_buff *skb);
 int security_ismaclabel(const char *name);
 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
@@ -1106,7 +1106,7 @@ static inline int security_getprocattr(struct task_struct *p, char *name, char *
 	return -EINVAL;
 }
 
-static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+static inline int security_setprocattr(char *name, void *value, size_t size)
 {
 	return -EINVAL;
 }
security/apparmor/lsm.c +2 -5
index 41b8cb1..8202e55 100644
@@ -495,8 +495,8 @@ static int apparmor_getprocattr(struct task_struct *task, char *name,
 	return error;
 }
 
-static int apparmor_setprocattr(struct task_struct *task, char *name,
-				void *value, size_t size)
+static int apparmor_setprocattr(const char *name, void *value,
+				size_t size)
 {
 	struct common_audit_data sa;
 	struct apparmor_audit_data aad = {0,};
@@ -506,9 +506,6 @@ static int apparmor_setprocattr(struct task_struct *task, char *name,
 
 	if (size == 0)
 		return -EINVAL;
-	/* task can only write its own attributes */
-	if (current != task)
-		return -EACCES;
 
 	/* AppArmor requires that the buffer must be null terminated atm */
 	if (args[size - 1] != '\0') {
security/security.c +2 -2
index f825304..32052f5 100644
@@ -1170,9 +1170,9 @@ int security_getprocattr(struct task_struct *p, char *name, char **value)
 	return call_int_hook(getprocattr, -EINVAL, p, name, value);
 }
 
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+int security_setprocattr(const char *name, void *value, size_t size)
 {
-	return call_int_hook(setprocattr, -EINVAL, p, name, value, size);
+	return call_int_hook(setprocattr, -EINVAL, name, value, size);
 }
 
 int security_netlink_send(struct sock *sk, struct sk_buff *skb)
security/selinux/hooks.c +1 -12
index 9992626..762276b 100644
@@ -5859,8 +5859,7 @@ static int selinux_getprocattr(struct task_struct *p,
 	return error;
 }
 
-static int selinux_setprocattr(struct task_struct *p,
-			       char *name, void *value, size_t size)
+static int selinux_setprocattr(const char *name, void *value, size_t size)
 {
 	struct task_security_struct *tsec;
 	struct cred *new;
@@ -5868,16 +5867,6 @@ static int selinux_setprocattr(struct task_struct *p,
 	int error;
 	char *str = value;
 
-	if (current != p) {
-		/*
-		 * A task may only alter its own credentials.
-		 * SELinux has always enforced this restriction,
-		 * and it is now mandated by the Linux credentials
-		 * infrastructure; see Documentation/security/credentials.txt.
-		 */
-		return -EACCES;
-	}
-
 	/*
 	 * Basic control over ability to set these attributes at all.
 	 */
security/smack/smack_lsm.c +1 -10
index 4d90257..9bde7f8 100644
@@ -3620,7 +3620,6 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
 
 /**
  * smack_setprocattr - Smack process attribute setting
- * @p: the object task
  * @name: the name of the attribute in /proc/.../attr
  * @value: the value to set
  * @size: the size of the value
@@ -3630,8 +3629,7 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
  *
  * Returns the length of the smack label or an error code
  */
-static int smack_setprocattr(struct task_struct *p, char *name,
-			     void *value, size_t size)
+static int smack_setprocattr(const char *name, void *value, size_t size)
 {
 	struct task_smack *tsp = current_security();
 	struct cred *new;
@@ -3639,13 +3637,6 @@ static int smack_setprocattr(struct task_struct *p, char *name,
 	struct smack_known_list_elem *sklep;
 	int rc;
 
-	/*
-	 * Changing another process' Smack value is too dangerous
-	 * and supports no sane use case.
-	 */
-	if (p != current)
-		return -EPERM;
-
 	if (!smack_privileged(CAP_MAC_ADMIN) && list_empty(&tsp->smk_relabel))
 		return -EPERM;
 
maintainer Acked-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Stephen Smalley
Quoted 10 lines · Stephen Smalley

Processes can only alter their own security attributes via /proc/pid/attr nodes. This is presently enforced by each individual security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials. Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security hook, and drop the unnecessary task argument to the security hook since it can only ever be the current task.

Quoted 190 lines
---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------
 7 files changed, 18 insertions(+), 37 deletions(-)
fs/proc/base.c +9 -4
index 6eae4d0..7b228ea 100644
@@ -2485,6 +2485,12 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
 	length = -ESRCH;
 	if (!task)
 		goto out_no_task;
+
+	/* A task may only write its own attributes. */
+	length = -EACCES;
+	if (current != task)
+		goto out;
+
 	if (count > PAGE_SIZE)
 		count = PAGE_SIZE;
 
@@ -2500,14 +2506,13 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
 	}
 
 	/* Guard against adverse ptrace interaction */
-	length = mutex_lock_interruptible(&task->signal->cred_guard_mutex);
+	length = mutex_lock_interruptible(&current->signal->cred_guard_mutex);
 	if (length < 0)
 		goto out_free;
 
-	length = security_setprocattr(task,
-				      (char*)file->f_path.dentry->d_name.name,
+	length = security_setprocattr(file->f_path.dentry->d_name.name,
 				      page, count);
-	mutex_unlock(&task->signal->cred_guard_mutex);
+	mutex_unlock(&current->signal->cred_guard_mutex);
 out_free:
 	kfree(page);
 out:
include/linux/lsm_hooks.h +1 -2
index 558adfa..0dde959 100644
@@ -1547,8 +1547,7 @@ union security_list_options {
 	void (*d_instantiate)(struct dentry *dentry, struct inode *inode);
 
 	int (*getprocattr)(struct task_struct *p, char *name, char **value);
-	int (*setprocattr)(struct task_struct *p, char *name, void *value,
-				size_t size);
+	int (*setprocattr)(const char *name, void *value, size_t size);
 	int (*ismaclabel)(const char *name);
 	int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
 	int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid);
include/linux/security.h +2 -2
index c2125e9..f4ebac1 100644
@@ -361,7 +361,7 @@ int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
 			unsigned nsops, int alter);
 void security_d_instantiate(struct dentry *dentry, struct inode *inode);
 int security_getprocattr(struct task_struct *p, char *name, char **value);
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
+int security_setprocattr(const char *name, void *value, size_t size);
 int security_netlink_send(struct sock *sk, struct sk_buff *skb);
 int security_ismaclabel(const char *name);
 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
@@ -1106,7 +1106,7 @@ static inline int security_getprocattr(struct task_struct *p, char *name, char *
 	return -EINVAL;
 }
 
-static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+static inline int security_setprocattr(char *name, void *value, size_t size)
 {
 	return -EINVAL;
 }
security/apparmor/lsm.c +2 -5
index 41b8cb1..8202e55 100644
@@ -495,8 +495,8 @@ static int apparmor_getprocattr(struct task_struct *task, char *name,
 	return error;
 }
 
-static int apparmor_setprocattr(struct task_struct *task, char *name,
-				void *value, size_t size)
+static int apparmor_setprocattr(const char *name, void *value,
+				size_t size)
 {
 	struct common_audit_data sa;
 	struct apparmor_audit_data aad = {0,};
@@ -506,9 +506,6 @@ static int apparmor_setprocattr(struct task_struct *task, char *name,
 
 	if (size == 0)
 		return -EINVAL;
-	/* task can only write its own attributes */
-	if (current != task)
-		return -EACCES;
 
 	/* AppArmor requires that the buffer must be null terminated atm */
 	if (args[size - 1] != '\0') {
security/security.c +2 -2
index f825304..32052f5 100644
@@ -1170,9 +1170,9 @@ int security_getprocattr(struct task_struct *p, char *name, char **value)
 	return call_int_hook(getprocattr, -EINVAL, p, name, value);
 }
 
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+int security_setprocattr(const char *name, void *value, size_t size)
 {
-	return call_int_hook(setprocattr, -EINVAL, p, name, value, size);
+	return call_int_hook(setprocattr, -EINVAL, name, value, size);
 }
 
 int security_netlink_send(struct sock *sk, struct sk_buff *skb)
security/selinux/hooks.c +1 -12
index 9992626..762276b 100644
@@ -5859,8 +5859,7 @@ static int selinux_getprocattr(struct task_struct *p,
 	return error;
 }
 
-static int selinux_setprocattr(struct task_struct *p,
-			       char *name, void *value, size_t size)
+static int selinux_setprocattr(const char *name, void *value, size_t size)
 {
 	struct task_security_struct *tsec;
 	struct cred *new;
@@ -5868,16 +5867,6 @@ static int selinux_setprocattr(struct task_struct *p,
 	int error;
 	char *str = value;
 
-	if (current != p) {
-		/*
-		 * A task may only alter its own credentials.
-		 * SELinux has always enforced this restriction,
-		 * and it is now mandated by the Linux credentials
-		 * infrastructure; see Documentation/security/credentials.txt.
-		 */
-		return -EACCES;
-	}
-
 	/*
 	 * Basic control over ability to set these attributes at all.
 	 */
security/smack/smack_lsm.c +1 -10
index 4d90257..9bde7f8 100644
@@ -3620,7 +3620,6 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
 
 /**
  * smack_setprocattr - Smack process attribute setting
- * @p: the object task
  * @name: the name of the attribute in /proc/.../attr
  * @value: the value to set
  * @size: the size of the value
@@ -3630,8 +3629,7 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
  *
  * Returns the length of the smack label or an error code
  */
-static int smack_setprocattr(struct task_struct *p, char *name,
-			     void *value, size_t size)
+static int smack_setprocattr(const char *name, void *value, size_t size)
 {
 	struct task_smack *tsp = current_security();
 	struct cred *new;
@@ -3639,13 +3637,6 @@ static int smack_setprocattr(struct task_struct *p, char *name,
 	struct smack_known_list_elem *sklep;
 	int rc;
 
-	/*
-	 * Changing another process' Smack value is too dangerous
-	 * and supports no sane use case.
-	 */
-	if (p != current)
-		return -EPERM;
-
 	if (!smack_privileged(CAP_MAC_ADMIN) && list_empty(&tsp->smk_relabel))
 		return -EPERM;
 
maintainer Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Stephen Smalley
Quoted 10 lines · Stephen Smalley

Processes can only alter their own security attributes via /proc/pid/attr nodes. This is presently enforced by each individual security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials. Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security hook, and drop the unnecessary task argument to the security hook since it can only ever be the current task.

Quoted 9 lines
---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------
 7 files changed, 18 insertions(+), 37 deletions(-)

Looks good to me. I'm happy to pull this in via the SELinux tree unless anyone else would rather take it?

Quoted 182 lines
fs/proc/base.c +9 -4
index 6eae4d0..7b228ea 100644
@@ -2485,6 +2485,12 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
        length = -ESRCH;
        if (!task)
                goto out_no_task;
+
+       /* A task may only write its own attributes. */
+       length = -EACCES;
+       if (current != task)
+               goto out;
+
        if (count > PAGE_SIZE)
                count = PAGE_SIZE;
 
@@ -2500,14 +2506,13 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
        }
 
        /* Guard against adverse ptrace interaction */
-       length = mutex_lock_interruptible(&task->signal->cred_guard_mutex);
+       length = mutex_lock_interruptible(&current->signal->cred_guard_mutex);
        if (length < 0)
                goto out_free;
 
-       length = security_setprocattr(task,
-                                     (char*)file->f_path.dentry->d_name.name,
+       length = security_setprocattr(file->f_path.dentry->d_name.name,
                                      page, count);
-       mutex_unlock(&task->signal->cred_guard_mutex);
+       mutex_unlock(&current->signal->cred_guard_mutex);
 out_free:
        kfree(page);
 out:
include/linux/lsm_hooks.h +1 -2
index 558adfa..0dde959 100644
@@ -1547,8 +1547,7 @@ union security_list_options {
        void (*d_instantiate)(struct dentry *dentry, struct inode *inode);
 
        int (*getprocattr)(struct task_struct *p, char *name, char **value);
-       int (*setprocattr)(struct task_struct *p, char *name, void *value,
-                               size_t size);
+       int (*setprocattr)(const char *name, void *value, size_t size);
        int (*ismaclabel)(const char *name);
        int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
        int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid);
include/linux/security.h +2 -2
index c2125e9..f4ebac1 100644
@@ -361,7 +361,7 @@ int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
                        unsigned nsops, int alter);
 void security_d_instantiate(struct dentry *dentry, struct inode *inode);
 int security_getprocattr(struct task_struct *p, char *name, char **value);
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
+int security_setprocattr(const char *name, void *value, size_t size);
 int security_netlink_send(struct sock *sk, struct sk_buff *skb);
 int security_ismaclabel(const char *name);
 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
@@ -1106,7 +1106,7 @@ static inline int security_getprocattr(struct task_struct *p, char *name, char *
        return -EINVAL;
 }
 
-static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+static inline int security_setprocattr(char *name, void *value, size_t size)
 {
        return -EINVAL;
 }
security/apparmor/lsm.c +2 -5
index 41b8cb1..8202e55 100644
@@ -495,8 +495,8 @@ static int apparmor_getprocattr(struct task_struct *task, char *name,
        return error;
 }
 
-static int apparmor_setprocattr(struct task_struct *task, char *name,
-                               void *value, size_t size)
+static int apparmor_setprocattr(const char *name, void *value,
+                               size_t size)
 {
        struct common_audit_data sa;
        struct apparmor_audit_data aad = {0,};
@@ -506,9 +506,6 @@ static int apparmor_setprocattr(struct task_struct *task, char *name,
 
        if (size == 0)
                return -EINVAL;
-       /* task can only write its own attributes */
-       if (current != task)
-               return -EACCES;
 
        /* AppArmor requires that the buffer must be null terminated atm */
        if (args[size - 1] != '\0') {
security/security.c +2 -2
index f825304..32052f5 100644
@@ -1170,9 +1170,9 @@ int security_getprocattr(struct task_struct *p, char *name, char **value)
        return call_int_hook(getprocattr, -EINVAL, p, name, value);
 }
 
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+int security_setprocattr(const char *name, void *value, size_t size)
 {
-       return call_int_hook(setprocattr, -EINVAL, p, name, value, size);
+       return call_int_hook(setprocattr, -EINVAL, name, value, size);
 }
 
 int security_netlink_send(struct sock *sk, struct sk_buff *skb)
security/selinux/hooks.c +1 -12
index 9992626..762276b 100644
@@ -5859,8 +5859,7 @@ static int selinux_getprocattr(struct task_struct *p,
        return error;
 }
 
-static int selinux_setprocattr(struct task_struct *p,
-                              char *name, void *value, size_t size)
+static int selinux_setprocattr(const char *name, void *value, size_t size)
 {
        struct task_security_struct *tsec;
        struct cred *new;
@@ -5868,16 +5867,6 @@ static int selinux_setprocattr(struct task_struct *p,
        int error;
        char *str = value;
 
-       if (current != p) {
-               /*
-                * A task may only alter its own credentials.
-                * SELinux has always enforced this restriction,
-                * and it is now mandated by the Linux credentials
-                * infrastructure; see Documentation/security/credentials.txt.
-                */
-               return -EACCES;
-       }
-
        /*
         * Basic control over ability to set these attributes at all.
         */
security/smack/smack_lsm.c +1 -11
index 4d90257..9bde7f8 100644
@@ -3620,7 +3620,6 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
 
 /**
  * smack_setprocattr - Smack process attribute setting
- * @p: the object task
  * @name: the name of the attribute in /proc/.../attr
  * @value: the value to set
  * @size: the size of the value
@@ -3630,8 +3629,7 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
  *
  * Returns the length of the smack label or an error code
  */
-static int smack_setprocattr(struct task_struct *p, char *name,
-                            void *value, size_t size)
+static int smack_setprocattr(const char *name, void *value, size_t size)
 {
        struct task_smack *tsp = current_security();
        struct cred *new;
@@ -3639,13 +3637,6 @@ static int smack_setprocattr(struct task_struct *p, char *name,
        struct smack_known_list_elem *sklep;
        int rc;
 
-       /*
-        * Changing another process' Smack value is too dangerous
-        * and supports no sane use case.
-        */
-       if (p != current)
-               return -EPERM;
-
        if (!smack_privileged(CAP_MAC_ADMIN) && list_empty(&tsp->smk_relabel))
                return -EPERM;
 
--

2.7.4

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer
#5 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 20 lines · Paul Moore
Quoted 10 lines · Stephen Smalley

Processes can only alter their own security attributes via /proc/pid/attr nodes. This is presently enforced by each individual security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials. Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security hook, and drop the unnecessary task argument to the security hook since it can only ever be the current task.

Quoted 9 lines
---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------
 7 files changed, 18 insertions(+), 37 deletions(-)
Quoted 2 lines

Looks good to me. I'm happy to pull this in via the SELinux tree unless anyone else would rather take it?

That works for me. It does need to go in atomically.

Quoted 187 lines
Quoted 182 lines
fs/proc/base.c +9 -4
index 6eae4d0..7b228ea 100644
@@ -2485,6 +2485,12 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
        length = -ESRCH;
        if (!task)
                goto out_no_task;
+
+       /* A task may only write its own attributes. */
+       length = -EACCES;
+       if (current != task)
+               goto out;
+
        if (count > PAGE_SIZE)
                count = PAGE_SIZE;
 
@@ -2500,14 +2506,13 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
        }
 
        /* Guard against adverse ptrace interaction */
-       length = mutex_lock_interruptible(&task->signal->cred_guard_mutex);
+       length = mutex_lock_interruptible(&current->signal->cred_guard_mutex);
        if (length < 0)
                goto out_free;
 
-       length = security_setprocattr(task,
-                                     (char*)file->f_path.dentry->d_name.name,
+       length = security_setprocattr(file->f_path.dentry->d_name.name,
                                      page, count);
-       mutex_unlock(&task->signal->cred_guard_mutex);
+       mutex_unlock(&current->signal->cred_guard_mutex);
 out_free:
        kfree(page);
 out:
include/linux/lsm_hooks.h +1 -2
index 558adfa..0dde959 100644
@@ -1547,8 +1547,7 @@ union security_list_options {
        void (*d_instantiate)(struct dentry *dentry, struct inode *inode);
 
        int (*getprocattr)(struct task_struct *p, char *name, char **value);
-       int (*setprocattr)(struct task_struct *p, char *name, void *value,
-                               size_t size);
+       int (*setprocattr)(const char *name, void *value, size_t size);
        int (*ismaclabel)(const char *name);
        int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
        int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid);
include/linux/security.h +2 -2
index c2125e9..f4ebac1 100644
@@ -361,7 +361,7 @@ int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
                        unsigned nsops, int alter);
 void security_d_instantiate(struct dentry *dentry, struct inode *inode);
 int security_getprocattr(struct task_struct *p, char *name, char **value);
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
+int security_setprocattr(const char *name, void *value, size_t size);
 int security_netlink_send(struct sock *sk, struct sk_buff *skb);
 int security_ismaclabel(const char *name);
 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
@@ -1106,7 +1106,7 @@ static inline int security_getprocattr(struct task_struct *p, char *name, char *
        return -EINVAL;
 }
 
-static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+static inline int security_setprocattr(char *name, void *value, size_t size)
 {
        return -EINVAL;
 }
security/apparmor/lsm.c +2 -5
index 41b8cb1..8202e55 100644
@@ -495,8 +495,8 @@ static int apparmor_getprocattr(struct task_struct *task, char *name,
        return error;
 }
 
-static int apparmor_setprocattr(struct task_struct *task, char *name,
-                               void *value, size_t size)
+static int apparmor_setprocattr(const char *name, void *value,
+                               size_t size)
 {
        struct common_audit_data sa;
        struct apparmor_audit_data aad = {0,};
@@ -506,9 +506,6 @@ static int apparmor_setprocattr(struct task_struct *task, char *name,
 
        if (size == 0)
                return -EINVAL;
-       /* task can only write its own attributes */
-       if (current != task)
-               return -EACCES;
 
        /* AppArmor requires that the buffer must be null terminated atm */
        if (args[size - 1] != '\0') {
security/security.c +2 -2
index f825304..32052f5 100644
@@ -1170,9 +1170,9 @@ int security_getprocattr(struct task_struct *p, char *name, char **value)
        return call_int_hook(getprocattr, -EINVAL, p, name, value);
 }
 
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+int security_setprocattr(const char *name, void *value, size_t size)
 {
-       return call_int_hook(setprocattr, -EINVAL, p, name, value, size);
+       return call_int_hook(setprocattr, -EINVAL, name, value, size);
 }
 
 int security_netlink_send(struct sock *sk, struct sk_buff *skb)
security/selinux/hooks.c +1 -12
index 9992626..762276b 100644
@@ -5859,8 +5859,7 @@ static int selinux_getprocattr(struct task_struct *p,
        return error;
 }
 
-static int selinux_setprocattr(struct task_struct *p,
-                              char *name, void *value, size_t size)
+static int selinux_setprocattr(const char *name, void *value, size_t size)
 {
        struct task_security_struct *tsec;
        struct cred *new;
@@ -5868,16 +5867,6 @@ static int selinux_setprocattr(struct task_struct *p,
        int error;
        char *str = value;
 
-       if (current != p) {
-               /*
-                * A task may only alter its own credentials.
-                * SELinux has always enforced this restriction,
-                * and it is now mandated by the Linux credentials
-                * infrastructure; see Documentation/security/credentials.txt.
-                */
-               return -EACCES;
-       }
-
        /*
         * Basic control over ability to set these attributes at all.
         */
security/smack/smack_lsm.c +1 -11
index 4d90257..9bde7f8 100644
@@ -3620,7 +3620,6 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
 
 /**
  * smack_setprocattr - Smack process attribute setting
- * @p: the object task
  * @name: the name of the attribute in /proc/.../attr
  * @value: the value to set
  * @size: the size of the value
@@ -3630,8 +3629,7 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
  *
  * Returns the length of the smack label or an error code
  */
-static int smack_setprocattr(struct task_struct *p, char *name,
-                            void *value, size_t size)
+static int smack_setprocattr(const char *name, void *value, size_t size)
 {
        struct task_smack *tsp = current_security();
        struct cred *new;
@@ -3639,13 +3637,6 @@ static int smack_setprocattr(struct task_struct *p, char *name,
        struct smack_known_list_elem *sklep;
        int rc;
 
-       /*
-        * Changing another process' Smack value is too dangerous
-        * and supports no sane use case.
-        */
-       if (p != current)
-               return -EPERM;
-
        if (!smack_privileged(CAP_MAC_ADMIN) && list_empty(&tsp->smk_relabel))
                return -EPERM;
 
--

2.7.4

maintainer
#6 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 21 lines · Casey Schaufler
Quoted 20 lines · Paul Moore
Quoted 19 lines · Stephen Smalley

Processes can only alter their own security attributes via /proc/pid/attr nodes. This is presently enforced by each individual security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials. Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security hook, and drop the unnecessary task argument to the security hook since it can only ever be the current task.

---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------
 7 files changed, 18 insertions(+), 37 deletions(-)
Quoted 4 lines
Quoted 2 lines

Looks good to me. I'm happy to pull this in via the SELinux tree unless anyone else would rather take it?

That works for me. It does need to go in atomically.

Even with all the discussion today, I still think this patch has value and I don't believe it should impact the PTAGS work as there are clearly larger issues that need to be resolved (e.g. reintroduce a task based security blob?). Unless I hear any objections that this will wreck everything for years to come (very doubtful), I'll go ahead and merge this into the SELinux tree tomorrow.

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer
#7 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 24 lines · Paul Moore
Quoted 23 lines · Casey Schaufler
Quoted 22 lines · Paul Moore
Quoted 10 lines · Stephen Smalley

Processes can only alter their own security attributes via /proc/pid/attr nodes. This is presently enforced by each individual security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials. Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security hook, and drop the unnecessary task argument to the security hook since it can only ever be the current task.

Quoted 9 lines
---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------
 7 files changed, 18 insertions(+), 37 deletions(-)

Looks good to me. I'm happy to pull this in via the SELinux tree unless anyone else would rather take it?

Quoted 7 lines
Quoted 1 line

That works for me. It does need to go in atomically.

Even with all the discussion today, I still think this patch has value and I don't believe it should impact the PTAGS work as there are clearly larger issues that need to be resolved (e.g. reintroduce a task based security blob?). Unless I hear any objections that this will wreck everything for years to come (very doubtful), I'll go ahead and merge this into the SELinux tree tomorrow.

I think this can go ahead without causing the end of western civilization.

#8 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Paul Moore

Le lundi 19 décembre 2016 à 20:30 -0500, Paul Moore a écrit :

Quoted 34 lines
Quoted 27 lines · Casey Schaufler
Quoted 26 lines · Paul Moore
Quoted 23 lines · Stephen Smalley

Processes can only alter their own security attributes via /proc/pid/attr nodes.  This is presently enforced by each individual
security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security hook,
and drop the unnecessary task argument to the security hook since it can
only ever be the current task.

---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------

 7 files changed, 18 insertions(+), 37 deletions(-)
Quoted 4 lines
Quoted 2 lines

Looks good to me.  I'm happy to pull this in via the SELinux tree unless anyone else would rather take it?

That works for me. It does need to go in atomically.

Quoted 8 lines

Even with all the discussion today, I still think this patch has value
and I don't believe it should impact the PTAGS work as there are clearly larger issues that need to be resolved (e.g. reintroduce a task based security blob?).  Unless I hear any objections that this will wreck everything for years to come (very doubtful), I'll go ahead
and merge this into the SELinux tree tomorrow.

Please explain first the relationship that you are supposing true:

    writing /proc/pid/attr/.. == writing creds

I'm feeling that there is here a weird logic.

I can agree that the use of creds that I made is wrong and must be changed. But how can I agree that writing to /proc/pid/attr/... is not good when for my purpose it is a valuable and working solution?

Best regards
José Bollo

#9 lore raw

Re: [PATCH 2/2] proc, security: move restriction on writing /proc/pid/attr nodes to proc

Jose Bollo

Quoted 10 lines

Please explain first the relationship that you are supposing true:

    writing /proc/pid/attr/.. == writing creds

I'm feeling that there is here a weird logic.

I can agree that the use of creds that I made is wrong and must be changed. But how can I agree that writing to /proc/pid/attr/... is not good when for my purpose it is a valuable and working solution?

Regarding TOMOYO, "writing creds" == "writing /sys/kernel/security/tomoyo/self_domain". I didn't choose /proc/pid/attr/ interface from the beginning, for I wanted to allow enabling multiple LSM modules concurrently and I thought existing userspace programs will be confused when multiple concurrent LSM modules are fully supported.

You can check Casey's "LSM: module hierarchy in /proc/.../attr" patches at
http://lkml.kernel.org/r/[email protected] . Since PTAGS is not yet in-tree, I think it is less harder (in other words, now is a chance) to reconsider the interface for PTAGS.

#10 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Le mardi 20 décembre 2016 à 20:13 +0900, Tetsuo Handa a écrit :

Quoted 8 lines

Jose Bollo

Quoted 7 lines

Please explain first the relationship that you are supposing true:

    writing /proc/pid/attr/.. == writing creds

I'm feeling that there is here a weird logic.

Quoted 7 lines
Quoted 4 lines

I can agree that the use of creds that I made is wrong and must be changed. But how can I agree that writing to /proc/pid/attr/... is not
good when for my purpose it is a valuable and working solution?

Regarding TOMOYO, "writing creds" == "writing
/sys/kernel/security/tomoyo/self_domain".

Hi Tetsuo,

It confirms what I wanted to point out, there is no real link between writing creds and writing /proc/.../attr. But here it is for SELF so it doesn't brakes the creds.

Quoted 7 lines

I didn't choose /proc/pid/attr/ interface from the beginning, for I wanted to allow
enabling multiple LSM modules concurrently and I thought existing userspace programs
will be confused when multiple concurrent LSM modules are fully supported.

Quoted 7 lines

You can check Casey's "LSM: module hierarchy in /proc/.../attr" patches at
http://lkml.kernel.org/r/00f80c77-9623-7e9e-8980-63b362a4f16c@schaufl
er-ca.com .
Since PTAGS is not yet in-tree, I think it is less harder (in other words, now
is a chance) to reconsider the interface for PTAGS.

I agree that it can be a chance. You pointed out the limitations in using existing /proc/.../attr implmentation and thank you for that.

But PTAGS is specifically bound to tasks.

So /proc/pid..., with its DAC and its MAC access control, with its already existing implementation PID of namespace is the natural place where control interface for PTAGS should occur.

I would really welcome proposal for other place but I guess that it would be of lesser evidence and that the implmentation would be much complicated.

I followed what Casey proposed and that you cite. It is a good proposal in its idea. It makes things a little more complicated than what already exist and I doubt a little that in a day (or a night ;) SELinux
Smacks Tomoyo. However it would makes things cleaner: a command like
'id' would be easier to implement.

Best regards
José

#11 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Stephen Smalley

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a écrit :

Quoted 11 lines

Processes can only alter their own security attributes via /proc/pid/attr nodes.  This is presently enforced by each individual security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security hook,
and drop the unnecessary task argument to the security hook since it can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files in /proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
- follows the life cycle of the process
- implements pid namespace

There is absolutely no way to get these features easyly outside that implementation context of /proc/pid/attr/xxx.

For these reasons I vote against that change.

You will probably ask me where is PTAGS used and what is is made for.

So it is not used but the principle of its use is benefical to the community. It allows a kind of user land implementation of capabilities.

You probably know that the kernel can not do all things for a good
reason: it is not intended to do all things. So there is a need for user land features. PTAGS is an intent to fulfill an empty gap.

I made a presentation at FOSDEM on the subject that may allows you to understand the beginning of the issue that I'm writing about [2].

[1] https://lkml.org/lkml/2016/11/23/122
[2] https://archive.fosdem.org/2015/schedule/event/sec_enforcement/

Quoted 230 lines

---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------

 7 files changed, 18 insertions(+), 37 deletions(-)
fs/proc/base.c +6 -0
index 6eae4d0..7b228ea 100644
@@ -2485,6 +2485,12 @@ static ssize_t proc_pid_attr_write(struct file
 * file, const char __user * buf,
  	length = -ESRCH;
  	if (!task)
  		goto out_no_task;
+
+	/* A task may only write its own attributes. */
+	length = -EACCES;
+	if (current != task)
+		goto out;
+
  	if (count > PAGE_SIZE)
  		count = PAGE_SIZE;

fs/proc/base.c +0 -0
@@ -2500,14 +2506,13 @@ static ssize_t proc_pid_attr_write(struct
 file * file, const char __user * buf,
  	}


  /* Guard against adverse ptrace interaction */

fs/proc/base.c +0 -1
-	length = mutex_lock_interruptible(&task->signal-
Quoted 1 line

cred_guard_mutex);

fs/proc/base.c +1 -0
+	length = mutex_lock_interruptible(&current->signal-
Quoted 1 line

cred_guard_mutex);

  if (length < 0)
  goto out_free;

fs/proc/base.c +0 -2
-	length = security_setprocattr(task,
-				      (char*)file->f_path.dentry-
Quoted 1 line

d_name.name,

fs/proc/base.c +1 -0
+	length = security_setprocattr(file->f_path.dentry-
Quoted 1 line

d_name.name,

        page, count);

fs/proc/base.c +1 -1
-	mutex_unlock(&task->signal->cred_guard_mutex);
+	mutex_unlock(&current->signal->cred_guard_mutex);

 out_free:
  kfree(page);
 out:

include/linux/lsm_hooks.h +0 -0
index 558adfa..0dde959 100644
@@ -1547,8 +1547,7 @@ union security_list_options {

  void (*d_instantiate)(struct dentry *dentry, struct inode *inode);

  int (*getprocattr)(struct task_struct *p, char *name, char **value);

include/linux/lsm_hooks.h +0 -1
-	int (*setprocattr)(struct task_struct *p, char *name, void

*value,

include/linux/lsm_hooks.h +1 -1
-				size_t size);
+	int (*setprocattr)(const char *name, void *value, size_t

size);
  int (*ismaclabel)(const char *name);
  int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
  int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid);

include/linux/security.h +0 -0
index c2125e9..f4ebac1 100644
@@ -361,7 +361,7 @@ int security_sem_semop(struct sem_array *sma,
 struct sembuf *sops,
  			unsigned nsops, int alter);

 void security_d_instantiate(struct dentry *dentry, struct inode *inode);
 int security_getprocattr(struct task_struct *p, char *name, char **value);
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
+int security_setprocattr(const char *name, void *value, size_t size);
 int security_netlink_send(struct sock *sk, struct sk_buff *skb); int security_ismaclabel(const char *name);
 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);

include/linux/security.h +0 -0
@@ -1106,7 +1106,7 @@ static inline int security_getprocattr(struct

task_struct *p, char *name, char *
  return -EINVAL;
 }

-static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+static inline int security_setprocattr(char *name, void *value, size_t size)
 {
  return -EINVAL;
 }

security/apparmor/lsm.c +0 -0
index 41b8cb1..8202e55 100644
@@ -495,8 +495,8 @@ static int apparmor_getprocattr(struct
 task_struct *task, char *name,
  	return error;
  }


-static int apparmor_setprocattr(struct task_struct *task, char *name,

security/apparmor/lsm.c +2 -1
-				void *value, size_t size)
+static int apparmor_setprocattr(const char *name, void *value,
+				size_t size)

 {
  struct common_audit_data sa;
  struct apparmor_audit_data aad = {0,};

security/apparmor/lsm.c +0 -0
@@ -506,9 +506,6 @@ static int apparmor_setprocattr(struct
 task_struct *task, char *name,


  if (size == 0)
  return -EINVAL;

security/apparmor/lsm.c +0 -3
-	/* task can only write its own attributes */
-	if (current != task)
-		return -EACCES;


  /* AppArmor requires that the buffer must be null terminated atm */
  if (args[size - 1] != '\0') {

security/security.c +0 -0
index f825304..32052f5 100644
@@ -1170,9 +1170,9 @@ int security_getprocattr(struct task_struct *p,
 char *name, char **value)
  	return call_int_hook(getprocattr, -EINVAL, p, name, value);
  }


-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+int security_setprocattr(const char *name, void *value, size_t size) {

security/security.c +0 -1
-	return call_int_hook(setprocattr, -EINVAL, p, name, value,

size);

security/security.c +1 -0
+	return call_int_hook(setprocattr, -EINVAL, name, value,

size);
 }

 int security_netlink_send(struct sock *sk, struct sk_buff *skb)

security/selinux/hooks.c +0 -0
index 9992626..762276b 100644
@@ -5859,8 +5859,7 @@ static int selinux_getprocattr(struct
 task_struct *p,
  	return error;
  }

security/selinux/hooks.c +1 -2
-static int selinux_setprocattr(struct task_struct *p,
-			       char *name, void *value, size_t size)
+static int selinux_setprocattr(const char *name, void *value, size_t

size)
 {
  struct task_security_struct *tsec;
  struct cred *new;

security/selinux/hooks.c +0 -0
@@ -5868,16 +5867,6 @@ static int selinux_setprocattr(struct
 task_struct *p,
  	int error;
  	char *str = value;

security/selinux/hooks.c +0 -6
-	if (current != p) {
-		/*
-		 * A task may only alter its own credentials.
-		 * SELinux has always enforced this restriction,
-		 * and it is now mandated by the Linux credentials
-		 * infrastructure; see

Documentation/security/credentials.txt.

security/selinux/hooks.c +0 -4
-		 */
-		return -EACCES;
-	}
-

  /*
   * Basic control over ability to set these attributes at all.
   */

security/smack/smack_lsm.c +0 -0
index 4d90257..9bde7f8 100644
@@ -3620,7 +3620,6 @@ static int smack_getprocattr(struct task_struct
 *p, char *name, char **value)


 /**
  * smack_setprocattr - Smack process attribute setting
- * @p: the object task
  * @name: the name of the attribute in /proc/.../attr
  * @value: the value to set
  * @size: the size of the value

security/smack/smack_lsm.c +1 -2
@@ -3630,8 +3629,7 @@ static int smack_getprocattr(struct task_struct
 *p, char *name, char **value)
   *
   * Returns the length of the smack label or an error code
   */
-static int smack_setprocattr(struct task_struct *p, char *name,
-			     void *value, size_t size)
+static int smack_setprocattr(const char *name, void *value, size_t
 size)
  {

  struct task_smack *tsp = current_security(); struct cred *new;

security/smack/smack_lsm.c +0 -0
@@ -3639,13 +3637,6 @@ static int smack_setprocattr(struct
 task_struct *p, char *name,
  	struct smack_known_list_elem *sklep;
  	int rc;

security/smack/smack_lsm.c +0 -7
-	/*
-	 * Changing another process' Smack value is too dangerous
-	 * and supports no sane use case.
-	 */
-	if (p != current)
-		return -EPERM;
-

  if (!smack_privileged(CAP_MAC_ADMIN) && list_empty(&tsp-

Quoted 1 line

smk_relabel))

  return -EPERM;

#12 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 22 lines · José Bollo

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a écrit :

Quoted 15 lines

Processes can only alter their own security attributes via /proc/pid/attr nodes.  This is presently enforced by each individual
security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security
hook,
and drop the unnecessary task argument to the security hook since it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files in /proc/pid/attr/...

Quoted 8 lines

Why did I used this files? Thaere are serious reasons:
 - follows the life cycle of the process
 - implements pid namespace

There is absolutely no way to get these features easyly outside that implementation context of /proc/pid/attr/xxx.

For these reasons I vote against that change.

It is already prohibited by the credentials framework; see Documentation/security/credentials.txt, under ALTERING CREDENTIALS. We are not imposing a new restriction here, just recognizing that it already exists (ever since Linux moved to using cred structures).  You might not agree with that restriction, but we didn't invent it.

Quoted 263 lines

You will probably ask me where is PTAGS used and what is is made for.

So it is not used but the principle of its use is benefical to the community. It allows a kind of user land implementation of capabilities.

You probably know that the kernel can not do all things for a good
reason: it is not intended to do all things. So there is a need for user land features. PTAGS is an intent to fulfill an empty gap.

I made a presentation at FOSDEM on the subject that may allows you to understand the beginning of the issue that I'm writing about [2].

[1] https://lkml.org/lkml/2016/11/23/122
[2] https://archive.fosdem.org/2015/schedule/event/sec_enforcement/

Quoted 247 lines

---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------

 7 files changed, 18 insertions(+), 37 deletions(-)
fs/proc/base.c +0 -0
index 6eae4d0..7b228ea 100644
@@ -2485,6 +2485,12 @@ static ssize_t proc_pid_attr_write(struct

file
* file, const char __user * buf,
  length = -ESRCH;
  if (!task)
  goto out_no_task;

fs/proc/base.c +6 -0
+
+	/* A task may only write its own attributes. */
+	length = -EACCES;
+	if (current != task)
+		goto out;
+

  if (count > PAGE_SIZE)
  count = PAGE_SIZE;

fs/proc/base.c +0 -0
@@ -2500,14 +2506,13 @@ static ssize_t proc_pid_attr_write(struct
 file * file, const char __user * buf,
  	}


  /* Guard against adverse ptrace interaction */

fs/proc/base.c +0 -1
-	length = mutex_lock_interruptible(&task->signal-
Quoted 2 lines

cred_guard_mutex);

fs/proc/base.c +1 -0
+	length = mutex_lock_interruptible(&current->signal-
Quoted 2 lines

cred_guard_mutex);

  if (length < 0)
  goto out_free;

fs/proc/base.c +0 -2
-	length = security_setprocattr(task,
-				      (char*)file->f_path.dentry-
Quoted 2 lines

d_name.name,

fs/proc/base.c +1 -0
+	length = security_setprocattr(file->f_path.dentry-
Quoted 2 lines

d_name.name,

        page, count);

fs/proc/base.c +1 -1
-	mutex_unlock(&task->signal->cred_guard_mutex);
+	mutex_unlock(&current->signal->cred_guard_mutex);

 out_free:
  kfree(page);
 out:

include/linux/lsm_hooks.h +0 -0
index 558adfa..0dde959 100644
@@ -1547,8 +1547,7 @@ union security_list_options {

  void (*d_instantiate)(struct dentry *dentry, struct inode *inode);

  int (*getprocattr)(struct task_struct *p, char *name, char **value);

include/linux/lsm_hooks.h +0 -1
-	int (*setprocattr)(struct task_struct *p, char *name, void

*value,

include/linux/lsm_hooks.h +1 -1
-				size_t size);
+	int (*setprocattr)(const char *name, void *value, size_t

size);
  int (*ismaclabel)(const char *name);
  int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
  int (*secctx_to_secid)(const char *secdata, u32 seclen, u32
*secid);

include/linux/security.h +0 -0
index c2125e9..f4ebac1 100644
@@ -361,7 +361,7 @@ int security_sem_semop(struct sem_array *sma,
 struct sembuf *sops,
  			unsigned nsops, int alter);

 void security_d_instantiate(struct dentry *dentry, struct inode *inode);
 int security_getprocattr(struct task_struct *p, char *name, char **value);
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
+int security_setprocattr(const char *name, void *value, size_t size);
 int security_netlink_send(struct sock *sk, struct sk_buff *skb); int security_ismaclabel(const char *name);
 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);

include/linux/security.h +0 -0
@@ -1106,7 +1106,7 @@ static inline int security_getprocattr(struct

task_struct *p, char *name, char *
  return -EINVAL;
 }

-static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+static inline int security_setprocattr(char *name, void *value, size_t size)
 {
  return -EINVAL;
 }

security/apparmor/lsm.c +0 -0
index 41b8cb1..8202e55 100644
@@ -495,8 +495,8 @@ static int apparmor_getprocattr(struct
 task_struct *task, char *name,
  	return error;
  }


-static int apparmor_setprocattr(struct task_struct *task, char *name,

security/apparmor/lsm.c +2 -1
-				void *value, size_t size)
+static int apparmor_setprocattr(const char *name, void *value,
+				size_t size)

 {
  struct common_audit_data sa;
  struct apparmor_audit_data aad = {0,};

security/apparmor/lsm.c +0 -0
@@ -506,9 +506,6 @@ static int apparmor_setprocattr(struct
 task_struct *task, char *name,


  if (size == 0)
  return -EINVAL;

security/apparmor/lsm.c +0 -3
-	/* task can only write its own attributes */
-	if (current != task)
-		return -EACCES;


  /* AppArmor requires that the buffer must be null terminated
atm */
  if (args[size - 1] != '\0') {

security/security.c +0 -0
index f825304..32052f5 100644
@@ -1170,9 +1170,9 @@ int security_getprocattr(struct task_struct
 *p,
 char *name, char **value)
  	return call_int_hook(getprocattr, -EINVAL, p, name,
 value);
  }


-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+int security_setprocattr(const char *name, void *value, size_t size)
 {

security/security.c +0 -1
-	return call_int_hook(setprocattr, -EINVAL, p, name, value,

size);

security/security.c +1 -0
+	return call_int_hook(setprocattr, -EINVAL, name, value,

size);
 }

 int security_netlink_send(struct sock *sk, struct sk_buff *skb)

security/selinux/hooks.c +0 -0
index 9992626..762276b 100644
@@ -5859,8 +5859,7 @@ static int selinux_getprocattr(struct
 task_struct *p,
  	return error;
  }

security/selinux/hooks.c +0 -2
-static int selinux_setprocattr(struct task_struct *p,
-			       char *name, void *value, size_t

size)
+static int selinux_setprocattr(const char *name, void *value, size_t
size)
 {
  struct task_security_struct *tsec;
  struct cred *new;

security/selinux/hooks.c +0 -0
@@ -5868,16 +5867,6 @@ static int selinux_setprocattr(struct
 task_struct *p,
  	int error;
  	char *str = value;

security/selinux/hooks.c +0 -6
-	if (current != p) {
-		/*
-		 * A task may only alter its own credentials.
-		 * SELinux has always enforced this restriction,
-		 * and it is now mandated by the Linux credentials
-		 * infrastructure; see

Documentation/security/credentials.txt.

security/selinux/hooks.c +0 -4
-		 */
-		return -EACCES;
-	}
-

  /*
   * Basic control over ability to set these attributes at all.
   */

security/smack/smack_lsm.c +0 -0
index 4d90257..9bde7f8 100644
@@ -3620,7 +3620,6 @@ static int smack_getprocattr(struct

task_struct
*p, char *name, char **value)

 /**
  * smack_setprocattr - Smack process attribute setting
- * @p: the object task
  * @name: the name of the attribute in /proc/.../attr
  * @value: the value to set
  * @size: the size of the value

security/smack/smack_lsm.c +0 -0
@@ -3630,8 +3629,7 @@ static int smack_getprocattr(struct

task_struct
*p, char *name, char **value)
  *
  * Returns the length of the smack label or an error code */

security/smack/smack_lsm.c +1 -2
-static int smack_setprocattr(struct task_struct *p, char *name,
-			     void *value, size_t size)
+static int smack_setprocattr(const char *name, void *value, size_t

size)
 {
  struct task_smack *tsp = current_security(); struct cred *new;

security/smack/smack_lsm.c +0 -0
@@ -3639,13 +3637,6 @@ static int smack_setprocattr(struct
 task_struct *p, char *name,
  	struct smack_known_list_elem *sklep;
  	int rc;

security/smack/smack_lsm.c +0 -7
-	/*
-	 * Changing another process' Smack value is too dangerous
-	 * and supports no sane use case.
-	 */
-	if (p != current)
-		return -EPERM;
-

  if (!smack_privileged(CAP_MAC_ADMIN) && list_empty(&tsp-

Quoted 2 lines

smk_relabel))

  return -EPERM;

#13 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Le lundi 19 décembre 2016 à 09:33 -0500, Stephen Smalley a écrit :

Quoted 29 lines · José Bollo
Quoted 28 lines

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a écrit :

Quoted 15 lines

Processes can only alter their own security attributes via /proc/pid/attr nodes.  This is presently enforced by each individual
security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security
hook,
and drop the unnecessary task argument to the security hook since it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files in
/proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
 - follows the life cycle of the process
 - implements pid namespace

Quoted 5 lines
Quoted 5 lines

There is absolutely no way to get these features easyly outside that
implementation context of /proc/pid/attr/xxx.

For these reasons I vote against that change.

Hi,

Quoted 4 lines

It is already prohibited by the credentials framework; see Documentation/security/credentials.txt, under ALTERING CREDENTIALS. We are not imposing a new restriction here, just recognizing that it already exists (ever since Linux moved to using cred structures).

Perhaps that the men who wrote that documentation had not think about other uses. It is not having eyecup or being ignorant. Who can really imagine the future uses?

Quoted 1 line

 You might not agree with that restriction, but we didn't invent it.

In fact, it is not really a disagreement. I can understand the why and I can agree or disagree if I had time to study the issues in deep. But, as I wrote, I found a very convenient use of writing this files and I explained it and why in presentations. Your patch breaks all and I repeat, implementing something like PTAGS would be very complicated outside of LSM.

Maybe it is not you that wrote the spec but someone invented it.

I propose to change the documentation.

Quoted 287 lines
Quoted 11 lines

You will probably ask me where is PTAGS used and what is is made for.

So it is not used but the principle of its use is benefical to the community. It allows a kind of user land implementation of capabilities.

You probably know that the kernel can not do all things for a good
reason: it is not intended to do all things. So there is a need for user land features. PTAGS is an intent to fulfill an empty gap.

Quoted 270 lines

I made a presentation at FOSDEM on the subject that may allows you to
understand the beginning of the issue that I'm writing about [2].

[1] https://lkml.org/lkml/2016/11/23/122
[2] https://archive.fosdem.org/2015/schedule/event/sec_enforcement/

Quoted 263 lines

---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------

 7 files changed, 18 insertions(+), 37 deletions(-)
fs/proc/base.c +0 -0
index 6eae4d0..7b228ea 100644
@@ -2485,6 +2485,12 @@ static ssize_t proc_pid_attr_write(struct

file
* file, const char __user * buf,
  length = -ESRCH;
  if (!task)
  goto out_no_task;

fs/proc/base.c +6 -0
+
+	/* A task may only write its own attributes. */
+	length = -EACCES;
+	if (current != task)
+		goto out;
+

  if (count > PAGE_SIZE)
  count = PAGE_SIZE;

fs/proc/base.c +0 -0
@@ -2500,14 +2506,13 @@ static ssize_t proc_pid_attr_write(struct
 file * file, const char __user * buf,
  	}


  /* Guard against adverse ptrace interaction */

fs/proc/base.c +0 -1
-	length = mutex_lock_interruptible(&task->signal-
Quoted 2 lines

cred_guard_mutex);

fs/proc/base.c +1 -0
+	length = mutex_lock_interruptible(&current->signal-
Quoted 2 lines

cred_guard_mutex);

  if (length < 0)
  goto out_free;

fs/proc/base.c +0 -2
-	length = security_setprocattr(task,
-				      (char*)file-
Quoted 3 lines

f_path.dentry-

d_name.name,

fs/proc/base.c +1 -0
+	length = security_setprocattr(file->f_path.dentry-
Quoted 2 lines

d_name.name,

        page, count);

fs/proc/base.c +1 -1
-	mutex_unlock(&task->signal->cred_guard_mutex);
+	mutex_unlock(&current->signal->cred_guard_mutex);

 out_free:
  kfree(page);
 out:

include/linux/lsm_hooks.h +0 -0
index 558adfa..0dde959 100644
@@ -1547,8 +1547,7 @@ union security_list_options {

  void (*d_instantiate)(struct dentry *dentry, struct inode
*inode);

  int (*getprocattr)(struct task_struct *p, char *name, char
**value);

include/linux/lsm_hooks.h +0 -1
-	int (*setprocattr)(struct task_struct *p, char *name,

void
*value,

include/linux/lsm_hooks.h +1 -1
-				size_t size);
+	int (*setprocattr)(const char *name, void *value, size_t

size);
  int (*ismaclabel)(const char *name);
  int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
  int (*secctx_to_secid)(const char *secdata, u32 seclen, u32
*secid);

include/linux/security.h +0 -0
index c2125e9..f4ebac1 100644
@@ -361,7 +361,7 @@ int security_sem_semop(struct sem_array *sma,
 struct sembuf *sops,
  			unsigned nsops, int alter);

 void security_d_instantiate(struct dentry *dentry, struct inode *inode);
 int security_getprocattr(struct task_struct *p, char *name, char **value);
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
+int security_setprocattr(const char *name, void *value, size_t size);
 int security_netlink_send(struct sock *sk, struct sk_buff *skb); int security_ismaclabel(const char *name);
 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);

include/linux/security.h +0 -0
@@ -1106,7 +1106,7 @@ static inline int

security_getprocattr(struct
task_struct *p, char *name, char *
  return -EINVAL;
 }

-static inline int security_setprocattr(struct task_struct *p, char
*name, void *value, size_t size)
+static inline int security_setprocattr(char *name, void *value, size_t size)
 {
  return -EINVAL;
 }

security/apparmor/lsm.c +0 -0
index 41b8cb1..8202e55 100644
@@ -495,8 +495,8 @@ static int apparmor_getprocattr(struct
 task_struct *task, char *name,
  	return error;
  }


-static int apparmor_setprocattr(struct task_struct *task, char *name,

security/apparmor/lsm.c +2 -1
-				void *value, size_t size)
+static int apparmor_setprocattr(const char *name, void *value,
+				size_t size)

 {
  struct common_audit_data sa;
  struct apparmor_audit_data aad = {0,};

security/apparmor/lsm.c +0 -0
@@ -506,9 +506,6 @@ static int apparmor_setprocattr(struct
 task_struct *task, char *name,


  if (size == 0)
  return -EINVAL;

security/apparmor/lsm.c +0 -3
-	/* task can only write its own attributes */
-	if (current != task)
-		return -EACCES;


  /* AppArmor requires that the buffer must be null terminated
atm */
  if (args[size - 1] != '\0') {

security/security.c +0 -0
index f825304..32052f5 100644
@@ -1170,9 +1170,9 @@ int security_getprocattr(struct task_struct
 *p,
 char *name, char **value)
  	return call_int_hook(getprocattr, -EINVAL, p, name,
 value);
  }


-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+int security_setprocattr(const char *name, void *value, size_t size)
 {

security/security.c +0 -1
-	return call_int_hook(setprocattr, -EINVAL, p, name,

value,
size);

security/security.c +1 -0
+	return call_int_hook(setprocattr, -EINVAL, name, value,

size);
 }

 int security_netlink_send(struct sock *sk, struct sk_buff *skb)

security/selinux/hooks.c +0 -0
index 9992626..762276b 100644
@@ -5859,8 +5859,7 @@ static int selinux_getprocattr(struct
 task_struct *p,
  	return error;
  }

security/selinux/hooks.c +0 -2
-static int selinux_setprocattr(struct task_struct *p,
-			       char *name, void *value, size_t

size)
+static int selinux_setprocattr(const char *name, void *value, size_t
size)
 {
  struct task_security_struct *tsec;
  struct cred *new;

security/selinux/hooks.c +0 -0
@@ -5868,16 +5867,6 @@ static int selinux_setprocattr(struct
 task_struct *p,
  	int error;
  	char *str = value;

security/selinux/hooks.c +0 -5
-	if (current != p) {
-		/*
-		 * A task may only alter its own credentials.
-		 * SELinux has always enforced this restriction,
-		 * and it is now mandated by the Linux

credentials

security/selinux/hooks.c +0 -1
-		 * infrastructure; see

Documentation/security/credentials.txt.

security/selinux/hooks.c +0 -4
-		 */
-		return -EACCES;
-	}
-

  /*
   * Basic control over ability to set these attributes at all.
   */

security/smack/smack_lsm.c +0 -0
index 4d90257..9bde7f8 100644
@@ -3620,7 +3620,6 @@ static int smack_getprocattr(struct

task_struct
*p, char *name, char **value)

 /**
  * smack_setprocattr - Smack process attribute setting
- * @p: the object task
  * @name: the name of the attribute in /proc/.../attr
  * @value: the value to set
  * @size: the size of the value

security/smack/smack_lsm.c +0 -0
@@ -3630,8 +3629,7 @@ static int smack_getprocattr(struct

task_struct
*p, char *name, char **value)
  *
  * Returns the length of the smack label or an error code */

security/smack/smack_lsm.c +1 -2
-static int smack_setprocattr(struct task_struct *p, char *name,
-			     void *value, size_t size)
+static int smack_setprocattr(const char *name, void *value,

size_t
size)
 {
  struct task_smack *tsp = current_security(); struct cred *new;

security/smack/smack_lsm.c +0 -0
@@ -3639,13 +3637,6 @@ static int smack_setprocattr(struct
 task_struct *p, char *name,
  	struct smack_known_list_elem *sklep;
  	int rc;

security/smack/smack_lsm.c +0 -2
-	/*
-	 * Changing another process' Smack value is too

dangerous

security/smack/smack_lsm.c +0 -5
-	 * and supports no sane use case.
-	 */
-	if (p != current)
-		return -EPERM;
-

  if (!smack_privileged(CAP_MAC_ADMIN) && list_empty(&tsp-

Quoted 2 lines

smk_relabel))

  return -EPERM;

--
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

#14 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Stephen Smalley

Le lundi 19 décembre 2016 à 09:33 -0500, Stephen Smalley a écrit :

Quoted 29 lines · José Bollo
Quoted 28 lines

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a écrit :

Quoted 15 lines

Processes can only alter their own security attributes via /proc/pid/attr nodes.  This is presently enforced by each individual
security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security
hook,
and drop the unnecessary task argument to the security hook since it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files in
/proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
 - follows the life cycle of the process
 - implements pid namespace

Quoted 7 lines
Quoted 5 lines

There is absolutely no way to get these features easyly outside that
implementation context of /proc/pid/attr/xxx.

For these reasons I vote against that change.

It is already prohibited by the credentials framework;

If it were REALLY prohibited, your patch shouldn't exist ;)

Best regards
José Bollo

Quoted 294 lines

see
Documentation/security/credentials.txt, under ALTERING CREDENTIALS. We are not imposing a new restriction here, just recognizing that it already exists (ever since Linux moved to using cred structures). You
might not agree with that restriction, but we didn't invent it.

Quoted 11 lines

You will probably ask me where is PTAGS used and what is is made for.

So it is not used but the principle of its use is benefical to the community. It allows a kind of user land implementation of capabilities.

You probably know that the kernel can not do all things for a good
reason: it is not intended to do all things. So there is a need for user land features. PTAGS is an intent to fulfill an empty gap.

Quoted 270 lines

I made a presentation at FOSDEM on the subject that may allows you to
understand the beginning of the issue that I'm writing about [2].

[1] https://lkml.org/lkml/2016/11/23/122
[2] https://archive.fosdem.org/2015/schedule/event/sec_enforcement/

Quoted 263 lines

---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------

 7 files changed, 18 insertions(+), 37 deletions(-)
fs/proc/base.c +0 -0
index 6eae4d0..7b228ea 100644
@@ -2485,6 +2485,12 @@ static ssize_t proc_pid_attr_write(struct

file
* file, const char __user * buf,
  length = -ESRCH;
  if (!task)
  goto out_no_task;

fs/proc/base.c +6 -0
+
+	/* A task may only write its own attributes. */
+	length = -EACCES;
+	if (current != task)
+		goto out;
+

  if (count > PAGE_SIZE)
  count = PAGE_SIZE;

fs/proc/base.c +0 -0
@@ -2500,14 +2506,13 @@ static ssize_t proc_pid_attr_write(struct
 file * file, const char __user * buf,
  	}


  /* Guard against adverse ptrace interaction */

fs/proc/base.c +0 -1
-	length = mutex_lock_interruptible(&task->signal-
Quoted 2 lines

cred_guard_mutex);

fs/proc/base.c +1 -0
+	length = mutex_lock_interruptible(&current->signal-
Quoted 2 lines

cred_guard_mutex);

  if (length < 0)
  goto out_free;

fs/proc/base.c +0 -2
-	length = security_setprocattr(task,
-				      (char*)file-
Quoted 3 lines

f_path.dentry-

d_name.name,

fs/proc/base.c +1 -0
+	length = security_setprocattr(file->f_path.dentry-
Quoted 2 lines

d_name.name,

        page, count);

fs/proc/base.c +1 -1
-	mutex_unlock(&task->signal->cred_guard_mutex);
+	mutex_unlock(&current->signal->cred_guard_mutex);

 out_free:
  kfree(page);
 out:

include/linux/lsm_hooks.h +0 -0
index 558adfa..0dde959 100644
@@ -1547,8 +1547,7 @@ union security_list_options {

  void (*d_instantiate)(struct dentry *dentry, struct inode
*inode);

  int (*getprocattr)(struct task_struct *p, char *name, char
**value);

include/linux/lsm_hooks.h +0 -1
-	int (*setprocattr)(struct task_struct *p, char *name,

void
*value,

include/linux/lsm_hooks.h +1 -1
-				size_t size);
+	int (*setprocattr)(const char *name, void *value, size_t

size);
  int (*ismaclabel)(const char *name);
  int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
  int (*secctx_to_secid)(const char *secdata, u32 seclen, u32
*secid);

include/linux/security.h +0 -0
index c2125e9..f4ebac1 100644
@@ -361,7 +361,7 @@ int security_sem_semop(struct sem_array *sma,
 struct sembuf *sops,
  			unsigned nsops, int alter);

 void security_d_instantiate(struct dentry *dentry, struct inode *inode);
 int security_getprocattr(struct task_struct *p, char *name, char **value);
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
+int security_setprocattr(const char *name, void *value, size_t size);
 int security_netlink_send(struct sock *sk, struct sk_buff *skb); int security_ismaclabel(const char *name);
 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);

include/linux/security.h +0 -0
@@ -1106,7 +1106,7 @@ static inline int

security_getprocattr(struct
task_struct *p, char *name, char *
  return -EINVAL;
 }

-static inline int security_setprocattr(struct task_struct *p, char
*name, void *value, size_t size)
+static inline int security_setprocattr(char *name, void *value, size_t size)
 {
  return -EINVAL;
 }

security/apparmor/lsm.c +0 -0
index 41b8cb1..8202e55 100644
@@ -495,8 +495,8 @@ static int apparmor_getprocattr(struct
 task_struct *task, char *name,
  	return error;
  }


-static int apparmor_setprocattr(struct task_struct *task, char *name,

security/apparmor/lsm.c +2 -1
-				void *value, size_t size)
+static int apparmor_setprocattr(const char *name, void *value,
+				size_t size)

 {
  struct common_audit_data sa;
  struct apparmor_audit_data aad = {0,};

security/apparmor/lsm.c +0 -0
@@ -506,9 +506,6 @@ static int apparmor_setprocattr(struct
 task_struct *task, char *name,


  if (size == 0)
  return -EINVAL;

security/apparmor/lsm.c +0 -3
-	/* task can only write its own attributes */
-	if (current != task)
-		return -EACCES;


  /* AppArmor requires that the buffer must be null terminated
atm */
  if (args[size - 1] != '\0') {

security/security.c +0 -0
index f825304..32052f5 100644
@@ -1170,9 +1170,9 @@ int security_getprocattr(struct task_struct
 *p,
 char *name, char **value)
  	return call_int_hook(getprocattr, -EINVAL, p, name,
 value);
  }


-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+int security_setprocattr(const char *name, void *value, size_t size)
 {

security/security.c +0 -1
-	return call_int_hook(setprocattr, -EINVAL, p, name,

value,
size);

security/security.c +1 -0
+	return call_int_hook(setprocattr, -EINVAL, name, value,

size);
 }

 int security_netlink_send(struct sock *sk, struct sk_buff *skb)

security/selinux/hooks.c +0 -0
index 9992626..762276b 100644
@@ -5859,8 +5859,7 @@ static int selinux_getprocattr(struct
 task_struct *p,
  	return error;
  }

security/selinux/hooks.c +0 -2
-static int selinux_setprocattr(struct task_struct *p,
-			       char *name, void *value, size_t

size)
+static int selinux_setprocattr(const char *name, void *value, size_t
size)
 {
  struct task_security_struct *tsec;
  struct cred *new;

security/selinux/hooks.c +0 -0
@@ -5868,16 +5867,6 @@ static int selinux_setprocattr(struct
 task_struct *p,
  	int error;
  	char *str = value;

security/selinux/hooks.c +0 -5
-	if (current != p) {
-		/*
-		 * A task may only alter its own credentials.
-		 * SELinux has always enforced this restriction,
-		 * and it is now mandated by the Linux

credentials

security/selinux/hooks.c +0 -1
-		 * infrastructure; see

Documentation/security/credentials.txt.

security/selinux/hooks.c +0 -4
-		 */
-		return -EACCES;
-	}
-

  /*
   * Basic control over ability to set these attributes at all.
   */

security/smack/smack_lsm.c +0 -0
index 4d90257..9bde7f8 100644
@@ -3620,7 +3620,6 @@ static int smack_getprocattr(struct

task_struct
*p, char *name, char **value)

 /**
  * smack_setprocattr - Smack process attribute setting
- * @p: the object task
  * @name: the name of the attribute in /proc/.../attr
  * @value: the value to set
  * @size: the size of the value

security/smack/smack_lsm.c +0 -0
@@ -3630,8 +3629,7 @@ static int smack_getprocattr(struct

task_struct
*p, char *name, char **value)
  *
  * Returns the length of the smack label or an error code */

security/smack/smack_lsm.c +1 -2
-static int smack_setprocattr(struct task_struct *p, char *name,
-			     void *value, size_t size)
+static int smack_setprocattr(const char *name, void *value,

size_t
size)
 {
  struct task_smack *tsp = current_security(); struct cred *new;

security/smack/smack_lsm.c +0 -0
@@ -3639,13 +3637,6 @@ static int smack_setprocattr(struct
 task_struct *p, char *name,
  	struct smack_known_list_elem *sklep;
  	int rc;

security/smack/smack_lsm.c +0 -2
-	/*
-	 * Changing another process' Smack value is too

dangerous

security/smack/smack_lsm.c +0 -5
-	 * and supports no sane use case.
-	 */
-	if (p != current)
-		return -EPERM;
-

  if (!smack_privileged(CAP_MAC_ADMIN) && list_empty(&tsp-

Quoted 2 lines

smk_relabel))

  return -EPERM;

--
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

#15 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 38 lines · José Bollo

Le lundi 19 décembre 2016 à 09:33 -0500, Stephen Smalley a écrit :

Quoted 37 lines · José Bollo
Quoted 35 lines

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a écrit :

Quoted 17 lines

Processes can only alter their own security attributes via /proc/pid/attr nodes.  This is presently enforced by each individual
security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security
hook,
and drop the unnecessary task argument to the security hook since
it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files in
/proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
 - follows the life cycle of the process
 - implements pid namespace

There is absolutely no way to get these features easyly outside that
implementation context of /proc/pid/attr/xxx.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

For these reasons I vote against that change.

It is already prohibited by the credentials framework;

If it were REALLY prohibited, your patch shouldn't exist ;)

You can't do it safely (and your current implementation is unsafe). Please, read Documentation/security/credentials.txt in full, and look at the setprocattr implementations in the upstream security modules for reference.

Quoted 333 lines

Best regards
José Bollo

Quoted 329 lines

 see
Documentation/security/credentials.txt, under ALTERING CREDENTIALS. We are not imposing a new restriction here, just recognizing that it
already exists (ever since Linux moved to using cred structures). You
might not agree with that restriction, but we didn't invent it.

Quoted 21 lines

You will probably ask me where is PTAGS used and what is is made for.

So it is not used but the principle of its use is benefical to the
community. It allows a kind of user land implementation of capabilities.

You probably know that the kernel can not do all things for a good
reason: it is not intended to do all things. So there is a need for
user land features. PTAGS is an intent to fulfill an empty gap.

I made a presentation at FOSDEM on the subject that may allows you
to
understand the beginning of the issue that I'm writing about [2].

Quoted 293 lines

[1] https://lkml.org/lkml/2016/11/23/122
[2] https://archive.fosdem.org/2015/schedule/event/sec_enforcemen
t/

Quoted 289 lines

---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------

 7 files changed, 18 insertions(+), 37 deletions(-)
fs/proc/base.c +0 -0
index 6eae4d0..7b228ea 100644
@@ -2485,6 +2485,12 @@ static ssize_t

proc_pid_attr_write(struct
file
* file, const char __user * buf,
  length = -ESRCH;
  if (!task)
  goto out_no_task;

fs/proc/base.c +6 -0
+
+	/* A task may only write its own attributes. */
+	length = -EACCES;
+	if (current != task)
+		goto out;
+

  if (count > PAGE_SIZE)
  count = PAGE_SIZE;

fs/proc/base.c +0 -0
@@ -2500,14 +2506,13 @@ static ssize_t

proc_pid_attr_write(struct
file * file, const char __user * buf,
  }

  /* Guard against adverse ptrace interaction */

fs/proc/base.c +0 -1
-	length = mutex_lock_interruptible(&task->signal-
Quoted 3 lines

cred_guard_mutex);

fs/proc/base.c +1 -0
+	length = mutex_lock_interruptible(&current->signal-
Quoted 3 lines

cred_guard_mutex);

  if (length < 0)
  goto out_free;

fs/proc/base.c +0 -2
-	length = security_setprocattr(task,
-				      (char*)file-
Quoted 4 lines

f_path.dentry-

d_name.name,

fs/proc/base.c +1 -0
+	length = security_setprocattr(file->f_path.dentry-
Quoted 3 lines

d_name.name,

        page, count);

fs/proc/base.c +1 -1
-	mutex_unlock(&task->signal->cred_guard_mutex);
+	mutex_unlock(&current->signal->cred_guard_mutex);

 out_free:
  kfree(page);
 out:

include/linux/lsm_hooks.h +0 -0
index 558adfa..0dde959 100644
@@ -1547,8 +1547,7 @@ union security_list_options {

  void (*d_instantiate)(struct dentry *dentry, struct inode
*inode);

  int (*getprocattr)(struct task_struct *p, char *name, char
**value);

include/linux/lsm_hooks.h +0 -1
-	int (*setprocattr)(struct task_struct *p, char *name,

void
*value,

include/linux/lsm_hooks.h +1 -1
-				size_t size);
+	int (*setprocattr)(const char *name, void *value,

size_t
size);
  int (*ismaclabel)(const char *name);
  int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
  int (*secctx_to_secid)(const char *secdata, u32 seclen,
u32
*secid);

include/linux/security.h +0 -0
index c2125e9..f4ebac1 100644
@@ -361,7 +361,7 @@ int security_sem_semop(struct sem_array
 *sma,
 struct sembuf *sops,
  			unsigned nsops, int alter);

 void security_d_instantiate(struct dentry *dentry, struct inode
*inode);
 int security_getprocattr(struct task_struct *p, char *name, char
**value);
-int security_setprocattr(struct task_struct *p, char *name, void
*value, size_t size);
+int security_setprocattr(const char *name, void *value, size_t size);
 int security_netlink_send(struct sock *sk, struct sk_buff *skb);
 int security_ismaclabel(const char *name);
 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);

include/linux/security.h +0 -0
@@ -1106,7 +1106,7 @@ static inline int

security_getprocattr(struct
task_struct *p, char *name, char *
  return -EINVAL;
 }

-static inline int security_setprocattr(struct task_struct *p, char
*name, void *value, size_t size)
+static inline int security_setprocattr(char *name, void *value,
size_t size)
 {
  return -EINVAL;
 }

security/apparmor/lsm.c +0 -0
index 41b8cb1..8202e55 100644
@@ -495,8 +495,8 @@ static int apparmor_getprocattr(struct
 task_struct *task, char *name,
  	return error;
  }


-static int apparmor_setprocattr(struct task_struct *task, char *name,

security/apparmor/lsm.c +2 -1
-				void *value, size_t size)
+static int apparmor_setprocattr(const char *name, void *value,
+				size_t size)

 {
  struct common_audit_data sa;
  struct apparmor_audit_data aad = {0,};

security/apparmor/lsm.c +0 -0
@@ -506,9 +506,6 @@ static int apparmor_setprocattr(struct
 task_struct *task, char *name,


  if (size == 0)
  return -EINVAL;

security/apparmor/lsm.c +0 -3
-	/* task can only write its own attributes */
-	if (current != task)
-		return -EACCES;


  /* AppArmor requires that the buffer must be null terminated
atm */
  if (args[size - 1] != '\0') {

security/security.c +0 -0
index f825304..32052f5 100644
@@ -1170,9 +1170,9 @@ int security_getprocattr(struct

task_struct
*p,
char *name, char **value)
  return call_int_hook(getprocattr, -EINVAL, p, name, value);
 }

-int security_setprocattr(struct task_struct *p, char *name, void
*value, size_t size)
+int security_setprocattr(const char *name, void *value, size_t size)
 {

security/security.c +0 -1
-	return call_int_hook(setprocattr, -EINVAL, p, name,

value,
size);

security/security.c +1 -0
+	return call_int_hook(setprocattr, -EINVAL, name,

value,
size);
 }

 int security_netlink_send(struct sock *sk, struct sk_buff *skb)

security/selinux/hooks.c +0 -0
index 9992626..762276b 100644
@@ -5859,8 +5859,7 @@ static int selinux_getprocattr(struct
 task_struct *p,
  	return error;
  }

security/selinux/hooks.c +0 -2
-static int selinux_setprocattr(struct task_struct *p,
-			       char *name, void *value, size_t

size)
+static int selinux_setprocattr(const char *name, void *value, size_t
size)
 {
  struct task_security_struct *tsec;
  struct cred *new;

security/selinux/hooks.c +0 -0
@@ -5868,16 +5867,6 @@ static int selinux_setprocattr(struct
 task_struct *p,
  	int error;
  	char *str = value;

security/selinux/hooks.c +0 -4
-	if (current != p) {
-		/*
-		 * A task may only alter its own credentials.
-		 * SELinux has always enforced this

restriction,

security/selinux/hooks.c +0 -1
-		 * and it is now mandated by the Linux

credentials

security/selinux/hooks.c +0 -1
-		 * infrastructure; see

Documentation/security/credentials.txt.

security/selinux/hooks.c +0 -4
-		 */
-		return -EACCES;
-	}
-

  /*
   * Basic control over ability to set these attributes at
all.
   */

security/smack/smack_lsm.c +0 -0
index 4d90257..9bde7f8 100644
@@ -3620,7 +3620,6 @@ static int smack_getprocattr(struct

task_struct
*p, char *name, char **value)

 /**
  * smack_setprocattr - Smack process attribute setting
- * @p: the object task
  * @name: the name of the attribute in /proc/.../attr
  * @value: the value to set
  * @size: the size of the value

security/smack/smack_lsm.c +0 -0
@@ -3630,8 +3629,7 @@ static int smack_getprocattr(struct

task_struct
*p, char *name, char **value)
  *
  * Returns the length of the smack label or an error code */
-static int smack_setprocattr(struct task_struct *p, char *name,

security/smack/smack_lsm.c +1 -1
-			     void *value, size_t size)
+static int smack_setprocattr(const char *name, void *value,

size_t
size)
 {
  struct task_smack *tsp = current_security(); struct cred *new;

security/smack/smack_lsm.c +0 -0
@@ -3639,13 +3637,6 @@ static int smack_setprocattr(struct
 task_struct *p, char *name,
  	struct smack_known_list_elem *sklep;
  	int rc;

security/smack/smack_lsm.c +0 -2
-	/*
-	 * Changing another process' Smack value is too

dangerous

security/smack/smack_lsm.c +0 -5
-	 * and supports no sane use case.
-	 */
-	if (p != current)
-		return -EPERM;
-

  if (!smack_privileged(CAP_MAC_ADMIN) &&
list_empty(&tsp-

Quoted 3 lines

smk_relabel))

  return -EPERM;

--
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

maintainer
#16 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 35 lines · Stephen Smalley
Quoted 34 lines · José Bollo
Quoted 33 lines · Stephen Smalley
Quoted 32 lines · José Bollo

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a écrit :

Quoted 16 lines

Processes can only alter their own security attributes via /proc/pid/attr nodes. This is presently enforced by each individual
security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security
hook,
and drop the unnecessary task argument to the security hook since
it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files in
/proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
- follows the life cycle of the process
- implements pid namespace

There is absolutely no way to get these features easyly outside that
implementation context of /proc/pid/attr/xxx.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

For these reasons I vote against that change.

It is already prohibited by the credentials framework;

If it were REALLY prohibited, your patch shouldn't exist ;)

You can't do it safely (and your current implementation is unsafe).
Please, read Documentation/security/credentials.txt in full, and look
at the setprocattr implementations in the upstream security modules for reference.

I just reviewed the referenced documentation (thanks David) and it does clearly identify why, from the viewpoint of the credential implementation, modifying another task's credentials is unsafe. Both Smack and SELinux view modification of task credentials as unsafe from a security viewpoint, so neither of these modules would force the credential implementation to allow the behavior.

This, unfortunately, leaves Jose in a bit of a bind. It looks to me like there are options, so let's not just tell him to go away. The options I see include:

- Fix the credential code so modifying another task is safe I don't advocate this approach because the existing implementation is only reasonable because of the restriction.
- Revert shared credentials
I confess to not being a fan of shared credentials, for reason of complexity. I would not expect a proposal to go back to embedding credentials in their containing structures to be considered seriously. Nonetheless, it would solve the problem.
- Add a security blob for the task
It is unfortunate that when shared credentials were introduced the task blob was not renamed a cred blob. It would be simple and consistent to add a security blob to the task in addition to the blob in the cred. I would add a t_security field to the task structure that associates security data with the task. This blob would be used for data that does not meet intent of a credential, which I believe may be the case for Jose's PTAGS.

I know which I would prefer, but as I expect someone to shout that none can possibly be acceptable I think I'll stop here and let the discussion go a while.

("Light fuse. Stand back. :))

Quoted 319 lines
Quoted 319 lines

Best regards
José Bollo

Quoted 315 lines

see
Documentation/security/credentials.txt, under ALTERING CREDENTIALS. We are not imposing a new restriction here, just recognizing that it
already exists (ever since Linux moved to using cred structures).
You
might not agree with that restriction, but we didn't invent it.

Quoted 20 lines

You will probably ask me where is PTAGS used and what is is made for.

So it is not used but the principle of its use is benefical to the
community. It allows a kind of user land implementation of capabilities.

You probably know that the kernel can not do all things for a good
reason: it is not intended to do all things. So there is a need for
user land features. PTAGS is an intent to fulfill an empty gap.

I made a presentation at FOSDEM on the subject that may allows you
to
understand the beginning of the issue that I'm writing about [2].

Quoted 282 lines

[1] https://lkml.org/lkml/2016/11/23/122
[2] https://archive.fosdem.org/2015/schedule/event/sec_enforcemen
t/

Quoted 278 lines
---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------
 7 files changed, 18 insertions(+), 37 deletions(-)
fs/proc/base.c +0 -0
index 6eae4d0..7b228ea 100644
@@ -2485,6 +2485,12 @@ static ssize_t

proc_pid_attr_write(struct
file
* file, const char __user * buf,

fs/proc/base.c +6 -0
 	length = -ESRCH;
 	if (!task)
 		goto out_no_task;
+
+	/* A task may only write its own attributes. */
+	length = -EACCES;
+	if (current != task)
+		goto out;
+
 	if (count > PAGE_SIZE)
 		count = PAGE_SIZE;
@@ -2500,14 +2506,13 @@ static ssize_t

proc_pid_attr_write(struct
file * file, const char __user * buf,

fs/proc/base.c +0 -1
 	}
 
 	/* Guard against adverse ptrace interaction */
-	length = mutex_lock_interruptible(&task->signal-
Quoted 2 lines

cred_guard_mutex);

fs/proc/base.c +1 -0
+	length = mutex_lock_interruptible(&current->signal-
Quoted 2 lines

cred_guard_mutex);

fs/proc/base.c +0 -2
 	if (length < 0)
 		goto out_free;
 
-	length = security_setprocattr(task,
-				      (char*)file-
Quoted 3 lines

f_path.dentry-

d_name.name,

fs/proc/base.c +1 -0
+	length = security_setprocattr(file->f_path.dentry-
Quoted 2 lines

d_name.name,

fs/proc/base.c +1 -1
 				      page, count);
-	mutex_unlock(&task->signal->cred_guard_mutex);
+	mutex_unlock(&current->signal->cred_guard_mutex);
 out_free:
 	kfree(page);
 out:
include/linux/lsm_hooks.h +0 -0
index 558adfa..0dde959 100644
@@ -1547,8 +1547,7 @@ union security_list_options {
 	void (*d_instantiate)(struct dentry *dentry, struct

inode
*inode);

int (*getprocattr)(struct task_struct *p, char *name,
char
**value);

include/linux/lsm_hooks.h +0 -1
-	int (*setprocattr)(struct task_struct *p, char *name,

void
*value,

include/linux/lsm_hooks.h +1 -1
-				size_t size);
+	int (*setprocattr)(const char *name, void *value,

size_t
size);

include/linux/lsm_hooks.h +0 -0
 	int (*ismaclabel)(const char *name);
 	int (*secid_to_secctx)(u32 secid, char **secdata, u32

*seclen);
int (*secctx_to_secid)(const char *secdata, u32
seclen,
u32
*secid);

include/linux/security.h +0 -0
index c2125e9..f4ebac1 100644
@@ -361,7 +361,7 @@ int security_sem_semop(struct sem_array
 *sma,
 struct sembuf *sops,
 			unsigned nsops, int alter);
 void security_d_instantiate(struct dentry *dentry, struct

inode
*inode);
int security_getprocattr(struct task_struct *p, char *name,
char
**value);
-int security_setprocattr(struct task_struct *p, char *name, void
*value, size_t size);
+int security_setprocattr(const char *name, void *value, size_t size);
int security_netlink_send(struct sock *sk, struct sk_buff
*skb);
int security_ismaclabel(const char *name);
int security_secid_to_secctx(u32 secid, char **secdata, u32
*seclen);

include/linux/security.h +0 -0
@@ -1106,7 +1106,7 @@ static inline int

security_getprocattr(struct
task_struct *p, char *name, char *

include/linux/security.h +0 -1
 	return -EINVAL;
 }
 
-static inline int security_setprocattr(struct task_struct *p,

char
*name, void *value, size_t size)
+static inline int security_setprocattr(char *name, void *value,
size_t size)
{

include/linux/security.h +0 -0
 	return -EINVAL;
 }
security/apparmor/lsm.c +2 -2
index 41b8cb1..8202e55 100644
@@ -495,8 +495,8 @@ static int apparmor_getprocattr(struct
 task_struct *task, char *name,
 	return error;
 }
 
-static int apparmor_setprocattr(struct task_struct *task, char
 *name,
-				void *value, size_t size)
+static int apparmor_setprocattr(const char *name, void *value,
+				size_t size)
 {
security/apparmor/lsm.c +0 -3
 	struct common_audit_data sa;
 	struct apparmor_audit_data aad = {0,};
@@ -506,9 +506,6 @@ static int apparmor_setprocattr(struct
 task_struct *task, char *name,
 
 	if (size == 0)
 		return -EINVAL;
-	/* task can only write its own attributes */
-	if (current != task)
-		return -EACCES;
 
 	/* AppArmor requires that the buffer must be null

terminated
atm */

security/apparmor/lsm.c +0 -0
 	if (args[size - 1] != '\0') {
security/security.c +0 -0
index f825304..32052f5 100644
@@ -1170,9 +1170,9 @@ int security_getprocattr(struct

task_struct
*p,
char *name, char **value)
return call_int_hook(getprocattr, -EINVAL, p, name,
value);
}

-int security_setprocattr(struct task_struct *p, char *name, void
*value, size_t size)
+int security_setprocattr(const char *name, void *value, size_t size)
{

security/security.c +0 -1
-	return call_int_hook(setprocattr, -EINVAL, p, name,

value,
size);

security/security.c +1 -0
+	return call_int_hook(setprocattr, -EINVAL, name,

value,
size);
}

int security_netlink_send(struct sock *sk, struct sk_buff
*skb)

security/selinux/hooks.c +1 -2
index 9992626..762276b 100644
@@ -5859,8 +5859,7 @@ static int selinux_getprocattr(struct
 task_struct *p,
 	return error;
 }
 
-static int selinux_setprocattr(struct task_struct *p,
-			       char *name, void *value, size_t
 size)
+static int selinux_setprocattr(const char *name, void *value,

size_t
size)
{

security/selinux/hooks.c +0 -5
 	struct task_security_struct *tsec;
 	struct cred *new;
@@ -5868,16 +5867,6 @@ static int selinux_setprocattr(struct
 task_struct *p,
 	int error;
 	char *str = value;
 
-	if (current != p) {
-		/*
-		 * A task may only alter its own credentials.
-		 * SELinux has always enforced this
 restriction,
-		 * and it is now mandated by the Linux

credentials

security/selinux/hooks.c +0 -1
-		 * infrastructure; see

Documentation/security/credentials.txt.

security/selinux/hooks.c +0 -4
-		 */
-		return -EACCES;
-	}
-
 	/*
 	 * Basic control over ability to set these attributes

at
all.

security/selinux/hooks.c +0 -0
 	 */
security/smack/smack_lsm.c +0 -0
index 4d90257..9bde7f8 100644
@@ -3620,7 +3620,6 @@ static int smack_getprocattr(struct

task_struct
*p, char *name, char **value)

/**
* smack_setprocattr - Smack process attribute setting
- * @p: the object task
* @name: the name of the attribute in /proc/.../attr
* @value: the value to set
* @size: the size of the value

security/smack/smack_lsm.c +0 -0
@@ -3630,8 +3629,7 @@ static int smack_getprocattr(struct

task_struct
*p, char *name, char **value)
*
* Returns the length of the smack label or an error code */
-static int smack_setprocattr(struct task_struct *p, char *name,

security/smack/smack_lsm.c +1 -1
-			     void *value, size_t size)
+static int smack_setprocattr(const char *name, void *value,

size_t
size)
{

security/smack/smack_lsm.c +0 -2
 	struct task_smack *tsp = current_security();
 	struct cred *new;
@@ -3639,13 +3637,6 @@ static int smack_setprocattr(struct
 task_struct *p, char *name,
 	struct smack_known_list_elem *sklep;
 	int rc;
 
-	/*
-	 * Changing another process' Smack value is too

dangerous

security/smack/smack_lsm.c +0 -5
-	 * and supports no sane use case.
-	 */
-	if (p != current)
-		return -EPERM;
-
 	if (!smack_privileged(CAP_MAC_ADMIN) &&

list_empty(&tsp-

Quoted 2 lines

smk_relabel))

return -EPERM;

--
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

#17 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 90 lines · Casey Schaufler
Quoted 47 lines · Stephen Smalley
Quoted 45 lines · José Bollo

Le lundi 19 décembre 2016 à 09:33 -0500, Stephen Smalley a écrit :

Quoted 42 lines · José Bollo
Quoted 40 lines

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a écrit :

Quoted 12 lines

Processes can only alter their own security attributes via /proc/pid/attr nodes.  This is presently enforced by each individual
security module and is also imposed by the Linux credentials
implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual
security modules to proc_pid_attr_write() before calling

Quoted 8 lines

the
security
hook,
and drop the unnecessary task argument to the security hook since
it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files
in
/proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
 - follows the life cycle of the process
 - implements pid namespace

There is absolutely no way to get these features easyly outside
that
implementation context of /proc/pid/attr/xxx.

For these reasons I vote against that change.

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

It is already prohibited by the credentials framework;

If it were REALLY prohibited, your patch shouldn't exist ;)

You can't do it safely (and your current implementation is unsafe). Please, read Documentation/security/credentials.txt in full, and look
at the setprocattr implementations in the upstream security modules for
reference.

I just reviewed the referenced documentation (thanks David) and it does clearly identify why, from the viewpoint of the credential implementation, modifying another task's credentials is unsafe. Both Smack and SELinux view modification of task credentials as unsafe from a security viewpoint, so neither of these modules would force the credential implementation to allow the behavior.

This, unfortunately, leaves Jose in a bit of a bind. It looks to me like there are options, so let's not just tell him to go away. The options I see include:

 - Fix the credential code so modifying another task is safe I don't advocate this approach because the existing implementation is only reasonable because of the restriction.
 - Revert shared credentials
I confess to not being a fan of shared credentials, for reason of complexity. I would not expect a proposal to go back to embedding credentials in their containing structures to be considered seriously. Nonetheless, it would solve the problem.
 - Add a security blob for the task
It is unfortunate that when shared credentials were introduced the task blob was not renamed a cred blob. It would be simple and consistent to add a security blob to the task in addition to the blob in the cred. I would add a t_security field to the task structure that associates security data with the task. This blob would be used for data that does not meet intent of a credential, which I believe may be the case for Jose's PTAGS.

Quoted 5 lines

I know which I would prefer, but as I expect someone to shout that none can possibly be acceptable I think I'll stop here and let the discussion go a while.

("Light fuse. Stand back. :))

Why not:

- Reconsider the approach used in PTAGS in light of the security implications of allowing one task to change another task's security attributes, and rework PTAGS to use a more secure approach.

maintainer
#18 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 89 lines · Stephen Smalley
Quoted 88 lines · Casey Schaufler
Quoted 42 lines · Stephen Smalley
Quoted 41 lines · José Bollo

Le lundi 19 décembre 2016 à 09:33 -0500, Stephen Smalley a écrit :

Quoted 39 lines · José Bollo
Quoted 38 lines

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a écrit :

Quoted 11 lines

Processes can only alter their own security attributes via /proc/pid/attr nodes. This is presently enforced by each individual
security module and is also imposed by the Linux credentials
implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual
security modules to proc_pid_attr_write() before calling

Quoted 8 lines

the
security
hook,
and drop the unnecessary task argument to the security hook since
it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files
in
/proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
- follows the life cycle of the process
- implements pid namespace

There is absolutely no way to get these features easyly outside
that
implementation context of /proc/pid/attr/xxx.

For these reasons I vote against that change.

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

It is already prohibited by the credentials framework;

If it were REALLY prohibited, your patch shouldn't exist ;)

You can't do it safely (and your current implementation is unsafe).
Please, read Documentation/security/credentials.txt in full, and
look
at the setprocattr implementations in the upstream security modules for
reference.

I just reviewed the referenced documentation (thanks David) and it does clearly identify why, from the viewpoint of the credential implementation, modifying another task's credentials is unsafe. Both Smack and SELinux view modification of task credentials as unsafe from a security viewpoint, so neither of these modules would force the credential implementation to allow the behavior.

This, unfortunately, leaves Jose in a bit of a bind. It looks to me like there are options, so let's not just tell him to go away. The options I see include:

- Fix the credential code so modifying another task is safe I don't advocate this approach because the existing implementation is only reasonable because of the restriction.
- Revert shared credentials
I confess to not being a fan of shared credentials, for reason of complexity. I would not expect a proposal to go back to embedding credentials in their containing structures to be considered seriously. Nonetheless, it would solve the problem.
- Add a security blob for the task
It is unfortunate that when shared credentials were introduced the task blob was not renamed a cred blob. It would be simple and consistent to add a security blob to the task in addition to the blob in the cred. I would add a t_security field to the task structure that associates security data with the task. This blob would be used for data that does not meet intent of a credential, which I believe may be the case for Jose's PTAGS.

I know which I would prefer, but as I expect someone to shout that none can possibly be acceptable I think I'll stop here and let the discussion go a while.

Quoted 6 lines
Quoted 1 line

("Light fuse. Stand back. :))

Why not:

- Reconsider the approach used in PTAGS in light of the security implications of allowing one task to change another task's security attributes, and rework PTAGS to use a more secure approach.

Not every approach to security relies on being unable to change another process' attributes. I know of people who believe that SELinux would be more secure if an application launcher could set the context on another process. While I do not agree with these people I understand the logic they use and why it does not apply to SELinux or Smack.

Consider a module that does statistical analysis on program behavior and tags (using PTAGS or something similar) processes that are behaving in suspect ways. You probably don't want the math running in the kernel. The kernel decides to start denying the suspect process access once some tagging threshold is exceeded. Sure, you might be able to come up with some mechanism to get the process to tag itself, but it's kind of silly to make it hard when it doesn't have to be.

If you can suggest a mechanism that achieves Jose's goals (which may not match your goals) that does not require allowing a process to change another's security attributes I'm sure we'd all be interested.

#19 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Le lundi 19 décembre 2016 à 10:00 -0800, Casey Schaufler a écrit :

(snip)

Quoted 7 lines

Not every approach to security relies on being unable to change another process' attributes. I know of people who believe that SELinux would be more secure if an application launcher could set the context on another process. While I do not agree with these people I understand the logic they use and why it does not apply to SELinux or Smack.

Quoted 8 lines

Consider a module that does statistical analysis on program behavior and tags (using PTAGS or something similar) processes that are behaving in suspect ways. You probably don't want the math running in the kernel. The kernel decides to start denying the suspect process access once some tagging threshold is exceeded. Sure, you might be able to come up with some mechanism to get the process to tag itself, but it's kind of silly to make it hard when it doesn't have to be.

That is a very example of what can be achieved using PTAGS. Thank you.

Quoted 4 lines

If you can suggest a mechanism that achieves Jose's goals (which may not match your goals) that does not require allowing a process to change another's security attributes I'm sure we'd all be interested.

Yes. And what would imply the ability to write to /proc/pid/attr

#20 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Stephen Smalley

Le lundi 19 décembre 2016 à 12:09 -0500, Stephen Smalley a écrit :

Quoted 1 line · Casey Schaufler

(snip)

Quoted 12 lines
Quoted 12 lines

I just reviewed the referenced documentation (thanks David) and it does clearly identify why, from the viewpoint of the credential implementation, modifying another task's credentials is unsafe. Both Smack and SELinux view modification of task credentials as unsafe from a security viewpoint, so neither of these modules would force the credential implementation to allow the behavior.

This, unfortunately, leaves Jose in a bit of a bind. It looks to me like there are options, so let's not just tell him to go away. The options I see include:

Quoted 10 lines
Quoted 10 lines

 - Fix the credential code so modifying another task is safe I don't advocate this approach because the existing implementation is only reasonable because of the restriction.
 - Revert shared credentials
I confess to not being a fan of shared credentials, for reason of complexity. I would not expect a proposal to go back to embedding credentials in their containing structures to be considered seriously. Nonetheless, it would solve the problem.

Hi Casey,

Thank you for this review of the possibilities because it opens my eyes on the fact that I probably missed this "sharing credentials". Now I understand better the issue (but probably only in surface): avoiding duplication not needed. I understand that it complicates things. For example, the current implementation of PTAGS copies every thing even for threads. It is more direct but it implies many unneeded duplications.

When were shared credentials introduced?

Quoted 15 lines
Quoted 15 lines

 - Add a security blob for the task
It is unfortunate that when shared credentials were introduced the task blob was not renamed a cred blob. It would be simple and consistent to add a security blob to the task in addition to the blob in the cred. I would add a t_security field to the task structure that associates security data with the task. This blob would be used for data that does not meet intent of a credential, which I believe may be the case for Jose's PTAGS.

I know which I would prefer, but as I expect someone to shout that none can possibly be acceptable I think I'll stop here and let the discussion go a while.

Quoted 7 lines
Quoted 1 line

("Light fuse. Stand back. :))

Why not:

- Reconsider the approach used in PTAGS in light of the security implications of allowing one task to change another task's security attributes, and rework PTAGS to use a more secure approach.

PTAGS has not much things to do with kernel internals. It is only intended to be available outside of the kernel (*).

Enforcing a task to only modify its attributes, not the one of other tasks, has strong implication on the architecture of the system that you build on top of PTAGS. It would make launchers mandatory, would prohibit revocations, would forbid dynamic permissions and security cookies. It could be possible but it would limit the possibilities.

The main idea of PTAGS is to attach data to tasks. How can it be done? To follow life of tasks, LSM hooks is great and stacking is formidable. To interface task's attributes, taking care of namespaces PID and user, /proc/pid/attr is a very good place.

Best regards
José

(*) I asked me whether it were valuable provide kernel API for using PTAGS internally but frankly it is a bad idea. Kernel has capabilities and that's all. PTAGS isn't here to duplicate this behaviour.

maintainer
#21 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Casey Schaufler
Quoted 77 lines · Casey Schaufler
Quoted 35 lines · Stephen Smalley
Quoted 34 lines · José Bollo
Quoted 33 lines · Stephen Smalley
Quoted 32 lines · José Bollo

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a écrit :

Quoted 16 lines

Processes can only alter their own security attributes via /proc/pid/attr nodes. This is presently enforced by each individual
security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security
hook,
and drop the unnecessary task argument to the security hook since
it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files in
/proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
- follows the life cycle of the process
- implements pid namespace

There is absolutely no way to get these features easyly outside that
implementation context of /proc/pid/attr/xxx.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

For these reasons I vote against that change.

It is already prohibited by the credentials framework;

If it were REALLY prohibited, your patch shouldn't exist ;)

You can't do it safely (and your current implementation is unsafe).
Please, read Documentation/security/credentials.txt in full, and look
at the setprocattr implementations in the upstream security modules for reference.

I just reviewed the referenced documentation (thanks David) and it does clearly identify why, from the viewpoint of the credential implementation, modifying another task's credentials is unsafe. Both Smack and SELinux view modification of task credentials as unsafe from a security viewpoint, so neither of these modules would force the credential implementation to allow the behavior.

This, unfortunately, leaves Jose in a bit of a bind. It looks to me like there are options, so let's not just tell him to go away. The options I see include:

- Fix the credential code so modifying another task is safe I don't advocate this approach because the existing implementation is only reasonable because of the restriction.
- Revert shared credentials
I confess to not being a fan of shared credentials, for reason of complexity. I would not expect a proposal to go back to embedding credentials in their containing structures to be considered seriously. Nonetheless, it would solve the problem.
- Add a security blob for the task
It is unfortunate that when shared credentials were introduced the task blob was not renamed a cred blob. It would be simple and consistent to add a security blob to the task in addition to the blob in the cred. I would add a t_security field to the task structure that associates security data with the task. This blob would be used for data that does not meet intent of a credential, which I believe may be the case for Jose's PTAGS.

Quoted 6 lines

I know which I would prefer, but as I expect someone to shout that none can possibly be acceptable I think I'll stop here and let the discussion go a while.

("Light fuse. Stand back. :))

Tetsuo has been asking for the return of the task security blob for years. It does makes sense as not everything fits the cred model, eg. seccomp rules aren't part of the cred, and I don't think it makes sense for PTAGS either.

AppArmor could make use of it as well, as currently we abuse the cred a little bit to store the change_hat, and setexeccon info.

maintainer
#22 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 82 lines · John Johansen
Quoted 75 lines · Casey Schaufler
Quoted 34 lines · Stephen Smalley
Quoted 33 lines · José Bollo
Quoted 32 lines · Stephen Smalley
Quoted 31 lines · José Bollo

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a écrit :

Quoted 7 lines

Processes can only alter their own security attributes via /proc/pid/attr nodes. This is presently enforced by each individual
security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual

Quoted 8 lines

security modules to proc_pid_attr_write() before calling the security
hook,
and drop the unnecessary task argument to the security hook since
it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files in
/proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
- follows the life cycle of the process
- implements pid namespace

There is absolutely no way to get these features easyly outside that
implementation context of /proc/pid/attr/xxx.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

For these reasons I vote against that change.

It is already prohibited by the credentials framework;

If it were REALLY prohibited, your patch shouldn't exist ;)

You can't do it safely (and your current implementation is unsafe).
Please, read Documentation/security/credentials.txt in full, and look
at the setprocattr implementations in the upstream security modules for reference.

I just reviewed the referenced documentation (thanks David) and it does clearly identify why, from the viewpoint of the credential implementation, modifying another task's credentials is unsafe. Both Smack and SELinux view modification of task credentials as unsafe from a security viewpoint, so neither of these modules would force the credential implementation to allow the behavior.

This, unfortunately, leaves Jose in a bit of a bind. It looks to me like there are options, so let's not just tell him to go away. The options I see include:

- Fix the credential code so modifying another task is safe I don't advocate this approach because the existing implementation is only reasonable because of the restriction.
- Revert shared credentials
I confess to not being a fan of shared credentials, for reason of complexity. I would not expect a proposal to go back to embedding credentials in their containing structures to be considered seriously. Nonetheless, it would solve the problem.
- Add a security blob for the task
It is unfortunate that when shared credentials were introduced the task blob was not renamed a cred blob. It would be simple and consistent to add a security blob to the task in addition to the blob in the cred. I would add a t_security field to the task structure that associates security data with the task. This blob would be used for data that does not meet intent of a credential, which I believe may be the case for Jose's PTAGS.

Quoted 6 lines

I know which I would prefer, but as I expect someone to shout that none can possibly be acceptable I think I'll stop here and let the discussion go a while.

("Light fuse. Stand back. :))

Quoted 7 lines

Tetsuo has been asking for the return of the task security blob for years. It does makes sense as not everything fits the cred model, eg. seccomp rules aren't part of the cred, and I don't think it makes sense for PTAGS either.

AppArmor could make use of it as well, as currently we abuse the cred a little bit to store the change_hat, and setexeccon info.

A brief look at the existing modules leads me to believe that everyone ought to be happier if we moved the LSM task blob out of the cred structure. SELinux keeps a small (6xu32) task blob that has no reason to share and refcount. Smack has a couple of lists in the task blob that really shouldn't be in the cred. There would have to be some rework of the task_alloc and task_free hooks to get the life of the blobs correct, but I think on the whole it would be lots cleaner.

Quoted 5 lines

--
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

#23 lore raw

Re: [PATCH 2/2] proc, security: move restriction on writing/proc/pid/attr nodes to proc

Quoted 41 lines · Casey Schaufler
Quoted 32 lines · John Johansen
Quoted 25 lines · Casey Schaufler

This, unfortunately, leaves Jose in a bit of a bind. It looks to me like there are options, so let's not just tell him to go away. The options I see include:

- Fix the credential code so modifying another task is safe I don't advocate this approach because the existing implementation is only reasonable because of the restriction.
- Revert shared credentials
I confess to not being a fan of shared credentials, for reason of complexity. I would not expect a proposal to go back to embedding credentials in their containing structures to be considered seriously. Nonetheless, it would solve the problem.
- Add a security blob for the task
It is unfortunate that when shared credentials were introduced the task blob was not renamed a cred blob. It would be simple and consistent to add a security blob to the task in addition to the blob in the cred. I would add a t_security field to the task structure that associates security data with the task. This blob would be used for data that does not meet intent of a credential, which I believe may be the case for Jose's PTAGS.

Quoted 6 lines

I know which I would prefer, but as I expect someone to shout that none can possibly be acceptable I think I'll stop here and let the discussion go a while.

("Light fuse. Stand back. :))

Quoted 7 lines

Tetsuo has been asking for the return of the task security blob for years. It does makes sense as not everything fits the cred model, eg. seccomp rules aren't part of the cred, and I don't think it makes sense for PTAGS either.

AppArmor could make use of it as well, as currently we abuse the cred a little bit to store the change_hat, and setexeccon info.

Quoted 8 lines

A brief look at the existing modules leads me to believe that everyone ought to be happier if we moved the LSM task blob out of the cred structure. SELinux keeps a small (6xu32) task blob that has no reason to share and refcount. Smack has a couple of lists in the task blob that really shouldn't be in the cred. There would have to be some rework of the task_alloc and task_free hooks to get the life of the blobs correct, but I think on the whole it would be lots cleaner.

Yes, I appreciate if the task security blob is revived. According to TOMOYO's security context definition, use of per task_struct attribute management (i.e. no cred override mechanism) is correct. Currently I'm using very tricky implementation in AKARI in order to emulate per task_struct attribute management.

#24 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Casey Schaufler
Quoted 112 lines · Casey Schaufler
Quoted 103 lines · John Johansen
Quoted 95 lines · Casey Schaufler
Quoted 52 lines · Stephen Smalley
Quoted 50 lines · José Bollo

Le lundi 19 décembre 2016 à 09:33 -0500, Stephen Smalley a écrit :

Quoted 47 lines · José Bollo
Quoted 38 lines

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a
écrit :

Quoted 15 lines

Processes can only alter their own security attributes via
/proc/pid/attr nodes.  This is presently enforced by each
individual
security module and is also imposed by the Linux credentials
implementation, which only allows a task to alter its own
credentials.
Move the check enforcing this restriction from the individual
security modules to proc_pid_attr_write() before calling the

Quoted 8 lines

security
hook,
and drop the unnecessary task argument to the security hook
since
it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files
in
/proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
 - follows the life cycle of the process
 - implements pid namespace

Quoted 6 lines

There is absolutely no way to get these features easyly outside
that
implementation context of /proc/pid/attr/xxx.

For these reasons I vote against that change.

It is already prohibited by the credentials framework;

Quoted 8 lines
Quoted 1 line

If it were REALLY prohibited, your patch shouldn't exist ;)

You can't do it safely (and your current implementation is unsafe).
 Please, read Documentation/security/credentials.txt in full, and look
at the setprocattr implementations in the upstream security modules for
reference.

I just reviewed the referenced documentation (thanks David) and it does clearly identify why, from the viewpoint of the credential implementation, modifying another task's credentials is unsafe. Both Smack and SELinux view modification of task credentials as unsafe from a security viewpoint, so neither of these modules would force the credential implementation to allow the behavior.

This, unfortunately, leaves Jose in a bit of a bind. It looks to me like there are options, so let's not just tell him to go away. The options I see include:

 - Fix the credential code so modifying another task is safe I don't advocate this approach because the existing implementation is only reasonable because of the restriction.
 - Revert shared credentials
I confess to not being a fan of shared credentials, for reason of complexity. I would not expect a proposal to go back to embedding credentials in their containing structures to be considered seriously. Nonetheless, it would solve the problem.
 - Add a security blob for the task
It is unfortunate that when shared credentials were introduced the task blob was not renamed a cred blob. It would be simple and consistent to add a security blob to the task in addition to the blob in the cred. I would add a t_security field to the task structure that associates security data with the task. This blob would be used for data that does not meet intent of a credential, which I believe may be the case for Jose's PTAGS.

Quoted 6 lines

I know which I would prefer, but as I expect someone to shout that none can possibly be acceptable I think I'll stop here and let the discussion go a while.

("Light fuse. Stand back. :))

Quoted 7 lines

Tetsuo has been asking for the return of the task security blob for years. It does makes sense as not everything fits the cred model, eg. seccomp rules aren't part of the cred, and I don't think it makes sense for PTAGS either.

AppArmor could make use of it as well, as currently we abuse the cred a little bit to store the change_hat, and setexeccon info.

Quoted 8 lines

A brief look at the existing modules leads me to believe that everyone ought to be happier if we moved the LSM task blob out of the cred structure. SELinux keeps a small (6xu32) task blob that has no reason to share and refcount. Smack has a couple of lists in the task blob that really shouldn't be in the cred. There would have to be some rework of the task_alloc and task_free hooks to get the life of the blobs correct, but I think on the whole it would be lots cleaner.

Moving everything back to per-task security blob is inadvisable; the kernel now passes around cred structures, including to some of the security hooks, and you don't always want to check the credentials/sid of the current task (that's one of the reasons creds were introduced).

You could perhaps move the SIDs other than the current one (e.g. exec_sid, create_sid, ...) to the per-task security blob without harm/confusion, but it is unclear what you gain from doing so; then we would need to look in two places to find all the information we need for certain hooks rather than one.  And certainly we'd end up consuming more memory that way.

No, I don't think we want SELinux changed in this regard.

maintainer
#25 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 113 lines · Stephen Smalley
Quoted 104 lines · Casey Schaufler
Quoted 96 lines · John Johansen
Quoted 89 lines · Casey Schaufler
Quoted 47 lines · Stephen Smalley
Quoted 46 lines · José Bollo

Le lundi 19 décembre 2016 à 09:33 -0500, Stephen Smalley a écrit :

Quoted 44 lines · José Bollo
Quoted 36 lines

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a
écrit :

Quoted 14 lines

Processes can only alter their own security attributes via
/proc/pid/attr nodes. This is presently enforced by each
individual
security module and is also imposed by the Linux credentials
implementation, which only allows a task to alter its own
credentials.
Move the check enforcing this restriction from the individual
security modules to proc_pid_attr_write() before calling the

Quoted 8 lines

security
hook,
and drop the unnecessary task argument to the security hook
since
it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files
in
/proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
- follows the life cycle of the process
- implements pid namespace

Quoted 6 lines

There is absolutely no way to get these features easyly outside
that
implementation context of /proc/pid/attr/xxx.

For these reasons I vote against that change.

It is already prohibited by the credentials framework;

Quoted 8 lines
Quoted 1 line

If it were REALLY prohibited, your patch shouldn't exist ;)

You can't do it safely (and your current implementation is unsafe).
Please, read Documentation/security/credentials.txt in full,
and look
at the setprocattr implementations in the upstream security modules for
reference.

I just reviewed the referenced documentation (thanks David) and it does clearly identify why, from the viewpoint of the credential implementation, modifying another task's credentials is unsafe. Both Smack and SELinux view modification of task credentials as unsafe from a security viewpoint, so neither of these modules would force the credential implementation to allow the behavior.

This, unfortunately, leaves Jose in a bit of a bind. It looks to me like there are options, so let's not just tell him to go away. The options I see include:

- Fix the credential code so modifying another task is safe I don't advocate this approach because the existing implementation is only reasonable because of the restriction.
- Revert shared credentials
I confess to not being a fan of shared credentials, for reason of complexity. I would not expect a proposal to go back to embedding credentials in their containing structures to be considered seriously. Nonetheless, it would solve the problem.
- Add a security blob for the task
It is unfortunate that when shared credentials were introduced the task blob was not renamed a cred blob. It would be simple and consistent to add a security blob to the task in addition to the blob in the cred. I would add a t_security field to the task structure that associates security data with the task. This blob would be used for data that does not meet intent of a credential, which I believe may be the case for Jose's PTAGS.

Quoted 6 lines

I know which I would prefer, but as I expect someone to shout that none can possibly be acceptable I think I'll stop here and let the discussion go a while.

("Light fuse. Stand back. :))

Quoted 7 lines

Tetsuo has been asking for the return of the task security blob for years. It does makes sense as not everything fits the cred model, eg. seccomp rules aren't part of the cred, and I don't think it makes sense for PTAGS either.

AppArmor could make use of it as well, as currently we abuse the cred a little bit to store the change_hat, and setexeccon info.

Quoted 8 lines

A brief look at the existing modules leads me to believe that everyone ought to be happier if we moved the LSM task blob out of the cred structure. SELinux keeps a small (6xu32) task blob that has no reason to share and refcount. Smack has a couple of lists in the task blob that really shouldn't be in the cred. There would have to be some rework of the task_alloc and task_free hooks to get the life of the blobs correct, but I think on the whole it would be lots cleaner.

Quoted 2 lines

Moving everything back to per-task security blob is inadvisable; the kernel now passes around cred structures,

No, it passes around pointers to cred structures.

Quoted 1 line

including to some of the security hooks,

Most of which are related to the shared, copy on write nature of credentials. From a little bit of poking about it seems that in general if you have access to cred->security you're going to have access to task->security just as readily.

Quoted 2 lines

and you don't always want to check the credentials/sid
of the current task (that's one of the reasons creds were introduced).

Who said anything about the current task? Sure, you've got outliers like dentry_create_files_as, but there's no reason they can't be corrected.

Quoted 3 lines

You could perhaps move the SIDs other than the current one (e.g. exec_sid, create_sid, ...) to the per-task security blob without harm/confusion, but it is unclear what you gain from doing so;

SELinux, I'm sure to noone's surprise, is the best match for the current implementation. Even at that, I don't see that the change would have real impact beyond the regrettable code churn.

Quoted 4 lines

then we
would need to look in two places to find all the information we need for certain hooks rather than one. And certainly we'd end up consuming more memory that way.

Which is one reason why I didn't and wouldn't suggest it.

Quoted 1 line

No, I don't think we want SELinux changed in this regard.

I'm looking at what would be best for the LSM infrastructure. So far what I hear is that the proposed change would be better for three of the four existing "major" modules and required for two modules that are out, but targeting mainline. Moving the complete infrastructure from cred->security to task->security (NOT the hybrid you've suggested) appears generally beneficial. There does not appear to be harmful to SELinux. In fact, I suspect you'll see a minor performance improvement out of the deal.

maintainer
#26 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Stephen Smalley
Quoted 122 lines · Stephen Smalley
Quoted 112 lines · Casey Schaufler
Quoted 103 lines · John Johansen
Quoted 95 lines · Casey Schaufler
Quoted 52 lines · Stephen Smalley
Quoted 50 lines · José Bollo

Le lundi 19 décembre 2016 à 09:33 -0500, Stephen Smalley a écrit :

Quoted 47 lines · José Bollo
Quoted 38 lines

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a
écrit :

Quoted 15 lines

Processes can only alter their own security attributes via
/proc/pid/attr nodes. This is presently enforced by each
individual
security module and is also imposed by the Linux credentials
implementation, which only allows a task to alter its own
credentials.
Move the check enforcing this restriction from the individual
security modules to proc_pid_attr_write() before calling the

Quoted 8 lines

security
hook,
and drop the unnecessary task argument to the security hook
since
it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files
in
/proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
- follows the life cycle of the process
- implements pid namespace

Quoted 6 lines

There is absolutely no way to get these features easyly outside
that
implementation context of /proc/pid/attr/xxx.

For these reasons I vote against that change.

It is already prohibited by the credentials framework;

Quoted 8 lines
Quoted 1 line

If it were REALLY prohibited, your patch shouldn't exist ;)

You can't do it safely (and your current implementation is unsafe).
Please, read Documentation/security/credentials.txt in full,
and look
at the setprocattr implementations in the upstream security modules for
reference.

I just reviewed the referenced documentation (thanks David) and it does clearly identify why, from the viewpoint of the credential implementation, modifying another task's credentials is unsafe. Both Smack and SELinux view modification of task credentials as unsafe from a security viewpoint, so neither of these modules would force the credential implementation to allow the behavior.

This, unfortunately, leaves Jose in a bit of a bind. It looks to me like there are options, so let's not just tell him to go away. The options I see include:

- Fix the credential code so modifying another task is safe I don't advocate this approach because the existing implementation is only reasonable because of the restriction.
- Revert shared credentials
I confess to not being a fan of shared credentials, for reason of complexity. I would not expect a proposal to go back to embedding credentials in their containing structures to be considered seriously. Nonetheless, it would solve the problem.
- Add a security blob for the task
It is unfortunate that when shared credentials were introduced the task blob was not renamed a cred blob. It would be simple and consistent to add a security blob to the task in addition to the blob in the cred. I would add a t_security field to the task structure that associates security data with the task. This blob would be used for data that does not meet intent of a credential, which I believe may be the case for Jose's PTAGS.

Quoted 6 lines

I know which I would prefer, but as I expect someone to shout that none can possibly be acceptable I think I'll stop here and let the discussion go a while.

("Light fuse. Stand back. :))

Quoted 7 lines

Tetsuo has been asking for the return of the task security blob for years. It does makes sense as not everything fits the cred model, eg. seccomp rules aren't part of the cred, and I don't think it makes sense for PTAGS either.

AppArmor could make use of it as well, as currently we abuse the cred a little bit to store the change_hat, and setexeccon info.

Quoted 8 lines

A brief look at the existing modules leads me to believe that everyone ought to be happier if we moved the LSM task blob out of the cred structure. SELinux keeps a small (6xu32) task blob that has no reason to share and refcount. Smack has a couple of lists in the task blob that really shouldn't be in the cred. There would have to be some rework of the task_alloc and task_free hooks to get the life of the blobs correct, but I think on the whole it would be lots cleaner.

Quoted 5 lines

Moving everything back to per-task security blob is inadvisable; the kernel now passes around cred structures, including to some of the security hooks, and you don't always want to check the credentials/sid of the current task (that's one of the reasons creds were introduced).

Unwinding the the cred, security relationship would be interesting. I'm not sure its even advisable, I would want to see a patch attempting it before I would make a call either way. I'm not convinced that they should be split but I do think it wouldn't hurt to have a t_security field for the ancillary data, and other models could benefit from it.

Quoted 7 lines

You could perhaps move the SIDs other than the current one (e.g. exec_sid, create_sid, ...) to the per-task security blob without harm/confusion, but it is unclear what you gain from doing so; then we would need to look in two places to find all the information we need for certain hooks rather than one. And certainly we'd end up consuming more memory that way.

In apparmor's case it would actually save memory as we could share the cred more often (instead of making new creds with none cred related info), and we wouldn't allocate the ancillary information unless it was needed.

It would certainly introduce a little bit of extra overhead to access the extra info when it is needed, but the overhead would be small for apparmor's use cases.

Quoted 2 lines

No, I don't think we want SELinux changed in this regard.

maintainer
#27 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 132 lines · John Johansen
Quoted 113 lines · Stephen Smalley
Quoted 104 lines · Casey Schaufler
Quoted 96 lines · John Johansen
Quoted 89 lines · Casey Schaufler
Quoted 47 lines · Stephen Smalley
Quoted 46 lines · José Bollo

Le lundi 19 décembre 2016 à 09:33 -0500, Stephen Smalley a écrit :

Quoted 44 lines · José Bollo
Quoted 36 lines

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a
écrit :

Quoted 14 lines

Processes can only alter their own security attributes via
/proc/pid/attr nodes. This is presently enforced by each
individual
security module and is also imposed by the Linux credentials
implementation, which only allows a task to alter its own
credentials.
Move the check enforcing this restriction from the individual
security modules to proc_pid_attr_write() before calling the

Quoted 8 lines

security
hook,
and drop the unnecessary task argument to the security hook
since
it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files
in
/proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
- follows the life cycle of the process
- implements pid namespace

Quoted 6 lines

There is absolutely no way to get these features easyly outside
that
implementation context of /proc/pid/attr/xxx.

For these reasons I vote against that change.

It is already prohibited by the credentials framework;

Quoted 8 lines
Quoted 1 line

If it were REALLY prohibited, your patch shouldn't exist ;)

You can't do it safely (and your current implementation is unsafe).
Please, read Documentation/security/credentials.txt in full,
and look
at the setprocattr implementations in the upstream security modules for
reference.

I just reviewed the referenced documentation (thanks David) and it does clearly identify why, from the viewpoint of the credential implementation, modifying another task's credentials is unsafe. Both Smack and SELinux view modification of task credentials as unsafe from a security viewpoint, so neither of these modules would force the credential implementation to allow the behavior.

This, unfortunately, leaves Jose in a bit of a bind. It looks to me like there are options, so let's not just tell him to go away. The options I see include:

- Fix the credential code so modifying another task is safe I don't advocate this approach because the existing implementation is only reasonable because of the restriction.
- Revert shared credentials
I confess to not being a fan of shared credentials, for reason of complexity. I would not expect a proposal to go back to embedding credentials in their containing structures to be considered seriously. Nonetheless, it would solve the problem.
- Add a security blob for the task
It is unfortunate that when shared credentials were introduced the task blob was not renamed a cred blob. It would be simple and consistent to add a security blob to the task in addition to the blob in the cred. I would add a t_security field to the task structure that associates security data with the task. This blob would be used for data that does not meet intent of a credential, which I believe may be the case for Jose's PTAGS.

Quoted 6 lines

I know which I would prefer, but as I expect someone to shout that none can possibly be acceptable I think I'll stop here and let the discussion go a while.

("Light fuse. Stand back. :))

Quoted 7 lines

Tetsuo has been asking for the return of the task security blob for years. It does makes sense as not everything fits the cred model, eg. seccomp rules aren't part of the cred, and I don't think it makes sense for PTAGS either.

AppArmor could make use of it as well, as currently we abuse the cred a little bit to store the change_hat, and setexeccon info.

Quoted 8 lines

A brief look at the existing modules leads me to believe that everyone ought to be happier if we moved the LSM task blob out of the cred structure. SELinux keeps a small (6xu32) task blob that has no reason to share and refcount. Smack has a couple of lists in the task blob that really shouldn't be in the cred. There would have to be some rework of the task_alloc and task_free hooks to get the life of the blobs correct, but I think on the whole it would be lots cleaner.

Quoted 5 lines

Moving everything back to per-task security blob is inadvisable; the kernel now passes around cred structures, including to some of the security hooks, and you don't always want to check the credentials/sid of the current task (that's one of the reasons creds were introduced).

Unwinding the the cred, security relationship would be interesting. I'm not sure its even advisable, I would want to see a patch attempting it before I would make a call either way. I'm not convinced that they should be split but I do think it wouldn't hurt to have a t_security field for the ancillary data, and other models could benefit from it.

Quoted 7 lines

You could perhaps move the SIDs other than the current one (e.g. exec_sid, create_sid, ...) to the per-task security blob without harm/confusion, but it is unclear what you gain from doing so; then we would need to look in two places to find all the information we need for certain hooks rather than one. And certainly we'd end up consuming more memory that way.

Quoted 12 lines

In apparmor's case it would actually save memory as we could share the cred more often (instead of making new creds with none cred related info), and we wouldn't allocate the ancillary information unless it was needed.

It would certainly introduce a little bit of extra overhead to access the extra info when it is needed, but the overhead would be small for apparmor's use cases.

Quoted 2 lines

No, I don't think we want SELinux changed in this regard.

I will also point out that SELinux and Smack predate the credential implementation. They worked before with a blob directly off of the task structure.

maintainer
#28 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 3 lines · Casey Schaufler

I will also point out that SELinux and Smack predate the credential implementation. They worked before with a blob directly off of the task structure.

It should also be noted that SELinux has added a some very tricky functionality since the current credential implementation was adopted and the changes to adopt that to a task based blob would not be trivial.

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer
#29 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Stephen Smalley
Quoted 10 lines · Stephen Smalley
Quoted 8 lines · Casey Schaufler

A brief look at the existing modules leads me to believe that everyone ought to be happier if we moved the LSM task blob out of the cred structure. SELinux keeps a small (6xu32) task blob that has no reason to share and refcount. Smack has a couple of lists in the task blob that really shouldn't be in the cred. There would have to be some rework of the task_alloc and task_free hooks to get the life of the blobs correct, but I think on the whole it would be lots cleaner.

Quoted 4 lines

Moving everything back to per-task security blob is inadvisable; the kernel now passes around cred structures, including to some of the security hooks, and you don't always want to check the credentials/sid of the current task (that's one of the reasons creds were introduced).

Casey, if you haven't looked at some of the stuff that we did recently in SELinux for overlayfs, it might be a good idea to look at that, especially with the world hurtling towards containers with wild abandon. I can't say I know exactly how it will affect Smack, but my guess is that you will end up with something very similar to what we do in SELinux.

Quoted 6 lines

You could perhaps move the SIDs other than the current one (e.g. exec_sid, create_sid, ...) to the per-task security blob without harm/confusion, but it is unclear what you gain from doing so; then we would need to look in two places to find all the information we need for certain hooks rather than one. And certainly we'd end up consuming more memory that way.

No thank you.

Quoted 1 line

No, I don't think we want SELinux changed in this regard.

Agreed. I have no object if other LSMs want to add a security blob to the task struct, I just don't want to see it replace the cred blobs.

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer
#30 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 14 lines · Paul Moore
Quoted 9 lines · Stephen Smalley
Quoted 8 lines · Casey Schaufler

A brief look at the existing modules leads me to believe that everyone ought to be happier if we moved the LSM task blob out of the cred structure. SELinux keeps a small (6xu32) task blob that has no reason to share and refcount. Smack has a couple of lists in the task blob that really shouldn't be in the cred. There would have to be some rework of the task_alloc and task_free hooks to get the life of the blobs correct, but I think on the whole it would be lots cleaner.

Quoted 4 lines

Moving everything back to per-task security blob is inadvisable; the kernel now passes around cred structures, including to some of the security hooks, and you don't always want to check the credentials/sid of the current task (that's one of the reasons creds were introduced).

Quoted 6 lines

Casey, if you haven't looked at some of the stuff that we did recently in SELinux for overlayfs, it might be a good idea to look at that, especially with the world hurtling towards containers with wild abandon. I can't say I know exactly how it will affect Smack, but my guess is that you will end up with something very similar to what we do in SELinux.

We've got someone looking (verrry carefully) at overlayfs. It's ... challenging. I wish that I had been able to track it more carefully during implementation.

Quoted 7 lines
Quoted 6 lines

You could perhaps move the SIDs other than the current one (e.g. exec_sid, create_sid, ...) to the per-task security blob without harm/confusion, but it is unclear what you gain from doing so; then we would need to look in two places to find all the information we need for certain hooks rather than one. And certainly we'd end up consuming more memory that way.

No thank you.

I don't think anyone would be happy with that.

Quoted 3 lines
Quoted 1 line

No, I don't think we want SELinux changed in this regard.

Agreed. I have no object if other LSMs want to add a security blob to the task struct, I just don't want to see it replace the cred blobs.

OK, that actually make life easiest, for me at least. Jose, Tetsuo, John, or anyone, want to propose a patch adding task->t_security and the changes to a module to consume it? No changes to SELinux required.

#31 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Casey Schaufler

Le lundi 19 décembre 2016 à 13:25 -0800, Casey Schaufler a écrit :

snip

Quoted 10 lines

A brief look at the existing modules leads me to believe that everyone ought to be happier if we moved the LSM task blob out of the cred structure. SELinux keeps a small (6xu32) task blob that has no reason to share and refcount. Smack has a couple of lists in the task blob that really shouldn't be in the cred. There would have to be some rework of the task_alloc and task_free hooks to get the life of the blobs correct, but I think on the whole it would be lots cleaner.

Hi Casey,

Let suppose that creds is, in effect, the wrong place for implementing PTAGS and let suppose that the correct way is to add a t_ptags element in the task structure.

How to use task_alloc and task_free? There is nothing there. Is it just possible to inherit or copy the parent attributes? no.

So there is a need to define a hook to copy or do something for the child based on the parent. A new hook, a kind of 'task_child_init' whose argument would be the task to init.

Is it it?

Best regards
José Bollo

maintainer
#32 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 21 lines · José Bollo

Le lundi 19 décembre 2016 à 13:25 -0800, Casey Schaufler a écrit :

snip

Quoted 9 lines

A brief look at the existing modules leads me to believe that everyone ought to be happier if we moved the LSM task blob out of the cred structure. SELinux keeps a small (6xu32) task blob that has no reason to share and refcount. Smack has a couple of lists in the task blob that really shouldn't be in the cred. There would have to be some rework of the task_alloc and task_free hooks to get the life of the blobs correct, but I think on the whole it would be lots cleaner.

Hi Casey,

Let suppose that creds is, in effect, the wrong place for implementing PTAGS and let suppose that the correct way is to add a t_ptags element in the task structure.

How to use task_alloc and task_free? There is nothing there. Is it just possible to inherit or copy the parent attributes? no.

Quoted 8 lines

So there is a need to define a hook to copy or do something for the child based on the parent. A new hook, a kind of 'task_child_init' whose argument would be the task to init.

Is it it?

Best regards
José Bollo

My suggestion at this point is that we introduce a "t_security" field to task_struct (in include/linux/sched.h) under #CONFIG_SECURITY. There is already a task_free hook that should suffice, but the existing task_create hook will either need to be changed to get passed the task_struct or supplemented with a task_alloc hook. A copy_task hook may prove necessary, but we'll have to look into that. Security module data that belongs associated with the task needs to get moved, but that can be done by the module maintainers. It doesn't sound like there would be resistance to this from the security side of the house, but it needs to get run past the task management maintainers. A patch set, used by an existing module would be the best approach for that. I do not think that Smack is a good example as it is the one module that would probably be best served by having some data in both places.

#33 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to José Bollo
Quoted 41 lines · José Bollo

Le vendredi 16 décembre 2016 à 12:41 -0500, Stephen Smalley a écrit :

Quoted 15 lines

Processes can only alter their own security attributes via /proc/pid/attr nodes.  This is presently enforced by each individual
security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security
hook,
and drop the unnecessary task argument to the security hook since it
can
only ever be the current task.

Hi Stephen,

The module PTAGS that I made relies on the ability to write files in /proc/pid/attr/...

Why did I used this files? Thaere are serious reasons:
 - follows the life cycle of the process
 - implements pid namespace

There is absolutely no way to get these features easyly outside that implementation context of /proc/pid/attr/xxx.

For these reasons I vote against that change.

You will probably ask me where is PTAGS used and what is is made for.

So it is not used but the principle of its use is benefical to the community. It allows a kind of user land implementation of capabilities.

You probably know that the kernel can not do all things for a good
reason: it is not intended to do all things. So there is a need for user land features. PTAGS is an intent to fulfill an empty gap.

Quoted 5 lines

I made a presentation at FOSDEM on the subject that may allows you to understand the beginning of the issue that I'm writing about [2].

[1] https://lkml.org/lkml/2016/11/23/122
[2] https://archive.fosdem.org/2015/schedule/event/sec_enforcement/

Looking at your PTAGS implementation, I feel it is only fair to warn you that your usage of /proc/pid/attr is insecure, regardless of whether you use task security blobs or cred security blobs.

Getting the attributes of another process via /proc/pid files is inherently racy, as the process may exit and another process with different attributes may be created with the same pid (and no, this is not theoretical; it has been demonstrated). Similarly, setting the attributes of another process via /proc/pid files is likewise inherently racy; you may end up setting the attributes on the wrong process entirely.  Setting another process' attributes in this manner is also prone to other kinds of races, since there is no coordination between the process execution state and when the new tag is applied.

Again, I encourage you to reconsider your approach if you want to have a secure solution.

#34 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Le mardi 20 décembre 2016 à 11:14 -0500, Stephen Smalley a écrit :

Quoted 4 lines

Looking at your PTAGS implementation, I feel it is only fair to warn you that your usage of /proc/pid/attr is insecure, regardless of whether you use task security blobs or cred security blobs.

Fair?!

Quoted 4 lines

Getting the attributes of another process via /proc/pid files is inherently racy, as the process may exit and another process with different attributes may be created with the same pid (and no, this is not theoretical; it has been demonstrated).

I know. And I'm surprized that you dont do anything to change that.

Quoted 4 lines

Similarly, setting the
attributes of another process via /proc/pid files is likewise inherently racy; you may end up setting the attributes on the wrong process entirely.

I also know that.

Quoted 3 lines

Setting another process' attributes in this manner
is also prone to other kinds of races, since there is no coordination between the process execution state and when the new tag is applied.

Yes it is expected.

Quoted 2 lines

Again, I encourage you to reconsider your approach if you want to have a secure solution.

Well I know that managing processes is not secure because there is no kind of unique id. But please instead of thinking that it is to risky, please hear that some risks are manageable or acceptable.

Best regards
José

#35 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 11 lines · José Bollo

Le mardi 20 décembre 2016 à 11:14 -0500, Stephen Smalley a écrit :

Quoted 6 lines

Looking at your PTAGS implementation, I feel it is only fair to warn
you that your usage of /proc/pid/attr is insecure, regardless of whether you use task security blobs or cred security blobs.

Fair?!

Quoted 1 line
Quoted 6 lines
Quoted 4 lines

Getting the attributes of another process via /proc/pid files is inherently racy, as the process may exit and another process with different attributes may be created with the same pid (and no, this is not theoretical; it has been demonstrated).

I know. And I'm surprized that you dont do anything to change that.

There is a reason why SO_PEERSEC and SCM_SECURITY exist.  Again, learn from the upstream security modules rather than re-inventing them, badly.

Quoted 19 lines
Quoted 6 lines

Similarly, setting the
attributes of another process via /proc/pid files is likewise inherently racy; you may end up setting the attributes on the wrong process entirely.

I also know that.

Quoted 6 lines

Setting another process' attributes in this manner is also prone to other kinds of races, since there is no coordination
between the process execution state and when the new tag is applied.

Yes it is expected.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

Again, I encourage you to reconsider your approach if you want to have a secure solution.

Well I know that managing processes is not secure because there is no kind of unique id. But please instead of thinking that it is to risky,
please hear that some risks are manageable or acceptable.

Even when there are known, better ways of doing things?

maintainer
#36 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 9 lines · Stephen Smalley
Quoted 8 lines · José Bollo
Quoted 5 lines · Stephen Smalley

Looking at your PTAGS implementation, I feel it is only fair to warn
you that your usage of /proc/pid/attr is insecure, regardless of whether you use task security blobs or cred security blobs.

Fair?!

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

Getting the attributes of another process via /proc/pid files is inherently racy, as the process may exit and another process with different attributes may be created with the same pid (and no, this is not theoretical; it has been demonstrated).

I know. And I'm surprized that you dont do anything to change that.

There is a reason why SO_PEERSEC and SCM_SECURITY exist. Again, learn from the upstream security modules rather than re-inventing them, badly.

SO_PEERSEC and SCM_SECURITY are spiffy for processes that are sending each other messages, but they identify the attributes associated with the message, not the process. Neither SELinux nor Smack get the information to send off of the process, it comes from the socket structure.

Quoted 21 lines
Quoted 12 lines
Quoted 5 lines

Similarly, setting the
attributes of another process via /proc/pid files is likewise inherently racy; you may end up setting the attributes on the wrong process entirely.

I also know that.

Quoted 5 lines

Setting another process' attributes in this manner is also prone to other kinds of races, since there is no coordination
between the process execution state and when the new tag is applied.

Quoted 8 lines

Yes it is expected.

Quoted 2 lines

Again, I encourage you to reconsider your approach if you want to have a secure solution.

Well I know that managing processes is not secure because there is no kind of unique id. But please instead of thinking that it is to risky,
please hear that some risks are manageable or acceptable.

Even when there are known, better ways of doing things?

#37 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 30 lines · Casey Schaufler
Quoted 22 lines · Stephen Smalley
Quoted 20 lines · José Bollo

Le mardi 20 décembre 2016 à 11:14 -0500, Stephen Smalley a écrit :

Quoted 7 lines

Looking at your PTAGS implementation, I feel it is only fair to warn
you that your usage of /proc/pid/attr is insecure, regardless of
whether you use task security blobs or cred security blobs.

Fair?!

Quoted 8 lines

Getting the attributes of another process via /proc/pid files is
inherently racy, as the process may exit and another process with
different attributes may be created with the same pid (and no, this
is not theoretical; it has been demonstrated).

Quoted 6 lines
Quoted 2 lines

I know. And I'm surprized that you dont do anything to change that.

There is a reason why SO_PEERSEC and SCM_SECURITY exist.  Again, learn
from the upstream security modules rather than re-inventing them, badly.

Quoted 5 lines

SO_PEERSEC and SCM_SECURITY are spiffy for processes that are sending each other messages, but they identify the attributes associated with the message, not the process. Neither SELinux nor Smack get the information to send off of the process, it comes from the socket structure.

Yes, but in the SELinux case at least, the socket is labeled with the label of the creating process (except in the rare case of using setsockcreatecon(3), which can only be used by suitably authorized processes).  So in general it serves quite well as a means of obtaining the peer label, which can then be used in access control (and this is in fact being used in a variety of applications in Linux and Android).

maintainer
#38 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 31 lines · Stephen Smalley
Quoted 25 lines · Casey Schaufler
Quoted 18 lines · Stephen Smalley
Quoted 17 lines · José Bollo

Le mardi 20 décembre 2016 à 11:14 -0500, Stephen Smalley a écrit :

Quoted 6 lines

Looking at your PTAGS implementation, I feel it is only fair to warn
you that your usage of /proc/pid/attr is insecure, regardless of
whether you use task security blobs or cred security blobs.

Fair?!

Quoted 7 lines

Getting the attributes of another process via /proc/pid files is
inherently racy, as the process may exit and another process with
different attributes may be created with the same pid (and no, this
is not theoretical; it has been demonstrated).

Quoted 6 lines
Quoted 2 lines

I know. And I'm surprized that you dont do anything to change that.

There is a reason why SO_PEERSEC and SCM_SECURITY exist. Again, learn
from the upstream security modules rather than re-inventing them, badly.

Quoted 5 lines

SO_PEERSEC and SCM_SECURITY are spiffy for processes that are sending each other messages, but they identify the attributes associated with the message, not the process. Neither SELinux nor Smack get the information to send off of the process, it comes from the socket structure.

Quoted 4 lines

Yes, but in the SELinux case at least, the socket is labeled with the label of the creating process (except in the rare case of using setsockcreatecon(3), which can only be used by suitably authorized processes).

Yes, it's the same with Smack. When it's not the label of the process it's the label the system wants the peer to think it is.

Quoted 3 lines

So in general it serves quite well as a means of obtaining
the peer label, which can then be used in access control (and this is in fact being used in a variety of applications in Linux and Android).

But only between processes that are in direct, explicit communication. There is no denying that these mechanisms work. They just aren't applicable to Jose's use.

Quoted 5 lines

--
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

#39 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 63 lines · Casey Schaufler
Quoted 45 lines · Stephen Smalley
Quoted 38 lines · Casey Schaufler
Quoted 28 lines · Stephen Smalley
Quoted 26 lines · José Bollo

Le mardi 20 décembre 2016 à 11:14 -0500, Stephen Smalley a écrit
:

Quoted 9 lines

Looking at your PTAGS implementation, I feel it is only fair to
warn
you that your usage of /proc/pid/attr is insecure, regardless
of
whether you use task security blobs or cred security blobs.

Fair?!

Quoted 11 lines

Getting the attributes of another process via /proc/pid files
is
inherently racy, as the process may exit and another process
with
different attributes may be created with the same pid (and no,
this
is not theoretical; it has been demonstrated).

Quoted 8 lines
Quoted 2 lines

I know. And I'm surprized that you dont do anything to change that.

There is a reason why SO_PEERSEC and SCM_SECURITY exist.  Again,
learn
from the upstream security modules rather than re-inventing them,
badly.

Quoted 5 lines

SO_PEERSEC and SCM_SECURITY are spiffy for processes that are sending each other messages, but they identify the attributes associated with the message, not the process. Neither SELinux nor Smack get the information to send off of the process, it comes from the socket structure.

Quoted 5 lines

Yes, but in the SELinux case at least, the socket is labeled with the
label of the creating process (except in the rare case of using setsockcreatecon(3), which can only be used by suitably authorized processes).

Yes, it's the same with Smack. When it's not the label of the process it's the label the system wants the peer to think it is.

Quoted 6 lines

  So in general it serves quite well as a means of obtaining the peer label, which can then be used in access control (and this is
in fact being used in a variety of applications in Linux and Android).

Quoted 4 lines

But only between processes that are in direct, explicit communication.
There is no denying that these mechanisms work. They just aren't applicable to Jose's use.

If you say so (although it is unclear to me why or what exactly his use case is), but regardless, there is also no denying that getting and setting another process' attributes via /proc/pid files is inherently racy.  He even acknowledged as much.  So we are left with a "security" module whose only purpose is to support getting and setting process tags for security enforcement purposes, and yet does so in a known- insecure manner.  Again, this is why I keep suggesting that he needs to reconsider his approach, not merely figure out how to implement per- task security blobs.

maintainer
#40 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 55 lines · Stephen Smalley
Quoted 54 lines · Casey Schaufler
Quoted 39 lines · Stephen Smalley
Quoted 33 lines · Casey Schaufler
Quoted 24 lines · Stephen Smalley
Quoted 23 lines · José Bollo

Le mardi 20 décembre 2016 à 11:14 -0500, Stephen Smalley a écrit
:

Quoted 8 lines

Looking at your PTAGS implementation, I feel it is only fair to
warn
you that your usage of /proc/pid/attr is insecure, regardless
of
whether you use task security blobs or cred security blobs.

Fair?!

Quoted 10 lines

Getting the attributes of another process via /proc/pid files
is
inherently racy, as the process may exit and another process
with
different attributes may be created with the same pid (and no,
this
is not theoretical; it has been demonstrated).

Quoted 8 lines
Quoted 2 lines

I know. And I'm surprized that you dont do anything to change that.

There is a reason why SO_PEERSEC and SCM_SECURITY exist. Again,
learn
from the upstream security modules rather than re-inventing them,
badly.

Quoted 5 lines

SO_PEERSEC and SCM_SECURITY are spiffy for processes that are sending each other messages, but they identify the attributes associated with the message, not the process. Neither SELinux nor Smack get the information to send off of the process, it comes from the socket structure.

Quoted 5 lines

Yes, but in the SELinux case at least, the socket is labeled with the
label of the creating process (except in the rare case of using setsockcreatecon(3), which can only be used by suitably authorized processes).

Yes, it's the same with Smack. When it's not the label of the process it's the label the system wants the peer to think it is.

Quoted 5 lines

So in general it serves quite well as a means of obtaining
the peer label, which can then be used in access control (and this is
in fact being used in a variety of applications in Linux and Android).

Quoted 8 lines
Quoted 4 lines

But only between processes that are in direct, explicit communication.
There is no denying that these mechanisms work. They just aren't applicable to Jose's use.

If you say so (although it is unclear to me why or what exactly his use case is), but regardless, there is also no denying that getting and setting another process' attributes via /proc/pid files is inherently racy.

You're right. How can we fix that? I have seen a gazillion cases where system security would be much simpler and easier to enforce and develop if we could (safely) ensure that the process under /proc/pid wouldn't change on you without you knowing.

Quoted 6 lines

He even acknowledged as much. So we are left with a "security" module whose only purpose is to support getting and setting process tags for security enforcement purposes, and yet does so in a known- insecure manner. Again, this is why I keep suggesting that he needs to reconsider his approach, not merely figure out how to implement per- task security blobs.

Whether or not Jose moves forward with PTAGS we have identified an issue with the current cred based hooks for AppArmor, TOMOYO and at least one other proposed module. Regardless of the issues of /proc/pid there is work to be done.

#41 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Le mardi 20 décembre 2016 à 12:03 -0800, Casey Schaufler a écrit :

Quoted 82 lines · Stephen Smalley
Quoted 74 lines · Casey Schaufler
Quoted 68 lines · Stephen Smalley
Quoted 48 lines · Casey Schaufler
Quoted 41 lines · Stephen Smalley
Quoted 33 lines · José Bollo
Quoted 28 lines

Le mardi 20 décembre 2016 à 11:14 -0500, Stephen Smalley a
écrit
:

Quoted 9 lines

Looking at your PTAGS implementation, I feel it is only fair to
warn
you that your usage of /proc/pid/attr is insecure, regardless
of
whether you use task security blobs or cred security blobs.

Fair?!

Quoted 11 lines

Getting the attributes of another process via /proc/pid files
is
inherently racy, as the process may exit and another process
with
different attributes may be created with the same pid (and
no,
this
is not theoretical; it has been demonstrated).

Quoted 3 lines

I know. And I'm surprized that you dont do anything to change
that.

Quoted 6 lines

There is a reason why SO_PEERSEC and SCM_SECURITY exist.  Again,
learn
from the upstream security modules rather than re-inventing them,
badly.

Quoted 5 lines

SO_PEERSEC and SCM_SECURITY are spiffy for processes that are sending each other messages, but they identify the attributes associated with the message, not the process. Neither SELinux nor Smack get the information to send off of the process, it comes from the socket structure.

Quoted 7 lines

Yes, but in the SELinux case at least, the socket is labeled with
the
label of the creating process (except in the rare case of using setsockcreatecon(3), which can only be used by suitably authorized
processes).

Yes, it's the same with Smack. When it's not the label of the process it's the label the system wants the peer to think it is.

Quoted 6 lines

  So in general it serves quite well as a means of obtaining the peer label, which can then be used in access control (and this
is
in fact being used in a variety of applications in Linux and Android).

Quoted 4 lines

But only between processes that are in direct, explicit communication.
There is no denying that these mechanisms work. They just aren't applicable to Jose's use.

Quoted 6 lines

If you say so (although it is unclear to me why or what exactly his use
case is), but regardless, there is also no denying that getting and setting another process' attributes via /proc/pid files is inherently
racy.

Quoted 4 lines

You're right. How can we fix that? I have seen a gazillion cases where system security would be much simpler and easier to enforce and develop if we could (safely) ensure that the process under /proc/pid wouldn't change on you without you knowing.

Yes, fully agreed. It summarizes well my mind. There is here a good job to be done. I can imagine solution to this problem. And what Stephen thinks as a law is just a bug.

Quoted 13 lines
Quoted 8 lines

He even acknowledged as much.  So we are left with a "security" module whose only purpose is to support getting and setting process tags for security enforcement purposes, and yet does so in a known- insecure manner.  Again, this is why I keep suggesting that he needs to
reconsider his approach, not merely figure out how to implement per-
task security blobs.

Whether or not Jose moves forward with PTAGS we have identified an issue with the current cred based hooks for AppArmor, TOMOYO and at least one other proposed module. Regardless of the issues of /proc/pid there is work to be done.

#42 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Casey Schaufler
Quoted 83 lines · Casey Schaufler
Quoted 75 lines · Stephen Smalley
Quoted 69 lines · Casey Schaufler
Quoted 49 lines · Stephen Smalley
Quoted 42 lines · Casey Schaufler
Quoted 34 lines · Stephen Smalley
Quoted 29 lines · José Bollo

Le mardi 20 décembre 2016 à 11:14 -0500, Stephen Smalley a
écrit
:

Quoted 10 lines

Looking at your PTAGS implementation, I feel it is only fair to
warn
you that your usage of /proc/pid/attr is insecure, regardless
of
whether you use task security blobs or cred security blobs.

Fair?!

Quoted 12 lines

Getting the attributes of another process via /proc/pid files
is
inherently racy, as the process may exit and another process
with
different attributes may be created with the same pid (and
no,
this
is not theoretical; it has been demonstrated).

Quoted 3 lines

I know. And I'm surprized that you dont do anything to change
that.

Quoted 6 lines

There is a reason why SO_PEERSEC and SCM_SECURITY exist.  Again,
learn
from the upstream security modules rather than re-inventing them,
badly.

Quoted 5 lines

SO_PEERSEC and SCM_SECURITY are spiffy for processes that are sending each other messages, but they identify the attributes associated with the message, not the process. Neither SELinux nor Smack get the information to send off of the process, it comes from the socket structure.

Quoted 7 lines

Yes, but in the SELinux case at least, the socket is labeled with
the
label of the creating process (except in the rare case of using setsockcreatecon(3), which can only be used by suitably authorized
processes).

Yes, it's the same with Smack. When it's not the label of the process it's the label the system wants the peer to think it is.

Quoted 7 lines

  So in general it serves quite well as a means of obtaining the peer label, which can then be used in access control (and this
is
in fact being used in a variety of applications in Linux and Android).

Quoted 4 lines

But only between processes that are in direct, explicit communication.
There is no denying that these mechanisms work. They just aren't applicable to Jose's use.

Quoted 6 lines

If you say so (although it is unclear to me why or what exactly his use
case is), but regardless, there is also no denying that getting and setting another process' attributes via /proc/pid files is inherently
racy.

Quoted 4 lines

You're right. How can we fix that? I have seen a gazillion cases where system security would be much simpler and easier to enforce and develop if we could (safely) ensure that the process under /proc/pid wouldn't change on you without you knowing.

I don't think that is viable.  systemd for example maintains its own cgroup hierarchy in order to manage processes.  But in the case of ptags, I don't even see why the kernel needs to be involved in storing the tags, since it never uses them and isn't even providing them in a robust manner.  Might as well just take the tag set/get interface to userspace too.  Or re-implement it using a capability-based model (in the classical sense) via binder or bus1 or just file/socket descriptors.  Or use polkit or any of the other userspace access control implementations that already exist.  What was the use case again?  And why aren't these processes communicating with each other?

Quoted 11 lines
Quoted 10 lines

He even acknowledged as much.  So we are left with a "security" module whose only purpose is to support getting and setting process tags for security enforcement purposes, and yet does so in a known- insecure manner.  Again, this is why I keep suggesting that he needs to
reconsider his approach, not merely figure out how to implement per-
task security blobs.

Quoted 4 lines

Whether or not Jose moves forward with PTAGS we have identified an issue with the current cred based hooks for AppArmor, TOMOYO and at least one other proposed module. Regardless of the issues of /proc/pid there is work to be done.

Just be aware that any checking or processing relying on task security blobs will not be affected by override_creds() elsewhere in the kernel, which is used not only by overlayfs but other parts of the kernel to switch credentials temporarily as needed.

maintainer
#43 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Casey Schaufler
Quoted 65 lines · Casey Schaufler
Quoted 55 lines · Stephen Smalley
Quoted 54 lines · Casey Schaufler
Quoted 39 lines · Stephen Smalley
Quoted 33 lines · Casey Schaufler
Quoted 24 lines · Stephen Smalley
Quoted 23 lines · José Bollo

Le mardi 20 décembre 2016 à 11:14 -0500, Stephen Smalley a écrit
:

Quoted 8 lines

Looking at your PTAGS implementation, I feel it is only fair to
warn
you that your usage of /proc/pid/attr is insecure, regardless
of
whether you use task security blobs or cred security blobs.

Fair?!

Quoted 10 lines

Getting the attributes of another process via /proc/pid files
is
inherently racy, as the process may exit and another process
with
different attributes may be created with the same pid (and no,
this
is not theoretical; it has been demonstrated).

Quoted 8 lines
Quoted 2 lines

I know. And I'm surprized that you dont do anything to change that.

There is a reason why SO_PEERSEC and SCM_SECURITY exist. Again,
learn
from the upstream security modules rather than re-inventing them,
badly.

Quoted 5 lines

SO_PEERSEC and SCM_SECURITY are spiffy for processes that are sending each other messages, but they identify the attributes associated with the message, not the process. Neither SELinux nor Smack get the information to send off of the process, it comes from the socket structure.

Quoted 5 lines

Yes, but in the SELinux case at least, the socket is labeled with the
label of the creating process (except in the rare case of using setsockcreatecon(3), which can only be used by suitably authorized processes).

Yes, it's the same with Smack. When it's not the label of the process it's the label the system wants the peer to think it is.

Quoted 5 lines

So in general it serves quite well as a means of obtaining
the peer label, which can then be used in access control (and this is
in fact being used in a variety of applications in Linux and Android).

Quoted 8 lines
Quoted 4 lines

But only between processes that are in direct, explicit communication.
There is no denying that these mechanisms work. They just aren't applicable to Jose's use.

If you say so (although it is unclear to me why or what exactly his use case is), but regardless, there is also no denying that getting and setting another process' attributes via /proc/pid files is inherently racy.

Quoted 5 lines

You're right. How can we fix that? I have seen a gazillion cases where system security would be much simpler and easier to enforce and develop if we could (safely) ensure that the process under /proc/pid wouldn't change on you without you knowing.

locking. In this case it would have to be user acquired file lock that would hold the entire set of pid files in place so you could do a read for some of its info and write to it. I haven't dug into it all so I have no idea how likely getting such a change in would be, but I have a feeling it will meet with a fair bit of resistance.

The other way pid based interfaces have been handled is using a tuple of pid + creation timestamp or some other monotonically increasing value, that way you can be sure that the referenced pid is the correct one. I'm not a fan of the creation timestamp because time isn't always monotonically increasing but Jose could easily use a monotonic value. This would require Jose to track the monotonic value per task and make the expected monotonic value part of the write spec so that his module could validate it before applying the written tags.

The monotonic value doesn't need to increase with each task, just each reuse, but the it would probably be easiest just to use a value that increases once per task created.

I'm sure there are probably a few other techniques that could be found to make PTAGS safe. Whether /proc/pid/attr/ is the best interface is a separate question.

Quoted 7 lines
Quoted 6 lines

He even acknowledged as much. So we are left with a "security" module whose only purpose is to support getting and setting process tags for security enforcement purposes, and yet does so in a known- insecure manner. Again, this is why I keep suggesting that he needs to reconsider his approach, not merely figure out how to implement per- task security blobs.

Quoted 5 lines

Whether or not Jose moves forward with PTAGS we have identified an issue with the current cred based hooks for AppArmor, TOMOYO and at least one other proposed module. Regardless of the issues of /proc/pid there is work to be done.

I can take a stab at it in a few weeks. While not critical for apparmor it would certainly cleanup apparmor's cred handling.

maintainer Applied
#44 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

In reply to Stephen Smalley
Quoted 10 lines · Stephen Smalley

Processes can only alter their own security attributes via /proc/pid/attr nodes. This is presently enforced by each individual security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials. Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security hook, and drop the unnecessary task argument to the security hook since it can only ever be the current task.

Quoted 9 lines
---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------
 7 files changed, 18 insertions(+), 37 deletions(-)

Merged into the selinux#next branch.

Quoted 182 lines
fs/proc/base.c +9 -4
index 6eae4d0..7b228ea 100644
@@ -2485,6 +2485,12 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
        length = -ESRCH;
        if (!task)
                goto out_no_task;
+
+       /* A task may only write its own attributes. */
+       length = -EACCES;
+       if (current != task)
+               goto out;
+
        if (count > PAGE_SIZE)
                count = PAGE_SIZE;
 
@@ -2500,14 +2506,13 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
        }
 
        /* Guard against adverse ptrace interaction */
-       length = mutex_lock_interruptible(&task->signal->cred_guard_mutex);
+       length = mutex_lock_interruptible(&current->signal->cred_guard_mutex);
        if (length < 0)
                goto out_free;
 
-       length = security_setprocattr(task,
-                                     (char*)file->f_path.dentry->d_name.name,
+       length = security_setprocattr(file->f_path.dentry->d_name.name,
                                      page, count);
-       mutex_unlock(&task->signal->cred_guard_mutex);
+       mutex_unlock(&current->signal->cred_guard_mutex);
 out_free:
        kfree(page);
 out:
include/linux/lsm_hooks.h +1 -2
index 558adfa..0dde959 100644
@@ -1547,8 +1547,7 @@ union security_list_options {
        void (*d_instantiate)(struct dentry *dentry, struct inode *inode);
 
        int (*getprocattr)(struct task_struct *p, char *name, char **value);
-       int (*setprocattr)(struct task_struct *p, char *name, void *value,
-                               size_t size);
+       int (*setprocattr)(const char *name, void *value, size_t size);
        int (*ismaclabel)(const char *name);
        int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
        int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid);
include/linux/security.h +2 -2
index c2125e9..f4ebac1 100644
@@ -361,7 +361,7 @@ int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
                        unsigned nsops, int alter);
 void security_d_instantiate(struct dentry *dentry, struct inode *inode);
 int security_getprocattr(struct task_struct *p, char *name, char **value);
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
+int security_setprocattr(const char *name, void *value, size_t size);
 int security_netlink_send(struct sock *sk, struct sk_buff *skb);
 int security_ismaclabel(const char *name);
 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
@@ -1106,7 +1106,7 @@ static inline int security_getprocattr(struct task_struct *p, char *name, char *
        return -EINVAL;
 }
 
-static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+static inline int security_setprocattr(char *name, void *value, size_t size)
 {
        return -EINVAL;
 }
security/apparmor/lsm.c +2 -5
index 41b8cb1..8202e55 100644
@@ -495,8 +495,8 @@ static int apparmor_getprocattr(struct task_struct *task, char *name,
        return error;
 }
 
-static int apparmor_setprocattr(struct task_struct *task, char *name,
-                               void *value, size_t size)
+static int apparmor_setprocattr(const char *name, void *value,
+                               size_t size)
 {
        struct common_audit_data sa;
        struct apparmor_audit_data aad = {0,};
@@ -506,9 +506,6 @@ static int apparmor_setprocattr(struct task_struct *task, char *name,
 
        if (size == 0)
                return -EINVAL;
-       /* task can only write its own attributes */
-       if (current != task)
-               return -EACCES;
 
        /* AppArmor requires that the buffer must be null terminated atm */
        if (args[size - 1] != '\0') {
security/security.c +2 -2
index f825304..32052f5 100644
@@ -1170,9 +1170,9 @@ int security_getprocattr(struct task_struct *p, char *name, char **value)
        return call_int_hook(getprocattr, -EINVAL, p, name, value);
 }
 
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+int security_setprocattr(const char *name, void *value, size_t size)
 {
-       return call_int_hook(setprocattr, -EINVAL, p, name, value, size);
+       return call_int_hook(setprocattr, -EINVAL, name, value, size);
 }
 
 int security_netlink_send(struct sock *sk, struct sk_buff *skb)
security/selinux/hooks.c +1 -12
index 9992626..762276b 100644
@@ -5859,8 +5859,7 @@ static int selinux_getprocattr(struct task_struct *p,
        return error;
 }
 
-static int selinux_setprocattr(struct task_struct *p,
-                              char *name, void *value, size_t size)
+static int selinux_setprocattr(const char *name, void *value, size_t size)
 {
        struct task_security_struct *tsec;
        struct cred *new;
@@ -5868,16 +5867,6 @@ static int selinux_setprocattr(struct task_struct *p,
        int error;
        char *str = value;
 
-       if (current != p) {
-               /*
-                * A task may only alter its own credentials.
-                * SELinux has always enforced this restriction,
-                * and it is now mandated by the Linux credentials
-                * infrastructure; see Documentation/security/credentials.txt.
-                */
-               return -EACCES;
-       }
-
        /*
         * Basic control over ability to set these attributes at all.
         */
security/smack/smack_lsm.c +1 -11
index 4d90257..9bde7f8 100644
@@ -3620,7 +3620,6 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
 
 /**
  * smack_setprocattr - Smack process attribute setting
- * @p: the object task
  * @name: the name of the attribute in /proc/.../attr
  * @value: the value to set
  * @size: the size of the value
@@ -3630,8 +3629,7 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
  *
  * Returns the length of the smack label or an error code
  */
-static int smack_setprocattr(struct task_struct *p, char *name,
-                            void *value, size_t size)
+static int smack_setprocattr(const char *name, void *value, size_t size)
 {
        struct task_smack *tsp = current_security();
        struct cred *new;
@@ -3639,13 +3637,6 @@ static int smack_setprocattr(struct task_struct *p, char *name,
        struct smack_known_list_elem *sklep;
        int rc;
 
-       /*
-        * Changing another process' Smack value is too dangerous
-        * and supports no sane use case.
-        */
-       if (p != current)
-               return -EPERM;
-
        if (!smack_privileged(CAP_MAC_ADMIN) && list_empty(&tsp->smk_relabel))
                return -EPERM;
 
--

2.7.4

Signature · 2 lines
paul moore
www.paul-moore.com
#45 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Le mardi 20 décembre 2016 à 21:37 -0500, Paul Moore a écrit :

Quoted 26 lines
Quoted 22 lines · Stephen Smalley

Processes can only alter their own security attributes via /proc/pid/attr nodes.  This is presently enforced by each individual
security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security hook,
and drop the unnecessary task argument to the security hook since it can
only ever be the current task.

---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------

Quoted 1 line
 7 files changed, 18 insertions(+), 37 deletions(-)
Quoted 1 line

Merged into the selinux#next branch.

is it fair?

Quoted 228 lines
Quoted 225 lines
fs/proc/base.c +8 -3
index 6eae4d0..7b228ea 100644
@@ -2485,6 +2485,12 @@ static ssize_t proc_pid_attr_write(struct
 file * file, const char __user * buf,
         length = -ESRCH;
         if (!task)
                 goto out_no_task;
+
+       /* A task may only write its own attributes. */
+       length = -EACCES;
+       if (current != task)
+               goto out;
+
         if (count > PAGE_SIZE)
                 count = PAGE_SIZE;
@@ -2500,14 +2506,13 @@ static ssize_t proc_pid_attr_write(struct
 file * file, const char __user * buf,
         }
 
         /* Guard against adverse ptrace interaction */
-       length = mutex_lock_interruptible(&task->signal-
 >cred_guard_mutex);
+       length = mutex_lock_interruptible(&current->signal-
 >cred_guard_mutex);
         if (length < 0)
                 goto out_free;
 
-       length = security_setprocattr(task,
-                                     (char*)file->f_path.dentry-
 >d_name.name,
+       length = security_setprocattr(file->f_path.dentry-
 >d_name.name,

                                      page, count); -       mutex_unlock(&task->signal->cred_guard_mutex); +       mutex_unlock(&current->signal->cred_guard_mutex); out_free:
        kfree(page);
 out:

include/linux/lsm_hooks.h +0 -0
index 558adfa..0dde959 100644
@@ -1547,8 +1547,7 @@ union security_list_options {

        void (*d_instantiate)(struct dentry *dentry, struct inode *inode);

        int (*getprocattr)(struct task_struct *p, char *name, char **value);
-       int (*setprocattr)(struct task_struct *p, char *name, void *value,
-                               size_t size);
+       int (*setprocattr)(const char *name, void *value, size_t size);
        int (*ismaclabel)(const char *name);
        int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
        int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid);

include/linux/security.h +0 -0
index c2125e9..f4ebac1 100644
@@ -361,7 +361,7 @@ int security_sem_semop(struct sem_array *sma,
 struct sembuf *sops,
                         unsigned nsops, int alter);

 void security_d_instantiate(struct dentry *dentry, struct inode *inode);
 int security_getprocattr(struct task_struct *p, char *name, char **value);
-int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
+int security_setprocattr(const char *name, void *value, size_t size);
 int security_netlink_send(struct sock *sk, struct sk_buff *skb); int security_ismaclabel(const char *name);
 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);

include/linux/security.h +0 -0
@@ -1106,7 +1106,7 @@ static inline int security_getprocattr(struct

task_struct *p, char *name, char *
        return -EINVAL;
 }

-static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
+static inline int security_setprocattr(char *name, void *value, size_t size)
 {
        return -EINVAL;
 }

security/apparmor/lsm.c +2 -2
index 41b8cb1..8202e55 100644
@@ -495,8 +495,8 @@ static int apparmor_getprocattr(struct
 task_struct *task, char *name,
         return error;
  }
 
-static int apparmor_setprocattr(struct task_struct *task, char
 *name,
-                               void *value, size_t size)
+static int apparmor_setprocattr(const char *name, void *value,
+                               size_t size)
  {

        struct common_audit_data sa;
        struct apparmor_audit_data aad = {0,};

security/apparmor/lsm.c +0 -3
@@ -506,9 +506,6 @@ static int apparmor_setprocattr(struct
 task_struct *task, char *name,
 
         if (size == 0)
                 return -EINVAL;
-       /* task can only write its own attributes */
-       if (current != task)
-               return -EACCES;
 
         /* AppArmor requires that the buffer must be null

terminated atm */
        if (args[size - 1] != '\0') {

security/security.c +1 -2
index f825304..32052f5 100644
@@ -1170,9 +1170,9 @@ int security_getprocattr(struct task_struct
 *p, char *name, char **value)
         return call_int_hook(getprocattr, -EINVAL, p, name, value);
  }
 
-int security_setprocattr(struct task_struct *p, char *name, void
 *value, size_t size)
+int security_setprocattr(const char *name, void *value, size_t
 size)
  {
-       return call_int_hook(setprocattr, -EINVAL, p, name, value,

size);
+       return call_int_hook(setprocattr, -EINVAL, name, value, size);
 }

 int security_netlink_send(struct sock *sk, struct sk_buff *skb)

security/selinux/hooks.c +1 -2
index 9992626..762276b 100644
@@ -5859,8 +5859,7 @@ static int selinux_getprocattr(struct
 task_struct *p,
         return error;
  }
 
-static int selinux_setprocattr(struct task_struct *p,
-                              char *name, void *value, size_t
 size)
+static int selinux_setprocattr(const char *name, void *value,
 size_t size)

 {
        struct task_security_struct *tsec;
        struct cred *new;

security/selinux/hooks.c +0 -6
@@ -5868,16 +5867,6 @@ static int selinux_setprocattr(struct
 task_struct *p,
         int error;
         char *str = value;
 
-       if (current != p) {
-               /*
-                * A task may only alter its own credentials.
-                * SELinux has always enforced this restriction,
-                * and it is now mandated by the Linux credentials
-                * infrastructure; see

Documentation/security/credentials.txt.
-                */
-               return -EACCES;
-       }
-
        /*
         * Basic control over ability to set these attributes at all.
         */

security/smack/smack_lsm.c +0 -1
index 4d90257..9bde7f8 100644
@@ -3620,7 +3620,6 @@ static int smack_getprocattr(struct
 task_struct *p, char *name, char **value)
 
  /**
   * smack_setprocattr - Smack process attribute setting
- * @p: the object task
   * @name: the name of the attribute in /proc/.../attr
   * @value: the value to set

  * @size: the size of the value

security/smack/smack_lsm.c +1 -2
@@ -3630,8 +3629,7 @@ static int smack_getprocattr(struct
 task_struct *p, char *name, char **value)
   *
   * Returns the length of the smack label or an error code
   */
-static int smack_setprocattr(struct task_struct *p, char *name,
-                            void *value, size_t size)
+static int smack_setprocattr(const char *name, void *value, size_t
 size)
  {

        struct task_smack *tsp = current_security(); struct cred *new;

security/smack/smack_lsm.c +0 -7
@@ -3639,13 +3637,6 @@ static int smack_setprocattr(struct
 task_struct *p, char *name,
         struct smack_known_list_elem *sklep;
         int rc;
 
-       /*
-        * Changing another process' Smack value is too dangerous
-        * and supports no sane use case.
-        */
-       if (p != current)
-               return -EPERM;
-

        if (!smack_privileged(CAP_MAC_ADMIN) && list_empty(&tsp-

Quoted 1 line

smk_relabel))

                return -EPERM;

--
2.7.4

maintainer
#46 lore raw

Re: [PATCH 2/2] proc,security: move restriction on writing /proc/pid/attr nodes to proc

Quoted 27 lines · José Bollo
Quoted 26 lines · Paul Moore
Quoted 23 lines · Stephen Smalley

Processes can only alter their own security attributes via /proc/pid/attr nodes. This is presently enforced by each individual
security module and is also imposed by the Linux credentials implementation, which only allows a task to alter its own credentials.
Move the check enforcing this restriction from the individual security modules to proc_pid_attr_write() before calling the security hook,
and drop the unnecessary task argument to the security hook since it can
only ever be the current task.

---
 fs/proc/base.c             | 13 +++++++++----
 include/linux/lsm_hooks.h  |  3 +--
 include/linux/security.h   |  4 ++--
 security/apparmor/lsm.c    |  7 ++-----
 security/security.c        |  4 ++--
 security/selinux/hooks.c   | 13 +------------
 security/smack/smack_lsm.c | 11 +----------
 7 files changed, 18 insertions(+), 37 deletions(-)
Quoted 3 lines
Quoted 1 line

Merged into the selinux#next branch.

is it fair?

I believe so, yes. As many have already mentioned, this patch doesn't introduce a new restriction, it simply cleans up an existing restriction. If/when PTAGS is merged upstream it can make any changes needed as long as those changes do not cause a regression in the safety or behavior of the existing LSMs and the kernel as a whole.

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer Applied
#47 lore raw
In reply to Stephen Smalley
Quoted 15 lines · Stephen Smalley

SELinux was sometimes using the task "objective" credentials when it could/should use the "subjective" credentials. This was sometimes hidden by the fact that we were unnecessarily passing around pointers to the current task, making it appear as if the task could be something other than current, so eliminate all such passing of current. Inline various permission checking helper functions that can be reduced to a single avc_has_perm() call.

Since the credentials infrastructure only allows a task to alter its own credentials, we can always assume that current must be the same as the target task in selinux_setprocattr after the check. We likely should move this check from selinux_setprocattr() to proc_pid_attr_write() and drop the task argument to the security hook altogether; it can only serve to confuse things.

Quoted 6 lines
---
 security/selinux/hooks.c          | 294 +++++++++++++++-----------------------
 security/selinux/include/objsec.h |  10 ++
 security/selinux/selinuxfs.c      |  73 +++++-----
 3 files changed, 166 insertions(+), 211 deletions(-)

Merged, thanks.

Looking at this patch, I think getting rid of the wrappers was the right way to go from a readability perspective.

Signature · 2 lines
paul moore
www.paul-moore.com