sysv_msg.c (159481) | sysv_msg.c (162468) |
---|---|
1/*- 2 * Implementation of SVID messages 3 * 4 * Author: Daniel Boulet 5 * 6 * Copyright 1993 Daniel Boulet and RTMX Inc. 7 * 8 * This system call was implemented by Daniel Boulet under contract from RTMX. --- 34 unchanged lines hidden (view full) --- 43 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 45 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 46 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 47 * SUCH DAMAGE. 48 */ 49 50#include <sys/cdefs.h> | 1/*- 2 * Implementation of SVID messages 3 * 4 * Author: Daniel Boulet 5 * 6 * Copyright 1993 Daniel Boulet and RTMX Inc. 7 * 8 * This system call was implemented by Daniel Boulet under contract from RTMX. --- 34 unchanged lines hidden (view full) --- 43 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 45 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 46 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 47 * SUCH DAMAGE. 48 */ 49 50#include <sys/cdefs.h> |
51__FBSDID("$FreeBSD: head/sys/kern/sysv_msg.c 159481 2006-06-10 14:34:07Z rwatson $"); | 51__FBSDID("$FreeBSD: head/sys/kern/sysv_msg.c 162468 2006-09-20 13:40:00Z rwatson $"); |
52 53#include "opt_sysvipc.h" 54#include "opt_mac.h" 55 56#include <sys/param.h> 57#include <sys/systm.h> 58#include <sys/sysproto.h> 59#include <sys/kernel.h> --- 16 unchanged lines hidden (view full) --- 76static int msgunload(void); 77static int sysvmsg_modload(struct module *, int, void *); 78 79#ifdef MSG_DEBUG 80#define DPRINTF(a) printf a 81#else 82#define DPRINTF(a) 83#endif | 52 53#include "opt_sysvipc.h" 54#include "opt_mac.h" 55 56#include <sys/param.h> 57#include <sys/systm.h> 58#include <sys/sysproto.h> 59#include <sys/kernel.h> --- 16 unchanged lines hidden (view full) --- 76static int msgunload(void); 77static int sysvmsg_modload(struct module *, int, void *); 78 79#ifdef MSG_DEBUG 80#define DPRINTF(a) printf a 81#else 82#define DPRINTF(a) 83#endif |
84#ifdef MAC_DEBUG 85#define MPRINTF(a) printf a 86#else 87#define MPRINTF(a) 88#endif | |
89 90static void msg_freehdr(struct msg *msghdr); 91 92/* XXX casting to (sy_call_t *) is bogus, as usual. */ 93static sy_call_t *msgcalls[] = { 94 (sy_call_t *)msgctl, (sy_call_t *)msgget, 95 (sy_call_t *)msgsnd, (sy_call_t *)msgrcv 96}; --- 343 unchanged lines hidden (view full) --- 440 } 441 if (msqkptr->u.msg_perm.seq != IPCID_TO_SEQ(msqid)) { 442 DPRINTF(("wrong sequence number\n")); 443 error = EINVAL; 444 goto done2; 445 } 446#ifdef MAC 447 error = mac_check_sysv_msqctl(td->td_ucred, msqkptr, cmd); | 84 85static void msg_freehdr(struct msg *msghdr); 86 87/* XXX casting to (sy_call_t *) is bogus, as usual. */ 88static sy_call_t *msgcalls[] = { 89 (sy_call_t *)msgctl, (sy_call_t *)msgget, 90 (sy_call_t *)msgsnd, (sy_call_t *)msgrcv 91}; --- 343 unchanged lines hidden (view full) --- 435 } 436 if (msqkptr->u.msg_perm.seq != IPCID_TO_SEQ(msqid)) { 437 DPRINTF(("wrong sequence number\n")); 438 error = EINVAL; 439 goto done2; 440 } 441#ifdef MAC 442 error = mac_check_sysv_msqctl(td->td_ucred, msqkptr, cmd); |
448 if (error != 0) { 449 MPRINTF(("mac_check_sysv_msqctl returned %d\n", error)); | 443 if (error != 0) |
450 goto done2; | 444 goto done2; |
451 } | |
452#endif 453 454 error = 0; 455 rval = 0; 456 457 switch (cmd) { 458 459 case IPC_RMID: --- 10 unchanged lines hidden (view full) --- 470 * msq/msghdr info as it progresses, and there is no going 471 * back if half the way through we discover that the 472 * thread cannot free a certain msghdr. The msq will get 473 * into an inconsistent state. 474 */ 475 for (msghdr = msqkptr->u.msg_first; msghdr != NULL; 476 msghdr = msghdr->msg_next) { 477 error = mac_check_sysv_msgrmid(td->td_ucred, msghdr); | 445#endif 446 447 error = 0; 448 rval = 0; 449 450 switch (cmd) { 451 452 case IPC_RMID: --- 10 unchanged lines hidden (view full) --- 463 * msq/msghdr info as it progresses, and there is no going 464 * back if half the way through we discover that the 465 * thread cannot free a certain msghdr. The msq will get 466 * into an inconsistent state. 467 */ 468 for (msghdr = msqkptr->u.msg_first; msghdr != NULL; 469 msghdr = msghdr->msg_next) { 470 error = mac_check_sysv_msgrmid(td->td_ucred, msghdr); |
478 if (error != 0) { 479 MPRINTF(("mac_check_sysv_msgrmid returned %d\n", 480 error)); | 471 if (error != 0) |
481 goto done2; | 472 goto done2; |
482 } | |
483 } 484#endif 485 486 /* Free the message headers */ 487 msghdr = msqkptr->u.msg_first; 488 while (msghdr != NULL) { 489 struct msg *msghdr_tmp; 490 --- 112 unchanged lines hidden (view full) --- 603 if ((error = ipcperm(td, &msqkptr->u.msg_perm, 604 msgflg & 0700))) { 605 DPRINTF(("requester doesn't have 0%o access\n", 606 msgflg & 0700)); 607 goto done2; 608 } 609#ifdef MAC 610 error = mac_check_sysv_msqget(cred, msqkptr); | 473 } 474#endif 475 476 /* Free the message headers */ 477 msghdr = msqkptr->u.msg_first; 478 while (msghdr != NULL) { 479 struct msg *msghdr_tmp; 480 --- 112 unchanged lines hidden (view full) --- 593 if ((error = ipcperm(td, &msqkptr->u.msg_perm, 594 msgflg & 0700))) { 595 DPRINTF(("requester doesn't have 0%o access\n", 596 msgflg & 0700)); 597 goto done2; 598 } 599#ifdef MAC 600 error = mac_check_sysv_msqget(cred, msqkptr); |
611 if (error != 0) { 612 MPRINTF(("mac_check_sysv_msqget returned %d\n", 613 error)); | 601 if (error != 0) |
614 goto done2; | 602 goto done2; |
615 } | |
616#endif 617 goto found; 618 } 619 } 620 621 DPRINTF(("need to allocate the msqid_ds\n")); 622 if (key == IPC_PRIVATE || (msgflg & IPC_CREAT)) { 623 for (msqid = 0; msqid < msginfo.msgmni; msqid++) { --- 104 unchanged lines hidden (view full) --- 728 729 if ((error = ipcperm(td, &msqkptr->u.msg_perm, IPC_W))) { 730 DPRINTF(("requester doesn't have write access\n")); 731 goto done2; 732 } 733 734#ifdef MAC 735 error = mac_check_sysv_msqsnd(td->td_ucred, msqkptr); | 603#endif 604 goto found; 605 } 606 } 607 608 DPRINTF(("need to allocate the msqid_ds\n")); 609 if (key == IPC_PRIVATE || (msgflg & IPC_CREAT)) { 610 for (msqid = 0; msqid < msginfo.msgmni; msqid++) { --- 104 unchanged lines hidden (view full) --- 715 716 if ((error = ipcperm(td, &msqkptr->u.msg_perm, IPC_W))) { 717 DPRINTF(("requester doesn't have write access\n")); 718 goto done2; 719 } 720 721#ifdef MAC 722 error = mac_check_sysv_msqsnd(td->td_ucred, msqkptr); |
736 if (error != 0) { 737 MPRINTF(("mac_check_sysv_msqsnd returned %d\n", error)); | 723 if (error != 0) |
738 goto done2; | 724 goto done2; |
739 } | |
740#endif 741 742 segs_needed = (msgsz + msginfo.msgssz - 1) / msginfo.msgssz; 743 DPRINTF(("msgsz=%d, msgssz=%d, segs_needed=%d\n", msgsz, msginfo.msgssz, 744 segs_needed)); 745 for (;;) { 746 int need_more_resources = 0; 747 --- 225 unchanged lines hidden (view full) --- 973 * suffice in that case. However, this hook may be required where 974 * individual policies derive a non-identical label for the msghdr 975 * from the current thread label and may want to check the msghdr 976 * enqueue permissions, along with read/write permissions to the 977 * msgq. 978 */ 979 error = mac_check_sysv_msgmsq(td->td_ucred, msghdr, msqkptr); 980 if (error != 0) { | 725#endif 726 727 segs_needed = (msgsz + msginfo.msgssz - 1) / msginfo.msgssz; 728 DPRINTF(("msgsz=%d, msgssz=%d, segs_needed=%d\n", msgsz, msginfo.msgssz, 729 segs_needed)); 730 for (;;) { 731 int need_more_resources = 0; 732 --- 225 unchanged lines hidden (view full) --- 958 * suffice in that case. However, this hook may be required where 959 * individual policies derive a non-identical label for the msghdr 960 * from the current thread label and may want to check the msghdr 961 * enqueue permissions, along with read/write permissions to the 962 * msgq. 963 */ 964 error = mac_check_sysv_msgmsq(td->td_ucred, msghdr, msqkptr); 965 if (error != 0) { |
981 MPRINTF(("mac_check_sysv_msqmsq returned %d\n", error)); | |
982 msg_freehdr(msghdr); 983 wakeup(msqkptr); 984 goto done2; 985 } 986#endif 987 988 /* 989 * Put the message into the queue --- 77 unchanged lines hidden (view full) --- 1067 1068 if ((error = ipcperm(td, &msqkptr->u.msg_perm, IPC_R))) { 1069 DPRINTF(("requester doesn't have read access\n")); 1070 goto done2; 1071 } 1072 1073#ifdef MAC 1074 error = mac_check_sysv_msqrcv(td->td_ucred, msqkptr); | 966 msg_freehdr(msghdr); 967 wakeup(msqkptr); 968 goto done2; 969 } 970#endif 971 972 /* 973 * Put the message into the queue --- 77 unchanged lines hidden (view full) --- 1051 1052 if ((error = ipcperm(td, &msqkptr->u.msg_perm, IPC_R))) { 1053 DPRINTF(("requester doesn't have read access\n")); 1054 goto done2; 1055 } 1056 1057#ifdef MAC 1058 error = mac_check_sysv_msqrcv(td->td_ucred, msqkptr); |
1075 if (error != 0) { 1076 MPRINTF(("mac_check_sysv_msqrcv returned %d\n", error)); | 1059 if (error != 0) |
1077 goto done2; | 1060 goto done2; |
1078 } | |
1079#endif 1080 1081 msghdr = NULL; 1082 while (msghdr == NULL) { 1083 if (msgtyp == 0) { 1084 msghdr = msqkptr->u.msg_first; 1085 if (msghdr != NULL) { 1086 if (msgsz < msghdr->msg_ts && 1087 (msgflg & MSG_NOERROR) == 0) { 1088 DPRINTF(("first message on the queue " 1089 "is too big (want %d, got %d)\n", 1090 msgsz, msghdr->msg_ts)); 1091 error = E2BIG; 1092 goto done2; 1093 } 1094#ifdef MAC 1095 error = mac_check_sysv_msgrcv(td->td_ucred, 1096 msghdr); | 1061#endif 1062 1063 msghdr = NULL; 1064 while (msghdr == NULL) { 1065 if (msgtyp == 0) { 1066 msghdr = msqkptr->u.msg_first; 1067 if (msghdr != NULL) { 1068 if (msgsz < msghdr->msg_ts && 1069 (msgflg & MSG_NOERROR) == 0) { 1070 DPRINTF(("first message on the queue " 1071 "is too big (want %d, got %d)\n", 1072 msgsz, msghdr->msg_ts)); 1073 error = E2BIG; 1074 goto done2; 1075 } 1076#ifdef MAC 1077 error = mac_check_sysv_msgrcv(td->td_ucred, 1078 msghdr); |
1097 if (error != 0) { 1098 MPRINTF(("mac_check_sysv_msgrcv " 1099 "returned %d\n", error)); | 1079 if (error != 0) |
1100 goto done2; | 1080 goto done2; |
1101 } | |
1102#endif 1103 if (msqkptr->u.msg_first == msqkptr->u.msg_last) { 1104 msqkptr->u.msg_first = NULL; 1105 msqkptr->u.msg_last = NULL; 1106 } else { 1107 msqkptr->u.msg_first = msghdr->msg_next; 1108 if (msqkptr->u.msg_first == NULL) 1109 panic("msg_first/last screwed up #1"); --- 27 unchanged lines hidden (view full) --- 1137 "(want %d, got %d)\n", 1138 msgsz, msghdr->msg_ts)); 1139 error = E2BIG; 1140 goto done2; 1141 } 1142#ifdef MAC 1143 error = mac_check_sysv_msgrcv( 1144 td->td_ucred, msghdr); | 1081#endif 1082 if (msqkptr->u.msg_first == msqkptr->u.msg_last) { 1083 msqkptr->u.msg_first = NULL; 1084 msqkptr->u.msg_last = NULL; 1085 } else { 1086 msqkptr->u.msg_first = msghdr->msg_next; 1087 if (msqkptr->u.msg_first == NULL) 1088 panic("msg_first/last screwed up #1"); --- 27 unchanged lines hidden (view full) --- 1116 "(want %d, got %d)\n", 1117 msgsz, msghdr->msg_ts)); 1118 error = E2BIG; 1119 goto done2; 1120 } 1121#ifdef MAC 1122 error = mac_check_sysv_msgrcv( 1123 td->td_ucred, msghdr); |
1145 if (error != 0) { 1146 MPRINTF(("mac_check_sysv_" 1147 "msgrcv returned %d\n", 1148 error)); | 1124 if (error != 0) |
1149 goto done2; | 1125 goto done2; |
1150 } | |
1151#endif 1152 *prev = msghdr->msg_next; 1153 if (msghdr == msqkptr->u.msg_last) { 1154 if (previous == NULL) { 1155 if (prev != 1156 &msqkptr->u.msg_first) 1157 panic("msg_first/last screwed up #2"); 1158 msqkptr->u.msg_first = --- 169 unchanged lines hidden --- | 1126#endif 1127 *prev = msghdr->msg_next; 1128 if (msghdr == msqkptr->u.msg_last) { 1129 if (previous == NULL) { 1130 if (prev != 1131 &msqkptr->u.msg_first) 1132 panic("msg_first/last screwed up #2"); 1133 msqkptr->u.msg_first = --- 169 unchanged lines hidden --- |