Skip to contentSkip to conversation

Introduce BSD-style user credential [3/3]

PATCH In review Trond Myklebust 7 participants 19 messages Aug 30, 2002 – Sep 1, 2002

Subsystems (10)
Networking VFS NFS client NFS server +6 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Introduce BSD-style user credential [3/3]

Introduce basic *BSD style user credentials of the form

struct ucred {
       atomic_t	count;
       uid_t	uid;
       gid_t	gid;
       int	ngroups;
       gid_t	*groups;
};

and replace fsuid, fsgid, ngroups, groups in the struct task.

The struct ucred will later be used as the basic element of user authentication at the VFS level in lieu of the current hodge-podge of partial creds in struct file and lower level filesystem code.

Cheers,
Trond

arch/s390x/kernel/linux32.c +2 -7
diff -u --recursive --new-file linux-2.5.32-cred2/arch/s390x/kernel/linux32.c linux-2.5.32-cred3/arch/s390x/kernel/linux32.c
@@ -194,12 +194,10 @@
 
 	if (gidsetsize < 0)
 		return -EINVAL;
-	i = current_ngroups();
+	i = current_getgroups16(NGROUPS, groups);
 	if (gidsetsize) {
 		if (i > gidsetsize)
 			return -EINVAL;
-		for(j=0;j<i;j++)
-			groups[j] = current->groups[j];
 		if (copy_to_user(grouplist, groups, sizeof(u16)*i))
 			return -EFAULT;
 	}
@@ -217,10 +215,7 @@
 		return -EINVAL;
 	if (copy_from_user(groups, grouplist, gidsetsize * sizeof(u16)))
 		return -EFAULT;
-	for (i = 0 ; i < gidsetsize ; i++)
-		current->groups[i] = (gid_t)groups[i];
-	current->ngroups = gidsetsize;
-	return 0;
+	return current_setgroups16(gidsetsize, grouplist);
 }
 
 asmlinkage long sys32_getuid16(void)
arch/sparc64/kernel/sys_sparc32.c +2 -7
diff -u --recursive --new-file linux-2.5.32-cred2/arch/sparc64/kernel/sys_sparc32.c linux-2.5.32-cred3/arch/sparc64/kernel/sys_sparc32.c
@@ -211,12 +211,10 @@
 
 	if (gidsetsize < 0)
 		return -EINVAL;
-	i = current_ngroups();
+	i = current_getgroups16(NGROUPS, groups);
 	if (gidsetsize) {
 		if (i > gidsetsize)
 			return -EINVAL;
-		for(j=0;j<i;j++)
-			groups[j] = current->groups[j];
 		if (copy_to_user(grouplist, groups, sizeof(u16)*i))
 			return -EFAULT;
 	}
@@ -234,10 +232,7 @@
 		return -EINVAL;
 	if (copy_from_user(groups, grouplist, gidsetsize * sizeof(u16)))
 		return -EFAULT;
-	for (i = 0 ; i < gidsetsize ; i++)
-		current->groups[i] = (gid_t)groups[i];
-	current->ngroups = gidsetsize;
-	return 0;
+	return current_setgroups16(gidsetsize, groups);
 }
 
 asmlinkage long sys32_getuid16(void)
fs/intermezzo/file.c +8 -5
diff -u --recursive --new-file linux-2.5.32-cred2/fs/intermezzo/file.c linux-2.5.32-cred3/fs/intermezzo/file.c
@@ -139,6 +139,7 @@
                 presto_set(file->f_dentry, PRESTO_ATTR | PRESTO_DATA);
 
         if (writable) { 
+		struct ucred *cred;
                 PRESTO_ALLOC(fdata, struct presto_file_data *, sizeof(*fdata));
                 if (!fdata) {
                         EXIT;
@@ -146,15 +147,17 @@
                 }
                 /* we believe that on open the kernel lock
                    assures that only one process will do this allocation */ 
+		cred = current_getucred();
                 fdata->fd_do_lml = 0;
-                fdata->fd_fsuid = current_fsuid();
-                fdata->fd_fsgid = current_fsgid();
+                fdata->fd_fsuid = cred->uid;
+                fdata->fd_fsgid = cred->gid;
                 fdata->fd_mode = file->f_dentry->d_inode->i_mode;
-                fdata->fd_ngroups = current_ngroups();
-                for (i=0 ; i<current_ngroups() ; i++)
-                        fdata->fd_groups[i] = current->groups[i]; 
+                fdata->fd_ngroups = cred->ngroups;
+                for (i=0 ; i<cred->ngroups ; i++)
+                        fdata->fd_groups[i] = cred->groups[i]; 
                 fdata->fd_bytes_written = 0; /*when open,written data is zero*/ 
                 file->private_data = fdata; 
+		put_ucred(cred);
         } else {
                 file->private_data = NULL;
         }
