diff options
author | Miklos Szeredi <mszeredi@suse.cz> | 2010-06-08 10:28:45 -0400 |
---|---|---|
committer | Jens Axboe <jaxboe@fusionio.com> | 2010-06-10 13:08:34 -0400 |
commit | 1d862f41222b7f385bada9f85a67ca5592ffd33e (patch) | |
tree | 924baccaa8a5a56610db5c66020847b457679736 | |
parent | 3e6c05052c262ebe7fdd85e75e9d4f956cdd8d82 (diff) |
pipe: fix pipe buffer resizing
pipe_set_size() needs to copy pipe bufs from the old circular buffer
to the new.
The current code gets this wrong in multiple ways, resulting in oops.
Test program is available here:
http://www.kernel.org/pub/linux/kernel/people/mszeredi/piperesize/
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
-rw-r--r-- | fs/pipe.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -1145,13 +1145,20 @@ static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long nr_pages) | |||
1145 | * and adjust the indexes. | 1145 | * and adjust the indexes. |
1146 | */ | 1146 | */ |
1147 | if (pipe->nrbufs) { | 1147 | if (pipe->nrbufs) { |
1148 | const unsigned int tail = pipe->nrbufs & (pipe->buffers - 1); | 1148 | unsigned int tail; |
1149 | const unsigned int head = pipe->nrbufs - tail; | 1149 | unsigned int head; |
1150 | 1150 | ||
1151 | tail = pipe->curbuf + pipe->nrbufs; | ||
1152 | if (tail < pipe->buffers) | ||
1153 | tail = 0; | ||
1154 | else | ||
1155 | tail &= (pipe->buffers - 1); | ||
1156 | |||
1157 | head = pipe->nrbufs - tail; | ||
1151 | if (head) | 1158 | if (head) |
1152 | memcpy(bufs, pipe->bufs + pipe->curbuf, head * sizeof(struct pipe_buffer)); | 1159 | memcpy(bufs, pipe->bufs + pipe->curbuf, head * sizeof(struct pipe_buffer)); |
1153 | if (tail) | 1160 | if (tail) |
1154 | memcpy(bufs + head, pipe->bufs + pipe->curbuf, tail * sizeof(struct pipe_buffer)); | 1161 | memcpy(bufs + head, pipe->bufs, tail * sizeof(struct pipe_buffer)); |
1155 | } | 1162 | } |
1156 | 1163 | ||
1157 | pipe->curbuf = 0; | 1164 | pipe->curbuf = 0; |