Allow passing O_PATH descriptors via SCM_RIGHTS datagrams
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 13 Mar 2011 21:08:22 +0000 (17:08 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 15 Mar 2011 06:21:45 +0000 (02:21 -0400)
Just need to make sure that AF_UNIX garbage collector won't
confuse O_PATHed socket on filesystem for real AF_UNIX opened
socket.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/file_table.c
net/core/scm.c
net/unix/garbage.c

index 3c16e1ca163ea57726d21829ec04cf8886dc6387..74a9544ac770a9870e9efb4d489fbe41394934e7 100644 (file)
@@ -305,6 +305,8 @@ struct file *fget_raw(unsigned int fd)
        return file;
 }
 
+EXPORT_SYMBOL(fget_raw);
+
 /*
  * Lightweight file lookup - no refcnt increment if fd table isn't shared.
  *
index bbe4544508016925726522f275e95aefadeb1664..4c1ef026d6955b8cadaf77ceee6538dd4b4e1800 100644 (file)
@@ -95,7 +95,7 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp)
                int fd = fdp[i];
                struct file *file;
 
-               if (fd < 0 || !(file = fget(fd)))
+               if (fd < 0 || !(file = fget_raw(fd)))
                        return -EBADF;
                *fpp++ = file;
                fpl->count++;
index f89f83bf828ee0e713ded75c84da22a1c1b2426e..b6f4b994eb356a0cd9c05851d49fff16bece3eb0 100644 (file)
@@ -104,7 +104,7 @@ struct sock *unix_get_socket(struct file *filp)
        /*
         *      Socket ?
         */
-       if (S_ISSOCK(inode->i_mode)) {
+       if (S_ISSOCK(inode->i_mode) && !(filp->f_mode & FMODE_PATH)) {
                struct socket *sock = SOCKET_I(inode);
                struct sock *s = sock->sk;