Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

Advertisement
[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Advertisement

Kernel v2.6.25-rc7 /fs/splice.c

Filename:/fs/splice.c
Lines Added:30
Lines Deleted:22
Also changed in: (Previous) 2.6.25-rc6  2.6.25-rc5  2.6.25-rc4  2.6.25-rc3-git6  2.6.25-rc3  2.6.25-rc2 
(Following) 2.6.25-rc8  2.6.25-rc8-git3  2.6.25-rc8-git4  2.6.25-rc8-git5  2.6.25-rc8-git6  2.6.25-rc8-git7 

Location
[  2.6.25-rc7
  [  fs
     o  splice.c

Patch

diff --git a/fs/splice.c b/fs/splice.c
index 6bdcb61..0670c91 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -254,11 +254,16 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
    }
 
    while (page_nr < spd_pages)
-      page_cache_release(spd->pages[page_nr++]);
+      spd->spd_release(spd, page_nr++);
 
    return ret;
 }
 
+static void spd_release_page(struct splice_pipe_desc *spd, unsigned int i)
+{
+   page_cache_release(spd->pages[i]);
+}
+
 static int
 __generic_file_splice_read(struct file *in, loff_t *ppos,
             struct pipe_inode_info *pipe, size_t len,
@@ -277,6 +282,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
       .partial = partial,
       .flags = flags,
       .ops = &page_cache_pipe_buf_ops,
+      .spd_release = spd_release_page,
    };
 
    index = *ppos >> PAGE_CACHE_SHIFT;
@@ -908,10 +914,6 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
    if (unlikely(ret < 0))
       return ret;
 
-   ret = security_file_permission(out, MAY_WRITE);
-   if (unlikely(ret < 0))
-      return ret;
-
    return out->f_op->splice_write(pipe, out, ppos, len, flags);
 }
 
@@ -934,10 +936,6 @@ static long do_splice_to(struct file *in, loff_t *ppos,
    if (unlikely(ret < 0))
       return ret;
 
-   ret = security_file_permission(in, MAY_READ);
-   if (unlikely(ret < 0))
-      return ret;
-
    return in->f_op->splice_read(in, ppos, pipe, len, flags);
 }
 
@@ -1033,7 +1031,9 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
          goto out_release;
    }
 
+done:
    pipe->nrbufs = pipe->curbuf = 0;
+   file_accessed(in);
    return bytes;
 
 out_release:
@@ -1049,16 +1049,11 @@ out_release:
          buf->ops = NULL;
       }
    }
-   pipe->nrbufs = pipe->curbuf = 0;
-
-   /*
-    * If we transferred some data, return the number of bytes:
-    */
-   if (bytes > 0)
-      return bytes;
 
-   return ret;
+   if (!bytes)
+      bytes = ret;
 
+   goto done;
 }
 EXPORT_SYMBOL(splice_direct_to_actor);
 
@@ -1184,6 +1179,9 @@ static int copy_from_user_mmap_sem(void *dst, const void __user *src, size_t n)
 {
    int partial;
 
+   if (!access_ok(VERIFY_READ, src, n))
+      return -EFAULT;
+
    pagefault_disable();
    partial = __copy_from_user_inatomic(dst, src, n);
    pagefault_enable();
@@ -1236,7 +1234,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
       if (unlikely(!len))
          break;
       error = -EFAULT;
-      if (unlikely(!base))
+      if (!access_ok(VERIFY_READ, base, len))
          break;
 
       /*
@@ -1392,6 +1390,11 @@ static long vmsplice_to_user(struct file *file, const struct iovec __user *iov,
          break;
       }
 
+      if (unlikely(!access_ok(VERIFY_WRITE, base, len))) {
+         error = -EFAULT;
+         break;
+      }
+
       sd.len = 0;
       sd.total_len = len;
       sd.flags = flags;
@@ -1440,6 +1443,7 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov,
       .partial = partial,
       .flags = flags,
       .ops = &user_page_pipe_buf_ops,
+      .spd_release = spd_release_page,
    };
 
    pipe = pipe_info(file->f_path.dentry->d_inode);
@@ -1665,6 +1669,13 @@ static int link_pipe(struct pipe_inode_info *ipipe,
       i++;
    } while (len);
 
+   /*
+    * return EAGAIN if we have the potential of some data in the
+    * future, otherwise just return 0
+    */
+   if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
+      ret = -EAGAIN;
+
    inode_double_unlock(ipipe->inode, opipe->inode);
 
    /*
@@ -1705,11 +1716,8 @@ static long do_tee(struct file *in, struct file *out, size_t len,
       ret = link_ipipe_prep(ipipe, flags);
       if (!ret) {
          ret = link_opipe_prep(opipe, flags);
-         if (!ret) {
+         if (!ret)
             ret = link_pipe(ipipe, opipe, len, flags);
-            if (!ret && (flags & SPLICE_F_NONBLOCK))
-               ret = -EAGAIN;
-         }
       }
    }
 


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.