|
@@ -1023,9 +1023,24 @@ static inline unsigned int round_pipe_size(unsigned int size)
|
|
* Allocate a new array of pipe buffers and copy the info over. Returns the
|
|
* Allocate a new array of pipe buffers and copy the info over. Returns the
|
|
* pipe size if successful, or return -ERROR on error.
|
|
* pipe size if successful, or return -ERROR on error.
|
|
*/
|
|
*/
|
|
-static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long nr_pages)
|
|
|
|
|
|
+static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long arg)
|
|
{
|
|
{
|
|
struct pipe_buffer *bufs;
|
|
struct pipe_buffer *bufs;
|
|
|
|
+ unsigned int size, nr_pages;
|
|
|
|
+
|
|
|
|
+ size = round_pipe_size(arg);
|
|
|
|
+ nr_pages = size >> PAGE_SHIFT;
|
|
|
|
+
|
|
|
|
+ if (!nr_pages)
|
|
|
|
+ return -EINVAL;
|
|
|
|
+
|
|
|
|
+ if (!capable(CAP_SYS_RESOURCE) && size > pipe_max_size)
|
|
|
|
+ return -EPERM;
|
|
|
|
+
|
|
|
|
+ if ((too_many_pipe_buffers_hard(pipe->user) ||
|
|
|
|
+ too_many_pipe_buffers_soft(pipe->user)) &&
|
|
|
|
+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
|
|
|
|
+ return -EPERM;
|
|
|
|
|
|
/*
|
|
/*
|
|
* We can shrink the pipe, if arg >= pipe->nrbufs. Since we don't
|
|
* We can shrink the pipe, if arg >= pipe->nrbufs. Since we don't
|
|
@@ -1109,28 +1124,9 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
|
|
__pipe_lock(pipe);
|
|
__pipe_lock(pipe);
|
|
|
|
|
|
switch (cmd) {
|
|
switch (cmd) {
|
|
- case F_SETPIPE_SZ: {
|
|
|
|
- unsigned int size, nr_pages;
|
|
|
|
-
|
|
|
|
- size = round_pipe_size(arg);
|
|
|
|
- nr_pages = size >> PAGE_SHIFT;
|
|
|
|
-
|
|
|
|
- ret = -EINVAL;
|
|
|
|
- if (!nr_pages)
|
|
|
|
- goto out;
|
|
|
|
-
|
|
|
|
- if (!capable(CAP_SYS_RESOURCE) && size > pipe_max_size) {
|
|
|
|
- ret = -EPERM;
|
|
|
|
- goto out;
|
|
|
|
- } else if ((too_many_pipe_buffers_hard(pipe->user) ||
|
|
|
|
- too_many_pipe_buffers_soft(pipe->user)) &&
|
|
|
|
- !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN)) {
|
|
|
|
- ret = -EPERM;
|
|
|
|
- goto out;
|
|
|
|
- }
|
|
|
|
- ret = pipe_set_size(pipe, nr_pages);
|
|
|
|
|
|
+ case F_SETPIPE_SZ:
|
|
|
|
+ ret = pipe_set_size(pipe, arg);
|
|
break;
|
|
break;
|
|
- }
|
|
|
|
case F_GETPIPE_SZ:
|
|
case F_GETPIPE_SZ:
|
|
ret = pipe->buffers * PAGE_SIZE;
|
|
ret = pipe->buffers * PAGE_SIZE;
|
|
break;
|
|
break;
|
|
@@ -1139,7 +1135,6 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
-out:
|
|
|
|
__pipe_unlock(pipe);
|
|
__pipe_unlock(pipe);
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|