fs/intermezzo/journal.c +17 -11
diff -u --recursive --new-file linux-2.5.32-cred2/fs/intermezzo/journal.c linux-2.5.32-cred3/fs/intermezzo/journal.c
@@ -254,18 +254,22 @@
 static inline char *
 journal_log_prefix(char *buf, int opcode, struct rec_info *rec)
 {
+	struct ucred *cred;
 	__u32 groups[NGROUPS_MAX]; 
 	int i; 
 
+	cred = current_getucred();
 	/* convert 16 bit gid's to 32 bit gid's */
-	for (i=0; i<current_ngroups(); i++) 
-		groups[i] = (__u32) current->groups[i];
+	for (i=0; i<cred->ngroups; i++) 
+		groups[i] = (__u32) cred->groups[i];
 	
-        return journal_log_prefix_with_groups_and_ids(buf, opcode, rec,
-                                                      (__u32)current_ngroups(),
+        i =  journal_log_prefix_with_groups_and_ids(buf, opcode, rec,
+                                                      (__u32)cred->ngroups,
 						      groups,
-                                                      (__u32)current_fsuid(),
-                                                      (__u32)current_fsgid());
+                                                      (__u32)cred->uid,
+                                                      (__u32)cred->gid);
+	put_ucred(cred);
+	return i;
 }
 
 static inline char *
@@ -1741,14 +1745,16 @@
                 open_fsuid = fd->fd_fsuid;
                 open_fsgid = fd->fd_fsgid;
         } else {
-                open_ngroups = current_ngroups();
-                for (i=0; i<current_ngroups(); i++)
-			open_groups[i] =  (__u32) current->groups[i]; 
+		struct ucred *cred = current_getucred();
+                open_ngroups = cred->ngroups;
+                for (i=0; i<cred->ngroups; i++)
+			open_groups[i] =  (__u32) cred->groups[i]; 
                 open_mode = dentry->d_inode->i_mode;
                 open_uid = dentry->d_inode->i_uid;
                 open_gid = dentry->d_inode->i_gid;
-                open_fsuid = current_fsuid();
-                open_fsgid = current_fsgid();
+                open_fsuid = cred->uid;
+                open_fsgid = cred->gid;
+		put_ucred(cred);
         }
         BUFF_ALLOC(buffer, NULL);
         path = presto_path(dentry, root, buffer, PAGE_SIZE);
fs/nfsd/auth.c +1 -2
diff -u --recursive --new-file linux-2.5.32-cred2/fs/nfsd/auth.c linux-2.5.32-cred3/fs/nfsd/auth.c
@@ -46,9 +46,8 @@
 		gid_t group = cred->cr_groups[i];
 		if (group == (gid_t) NOGROUP)
 			break;
-		current->groups[i] = group;
 	}
-	current->ngroups = i;
+	current_setgroups(i, cred->cr_groups);
 
 	if ((cred->cr_uid)) {
 		cap_t(current->cap_effective) &= ~CAP_NFSD_MASK;
fs/proc/array.c +7 -4
diff -u --recursive --new-file linux-2.5.32-cred2/fs/proc/array.c linux-2.5.32-cred3/fs/proc/array.c
@@ -148,9 +148,11 @@
 
 static inline char * task_state(struct task_struct *p, char *buffer)
 {
+	struct ucred *cred;
 	int g;
 
 	read_lock(&tasklist_lock);
+	cred = task_getucred(p);
 	buffer += sprintf(buffer,
 		"State:\t%s\n"
 		"Tgid:\t%d\n"
@@ -161,8 +163,8 @@
 		"Gid:\t%d\t%d\t%d\t%d\n",
 		get_task_state(p), p->tgid,
 		p->pid, p->pid ? p->real_parent->pid : 0, 0,
-		p->uid, p->euid, p->suid, p->fsuid,
-		p->gid, p->egid, p->sgid, p->fsgid);
+		p->uid, p->euid, p->suid, cred->uid,
+		p->gid, p->egid, p->sgid, cred->gid);
 	read_unlock(&tasklist_lock);	
 	task_lock(p);
 	buffer += sprintf(buffer,
@@ -171,10 +173,11 @@
 		p->files ? p->files->max_fds : 0);
 	task_unlock(p);
 
-	for (g = 0; g < p->ngroups; g++)
-		buffer += sprintf(buffer, "%d ", p->groups[g]);
+	for (g = 0; g < cred->ngroups; g++)
+		buffer += sprintf(buffer, "%d ", cred->groups[g]);
 
 	buffer += sprintf(buffer, "\n");
+	put_ucred(cred);
 	return buffer;
 }
 
