Index: kern/kern_mac.c
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/kern/kern_mac.c,v
retrieving revision 1.107
diff -c -r1.107 kern_mac.c
*** kern/kern_mac.c	7 Mar 2002 17:18:25 -0000	1.107
--- kern/kern_mac.c	15 Mar 2002 10:01:43 -0000
***************
*** 70,75 ****
--- 70,77 ----
  #include <net/if.h>
  #include <net/if_var.h>
  
+ #include <sys/ipc.h>
+ 
  #ifdef MAC
  
  SYSCTL_DECL(_security);
***************
*** 104,109 ****
--- 106,116 ----
      &mac_enforce_socket, 0, "Enforce MAC policy on socket operations");
  TUNABLE_INT("security.mac.enforce_socket", &mac_enforce_socket);
  
+ static int	mac_enforce_ipc = 1;
+ SYSCTL_INT(_security_mac, OID_AUTO, enforce_ipc, CTLFLAG_RW,
+     &mac_enforce_socket, 0, "Enforce MAC policy on System V IPC operations");
+ TUNABLE_INT("security.mac.enforce_ipc", &mac_enforce_ipc);
+ 
  static int	mac_label_size = sizeof(struct mac);
  SYSCTL_INT(_security_mac, OID_AUTO, label_size, CTLFLAG_RD,
      &mac_label_size, 0, "Pre-compiled MAC label size");
***************
*** 1068,1073 ****
--- 1075,1101 ----
  
  	MAC_CHECK(cred_check_statfs, cred, mount);
  
+ 	return (error);
+ }
+ 
+ int
+ mac_check_ipc(struct ucred *cred,struct ipc_perm *perm, int mode)
+ {
+ 	int error, access;
+ 
+ 	if (!mac_enforce_ipc)
+ 		return (0);
+ 
+ 	access = 0;
+ 	if((mode & IPC_W) || (mode & IPC_M))
+ 		access |= IPC_WRITE;
+ 	if(mode & IPC_R)
+ 		access |= IPC_READ;
+ 
+ 	MAC_CHECK(ipc_cred_check_op, cred, &perm->label, access);
+ /*
+ int (*mpo_ipc_cred_check_op)(struct ucred *cred, struct mac *label, int access);
+ */
  	return (error);
  }
  
