diff options
Diffstat (limited to 'ipc/mqueue.c')
-rw-r--r-- | ipc/mqueue.c | 97 |
1 files changed, 49 insertions, 48 deletions
diff --git a/ipc/mqueue.c b/ipc/mqueue.c index d9393f8e4c3e..d448b69672b5 100644 --- a/ipc/mqueue.c +++ b/ipc/mqueue.c | |||
@@ -524,31 +524,27 @@ static void __do_notify(struct mqueue_inode_info *info) | |||
524 | wake_up(&info->wait_q); | 524 | wake_up(&info->wait_q); |
525 | } | 525 | } |
526 | 526 | ||
527 | static long prepare_timeout(const struct timespec __user *u_arg) | 527 | static long prepare_timeout(struct timespec *p) |
528 | { | 528 | { |
529 | struct timespec ts, nowts; | 529 | struct timespec nowts; |
530 | long timeout; | 530 | long timeout; |
531 | 531 | ||
532 | if (u_arg) { | 532 | if (p) { |
533 | if (unlikely(copy_from_user(&ts, u_arg, | 533 | if (unlikely(p->tv_nsec < 0 || p->tv_sec < 0 |
534 | sizeof(struct timespec)))) | 534 | || p->tv_nsec >= NSEC_PER_SEC)) |
535 | return -EFAULT; | ||
536 | |||
537 | if (unlikely(ts.tv_nsec < 0 || ts.tv_sec < 0 | ||
538 | || ts.tv_nsec >= NSEC_PER_SEC)) | ||
539 | return -EINVAL; | 535 | return -EINVAL; |
540 | nowts = CURRENT_TIME; | 536 | nowts = CURRENT_TIME; |
541 | /* first subtract as jiffies can't be too big */ | 537 | /* first subtract as jiffies can't be too big */ |
542 | ts.tv_sec -= nowts.tv_sec; | 538 | p->tv_sec -= nowts.tv_sec; |
543 | if (ts.tv_nsec < nowts.tv_nsec) { | 539 | if (p->tv_nsec < nowts.tv_nsec) { |
544 | ts.tv_nsec += NSEC_PER_SEC; | 540 | p->tv_nsec += NSEC_PER_SEC; |
545 | ts.tv_sec--; | 541 | p->tv_sec--; |
546 | } | 542 | } |
547 | ts.tv_nsec -= nowts.tv_nsec; | 543 | p->tv_nsec -= nowts.tv_nsec; |
548 | if (ts.tv_sec < 0) | 544 | if (p->tv_sec < 0) |
549 | return 0; | 545 | return 0; |
550 | 546 | ||
551 | timeout = timespec_to_jiffies(&ts) + 1; | 547 | timeout = timespec_to_jiffies(p) + 1; |
552 | } else | 548 | } else |
553 | return MAX_SCHEDULE_TIMEOUT; | 549 | return MAX_SCHEDULE_TIMEOUT; |
554 | 550 | ||
@@ -592,22 +588,18 @@ static int mq_attr_ok(struct mq_attr *attr) | |||
592 | * Invoked when creating a new queue via sys_mq_open | 588 | * Invoked when creating a new queue via sys_mq_open |
593 | */ | 589 | */ |
594 | static struct file *do_create(struct dentry *dir, struct dentry *dentry, | 590 | static struct file *do_create(struct dentry *dir, struct dentry *dentry, |
595 | int oflag, mode_t mode, struct mq_attr __user *u_attr) | 591 | int oflag, mode_t mode, struct mq_attr *attr) |
596 | { | 592 | { |
597 | const struct cred *cred = current_cred(); | 593 | const struct cred *cred = current_cred(); |
598 | struct mq_attr attr; | ||
599 | struct file *result; | 594 | struct file *result; |
600 | int ret; | 595 | int ret; |
601 | 596 | ||
602 | if (u_attr) { | 597 | if (attr) { |
603 | ret = -EFAULT; | ||
604 | if (copy_from_user(&attr, u_attr, sizeof(attr))) | ||
605 | goto out; | ||
606 | ret = -EINVAL; | 598 | ret = -EINVAL; |
607 | if (!mq_attr_ok(&attr)) | 599 | if (!mq_attr_ok(attr)) |
608 | goto out; | 600 | goto out; |
609 | /* store for use during create */ | 601 | /* store for use during create */ |
610 | dentry->d_fsdata = &attr; | 602 | dentry->d_fsdata = attr; |
611 | } | 603 | } |
612 | 604 | ||
613 | mode &= ~current->fs->umask; | 605 | mode &= ~current->fs->umask; |
@@ -664,11 +656,13 @@ asmlinkage long sys_mq_open(const char __user *u_name, int oflag, mode_t mode, | |||
664 | struct dentry *dentry; | 656 | struct dentry *dentry; |
665 | struct file *filp; | 657 | struct file *filp; |
666 | char *name; | 658 | char *name; |
659 | struct mq_attr attr; | ||
667 | int fd, error; | 660 | int fd, error; |
668 | 661 | ||
669 | error = audit_mq_open(oflag, mode, u_attr); | 662 | if (u_attr && copy_from_user(&attr, u_attr, sizeof(struct mq_attr))) |
670 | if (error != 0) | 663 | return -EFAULT; |
671 | return error; | 664 | |
665 | audit_mq_open(oflag, mode, u_attr ? &attr : NULL); | ||
672 | 666 | ||
673 | if (IS_ERR(name = getname(u_name))) | 667 | if (IS_ERR(name = getname(u_name))) |
674 | return PTR_ERR(name); | 668 | return PTR_ERR(name); |
@@ -694,7 +688,8 @@ asmlinkage long sys_mq_open(const char __user *u_name, int oflag, mode_t mode, | |||
694 | filp = do_open(dentry, oflag); | 688 | filp = do_open(dentry, oflag); |
695 | } else { | 689 | } else { |
696 | filp = do_create(mqueue_mnt->mnt_root, dentry, | 690 | filp = do_create(mqueue_mnt->mnt_root, dentry, |
697 | oflag, mode, u_attr); | 691 | oflag, mode, |
692 | u_attr ? &attr : NULL); | ||
698 | } | 693 | } |
699 | } else { | 694 | } else { |
700 | error = -ENOENT; | 695 | error = -ENOENT; |
@@ -829,17 +824,22 @@ asmlinkage long sys_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr, | |||
829 | struct ext_wait_queue *receiver; | 824 | struct ext_wait_queue *receiver; |
830 | struct msg_msg *msg_ptr; | 825 | struct msg_msg *msg_ptr; |
831 | struct mqueue_inode_info *info; | 826 | struct mqueue_inode_info *info; |
827 | struct timespec ts, *p = NULL; | ||
832 | long timeout; | 828 | long timeout; |
833 | int ret; | 829 | int ret; |
834 | 830 | ||
835 | ret = audit_mq_timedsend(mqdes, msg_len, msg_prio, u_abs_timeout); | 831 | if (u_abs_timeout) { |
836 | if (ret != 0) | 832 | if (copy_from_user(&ts, u_abs_timeout, |
837 | return ret; | 833 | sizeof(struct timespec))) |
834 | return -EFAULT; | ||
835 | p = &ts; | ||
836 | } | ||
838 | 837 | ||
839 | if (unlikely(msg_prio >= (unsigned long) MQ_PRIO_MAX)) | 838 | if (unlikely(msg_prio >= (unsigned long) MQ_PRIO_MAX)) |
840 | return -EINVAL; | 839 | return -EINVAL; |
841 | 840 | ||
842 | timeout = prepare_timeout(u_abs_timeout); | 841 | audit_mq_sendrecv(mqdes, msg_len, msg_prio, p); |
842 | timeout = prepare_timeout(p); | ||
843 | 843 | ||
844 | ret = -EBADF; | 844 | ret = -EBADF; |
845 | filp = fget(mqdes); | 845 | filp = fget(mqdes); |
@@ -918,12 +918,17 @@ asmlinkage ssize_t sys_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr, | |||
918 | struct inode *inode; | 918 | struct inode *inode; |
919 | struct mqueue_inode_info *info; | 919 | struct mqueue_inode_info *info; |
920 | struct ext_wait_queue wait; | 920 | struct ext_wait_queue wait; |
921 | struct timespec ts, *p = NULL; | ||
921 | 922 | ||
922 | ret = audit_mq_timedreceive(mqdes, msg_len, u_msg_prio, u_abs_timeout); | 923 | if (u_abs_timeout) { |
923 | if (ret != 0) | 924 | if (copy_from_user(&ts, u_abs_timeout, |
924 | return ret; | 925 | sizeof(struct timespec))) |
926 | return -EFAULT; | ||
927 | p = &ts; | ||
928 | } | ||
925 | 929 | ||
926 | timeout = prepare_timeout(u_abs_timeout); | 930 | audit_mq_sendrecv(mqdes, msg_len, 0, p); |
931 | timeout = prepare_timeout(p); | ||
927 | 932 | ||
928 | ret = -EBADF; | 933 | ret = -EBADF; |
929 | filp = fget(mqdes); | 934 | filp = fget(mqdes); |
@@ -1003,17 +1008,17 @@ asmlinkage long sys_mq_notify(mqd_t mqdes, | |||
1003 | struct mqueue_inode_info *info; | 1008 | struct mqueue_inode_info *info; |
1004 | struct sk_buff *nc; | 1009 | struct sk_buff *nc; |
1005 | 1010 | ||
1006 | ret = audit_mq_notify(mqdes, u_notification); | 1011 | if (u_notification) { |
1007 | if (ret != 0) | ||
1008 | return ret; | ||
1009 | |||
1010 | nc = NULL; | ||
1011 | sock = NULL; | ||
1012 | if (u_notification != NULL) { | ||
1013 | if (copy_from_user(¬ification, u_notification, | 1012 | if (copy_from_user(¬ification, u_notification, |
1014 | sizeof(struct sigevent))) | 1013 | sizeof(struct sigevent))) |
1015 | return -EFAULT; | 1014 | return -EFAULT; |
1015 | } | ||
1016 | 1016 | ||
1017 | audit_mq_notify(mqdes, u_notification ? ¬ification : NULL); | ||
1018 | |||
1019 | nc = NULL; | ||
1020 | sock = NULL; | ||
1021 | if (u_notification != NULL) { | ||
1017 | if (unlikely(notification.sigev_notify != SIGEV_NONE && | 1022 | if (unlikely(notification.sigev_notify != SIGEV_NONE && |
1018 | notification.sigev_notify != SIGEV_SIGNAL && | 1023 | notification.sigev_notify != SIGEV_SIGNAL && |
1019 | notification.sigev_notify != SIGEV_THREAD)) | 1024 | notification.sigev_notify != SIGEV_THREAD)) |
@@ -1150,11 +1155,7 @@ asmlinkage long sys_mq_getsetattr(mqd_t mqdes, | |||
1150 | omqstat = info->attr; | 1155 | omqstat = info->attr; |
1151 | omqstat.mq_flags = filp->f_flags & O_NONBLOCK; | 1156 | omqstat.mq_flags = filp->f_flags & O_NONBLOCK; |
1152 | if (u_mqstat) { | 1157 | if (u_mqstat) { |
1153 | ret = audit_mq_getsetattr(mqdes, &mqstat); | 1158 | audit_mq_getsetattr(mqdes, &mqstat); |
1154 | if (ret != 0) { | ||
1155 | spin_unlock(&info->lock); | ||
1156 | goto out_fput; | ||
1157 | } | ||
1158 | if (mqstat.mq_flags & O_NONBLOCK) | 1159 | if (mqstat.mq_flags & O_NONBLOCK) |
1159 | filp->f_flags |= O_NONBLOCK; | 1160 | filp->f_flags |= O_NONBLOCK; |
1160 | else | 1161 | else |