include/linux/cred.h +92 -0

92 lines not on this page · raw message

include/linux/init_task.h +1 -0
diff -u --recursive --new-file linux-2.5.32-cred2/include/linux/init_task.h linux-2.5.32-cred3/include/linux/init_task.h
@@ -65,6 +65,7 @@
 	.real_timer	= {						\
 		.function	= it_real_fn				\
 	},								\
+	.ucred		= &init_ucred,					\
 	.cap_effective	= CAP_INIT_EFF_SET,				\
 	.cap_inheritable = CAP_INIT_INH_SET,				\
 	.cap_permitted	= CAP_FULL_SET,					\
include/linux/sched.h +4 -26
diff -u --recursive --new-file linux-2.5.32-cred2/include/linux/sched.h linux-2.5.32-cred3/include/linux/sched.h
@@ -27,6 +27,7 @@
 #include <linux/securebits.h>
 #include <linux/fs_struct.h>
 #include <linux/compiler.h>
+#include <linux/cred.h>
 
 struct exec_domain;
 
@@ -327,10 +328,9 @@
 	unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
 	int swappable:1;
 /* process credentials */
-	uid_t uid,euid,suid,fsuid;
-	gid_t gid,egid,sgid,fsgid;
-	int ngroups;
-	gid_t	groups[NGROUPS];
+	uid_t uid,euid,suid;
+	gid_t gid,egid,sgid;
+	struct ucred *ucred;
 	kernel_cap_t   cap_effective, cap_inheritable, cap_permitted;
 	int keep_capabilities:1;
 	struct user_struct *user;
@@ -946,28 +946,6 @@
 
 #endif /* CONFIG_SMP */
 
-/* Provisional functions for the transition to reference-counted ucreds */
-static inline uid_t current_fsuid(void)
-{
-	return current->fsuid;
-}
-static inline gid_t current_fsgid(void)
-{
-	return current->fsgid;
-}
-static inline int current_ngroups(void)
-{
-	return current->ngroups;
-}
-static inline void current_setfsuid(uid_t uid)
-{
-	current->fsuid = uid;
-}
-static inline void current_setfsgid(gid_t gid)
-{
-	current->fsgid = gid;
-}
-
 #endif /* __KERNEL__ */
 
 #endif
init/main.c +1 -0
diff -u --recursive --new-file linux-2.5.32-cred2/init/main.c linux-2.5.32-cred3/init/main.c
@@ -438,6 +438,7 @@
 	kmem_cache_sizes_init();
 	pgtable_cache_init();
 	pte_chain_init();
+	credentials_init();
 	fork_init(num_physpages);
 	proc_caches_init();
 	security_scaffolding_startup();
kernel/Makefile +3 -2
diff -u --recursive --new-file linux-2.5.32-cred2/kernel/Makefile linux-2.5.32-cred3/kernel/Makefile
@@ -10,12 +10,13 @@
 O_TARGET := kernel.o
 
 export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o \
-		printk.o platform.o suspend.o dma.o
+		printk.o platform.o suspend.o dma.o cred.o
 
 obj-y     = sched.o fork.o exec_domain.o panic.o printk.o \
 	    module.o exit.o itimer.o time.o softirq.o resource.o \
 	    sysctl.o capability.o ptrace.o timer.o user.o \
-	    signal.o sys.o kmod.o context.o futex.o platform.o
+	    signal.o sys.o kmod.o context.o futex.o platform.o \
+	    cred.o
 
 obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
 obj-$(CONFIG_SMP) += cpu.o
kernel/cred.c +475 -0

475 lines not on this page · raw message

