aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2017-12-01 17:34:22 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2018-01-05 11:54:34 -0500
commitaf4a5372e4166e8f13cb5cd36d936a0f56bc8418 (patch)
tree42af71ebe29af83e00c4c2730d02e877f24d1031
parenteecec19d9e705cb670a387d18973feeffd412970 (diff)
move dentry_open() calls up into do_mq_open()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--ipc/mqueue.c44
1 files changed, 20 insertions, 24 deletions
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index e011ccd4c798..fee67559acbe 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -727,17 +727,16 @@ static int mq_attr_ok(struct ipc_namespace *ipc_ns, struct mq_attr *attr)
727/* 727/*
728 * Invoked when creating a new queue via sys_mq_open 728 * Invoked when creating a new queue via sys_mq_open
729 */ 729 */
730static struct file *do_create(struct ipc_namespace *ipc_ns, struct inode *dir, 730static int do_create(struct ipc_namespace *ipc_ns, struct inode *dir,
731 struct path *path, int oflag, umode_t mode, 731 struct path *path, int oflag, umode_t mode,
732 struct mq_attr *attr) 732 struct mq_attr *attr)
733{ 733{
734 const struct cred *cred = current_cred();
735 int ret; 734 int ret;
736 735
737 if (attr) { 736 if (attr) {
738 ret = mq_attr_ok(ipc_ns, attr); 737 ret = mq_attr_ok(ipc_ns, attr);
739 if (ret) 738 if (ret)
740 return ERR_PTR(ret); 739 return ret;
741 } else { 740 } else {
742 struct mq_attr def_attr; 741 struct mq_attr def_attr;
743 742
@@ -747,28 +746,23 @@ static struct file *do_create(struct ipc_namespace *ipc_ns, struct inode *dir,
747 ipc_ns->mq_msgsize_default); 746 ipc_ns->mq_msgsize_default);
748 ret = mq_attr_ok(ipc_ns, &def_attr); 747 ret = mq_attr_ok(ipc_ns, &def_attr);
749 if (ret) 748 if (ret)
750 return ERR_PTR(ret); 749 return ret;
751 } 750 }
752 751
753 ret = vfs_mkobj(path->dentry, mode & ~current_umask(), 752 return vfs_mkobj(path->dentry, mode & ~current_umask(),
754 mqueue_create_attr, attr); 753 mqueue_create_attr, attr);
755 if (ret)
756 return ERR_PTR(ret);
757 return dentry_open(path, oflag, cred);
758} 754}
759 755
760/* Opens existing queue */ 756/* Opens existing queue */
761static struct file *do_open(struct path *path, int oflag) 757static int do_open(struct path *path, int oflag)
762{ 758{
763 static const int oflag2acc[O_ACCMODE] = { MAY_READ, MAY_WRITE, 759 static const int oflag2acc[O_ACCMODE] = { MAY_READ, MAY_WRITE,
764 MAY_READ | MAY_WRITE }; 760 MAY_READ | MAY_WRITE };
765 int acc; 761 int acc;
766 if ((oflag & O_ACCMODE) == (O_RDWR | O_WRONLY)) 762 if ((oflag & O_ACCMODE) == (O_RDWR | O_WRONLY))
767 return ERR_PTR(-EINVAL); 763 return -EINVAL;
768 acc = oflag2acc[oflag & O_ACCMODE]; 764 acc = oflag2acc[oflag & O_ACCMODE];
769 if (inode_permission(d_inode(path->dentry), acc)) 765 return inode_permission(d_inode(path->dentry), acc);
770 return ERR_PTR(-EACCES);
771 return dentry_open(path, oflag, current_cred());
772} 766}
773 767
774static int do_mq_open(const char __user *u_name, int oflag, umode_t mode, 768static int do_mq_open(const char __user *u_name, int oflag, umode_t mode,
@@ -805,28 +799,30 @@ static int do_mq_open(const char __user *u_name, int oflag, umode_t mode,
805 if (oflag & O_CREAT) { 799 if (oflag & O_CREAT) {
806 if (d_really_is_positive(path.dentry)) { /* entry already exists */ 800 if (d_really_is_positive(path.dentry)) { /* entry already exists */
807 audit_inode(name, path.dentry, 0); 801 audit_inode(name, path.dentry, 0);
808 if (oflag & O_EXCL) { 802 if (oflag & O_EXCL)
809 error = -EEXIST; 803 error = -EEXIST;
810 goto out; 804 else
811 } 805 error = do_open(&path, oflag);
812 filp = do_open(&path, oflag);
813 } else { 806 } else {
814 if (ro) { 807 if (ro) {
815 error = ro; 808 error = ro;
816 goto out; 809 } else {
810 audit_inode_parent_hidden(name, root);
811 error = do_create(ipc_ns, d_inode(root), &path,
812 oflag, mode, attr);
817 } 813 }
818 audit_inode_parent_hidden(name, root);
819 filp = do_create(ipc_ns, d_inode(root), &path,
820 oflag, mode, attr);
821 } 814 }
822 } else { 815 } else {
823 if (d_really_is_negative(path.dentry)) { 816 if (d_really_is_negative(path.dentry)) {
824 error = -ENOENT; 817 error = -ENOENT;
825 goto out; 818 } else {
819 audit_inode(name, path.dentry, 0);
820 error = do_open(&path, oflag);
826 } 821 }
827 audit_inode(name, path.dentry, 0);
828 filp = do_open(&path, oflag);
829 } 822 }
823 if (error)
824 goto out;
825 filp = dentry_open(&path, oflag, current_cred());
830 826
831 if (!IS_ERR(filp)) 827 if (!IS_ERR(filp))
832 fd_install(fd, filp); 828 fd_install(fd, filp);