Index: kern/sysv_ipc.c
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/kern/sysv_ipc.c,v
retrieving revision 1.3
diff -c -r1.3 sysv_ipc.c
*** kern/sysv_ipc.c	5 Mar 2002 03:49:52 -0000	1.3
--- kern/sysv_ipc.c	15 Mar 2002 09:48:55 -0000
***************
*** 78,83 ****
--- 78,95 ----
  {
  	struct ucred *cred = td->td_ucred;
  
+ #ifdef MAC 
+ 	/*if(((mode & IPC_M) || (mode & IPC_W)) &&
+ 	   (!mac_equal(cred->label, perm->label)))
+ 		return (EACCES);
+ 	if((mode & IPC_R) && (!mac_dominate(cred->label, perm->label)))
+ 		return (EACCES);*/
+ 
+ 	if (mac_check_ipc(cred, perm, mode))
+ 		return (EACCES);
+ 
+ #endif
+ 
  	/* Check for user match. */
  	if (cred->cr_uid != perm->cuid && cred->cr_uid != perm->uid) {
  		if (mode & IPC_M)
Index: kern/sysv_msg.c
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/kern/sysv_msg.c,v
retrieving revision 1.3
diff -c -r1.3 sysv_msg.c
*** kern/sysv_msg.c	7 Mar 2002 18:35:10 -0000	1.3
--- kern/sysv_msg.c	15 Mar 2002 09:01:37 -0000
***************
*** 557,562 ****
--- 557,566 ----
  #ifdef MSG_DEBUG_OK
  		printf("msqid %d is available\n", msqid);
  #endif
+ #ifdef MAC
+ 		/* MACXXX: set msg queue label */
+ 		mac_copy_label(&cred->label, &msqptr->msg_perm.label);
+ #endif
  		msqptr->msg_perm.key = key;
  		msqptr->msg_perm.cuid = cred->cr_uid;
  		msqptr->msg_perm.uid = cred->cr_uid;
***************
*** 637,642 ****
--- 641,647 ----
  	}
  
  	msqptr = &msqids[msqid];
+ 
  	if (msqptr->msg_qbytes == 0) {
  #ifdef MSG_DEBUG_OK
  		printf("no such message queue id\n");
Index: kern/sysv_sem.c
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/kern/sysv_sem.c,v
retrieving revision 1.4
diff -c -r1.4 sysv_sem.c
*** kern/sysv_sem.c	7 Mar 2002 18:35:10 -0000	1.4
--- kern/sysv_sem.c	15 Mar 2002 09:12:05 -0000
***************
*** 761,766 ****
--- 761,772 ----
  #ifdef SEM_DEBUG
  		printf("semid %d is available\n", semid);
  #endif
+ 
+ #ifdef MAC
+ 		/* MACXXX: set semaphore label */
+ 		mac_copy_label(&cred->label, &sema[semid].sem_perm.label);
+ #endif
+ 
  		sema[semid].sem_perm.key = key;
  		sema[semid].sem_perm.cuid = cred->cr_uid;
  		sema[semid].sem_perm.uid = cred->cr_uid;
Index: kern/sysv_shm.c
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/kern/sysv_shm.c,v
retrieving revision 1.4
diff -c -r1.4 sysv_shm.c
*** kern/sysv_shm.c	7 Mar 2002 18:35:10 -0000	1.4
--- kern/sysv_shm.c	15 Mar 2002 09:16:28 -0000
***************
*** 327,332 ****
--- 327,333 ----
  		error = EINVAL;
  		goto done2;
  	}
+ 
  	error = ipcperm(td, &shmseg->shm_perm,
  	    (uap->shmflg & SHM_RDONLY) ? IPC_R : IPC_R|IPC_W);
  	if (error)
***************
*** 483,488 ****
--- 484,490 ----
  	if (!jail_sysvipc_allowed && jailed(td->td_ucred))
  		return (ENOSYS);
  	mtx_lock(&Giant);
+ 	/* MACXXX: what's that??? */
  	switch (uap->cmd) {
  	case IPC_INFO:
  		error = copyout( (caddr_t)&shminfo, uap->buf, sizeof( shminfo ) );
***************
*** 642,647 ****
--- 644,653 ----
  	 * In case we sleep in malloc(), mark the segment present but deleted
  	 * so that noone else tries to create the same key.
  	 */
+ #ifdef MAC
+ 	/* MACXXX: set shared memory segment label */
+ 	mac_copy_label(&cred->label, &shmseg->shm_perm.label);
+ #endif
  	shmseg->shm_perm.mode = SHMSEG_ALLOCATED | SHMSEG_REMOVED;
  	shmseg->shm_perm.key = uap->key;
  	shmseg->shm_perm.seq = (shmseg->shm_perm.seq + 1) & 0x7fff;
Index: security/babyaudit/babyaudit.c
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/security/babyaudit/babyaudit.c,v
retrieving revision 1.2
diff -c -r1.2 babyaudit.c
*** security/babyaudit/babyaudit.c	7 Mar 2002 17:18:26 -0000	1.2
--- security/babyaudit/babyaudit.c	15 Mar 2002 09:35:32 -0000
***************
*** 222,227 ****
--- 222,233 ----
  	return (0);
  }
  
+ static int
+ babyaudit_ipc_cred_check_op(struct ucred *cred, struct mac *label, int access)
+ {
+ 	return (0);
+ }
+ 
  static struct mac_policy_ops babyaudit_ops =
  {
  	NULL /* babyaudit_destroy */,
***************
*** 284,290 ****
  	NULL /* babyaudit_cred_check_sched_proc */,
  	NULL /* babyaudit_cred_check_signal_proc */,
  	NULL /* babyaudit_ifnet_check_send_mbuf */,
! 	NULL /* babyaudit_socket_check_receive_mbuf */
  };
  
  MAC_POLICY_SET(babyaudit_ops, trustedbsd_babyaudit, "TrustedBSD MAC/babyaudit");
--- 290,297 ----
  	NULL /* babyaudit_cred_check_sched_proc */,
  	NULL /* babyaudit_cred_check_signal_proc */,
  	NULL /* babyaudit_ifnet_check_send_mbuf */,
! 	NULL /* babyaudit_socket_check_receive_mbuf */,
! 	babyaudit_ipc_cred_check_op
  };
  
  MAC_POLICY_SET(babyaudit_ops, trustedbsd_babyaudit, "TrustedBSD MAC/babyaudit");
Index: security/mac_biba/mac_biba.c
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/security/mac_biba/mac_biba.c,v
retrieving revision 1.21
diff -c -r1.21 mac_biba.c
*** security/mac_biba/mac_biba.c	7 Mar 2002 17:18:27 -0000	1.21
--- security/mac_biba/mac_biba.c	15 Mar 2002 09:43:41 -0000
***************
*** 985,990 ****
--- 985,1004 ----
  	return (0);
  }
  