kernel/fork.c +17 -0
diff -u --recursive --new-file linux-2.5.32-cred2/kernel/fork.c linux-2.5.32-cred3/kernel/fork.c
@@ -62,6 +62,7 @@
 void __put_task_struct(struct task_struct *tsk)
 {
 	if (tsk != current) {
+		put_ucred(tsk->ucred);
 		free_thread_info(tsk->thread_info);
 		kmem_cache_free(task_struct_cachep,tsk);
 	} else {
@@ -69,6 +70,7 @@
 
 		tsk = task_cache[cpu];
 		if (tsk) {
+			put_ucred(tsk->ucred);
 			free_thread_info(tsk->thread_info);
 			kmem_cache_free(task_struct_cachep,tsk);
 		}
@@ -146,6 +148,7 @@
 	*tsk = *orig;
 	tsk->thread_info = ti;
 	ti->task = tsk;
+	tsk->ucred = task_getucred(orig);
 	atomic_set(&tsk->usage,1);
 
 	return tsk;
@@ -502,6 +505,18 @@
 	return i;
 }
 
+/* For the moment, we never share credentials between processes */
+static int copy_cred(unsigned long clone_flags, struct task_struct * tsk)
+{
+	struct ucred *cred;
+	cred = current_clone_ucred();
+	if (!cred)
+		return -ENOMEM;
+	task_setucred(tsk, cred);
+	put_ucred(cred);
+	return 0;
+}
+
 static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
 {
 	struct files_struct *oldf, *newf;
@@ -671,6 +686,8 @@
 		if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE))
 			goto bad_fork_free;
 	}
+	if (copy_cred(clone_flags, p))
+		goto bad_fork_free;
 
 	atomic_inc(&p->user->__count);
 	atomic_inc(&p->user->processes);
kernel/kmod.c +4 -2
diff -u --recursive --new-file linux-2.5.32-cred2/kernel/kmod.c linux-2.5.32-cred3/kernel/kmod.c
@@ -132,8 +132,10 @@
 	}
 
 	/* Give kmod all effective privileges.. */
-	curtask->euid = curtask->fsuid = 0;
-	curtask->egid = curtask->fsgid = 0;
+	curtask->euid = 0;
+	curtask->egid = 0;
+	current_setfsuid(0);
+	current_setfsgid(0);
 	security_ops->task_kmod_set_label();
 
 	/* Allow execve args to be in kernel space. */
