Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Hijack the credentials used to evaluate access, to ...



details:   https://anonhg.NetBSD.org/src/rev/4273ae5e6c95
branches:  trunk
changeset: 514669:4273ae5e6c95
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Sep 08 02:05:39 2001 +0000

description:
Hijack the credentials used to evaluate access, to avoid a potential lwp
race by modifying the proc's credentials temporarily. From Bill Sommerfeld.
Thanks for forcing me to do this right :-)

diffstat:

 sys/kern/vfs_syscalls.c |  18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diffs (47 lines):

diff -r baad90f9b37c -r 4273ae5e6c95 sys/kern/vfs_syscalls.c
--- a/sys/kern/vfs_syscalls.c   Sat Sep 08 02:02:04 2001 +0000
+++ b/sys/kern/vfs_syscalls.c   Sat Sep 08 02:05:39 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_syscalls.c,v 1.168 2001/07/24 15:39:31 assar Exp $ */
+/*     $NetBSD: vfs_syscalls.c,v 1.169 2001/09/08 02:05:39 christos Exp $      */
 
 /*
  * Copyright (c) 1989, 1993
@@ -1895,19 +1895,20 @@
                syscallarg(const char *) path;
                syscallarg(int) flags;
        } */ *uap = v;
-       struct ucred *cred = p->p_ucred;
+       struct ucred *cred = crget();
        struct vnode *vp;
-       int error, flags, t_gid, t_uid;
+       int error, flags;
        struct nameidata nd;
 
-       t_uid = cred->cr_uid;
-       t_gid = cred->cr_gid;
+       (void)memcpy(cred, p->p_ucred, sizeof(*cred));
        cred->cr_uid = p->p_cred->p_ruid;
        cred->cr_gid = p->p_cred->p_rgid;
        NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
            SCARG(uap, path), p);
+       /* Override default credentials */
+       nd.ni_cnd.cn_cred = cred;
        if ((error = namei(&nd)) != 0)
-               goto out1;
+               goto out;
        vp = nd.ni_vp;
 
        /* Flags == 0 means only check for existence. */
@@ -1925,9 +1926,8 @@
                        error = vn_writechk(vp);
        }
        vput(vp);
-out1:
-       cred->cr_uid = t_uid;
-       cred->cr_gid = t_gid;
+out:
+       crfree(cred);
        return (error);
 }
 



Home | Main Index | Thread Index | Old Index