Skip to contentSkip to conversation

capabilities: cleanups

PATCH In review Andy Lutomirski 2 participants 2 messages May 12, 2004 – May 13, 2004

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

PATCH 1/2 capabilities: cleanups

Move setuid logic out of cap_brpm_set_security; modify linux_binprm to store the relevent information.

 fs/exec.c               |   25 +++++++++++++++++-------
 include/linux/binfmts.h |    8 +++++--

security/commoncap.c | 50 ++++++++++++++++++++---------------------------- 3 files changed, 45 insertions(+), 38 deletions(-)

fs/exec.c renamed from fs/exec.c~cap_1_cleanup +18 -7
@@ -833,7 +833,7 @@
 
 	flush_thread();
 
-	if (bprm->e_uid != current->euid || bprm->e_gid != current->egid || 
+	if (bprm->set_uid != current->euid || bprm->set_gid != current->egid || 
 	    permission(bprm->file->f_dentry->d_inode,MAY_READ, NULL) ||
 	    (bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP))
 		current->mm->dumpable = 0;
@@ -877,13 +877,15 @@
 	if (bprm->file->f_op == NULL)
 		return -EACCES;
 
-	bprm->e_uid = current->euid;
-	bprm->e_gid = current->egid;
+	bprm->set_uid = current->euid;
+	bprm->set_gid = current->egid;
 
 	if(!(bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID)) {
 		/* Set-uid? */
-		if (mode & S_ISUID)
-			bprm->e_uid = inode->i_uid;
+		if (mode & S_ISUID) {
+			bprm->set_uid = inode->i_uid;
+			bprm->secflags |= BINPRM_SEC_SETUID;
+		}
 
 		/* Set-gid? */
 		/*
@@ -891,10 +893,19 @@
 		 * is a candidate for mandatory locking, not a setgid
 		 * executable.
 		 */
-		if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
-			bprm->e_gid = inode->i_gid;
+		if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
+			bprm->set_gid = inode->i_gid;
+			bprm->secflags |= BINPRM_SEC_SETGID;
+		}
 	}
 
+	/* Pretend we have VFS capabilities */
+	cap_set_full(bprm->cap_inheritable);
+	if((bprm->secflags & BINPRM_SEC_SETUID) && bprm->set_uid == 0)
+		cap_set_full(bprm->cap_permitted);
+	else
+		cap_clear(bprm->cap_permitted);
+
 	/* fill in binprm security blob */
 	retval = security_bprm_set(bprm);
 	if (retval)
security/commoncap.c renamed from security/commoncap.c~cap_1_cleanup +21 -29

85 lines not on this page · raw message

include/linux/binfmts.h renamed from include/linux/binfmts.h~cap_1_cleanup +6 -2
@@ -20,6 +20,9 @@
 /*
  * This structure is used to hold the arguments that are used when loading binaries.
  */
+#define BINPRM_SEC_SETUID	1
+#define BINPRM_SEC_SETGID	2
+#define BINPRM_SEC_SECUREEXEC	4
 struct linux_binprm{
 	char buf[BINPRM_BUF_SIZE];
 	struct page *page[MAX_ARG_PAGES];
@@ -27,8 +30,9 @@
 	unsigned long p; /* current top of mem */
 	int sh_bang;
 	struct file * file;
-	int e_uid, e_gid;
-	kernel_cap_t cap_inheritable, cap_permitted, cap_effective;
+	int set_uid, set_gid;
+	int secflags;
+	kernel_cap_t cap_inheritable, cap_permitted;
 	void *security;
 	int argc, envc;
 	char * filename;	/* Name of binary as seen by procps */
#1 lore raw
Quoted 14 lines · Andy Lutomirski

--- linux-2.6.6-mm1/include/linux/binfmts.h~cap_1_cleanup 2004-05-10 23:52:05.000000000 -0700
+++ linux-2.6.6-mm1/include/linux/binfmts.h 2004-05-11 00:58:13.000000000 -0700
@@ -20,6 +20,9 @@
/*
* This structure is used to hold the arguments that are used when loading binaries. */
+#define BINPRM_SEC_SETUID 1
+#define BINPRM_SEC_SETGID 2
+#define BINPRM_SEC_SECUREEXEC 4
struct linux_binprm{
char buf[BINPRM_BUF_SIZE];
struct page *page[MAX_ARG_PAGES];
@@ -27,8 +30,9 @@

Quoted 8 lines

unsigned long p; /* current top of mem */
int sh_bang;
struct file * file;
- int e_uid, e_gid;
- kernel_cap_t cap_inheritable, cap_permitted, cap_effective;
+ int set_uid, set_gid;
+ int secflags;
+ kernel_cap_t cap_inheritable, cap_permitted;

security/dummy.c: In function `dummy_bprm_apply_creds':
security/dummy.c:176: structure has no member named e_uid' security/dummy.c:176: structure has no member named e_gid' security/dummy.c:180: structure has no member named e_uid' security/dummy.c:181: structure has no member named e_gid' security/dummy.c:185: structure has no member named e_uid' security/dummy.c:186: structure has no member named e_gid'