summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortholo <tholo@openbsd.org>1996-08-08 04:23:03 +0000
committertholo <tholo@openbsd.org>1996-08-08 04:23:03 +0000
commit50fde5c4f1f810cf9bd35ab48b73035237dff704 (patch)
tree075fd36a3d92220eb6860ce89da82165b8613d00
parentReset the cycle counter at boot on P5 or better wether or not we have been (diff)
downloadwireguard-openbsd-50fde5c4f1f810cf9bd35ab48b73035237dff704.tar.xz
wireguard-openbsd-50fde5c4f1f810cf9bd35ab48b73035237dff704.zip
Lose the SUID bit if owner changes in {,f}chown
Lose the SGID bit if group changes in {,f}chown
-rw-r--r--sys/kern/vfs_syscalls.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 788aa3b2ed0..783d9779c59 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls.c,v 1.10 1996/08/02 19:59:01 tholo Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.11 1996/08/08 04:23:03 tholo Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
@@ -1487,6 +1487,7 @@ sys_chown(p, v, retval)
struct vattr vattr;
int error;
struct nameidata nd;
+ u_short mode;
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
if ((error = namei(&nd)) != 0)
@@ -1497,11 +1498,23 @@ sys_chown(p, v, retval)
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
else {
+ error = VOP_GETATTR(vp, &vattr, p->p_ucred, p);
+ if (error)
+ goto out;
+ mode = vattr.va_mode;
+ if (vattr.va_uid != SCARG(uap, uid))
+ mode &= ~VSUID;
+ if (vattr.va_gid != SCARG(uap, gid))
+ mode &= ~VSGID;
+ if (mode == vattr.va_mode)
+ mode = VNOVAL;
VATTR_NULL(&vattr);
vattr.va_uid = SCARG(uap, uid);
vattr.va_gid = SCARG(uap, gid);
+ vattr.va_mode = mode;
error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
}
+out:
vput(vp);
return (error);
}
@@ -1525,6 +1538,7 @@ sys_fchown(p, v, retval)
struct vattr vattr;
int error;
struct file *fp;
+ u_short mode;
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
@@ -1534,11 +1548,23 @@ sys_fchown(p, v, retval)
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
else {
+ error = VOP_GETATTR(vp, &vattr, p->p_ucred, p);
+ if (error)
+ goto out;
+ mode = vattr.va_mode;
+ if (vattr.va_uid != SCARG(uap, uid))
+ mode &= ~VSUID;
+ if (vattr.va_gid != SCARG(uap, gid))
+ mode &= ~VSGID;
+ if (mode == vattr.va_mode)
+ mode = VNOVAL;
VATTR_NULL(&vattr);
vattr.va_uid = SCARG(uap, uid);
vattr.va_gid = SCARG(uap, gid);
+ vattr.va_mode = mode;
error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
}
+out:
VOP_UNLOCK(vp);
return (error);
}