-/* $OpenBSD: kern_pledge.c,v 1.24 2015/10/14 04:05:43 deraadt Exp $ */
+/* $OpenBSD: kern_pledge.c,v 1.25 2015/10/14 14:24:03 deraadt Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
return (EFAULT);
}
+int
+pledge_chown_check(struct proc *p, uid_t uid, gid_t gid)
+{
+ if ((p->p_p->ps_flags & PS_PLEDGE) == 0)
+ return (0);
+ if (uid != -1 && uid != p->p_ucred->cr_uid)
+ return (EPERM);
+ if (gid != -1 && !groupmember(gid, p->p_ucred))
+ return (EPERM);
+ return (0);
+}
+
int
pledge_adjtime_check(struct proc *p, const void *v)
{
-/* $OpenBSD: vfs_syscalls.c,v 1.229 2015/10/09 01:10:27 deraadt Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.230 2015/10/14 14:24:03 deraadt Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/proc.h>
+#include <sys/pledge.h>
#include <sys/uio.h>
#include <sys/malloc.h>
#include <sys/pool.h>
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
else {
- if ((p->p_p->ps_flags & PS_PLEDGE) &&
- ((uid != -1 && uid != p->p_ucred->cr_uid) ||
- (gid != -1 && gid != p->p_ucred->cr_gid))) {
- error = EPERM;
+ if ((error = pledge_chown_check(p, uid, gid)))
goto out;
- }
if ((uid != -1 || gid != -1) &&
(suser(p, 0) || suid_clear)) {
error = VOP_GETATTR(vp, &vattr, p->p_ucred, p);
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
else {
- if ((p->p_p->ps_flags & PS_PLEDGE) &&
- ((uid != -1 && uid != p->p_ucred->cr_uid) ||
- (gid != -1 && gid != p->p_ucred->cr_gid))) {
- error = EPERM;
+ if ((error = pledge_chown_check(p, uid, gid)))
goto out;
- }
if ((uid != -1 || gid != -1) &&
(suser(p, 0) || suid_clear)) {
error = VOP_GETATTR(vp, &vattr, p->p_ucred, p);
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
else {
- if ((p->p_p->ps_flags & PS_PLEDGE) &&
- ((uid != -1 && uid != p->p_ucred->cr_uid) ||
- (gid != -1 && gid != p->p_ucred->cr_gid))) {
- error = EPERM;
+ if ((error = pledge_chown_check(p, uid, gid)))
goto out;
- }
if ((uid != -1 || gid != -1) &&
(suser(p, 0) || suid_clear)) {
error = VOP_GETATTR(vp, &vattr, p->p_ucred, p);
-/* $OpenBSD: pledge.h,v 1.1 2015/10/09 01:10:27 deraadt Exp $ */
+/* $OpenBSD: pledge.h,v 1.2 2015/10/14 14:24:03 deraadt Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
int pledge_cmsg_send(struct proc *p, struct mbuf *control);
int pledge_cmsg_recv(struct proc *p, struct mbuf *control);
int pledge_sysctl_check(struct proc *p, int namelen, int *name, void *new);
+int pledge_chown_check(struct proc *p, uid_t, gid_t);
int pledge_adjtime_check(struct proc *p, const void *v);
int pledge_recvfrom_check(struct proc *p, void *from);
int pledge_sendto_check(struct proc *p, const void *to);