kernel/sys.c +16 -18
diff -u --recursive --new-file linux-2.5.32-cred2/kernel/sys.c linux-2.5.32-cred3/kernel/sys.c
@@ -984,6 +984,7 @@
  */
 asmlinkage long sys_getgroups(int gidsetsize, gid_t *grouplist)
 {
+	gid_t groups[NGROUPS];
 	int i;
 	
 	/*
@@ -993,11 +994,11 @@
 
 	if (gidsetsize < 0)
 		return -EINVAL;
-	i = current_ngroups();
+	i = current_getgroups(NGROUPS, groups);
 	if (gidsetsize) {
 		if (i > gidsetsize)
 			return -EINVAL;
-		if (copy_to_user(grouplist, current->groups, sizeof(gid_t)*i))
+		if (copy_to_user(grouplist, groups, sizeof(gid_t)*i))
 			return -EFAULT;
 	}
 	return i;
@@ -1022,25 +1023,18 @@
 	retval = security_ops->task_setgroups(gidsetsize, groups);
 	if (retval)
 		return retval;
-	memcpy(current->groups, groups, gidsetsize * sizeof(gid_t));
-	current->ngroups = gidsetsize;
-	return 0;
+	return current_setgroups(gidsetsize, groups);
 }
 
 static int supplemental_group_member(gid_t grp)
 {
-	int i = current_ngroups();
+	struct ucred *cred;
+	int retval;
 
-	if (i) {
-		gid_t *groups = current->groups;
-		do {
-			if (*groups == grp)
-				return 1;
-			groups++;
-			i--;
-		} while (i);
-	}
-	return 0;
+	cred = current_getucred();
+	retval = ucred_match_supplemental(cred, grp);
+	put_ucred(cred);
+	return retval;
 }
 
 /*
@@ -1048,9 +1042,13 @@
  */
 int in_group_p(gid_t grp)
 {
+	struct ucred *cred;
 	int retval = 1;
-	if (grp != current_fsgid())
-		retval = supplemental_group_member(grp);
+
+	cred = current_getucred();
+	if (grp != cred->gid)
+		retval = ucred_match_supplemental(cred, grp);
+	put_ucred(cred);
 	return retval;
 }
 
kernel/uid16.c +4 -5
diff -u --recursive --new-file linux-2.5.32-cred2/kernel/uid16.c linux-2.5.32-cred3/kernel/uid16.c
@@ -109,17 +109,18 @@
 
 asmlinkage long sys_getgroups16(int gidsetsize, old_gid_t *grouplist)
 {
+	gid_t gids[NGROUPS];
 	old_gid_t groups[NGROUPS];
 	int i,j;
 
 	if (gidsetsize < 0)
 		return -EINVAL;
-	i = current_ngroups();
+	i = current_getgroups(NGROUPS, gids);
 	if (gidsetsize) {
 		if (i > gidsetsize)
 			return -EINVAL;
 		for(j=0;j<i;j++)
-			groups[j] = current->groups[j];
+			groups[j] = gids[j];
 		if (copy_to_user(grouplist, groups, sizeof(old_gid_t)*i))
 			return -EFAULT;
 	}
@@ -143,9 +144,7 @@
 	i = security_ops->task_setgroups(gidsetsize, new_groups);
 	if (i)
 		return i;
-	memcpy(current->groups, new_groups, gidsetsize * sizeof(gid_t));
-	current->ngroups = gidsetsize;
-	return 0;
+	return current_setgroups(gidsetsize, new_groups);
 }
 
 asmlinkage long sys_getuid16(void)
net/sunrpc/auth_unix.c +28 -27

73 lines not on this page · raw message

security/dummy.c +3 -2
diff -u --recursive --new-file linux-2.5.32-cred2/security/dummy.c linux-2.5.32-cred3/security/dummy.c
@@ -53,7 +53,7 @@
 
 static int dummy_capable (struct task_struct *tsk, int cap)
 {
-	if (cap_is_fs_cap (cap) ? tsk->fsuid == 0 : tsk->euid == 0)
+	if (cap_is_fs_cap (cap) ? task_fsuid(tsk) == 0 : tsk->euid == 0)
 		/* capability granted */
 		return 0;
 
@@ -489,7 +489,8 @@
 
 static void dummy_task_reparent_to_init (struct task_struct *p)
 {
-	p->euid = p->fsuid = 0;
+	p->euid = 0;
+	task_setfsuid(p, 0);
 	return;
 }
 
#1 lore raw

Hmm..
your <linux/cred.h> file exposes "struct ucred" to user space (or at
least has a #ifdef __KERNEL__ that does not protect it). Why?

Also, I don't see how this is going to solve the credential clone problem, which basically says that sometimes you do _not_ want to do COW on the credentials (when changing them when they are shared with other threads) and sometimes you do (when changing them when they are shared with a background filesystem lookup).

Any ideas on that?

(And I _really_ don't like those trivial inline functions in [1/3] - I think it's much better to just show that we're doing a pointer dereference than trying to hide it behind some silly "current_fsuid()" inline function).

Linus

#2 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

" " == Linus Torvalds <[email protected]> writes:

> Also, I don't see how this is going to solve the credential > clone problem, which basically says that sometimes you do _not_ > want to do COW on the credentials (when changing them when they > are shared with other threads) and sometimes you do (when > changing them when they are shared with a background filesystem > lookup).

> Any ideas on that?

task->ucred is not the unit for implementing shared creds between threads. In the BSD design (on which this is loosely based) the ucred is a structure designed for caching user credentials so that you can pass them around inside the VFS. It is supposed to ensure that despite shared creds, we always use the same authentication for a given 'atomic' sequence of VFS ops.

For instance the sequence

  lookup(cred, dir, dentry)
  permission(cred, dentry->d_inode, MAY_WRITE);
  dentry_open(cred, dentry, mnt, FMODE_WRITE)

should all be using the same credentials, so here you will always want 'cred' to be a COW structure even if it is shared among several threads.

For CLONE_CRED, the idea is that once we've got the ucred firmly established as part of the VFS' API, we can add the concept of process credentials ('pcred' in *BSD parlance). The latter are indeed shared between the threads, and their contents are *not* COW. They will be something of the form

struct pcred {
       atomic_t	count;
       uid_t	uid, euid, suid;
       gid_t	gid, egid, sgid;
       struct ucred  *cred;
       kernel_cap_t ... capabilities ...
       struct user_struct *user;
};

For 'pcred' any one thread could be allowed to swap any one of its member elements without breaking the filesystem auth checking premises. i.e. it would still not be allowed to change the member elements of cred, but it could swap out one struct ucred for another.

> (And I _really_ don't like those trivial inline functions in > [1/3] - I think it's much better to just show that we're doing > a pointer dereference than trying to hide it behind some silly > "current_fsuid()" inline function).

The current_fsuid() thing is an artifice that is designed to make the actual patches smaller and more readable. I would expect all of them to have disappeared once we get to the point of full VFS support for ucreds in place. When that is done, I would something like open() should be doing a single

cred = current_getucred();

and then passing the resulting ucred directly down to the file subsystems. References to current_fsuid() will be unnecessary and indeed *wrong* once we get to that point, since they will break the 'atomicity' premise as described above.
In fact, at some point we could probably set
#define current_fsuid() BUG()

Cheers,
Trond

#3 lore raw
Quoted 3 lines · Trond Myklebust

task->ucred is not the unit for implementing shared creds between threads.

Fair enough, but some solution to this has to be found. I do not want to apply something that simply cannot work sanely, and I want to have at least a _plan_ on the table.

Quoted 8 lines
struct pcred {
       atomic_t	count;
       uid_t	uid, euid, suid;
       gid_t	gid, egid, sgid;
       struct ucred  *cred;
       kernel_cap_t ... capabilities ...
       struct user_struct *user;
};

Ok, that sounds reasonable, except the naming just has to go. Yes, things like "pcred/ucred" may be what BSD uses, but BSD uses things like "uarea" too, which just isn't the Linux way. The names should make sense _without_ having to have single-letter differences.

This really ties in with the patches Dave has done (which are equivalent to your "pcred"), and I'd like to see them work together in practice.

(I would suggest calling the FS credentials "struct vfs_cred", while the regular user credentials might just be "struct cred". Other suggestions?)

Linus

#4 lore raw
Quoted 9 lines · Linus Torvalds
Quoted 8 lines
struct pcred {
       atomic_t	count;
       uid_t	uid, euid, suid;
       gid_t	gid, egid, sgid;
       struct ucred  *cred;
       kernel_cap_t ... capabilities ...
       struct user_struct *user;
};

Needs fsuid too, and space for the security LSM modules to attach private information. SELinux needs a few more credentials than base kernels!

#5 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

" " == Alan Cox <[email protected]> writes:

> Needs fsuid too,

Sorry? 'fsuid' and 'fsgid' are supposed to be represented by the 'struct ucred' (or 'vfs_cred').

Cheers,
Trond

#6 lore raw
In reply to Alan Cox
Quoted 12 lines · Alan Cox
Quoted 9 lines · Linus Torvalds
Quoted 8 lines
struct pcred {
       atomic_t	count;
       uid_t	uid, euid, suid;
       gid_t	gid, egid, sgid;
       struct ucred  *cred;
       kernel_cap_t ... capabilities ...
       struct user_struct *user;
};
Quoted 3 lines

Needs fsuid too, and space for the security LSM modules to attach private information. SELinux needs a few more credentials than base kernels!

Note that "fsuid" would _be_ the "struct ucred *" thing (but hopefully
renamed: "ucred" is a really bad name, since it has almost nothing to do with the user, and has everything to do with VFS. I don't know where BSD got the "u" from).

Think of "fsuid" and "fsgid" as small special-case "filesystem credentials" already - they're separate from the regular uid/gid because they have different sharing semantics (uid/euid are visible to signals, the FS credentials aren't).

So I dont' think that is a problem.

The issue about attaching additional credential information (both to the user credentials _and_ to the VFS credentials) is true, though.

Linus

#7 lore raw
In reply to Alan Cox
Quoted 4 lines · * Alan Cox ([email protected]) wrote:

Needs fsuid too, and space for the security LSM modules to attach private information. SELinux needs a few more credentials than base kernels!

Yes, I agree. LSM is just using opaque blobs, so it's simple enough to add.

thanks,
-chris

Signature · 1 line
Linux Security Modules     http://lsm.immunix.org     http://lsm.bkbits.net
#8 lore raw
In reply to Alan Cox
Quoted 12 lines · Alan Cox
Quoted 9 lines · Linus Torvalds
Quoted 8 lines
struct pcred {
       atomic_t	count;
       uid_t	uid, euid, suid;
       gid_t	gid, egid, sgid;
       struct ucred  *cred;
       kernel_cap_t ... capabilities ...
       struct user_struct *user;
};
Quoted 3 lines

Needs fsuid too, and space for the security LSM modules to attach private information. SELinux needs a few more credentials than base kernels!

Note that "fsuid" would _be_ the "struct ucred *" thing (but hopefully
renamed: "ucred" is a really bad name, since it has almost nothing to do with the user, and has everything to do with VFS. I don't know where BSD got the "u" from).

Think of "fsuid" and "fsgid" as small special-case "filesystem credentials" already - they're separate from the regular uid/gid because they have different sharing semantics (uid/euid are visible to signals, the FS credentials aren't).

So I dont' think that is a problem.

The issue about attaching additional credential information (both to the user credentials _and_ to the VFS credentials) is true, though.

Linus

#9 lore raw
In reply to Alan Cox
Quoted 11 lines · Alan Cox
Quoted 9 lines · Linus Torvalds
Quoted 8 lines
struct pcred {
       atomic_t	count;
       uid_t	uid, euid, suid;
       gid_t	gid, egid, sgid;
       struct ucred  *cred;
       kernel_cap_t ... capabilities ...
       struct user_struct *user;
};
Quoted 3 lines

Needs fsuid too, and space for the security LSM modules to attach private information. SELinux needs a few more credentials than base kernels!

Why worry about what SELinux needs, since it is proprietary, and may not even be legal to distribute? Perhaps there is some other set of security plugins that actually matter.

Signature · 1 line
Daniel
#10 lore raw
Quoted 3 lines · Daniel Phillips

Why worry about what SELinux needs, since it is proprietary, and may not even be legal to distribute? Perhaps there is some other set of security plugins that actually matter.

SELinux is GPL. Americans may not be allowed to use it but that doesn't make it proprietary. As it happens there are several very plausible ways of working around the bogus patents anyway

#11 lore raw
In reply to Daniel Phillips
Quoted 3 lines · Daniel Phillips

Why worry about what SELinux needs, since it is proprietary, and may not even be legal to distribute? Perhaps there is some other set of security plugins that actually matter.

SELinux is GPL. Americans may not be allowed to use it but that doesn't make it proprietary. As it happens there are several very plausible ways of working around the bogus patents anyway

#12 lore raw
In reply to Linus Torvalds
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

" " == Linus Torvalds <[email protected]> writes:

> On Sat, 31 Aug 2002, Trond Myklebust wrote:
>>
>> task-> ucred is not the unit for implementing shared creds >> between threads.

> Fair enough, but some solution to this has to be found. I do > not want to apply something that simply cannot work sanely, and > I want to have at least a _plan_ on the table.

The plan is pretty rough at the moment, and not all of the code has been written yet. Basically, it boils down to:

Add the COW structure 'vfs_cred'

Make VFS changes to replace all instances of current->fsuid/fsgid/ngroups/groups with a single 'vfs_cred' that never can be changed by CLONE_CRED after we call down into the VFS. This means that we have to actually invent mechanisms for passing those creds down to address_space_operations, inode_operations.

Add the more volatile 'pcred' a.k.a. 'task_cred' (see below), which forms the necessary basis for CLONE_CRED tasks.

Audit 'task_cred' to ensure that CLONE_CRED won't introduce new security holes. Things like capabilities, which can sometimes override 'standard credentials', will for instance need to be looked into.

.... end of process -> add CLONE_CRED flag to 'clone()'

> This really ties in with the patches Dave has done (which are > equivalent to your "pcred"), and I'd like to see them work > together in practice.

Dave and I have already been discussing this on l-k, and we appear now to be in agreement on general procedure. Dave has said that he'd like to contribute once we get vfs_cred well established. I'm hoping he'll help out on the latter too ;-)

> (I would suggest calling the FS credentials "struct vfs_cred", > while the regular user credentials might just be "struct cred". > Other suggestions?)

I'm fine about 'vfs'cred', but how about 'struct task_cred' instead for the second? That ties them directly in to the task_struct, and avoids people mistaking for 'ucred'. Since the distinction between COW and non-COW is pretty profound, it might be useful in order to help emphasize to which category they belong...

Cheers,
Trond

#13 lore raw
Quoted 6 lines · Trond Myklebust

Add the COW structure 'vfs_cred'

Make VFS changes to replace all instances of current->fsuid/fsgid/ngroups/groups with a single 'vfs_cred' that never can be changed by CLONE_CRED after we call down into the VFS.

Yup, I think I like that plan.

One thing that may be interesting (I certainly think it migth be), would be to add a "struct user_struct *" pointer to the vfs_cred as well. This is because I'd just _love_ to have that "user_struct" fed down to the VFS layer, since I think that is where we may some day want to put things like user-supplied cryptographic keys etc.

The advantage of "struct user_struct" (as opposed to just a uid_t) is that it can have information that lives for the whole duration of a login, and it's really the only kind of data structure in the kernel that can track that kind of information.

Quoted 6 lines

> (I would suggest calling the FS credentials "struct vfs_cred", > while the regular user credentials might just be "struct cred". > Other suggestions?)

I'm fine about 'vfs_cred', but how about 'struct task_cred' instead for the second?

Sounds fine to me.

Linus

#14 lore raw

[email protected] (Linus Torvalds) wrote on 30.08.02 in <[email protected]>:

Quoted 10 lines

One thing that may be interesting (I certainly think it migth be), would be to add a "struct user_struct *" pointer to the vfs_cred as well. This is because I'd just _love_ to have that "user_struct" fed down to the VFS layer, since I think that is where we may some day want to put things like user-supplied cryptographic keys etc.

The advantage of "struct user_struct" (as opposed to just a uid_t) is that it can have information that lives for the whole duration of a login, and it's really the only kind of data structure in the kernel that can track that kind of information.

In that case, wouldn't "struct session" be a better name?

MfG Kai

#15 lore raw
In reply to Linus Torvalds
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

" " == Linus Torvalds <[email protected]> writes:

> One thing that may be interesting (I certainly think it migth > be), would be to add a "struct user_struct *" pointer to the > vfs_cred as well. This is because I'd just _love_ to have that > "user_struct" fed down to the VFS layer, since I think that is > where we may some day want to put things like user-supplied > cryptographic keys etc.

> The advantage of "struct user_struct" (as opposed to just a > uid_t) is that it can have information that lives for the whole > duration of a login, and it's really the only kind of data > structure in the kernel that can track that kind of > information.

No problem at all with this. Indeed I agree it makes a lot of sense...

The only thing is if you'd allow me to do it as an incremental patch to the initial one?
I don't see 'struct user_struct *' as replacing the existing 'uid' entry, so there should be no need to change the existing API. Instead, we can just add in the necessary call to alloc_uid() to vfscred_create() and/or setfsuid()...

Cheers,
Trond

#16 lore raw
Quoted 15 lines · Trond Myklebust
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

" " == Linus Torvalds <[email protected]> writes:

> One thing that may be interesting (I certainly think it migth > be), would be to add a "struct user_struct *" pointer to the > vfs_cred as well. This is because I'd just _love_ to have that > "user_struct" fed down to the VFS layer, since I think that is > where we may some day want to put things like user-supplied > cryptographic keys etc.

> The advantage of "struct user_struct" (as opposed to just a > uid_t) is that it can have information that lives for the whole > duration of a login, and it's really the only kind of data > structure in the kernel that can track that kind of > information.

Quoted 8 lines

No problem at all with this. Indeed I agree it makes a lot of sense...

The only thing is if you'd allow me to do it as an incremental patch to the initial one?
I don't see 'struct user_struct *' as replacing the existing 'uid' entry, so there should be no need to change the existing API. Instead, we can just add in the necessary call to alloc_uid() to vfscred_create() and/or setfsuid()...

I really do like Kai's name suggestion 'struct session'.

Signature · 1 line
Daniel
#17 lore raw
In reply to Trond Myklebust
Quoted 3 lines · Trond Myklebust

task->ucred is not the unit for implementing shared creds between threads.

Fair enough, but some solution to this has to be found. I do not want to apply something that simply cannot work sanely, and I want to have at least a _plan_ on the table.

Quoted 8 lines
struct pcred {
       atomic_t	count;
       uid_t	uid, euid, suid;
       gid_t	gid, egid, sgid;
       struct ucred  *cred;
       kernel_cap_t ... capabilities ...
       struct user_struct *user;
};

Ok, that sounds reasonable, except the naming just has to go. Yes, things like "pcred/ucred" may be what BSD uses, but BSD uses things like "uarea" too, which just isn't the Linux way. The names should make sense _without_ having to have single-letter differences.

This really ties in with the patches Dave has done (which are equivalent to your "pcred"), and I'd like to see them work together in practice.

(I would suggest calling the FS credentials "struct vfs_cred", while the regular user credentials might just be "struct cred". Other suggestions?)

Linus

#18 lore raw
In reply to Trond Myklebust
Quoted 11 lines · Trond Myklebust

Introduce basic *BSD style user credentials of the form

struct ucred {
       atomic_t	count;
       uid_t	uid;
       gid_t	gid;
       int	ngroups;
       gid_t	*groups;
};

and replace fsuid, fsgid, ngroups, groups in the struct task.

What about the fs member in struct task?