1994-09-13 14:47:38 +00:00
|
|
|
/* $NetBSD: sysv_ipc.c,v 1.7 1994/06/29 06:33:11 cgd Exp $ */
|
2005-01-06 23:35:40 +00:00
|
|
|
/*-
|
1994-09-13 14:47:38 +00:00
|
|
|
* Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
|
Restore sysv_ipc.c:1.30, which was backed out due to interactions with
System V shared memory, now believed fixed in sysv_shm.c:1.109:
date: 2006/11/06 13:42:01; author: rwatson; state: Exp; lines: +65 -37
Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.
Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>
This restores fine-grained privilege support to System V IPC.
PR: 106078
2007-02-19 22:59:23 +00:00
|
|
|
* Copyright (c) 2006 nCircle Network Security, Inc.
|
1994-09-13 14:47:38 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
Restore sysv_ipc.c:1.30, which was backed out due to interactions with
System V shared memory, now believed fixed in sysv_shm.c:1.109:
date: 2006/11/06 13:42:01; author: rwatson; state: Exp; lines: +65 -37
Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.
Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>
This restores fine-grained privilege support to System V IPC.
PR: 106078
2007-02-19 22:59:23 +00:00
|
|
|
* This software was developed by Robert N. M. Watson for the TrustedBSD
|
|
|
|
* Project under contract to nCircle Network Security, Inc.
|
|
|
|
*
|
1994-09-13 14:47:38 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Herb Peyerl.
|
|
|
|
* 4. The name of Herb Peyerl may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2009-06-24 21:10:52 +00:00
|
|
|
#include "opt_compat.h"
|
1996-01-05 16:38:03 +00:00
|
|
|
#include "opt_sysvipc.h"
|
|
|
|
|
1994-09-13 14:47:38 +00:00
|
|
|
#include <sys/param.h>
|
2000-10-29 16:06:56 +00:00
|
|
|
#include <sys/systm.h>
|
2000-12-01 08:57:47 +00:00
|
|
|
#include <sys/sem.h>
|
|
|
|
#include <sys/shm.h>
|
1996-01-08 04:30:48 +00:00
|
|
|
#include <sys/ipc.h>
|
Restore sysv_ipc.c:1.30, which was backed out due to interactions with
System V shared memory, now believed fixed in sysv_shm.c:1.109:
date: 2006/11/06 13:42:01; author: rwatson; state: Exp; lines: +65 -37
Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.
Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>
This restores fine-grained privilege support to System V IPC.
PR: 106078
2007-02-19 22:59:23 +00:00
|
|
|
#include <sys/priv.h>
|
1999-04-27 12:21:16 +00:00
|
|
|
#include <sys/proc.h>
|
1997-11-18 12:52:10 +00:00
|
|
|
#include <sys/ucred.h>
|
1996-01-08 04:30:48 +00:00
|
|
|
|
2000-12-01 08:57:47 +00:00
|
|
|
void (*shmfork_hook)(struct proc *, struct proc *) = NULL;
|
2003-01-13 23:04:32 +00:00
|
|
|
void (*shmexit_hook)(struct vmspace *) = NULL;
|
2000-12-01 08:57:47 +00:00
|
|
|
|
|
|
|
/* called from kern_fork.c */
|
|
|
|
void
|
|
|
|
shmfork(p1, p2)
|
|
|
|
struct proc *p1, *p2;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (shmfork_hook != NULL)
|
|
|
|
shmfork_hook(p1, p2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* called from kern_exit.c */
|
|
|
|
void
|
2003-01-13 23:04:32 +00:00
|
|
|
shmexit(struct vmspace *vm)
|
2000-12-01 08:57:47 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (shmexit_hook != NULL)
|
2003-01-13 23:04:32 +00:00
|
|
|
shmexit_hook(vm);
|
2000-12-01 08:57:47 +00:00
|
|
|
return;
|
|
|
|
}
|
1994-09-13 14:47:38 +00:00
|
|
|
|
|
|
|
/*
|
2004-10-22 12:12:40 +00:00
|
|
|
* Check for IPC permission.
|
|
|
|
*
|
|
|
|
* Note: The MAC Framework does not require any modifications to the
|
|
|
|
* ipcperm() function, as access control checks are performed throughout the
|
|
|
|
* implementation of each primitive. Those entry point calls complement the
|
Restore sysv_ipc.c:1.30, which was backed out due to interactions with
System V shared memory, now believed fixed in sysv_shm.c:1.109:
date: 2006/11/06 13:42:01; author: rwatson; state: Exp; lines: +65 -37
Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.
Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>
This restores fine-grained privilege support to System V IPC.
PR: 106078
2007-02-19 22:59:23 +00:00
|
|
|
* ipcperm() discertionary checks. Unlike file system discretionary access
|
|
|
|
* control, the original create of an object is given the same rights as the
|
|
|
|
* current owner.
|
1994-09-13 14:47:38 +00:00
|
|
|
*/
|
|
|
|
int
|
Restore sysv_ipc.c:1.30, which was backed out due to interactions with
System V shared memory, now believed fixed in sysv_shm.c:1.109:
date: 2006/11/06 13:42:01; author: rwatson; state: Exp; lines: +65 -37
Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.
Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>
This restores fine-grained privilege support to System V IPC.
PR: 106078
2007-02-19 22:59:23 +00:00
|
|
|
ipcperm(struct thread *td, struct ipc_perm *perm, int acc_mode)
|
1994-09-13 14:47:38 +00:00
|
|
|
{
|
2002-02-27 18:32:23 +00:00
|
|
|
struct ucred *cred = td->td_ucred;
|
Restore sysv_ipc.c:1.30, which was backed out due to interactions with
System V shared memory, now believed fixed in sysv_shm.c:1.109:
date: 2006/11/06 13:42:01; author: rwatson; state: Exp; lines: +65 -37
Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.
Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>
This restores fine-grained privilege support to System V IPC.
PR: 106078
2007-02-19 22:59:23 +00:00
|
|
|
int error, obj_mode, dac_granted, priv_granted;
|
|
|
|
|
|
|
|
dac_granted = 0;
|
|
|
|
if (cred->cr_uid == perm->cuid || cred->cr_uid == perm->uid) {
|
|
|
|
obj_mode = perm->mode;
|
|
|
|
dac_granted |= IPC_M;
|
|
|
|
} else if (groupmember(perm->gid, cred) ||
|
|
|
|
groupmember(perm->cgid, cred)) {
|
|
|
|
obj_mode = perm->mode;
|
|
|
|
obj_mode <<= 3;
|
2003-05-31 23:31:51 +00:00
|
|
|
} else {
|
Restore sysv_ipc.c:1.30, which was backed out due to interactions with
System V shared memory, now believed fixed in sysv_shm.c:1.109:
date: 2006/11/06 13:42:01; author: rwatson; state: Exp; lines: +65 -37
Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.
Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>
This restores fine-grained privilege support to System V IPC.
PR: 106078
2007-02-19 22:59:23 +00:00
|
|
|
obj_mode = perm->mode;
|
|
|
|
obj_mode <<= 6;
|
1994-09-13 14:47:38 +00:00
|
|
|
}
|
|
|
|
|
Restore sysv_ipc.c:1.30, which was backed out due to interactions with
System V shared memory, now believed fixed in sysv_shm.c:1.109:
date: 2006/11/06 13:42:01; author: rwatson; state: Exp; lines: +65 -37
Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.
Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>
This restores fine-grained privilege support to System V IPC.
PR: 106078
2007-02-19 22:59:23 +00:00
|
|
|
/*
|
|
|
|
* While the System V IPC permission model allows IPC_M to be
|
|
|
|
* granted, as part of the mode, our implementation requires
|
|
|
|
* privilege to adminster the object if not the owner or creator.
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
if (obj_mode & IPC_M)
|
|
|
|
dac_granted |= IPC_M;
|
|
|
|
#endif
|
|
|
|
if (obj_mode & IPC_R)
|
|
|
|
dac_granted |= IPC_R;
|
|
|
|
if (obj_mode & IPC_W)
|
|
|
|
dac_granted |= IPC_W;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simple case: all required rights are granted by DAC.
|
|
|
|
*/
|
|
|
|
if ((dac_granted & acc_mode) == acc_mode)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Privilege is required to satisfy the request.
|
|
|
|
*/
|
|
|
|
priv_granted = 0;
|
|
|
|
if ((acc_mode & IPC_M) && !(dac_granted & IPC_M)) {
|
2007-06-12 00:12:01 +00:00
|
|
|
error = priv_check(td, PRIV_IPC_ADMIN);
|
Restore sysv_ipc.c:1.30, which was backed out due to interactions with
System V shared memory, now believed fixed in sysv_shm.c:1.109:
date: 2006/11/06 13:42:01; author: rwatson; state: Exp; lines: +65 -37
Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.
Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>
This restores fine-grained privilege support to System V IPC.
PR: 106078
2007-02-19 22:59:23 +00:00
|
|
|
if (error == 0)
|
|
|
|
priv_granted |= IPC_M;
|
2003-05-31 23:17:30 +00:00
|
|
|
}
|
Restore sysv_ipc.c:1.30, which was backed out due to interactions with
System V shared memory, now believed fixed in sysv_shm.c:1.109:
date: 2006/11/06 13:42:01; author: rwatson; state: Exp; lines: +65 -37
Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.
Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>
This restores fine-grained privilege support to System V IPC.
PR: 106078
2007-02-19 22:59:23 +00:00
|
|
|
|
|
|
|
if ((acc_mode & IPC_R) && !(dac_granted & IPC_R)) {
|
2007-06-12 00:12:01 +00:00
|
|
|
error = priv_check(td, PRIV_IPC_READ);
|
Restore sysv_ipc.c:1.30, which was backed out due to interactions with
System V shared memory, now believed fixed in sysv_shm.c:1.109:
date: 2006/11/06 13:42:01; author: rwatson; state: Exp; lines: +65 -37
Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.
Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>
This restores fine-grained privilege support to System V IPC.
PR: 106078
2007-02-19 22:59:23 +00:00
|
|
|
if (error == 0)
|
|
|
|
priv_granted |= IPC_R;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((acc_mode & IPC_W) && !(dac_granted & IPC_W)) {
|
2007-06-12 00:12:01 +00:00
|
|
|
error = priv_check(td, PRIV_IPC_WRITE);
|
Restore sysv_ipc.c:1.30, which was backed out due to interactions with
System V shared memory, now believed fixed in sysv_shm.c:1.109:
date: 2006/11/06 13:42:01; author: rwatson; state: Exp; lines: +65 -37
Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.
Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>
This restores fine-grained privilege support to System V IPC.
PR: 106078
2007-02-19 22:59:23 +00:00
|
|
|
if (error == 0)
|
|
|
|
priv_granted |= IPC_W;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((dac_granted | priv_granted) & acc_mode) == acc_mode)
|
|
|
|
return (0);
|
|
|
|
else
|
|
|
|
return (EACCES);
|
1994-09-13 14:47:38 +00:00
|
|
|
}
|
2009-06-24 21:10:52 +00:00
|
|
|
|
|
|
|
#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
|
|
|
|
defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
|
|
|
|
void
|
|
|
|
ipcperm_old2new(struct ipc_perm_old *old, struct ipc_perm *new)
|
|
|
|
{
|
|
|
|
|
|
|
|
new->cuid = old->cuid;
|
|
|
|
new->cgid = old->cgid;
|
|
|
|
new->uid = old->uid;
|
|
|
|
new->gid = old->gid;
|
|
|
|
new->mode = old->mode;
|
|
|
|
new->seq = old->seq;
|
|
|
|
new->key = old->key;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ipcperm_new2old(struct ipc_perm *new, struct ipc_perm_old *old)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* XXX: How to handle ID's > USHORT_MAX? */
|
|
|
|
old->cuid = new->cuid;
|
|
|
|
old->cgid = new->cgid;
|
|
|
|
old->uid = new->uid;
|
|
|
|
old->gid = new->gid;
|
|
|
|
old->mode = new->mode;
|
|
|
|
old->seq = new->seq;
|
|
|
|
old->key = new->key;
|
|
|
|
}
|
|
|
|
#endif
|