瀏覽代碼

[PATCH] generic_file_buffered_write fixes

Anton Altaparmakov <aia21@cam.ac.uk> points out:

- It calls fault_in_pages_readable() which is completely bogus if @nr_segs >
  1.  It needs to be replaced by a to be written
  "fault_in_pages_readable_iovec()".

- It increments @buf even in the iovec case thus @buf can point to random
  memory really quickly (in the iovec case) and then it calls
  fault_in_pages_readable() on this random memory.

Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
akpm@osdl.org 20 年之前
父節點
當前提交
f021e92101
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      mm/filemap.c

+ 4 - 2
mm/filemap.c

@@ -1949,7 +1949,7 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov,
 		buf = iov->iov_base + written;
 		buf = iov->iov_base + written;
 	else {
 	else {
 		filemap_set_next_iovec(&cur_iov, &iov_base, written);
 		filemap_set_next_iovec(&cur_iov, &iov_base, written);
-		buf = iov->iov_base + iov_base;
+		buf = cur_iov->iov_base + iov_base;
 	}
 	}
 
 
 	do {
 	do {
@@ -2007,9 +2007,11 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov,
 				count -= status;
 				count -= status;
 				pos += status;
 				pos += status;
 				buf += status;
 				buf += status;
-				if (unlikely(nr_segs > 1))
+				if (unlikely(nr_segs > 1)) {
 					filemap_set_next_iovec(&cur_iov,
 					filemap_set_next_iovec(&cur_iov,
 							&iov_base, status);
 							&iov_base, status);
+					buf = cur_iov->iov_base + iov_base;
+				}
 			}
 			}
 		}
 		}
 		if (unlikely(copied != bytes))
 		if (unlikely(copied != bytes))