linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] pipe: fix pipe buffer resizing
@ 2010-06-08 14:28 Miklos Szeredi
  2010-06-08 14:30 ` [PATCH 2/2] pipe: remove bogus check from "set size" fcntl Miklos Szeredi
  0 siblings, 1 reply; 4+ messages in thread
From: Miklos Szeredi @ 2010-06-08 14:28 UTC (permalink / raw)
  To: jens.axboe; +Cc: akpm, torvalds, linux-fsdevel, linux-kernel

From: Miklos Szeredi <mszeredi@suse.cz>

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>
---
 fs/pipe.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Index: linux.git/fs/pipe.c
===================================================================
--- linux.git.orig/fs/pipe.c	2010-06-08 15:02:16.000000000 +0200
+++ linux.git/fs/pipe.c	2010-06-08 15:50:07.000000000 +0200
@@ -1145,13 +1145,20 @@ static long pipe_set_size(struct pipe_in
 	 * and adjust the indexes.
 	 */
 	if (pipe->nrbufs) {
-		const unsigned int tail = pipe->nrbufs & (pipe->buffers - 1);
-		const unsigned int head = pipe->nrbufs - tail;
+		unsigned int tail;
+		unsigned int head;
 
+		tail = pipe->curbuf + pipe->nrbufs;
+		if (tail < pipe->buffers)
+			tail = 0;
+		else
+			tail &= (pipe->buffers - 1);
+
+		head = pipe->nrbufs - tail;
 		if (head)
 			memcpy(bufs, pipe->bufs + pipe->curbuf, head * sizeof(struct pipe_buffer));
 		if (tail)
-			memcpy(bufs + head, pipe->bufs + pipe->curbuf, tail * sizeof(struct pipe_buffer));
+			memcpy(bufs + head, pipe->bufs, tail * sizeof(struct pipe_buffer));
 	}
 
 	pipe->curbuf = 0;

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-06-08 18:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-08 14:28 [PATCH 1/2] pipe: fix pipe buffer resizing Miklos Szeredi
2010-06-08 14:30 ` [PATCH 2/2] pipe: remove bogus check from "set size" fcntl Miklos Szeredi
2010-06-08 15:14   ` Miklos Szeredi
2010-06-08 18:59     ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).