]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
relay: fix subbuf_splice_actor() adding too many pages
authorJens Axboe <jens.axboe@oracle.com>
Mon, 17 Mar 2008 08:04:59 +0000 (09:04 +0100)
committerChris Wright <chrisw@sous-sol.org>
Mon, 24 Mar 2008 18:48:35 +0000 (11:48 -0700)
If subbuf_pages was larger than the max number of pages the pipe
buffer will hold, subbuf_splice_actor() would happily go beyond
the array size.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
kernel/relay.c

index 7c0373322f18892eea75e3773714554f59f46c1e..889102a01d8d6d6576d67db4f79412f8e13ab8ee 100644 (file)
@@ -1072,7 +1072,7 @@ static int subbuf_splice_actor(struct file *in,
                               unsigned int flags,
                               int *nonpad_ret)
 {
-       unsigned int pidx, poff, total_len, subbuf_pages, ret;
+       unsigned int pidx, poff, total_len, subbuf_pages, nr_pages, ret;
        struct rchan_buf *rbuf = in->private_data;
        unsigned int subbuf_size = rbuf->chan->subbuf_size;
        uint64_t pos = (uint64_t) *ppos;
@@ -1103,8 +1103,9 @@ static int subbuf_splice_actor(struct file *in,
        subbuf_pages = rbuf->chan->alloc_size >> PAGE_SHIFT;
        pidx = (read_start / PAGE_SIZE) % subbuf_pages;
        poff = read_start & ~PAGE_MASK;
+       nr_pages = min_t(unsigned int, subbuf_pages, PIPE_BUFFERS);
 
-       for (total_len = 0; spd.nr_pages < subbuf_pages; spd.nr_pages++) {
+       for (total_len = 0; spd.nr_pages < nr_pages; spd.nr_pages++) {
                unsigned int this_len, this_end, private;
                unsigned int cur_pos = read_start + total_len;