+ static int
+ mac_biba_ipc_cred_check_op(struct ucred *cred, struct mac *label, int access)
+ {
+ 	if (!mac_biba_enabled)
+ 		return (0);
+ 	if ((access & IPC_WRITE) &&
+ 	    (!mac_biba_single_equal(&label, &cred->cr_label)))
+ 		return (EACCES);
+ 	if ((access & IPC_READ) &&
+ 	    (!mac_biba_single_dominate(label, &cred->cr_label)))
+ 		return (EACCES);
+ 	return (0);
+ }
+ 
  static struct mac_policy_ops mac_biba_ops =
  {
  	NULL,
***************
*** 1048,1054 ****
  	mac_biba_cred_check_signal_proc,
  	mac_biba_cred_check_stat_vnode,
  	mac_biba_ifnet_check_send_mbuf,
! 	mac_biba_socket_check_receive_mbuf
  };
  	
  MAC_POLICY_SET(mac_biba_ops, trustedbsd_mac_biba, "TrustedBSD MAC/Biba");
--- 1062,1069 ----
  	mac_biba_cred_check_signal_proc,
  	mac_biba_cred_check_stat_vnode,
  	mac_biba_ifnet_check_send_mbuf,
! 	mac_biba_socket_check_receive_mbuf,
! 	mac_biba_ipc_cred_check_op
  };
  	
  MAC_POLICY_SET(mac_biba_ops, trustedbsd_mac_biba, "TrustedBSD MAC/Biba");
Index: security/mac_bsdextended/mac_bsdextended.c
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/security/mac_bsdextended/mac_bsdextended.c,v
retrieving revision 1.21
diff -c -r1.21 mac_bsdextended.c
*** security/mac_bsdextended/mac_bsdextended.c	7 Mar 2002 17:18:28 -0000	1.21
--- security/mac_bsdextended/mac_bsdextended.c	15 Mar 2002 09:41:19 -0000
***************
*** 578,583 ****
--- 578,590 ----
  	return (mac_bsdextended_cred_cantouch(cred, proc));
  }
  
+ static int
+ mac_bsdextended_ipc_cred_check_op(struct ucred *cred, struct mac *label,
+ 	int access)
+ {
+ 	return (0);
+ }
+ 
  static struct mac_policy_ops mac_bsdextended_ops =
  {
  	mac_bsdextended_init,
***************
*** 642,647 ****
--- 649,655 ----
  	mac_bsdextended_cred_check_stat_vnode,
  	NULL,					/* ifnet check send mbuf */
  	NULL,					/* socket check receive mbuf */
+ 	mac_bsdextended_ipc_cred_check_op,
  };
  	
  MAC_POLICY_SET(mac_bsdextended_ops, trustedbsd_mac_bsdextended,
Index: security/mac_mls/mac_mls.c
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/security/mac_mls/mac_mls.c,v
retrieving revision 1.17
diff -c -r1.17 mac_mls.c
*** security/mac_mls/mac_mls.c	7 Mar 2002 17:18:29 -0000	1.17
--- security/mac_mls/mac_mls.c	15 Mar 2002 09:44:30 -0000
***************
*** 954,959 ****
--- 954,975 ----
  	return (0);
  }
  
+ static int
+ mac_mls_ipc_cred_check_op(struct ucred *cred, struct mac *label, int access)
+ {
+ 
+ 	if (!mac_mls_enabled)
+ 		return (0);
+ 	
+ 	if ((access & IPC_READ) &&
+ 	    !mac_mls_single_dominate(&cred->cr_label, label))
+ 		return (EACCES);
+ 	if ((access & IPC_WRITE) &&
+ 	    !mac_mls_single_equal(&cred->cr_label, label))
+ 		return (EACCES);
+ 	return (0);
+ }
+ 
  static struct mac_policy_ops mac_mls_ops =
  {
  	NULL,
***************
*** 1017,1023 ****
  	mac_mls_cred_check_signal_proc,
  	mac_mls_cred_check_stat_vnode,
  	mac_mls_ifnet_check_send_mbuf,
! 	mac_mls_socket_check_receive_mbuf
  };
  	
  MAC_POLICY_SET(mac_mls_ops, trustedbsd_mac_mls, "TrustedBSD MAC/MLS");
--- 1033,1040 ----
  	mac_mls_cred_check_signal_proc,
  	mac_mls_cred_check_stat_vnode,
  	mac_mls_ifnet_check_send_mbuf,
! 	mac_mls_socket_check_receive_mbuf,
! 	mac_mls_ipc_cred_check_op
  };
  	
  MAC_POLICY_SET(mac_mls_ops, trustedbsd_mac_mls, "TrustedBSD MAC/MLS");
Index: security/mac_none/mac_none.c
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/security/mac_none/mac_none.c,v
retrieving revision 1.15
diff -c -r1.15 mac_none.c
*** security/mac_none/mac_none.c	7 Mar 2002 17:18:30 -0000	1.15
--- security/mac_none/mac_none.c	15 Mar 2002 09:45:29 -0000
***************
*** 578,583 ****
--- 578,591 ----
  	return (0);
  }
  
