Deleted Added
full compact
uipc_sem.c (163606) uipc_sem.c (164033)
1/*-
2 * Copyright (c) 2002 Alfred Perlstein <alfred@FreeBSD.org>
3 * Copyright (c) 2003-2005 SPARTA, Inc.
4 * Copyright (c) 2005 Robert N. M. Watson
5 * All rights reserved.
6 *
7 * This software was developed for the FreeBSD Project in part by Network
8 * Associates Laboratories, the Security Research Division of Network

--- 18 unchanged lines hidden (view full) ---

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2002 Alfred Perlstein <alfred@FreeBSD.org>
3 * Copyright (c) 2003-2005 SPARTA, Inc.
4 * Copyright (c) 2005 Robert N. M. Watson
5 * All rights reserved.
6 *
7 * This software was developed for the FreeBSD Project in part by Network
8 * Associates Laboratories, the Security Research Division of Network

--- 18 unchanged lines hidden (view full) ---

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/kern/uipc_sem.c 163606 2006-10-22 11:52:19Z rwatson $");
35__FBSDID("$FreeBSD: head/sys/kern/uipc_sem.c 164033 2006-11-06 13:42:10Z rwatson $");
36
37#include "opt_mac.h"
38#include "opt_posix.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/sysproto.h>
43#include <sys/eventhandler.h>
44#include <sys/kernel.h>
36
37#include "opt_mac.h"
38#include "opt_posix.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/sysproto.h>
43#include <sys/eventhandler.h>
44#include <sys/kernel.h>
45#include <sys/priv.h>
45#include <sys/proc.h>
46#include <sys/lock.h>
47#include <sys/mutex.h>
48#include <sys/module.h>
49#include <sys/condvar.h>
50#include <sys/sem.h>
51#include <sys/uio.h>
52#include <sys/syscall.h>

--- 361 unchanged lines hidden (view full) ---

414 return (error);
415}
416
417static int
418sem_perm(struct thread *td, struct ksem *ks)
419{
420 struct ucred *uc;
421
46#include <sys/proc.h>
47#include <sys/lock.h>
48#include <sys/mutex.h>
49#include <sys/module.h>
50#include <sys/condvar.h>
51#include <sys/sem.h>
52#include <sys/uio.h>
53#include <sys/syscall.h>

--- 361 unchanged lines hidden (view full) ---

415 return (error);
416}
417
418static int
419sem_perm(struct thread *td, struct ksem *ks)
420{
421 struct ucred *uc;
422
423 /*
424 * XXXRW: This permission routine appears to be incorrect. If the
425 * user matches, we shouldn't go on to the group if the user
426 * permissions don't allow the action? Not changed for now. To fix,
427 * change from a series of if (); if (); to if () else if () else...
428 */
422 uc = td->td_ucred;
423 DP(("sem_perm: uc(%d,%d) ks(%d,%d,%o)\n",
424 uc->cr_uid, uc->cr_gid,
425 ks->ks_uid, ks->ks_gid, ks->ks_mode));
429 uc = td->td_ucred;
430 DP(("sem_perm: uc(%d,%d) ks(%d,%d,%o)\n",
431 uc->cr_uid, uc->cr_gid,
432 ks->ks_uid, ks->ks_gid, ks->ks_mode));
426 if ((uc->cr_uid == ks->ks_uid && (ks->ks_mode & S_IWUSR) != 0) ||
427 (uc->cr_gid == ks->ks_gid && (ks->ks_mode & S_IWGRP) != 0) ||
428 (ks->ks_mode & S_IWOTH) != 0 || suser(td) == 0)
433 if ((uc->cr_uid == ks->ks_uid) && (ks->ks_mode & S_IWUSR) != 0)
429 return (0);
434 return (0);
430 return (EPERM);
435 if ((uc->cr_gid == ks->ks_gid) && (ks->ks_mode & S_IWGRP) != 0)
436 return (0);
437 if ((ks->ks_mode & S_IWOTH) != 0)
438 return (0);
439 return (priv_check(td, PRIV_SEM_WRITE));
431}
432
433static void
434sem_free(struct ksem *ks)
435{
436
437 nsems--;
438 if (ks->ks_onlist)

--- 565 unchanged lines hidden ---
440}
441
442static void
443sem_free(struct ksem *ks)
444{
445
446 nsems--;
447 if (ks->ks_onlist)

--- 565 unchanged lines hidden ---