Deleted Added
full compact
sysv_msg.c (140614) sysv_msg.c (140839)
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 140614 2005-01-22 18:51:43Z rwatson $");
51__FBSDID("$FreeBSD: head/sys/kern/sysv_msg.c 140839 2005-01-26 00:46:36Z sobomax $");
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>
60#include <sys/proc.h>
61#include <sys/lock.h>
62#include <sys/mac.h>
63#include <sys/mutex.h>
64#include <sys/module.h>
65#include <sys/msg.h>
66#include <sys/syscall.h>
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>
60#include <sys/proc.h>
61#include <sys/lock.h>
62#include <sys/mac.h>
63#include <sys/mutex.h>
64#include <sys/module.h>
65#include <sys/msg.h>
66#include <sys/syscall.h>
67#include <sys/syscallsubr.h>
67#include <sys/sysent.h>
68#include <sys/sysctl.h>
69#include <sys/malloc.h>
70#include <sys/jail.h>
71
72static MALLOC_DEFINE(M_MSG, "msg", "SVID compatible message queues");
73
74static void msginit(void);

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

390 */
391int
392msgctl(td, uap)
393 struct thread *td;
394 register struct msgctl_args *uap;
395{
396 int msqid = uap->msqid;
397 int cmd = uap->cmd;
68#include <sys/sysent.h>
69#include <sys/sysctl.h>
70#include <sys/malloc.h>
71#include <sys/jail.h>
72
73static MALLOC_DEFINE(M_MSG, "msg", "SVID compatible message queues");
74
75static void msginit(void);

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

391 */
392int
393msgctl(td, uap)
394 struct thread *td;
395 register struct msgctl_args *uap;
396{
397 int msqid = uap->msqid;
398 int cmd = uap->cmd;
398 struct msqid_ds *user_msqptr = uap->buf;
399 int rval, error;
400 struct msqid_ds msqbuf;
399 struct msqid_ds msqbuf;
400 struct msqid_ds *msqptr;
401 int error;
402
403 DPRINTF(("call to msgctl(%d, %d, 0x%x)\n", msqid, cmd, uap->buf));
404 if (cmd == IPC_SET &&
405 (error = copyin(uap->buf, &msqbuf, sizeof(msqbuf))) != 0)
406 return (error);
407 error = kern_msgctl(td, msqid, cmd, &msqbuf, &msqptr);
408 if (cmd == IPC_STAT && error == 0)
409 error = copyout(msqptr, uap->buf, sizeof(struct msqid_ds));
410 return (error);
411}
412
413int
414kern_msgctl(td, msqid, cmd, msqbuf, msqptr)
415 struct thread *td;
416 int msqid;
417 int cmd;
418 struct msqid_ds *msqbuf;
419 struct msqid_ds **msqptr;
420{
421 int rval, error, msqix;
401 register struct msqid_kernel *msqkptr;
402
422 register struct msqid_kernel *msqkptr;
423
403 DPRINTF(("call to msgctl(%d, %d, 0x%x)\n", msqid, cmd, user_msqptr));
404 if (!jail_sysvipc_allowed && jailed(td->td_ucred))
405 return (ENOSYS);
406
424 if (!jail_sysvipc_allowed && jailed(td->td_ucred))
425 return (ENOSYS);
426
407 msqid = IPCID_TO_IX(msqid);
427 msqix = IPCID_TO_IX(msqid);
408
428
409 if (msqid < 0 || msqid >= msginfo.msgmni) {
410 DPRINTF(("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
429 if (msqix < 0 || msqix >= msginfo.msgmni) {
430 DPRINTF(("msqid (%d) out of range (0<=msqid<%d)\n", msqix,
411 msginfo.msgmni));
412 return (EINVAL);
413 }
431 msginfo.msgmni));
432 return (EINVAL);
433 }
414 if (cmd == IPC_SET &&
415 (error = copyin(user_msqptr, &msqbuf, sizeof(msqbuf))) != 0)
416 return (error);
417
434
418 msqkptr = &msqids[msqid];
435 msqkptr = &msqids[msqix];
419
420 mtx_lock(&msq_mtx);
421 if (msqkptr->u.msg_qbytes == 0) {
422 DPRINTF(("no such msqid\n"));
423 error = EINVAL;
424 goto done2;
425 }
436
437 mtx_lock(&msq_mtx);
438 if (msqkptr->u.msg_qbytes == 0) {
439 DPRINTF(("no such msqid\n"));
440 error = EINVAL;
441 goto done2;
442 }
426 if (msqkptr->u.msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
443 if (msqkptr->u.msg_perm.seq != IPCID_TO_SEQ(msqid)) {
427 DPRINTF(("wrong sequence number\n"));
428 error = EINVAL;
429 goto done2;
430 }
431#ifdef MAC
432 error = mac_check_sysv_msqctl(td->td_ucred, msqkptr, cmd);
433 if (error != 0) {
434 MPRINTF(("mac_check_sysv_msqctl returned %d\n", error));

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

495 wakeup(msqkptr);
496 }
497
498 break;
499
500 case IPC_SET:
501 if ((error = ipcperm(td, &msqkptr->u.msg_perm, IPC_M)))
502 goto done2;
444 DPRINTF(("wrong sequence number\n"));
445 error = EINVAL;
446 goto done2;
447 }
448#ifdef MAC
449 error = mac_check_sysv_msqctl(td->td_ucred, msqkptr, cmd);
450 if (error != 0) {
451 MPRINTF(("mac_check_sysv_msqctl returned %d\n", error));

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

512 wakeup(msqkptr);
513 }
514
515 break;
516
517 case IPC_SET:
518 if ((error = ipcperm(td, &msqkptr->u.msg_perm, IPC_M)))
519 goto done2;
503 if (msqbuf.msg_qbytes > msqkptr->u.msg_qbytes) {
520 if (msqbuf->msg_qbytes > msqkptr->u.msg_qbytes) {
504 error = suser(td);
505 if (error)
506 goto done2;
507 }
521 error = suser(td);
522 if (error)
523 goto done2;
524 }
508 if (msqbuf.msg_qbytes > msginfo.msgmnb) {
525 if (msqbuf->msg_qbytes > msginfo.msgmnb) {
509 DPRINTF(("can't increase msg_qbytes beyond %d"
510 "(truncating)\n", msginfo.msgmnb));
526 DPRINTF(("can't increase msg_qbytes beyond %d"
527 "(truncating)\n", msginfo.msgmnb));
511 msqbuf.msg_qbytes = msginfo.msgmnb; /* silently restrict qbytes to system limit */
528 msqbuf->msg_qbytes = msginfo.msgmnb; /* silently restrict qbytes to system limit */
512 }
529 }
513 if (msqbuf.msg_qbytes == 0) {
530 if (msqbuf->msg_qbytes == 0) {
514 DPRINTF(("can't reduce msg_qbytes to 0\n"));
515 error = EINVAL; /* non-standard errno! */
516 goto done2;
517 }
531 DPRINTF(("can't reduce msg_qbytes to 0\n"));
532 error = EINVAL; /* non-standard errno! */
533 goto done2;
534 }
518 msqkptr->u.msg_perm.uid = msqbuf.msg_perm.uid; /* change the owner */
519 msqkptr->u.msg_perm.gid = msqbuf.msg_perm.gid; /* change the owner */
535 msqkptr->u.msg_perm.uid = msqbuf->msg_perm.uid; /* change the owner */
536 msqkptr->u.msg_perm.gid = msqbuf->msg_perm.gid; /* change the owner */
520 msqkptr->u.msg_perm.mode = (msqkptr->u.msg_perm.mode & ~0777) |
537 msqkptr->u.msg_perm.mode = (msqkptr->u.msg_perm.mode & ~0777) |
521 (msqbuf.msg_perm.mode & 0777);
522 msqkptr->u.msg_qbytes = msqbuf.msg_qbytes;
538 (msqbuf->msg_perm.mode & 0777);
539 msqkptr->u.msg_qbytes = msqbuf->msg_qbytes;
523 msqkptr->u.msg_ctime = time_second;
524 break;
525
526 case IPC_STAT:
527 if ((error = ipcperm(td, &msqkptr->u.msg_perm, IPC_R))) {
528 DPRINTF(("requester doesn't have read access\n"));
529 goto done2;
530 }
540 msqkptr->u.msg_ctime = time_second;
541 break;
542
543 case IPC_STAT:
544 if ((error = ipcperm(td, &msqkptr->u.msg_perm, IPC_R))) {
545 DPRINTF(("requester doesn't have read access\n"));
546 goto done2;
547 }
548 *msqptr = &(msqkptr->u);
531 break;
532
533 default:
534 DPRINTF(("invalid command %d\n", cmd));
535 error = EINVAL;
536 goto done2;
537 }
538
539 if (error == 0)
540 td->td_retval[0] = rval;
541done2:
542 mtx_unlock(&msq_mtx);
549 break;
550
551 default:
552 DPRINTF(("invalid command %d\n", cmd));
553 error = EINVAL;
554 goto done2;
555 }
556
557 if (error == 0)
558 td->td_retval[0] = rval;
559done2:
560 mtx_unlock(&msq_mtx);
543 if (cmd == IPC_STAT && error == 0)
544 error = copyout(&(msqkptr->u), user_msqptr, sizeof(struct msqid_ds));
545 return(error);
546}
547
548#ifndef _SYS_SYSPROTO_H_
549struct msgget_args {
550 key_t key;
551 int msgflg;
552};

--- 756 unchanged lines hidden ---
561 return(error);
562}
563
564#ifndef _SYS_SYSPROTO_H_
565struct msgget_args {
566 key_t key;
567 int msgflg;
568};

--- 756 unchanged lines hidden ---