+ static int
+ mac_none_ipc_cred_check_op(struct ucred *cred, struct mac *label, int access)
+ {
+ 
+ 	/* Perform access control check here. */
+ 	return (0);
+ }
+ 
  static struct mac_policy_ops mac_none_ops =
  {
  	mac_none_destroy,
***************
*** 641,647 ****
  	mac_none_cred_check_signal_proc,
  	mac_none_cred_check_stat_vnode,
  	mac_none_ifnet_check_send_mbuf,
! 	mac_none_socket_check_receive_mbuf
  };
  	
  MAC_POLICY_SET(mac_none_ops, trustedbsd_mac_none, "TrustedBSD MAC/None");
--- 649,656 ----
  	mac_none_cred_check_signal_proc,
  	mac_none_cred_check_stat_vnode,
  	mac_none_ifnet_check_send_mbuf,
! 	mac_none_socket_check_receive_mbuf,
! 	mac_none_ipc_cred_check_op
  };
  	
  MAC_POLICY_SET(mac_none_ops, trustedbsd_mac_none, "TrustedBSD MAC/None");
Index: security/mac_te/mac_te.c
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/security/mac_te/mac_te.c,v
retrieving revision 1.16
diff -c -r1.16 mac_te.c
*** security/mac_te/mac_te.c	7 Mar 2002 17:18:31 -0000	1.16
--- security/mac_te/mac_te.c	15 Mar 2002 09:47:04 -0000
***************
*** 1031,1036 ****
--- 1031,1046 ----
  	return (error);
  }
  
+ static int
+ mac_te_ipc_cred_check_op(struct ucred *cred, struct mac *label, int access)
+ {
+ 	int error;
+ 
+ 	error = 0; /* don't know what to put here */
+ 
+ 	return (error);
+ }
+ 
  static struct mac_policy_ops mac_te_ops =
  {
  	NULL,
***************
*** 1094,1100 ****
  	mac_te_cred_check_signal_proc,
  	mac_te_cred_check_stat_vnode,
  	mac_te_ifnet_check_send_mbuf,
! 	mac_te_socket_check_receive_mbuf
  };
  	
  MAC_POLICY_SET(mac_te_ops, trustedbsd_mac_te, "TrustedBSD MAC/TE");
--- 1104,1111 ----
  	mac_te_cred_check_signal_proc,
  	mac_te_cred_check_stat_vnode,
  	mac_te_ifnet_check_send_mbuf,
! 	mac_te_socket_check_receive_mbuf,
! 	mac_te_ipc_cred_check_op
  };
  	
  MAC_POLICY_SET(mac_te_ops, trustedbsd_mac_te, "TrustedBSD MAC/TE");
Index: sys/ipc.h
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/sys/ipc.h,v
retrieving revision 1.2
diff -c -r1.2 ipc.h
*** sys/ipc.h	1 Jan 2002 06:00:06 -0000	1.2
--- sys/ipc.h	15 Mar 2002 10:00:13 -0000
***************
*** 58,63 ****
--- 58,66 ----
  	ushort	mode;	/* r/w permission */
  	ushort	seq;	/* sequence # (to generate unique msg/sem/shm id) */
  	key_t	key;	/* user specified msg/sem/shm key */
+ #ifdef MAC
+ 	struct mac label;	/* MAC label */
+ #endif
  };
  
  /* common mode bits */
Index: sys/mac.h
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/sys/mac.h,v
retrieving revision 1.80
diff -c -r1.80 mac.h
*** sys/mac.h	19 Feb 2002 21:15:33 -0000	1.80
--- sys/mac.h	15 Mar 2002 09:23:41 -0000
***************
*** 52,57 ****
--- 52,60 ----
  #define	FREEBSD_MAC_EXTATTR_NAME	"freebsd.mac"
  #define	FREEBSD_MAC_EXTATTR_NAMESPACE	EXTATTR_NAMESPACE_SYSTEM
  
+ #define IPC_READ	0x0001
+ #define IPC_WRITE	0x0002
+ 
  /*
   * Structures and constants associated with a Biba Integrity policy.
   * mac_biba represents a Biba label, with mb_type determining its properties,
Index: sys/mac_policy.h
===================================================================
RCS file: /mnt/cvs/TrustedBSD/projects/trustedbsd/mac/sys/sys/mac_policy.h,v
retrieving revision 1.46
diff -c -r1.46 mac_policy.h
*** sys/mac_policy.h	19 Feb 2002 21:15:33 -0000	1.46
--- sys/mac_policy.h	15 Mar 2002 09:22:04 -0000
***************
*** 199,204 ****
--- 199,208 ----
  		    struct mbuf *mbuf);
  	int	(*mpo_socket_check_receive_mbuf)(struct socket *socket,
  		    struct mbuf *mbuf);
+ 
+ 	int	(*mpo_ipc_cred_check_op)(struct ucred *cred, struct mac *label,
+ 		    int access);
+ 
  };
  
  struct mac_policy_conf {
