Skip to contentSkip to conversation

fuse: fix possible bug in fuse_direct_io on 64-bit system

PATCH In review Marcin Slusarz 2 participants 2 messages Apr 10, 2009 – Apr 11, 2009 FUSE filesystem core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fuse: fix possible bug in fuse_direct_io on 64-bit system

Fix possible bug on 64-bit system when user requests > 4GB of data by direct_io read/write, but provides smaller buffer.

(passing nbytes>4GB to fuse_get_user_pages truncates nbytes and get_user_pages is called with wrong value of npages)

Found by gcc:
fs/fuse/file.c: In function 'fuse_direct_io':
fs/fuse/file.c:1002: warning: passing argument 3 of 'fuse_get_user_pages' from incompatible pointer type

---
 fs/fuse/file.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
fs/fuse/file.c +3 -3
index 2b25133..0bb60c3 100644
@@ -938,9 +938,9 @@ static void fuse_release_user_pages(struct fuse_req *req, int write)
 }
 
 static int fuse_get_user_pages(struct fuse_req *req, const char __user *buf,
-			       unsigned *nbytesp, int write)
+			       size_t *nbytesp, int write)
 {
-	unsigned nbytes = *nbytesp;
+	size_t nbytes = *nbytesp;
 	unsigned long user_addr = (unsigned long) buf;
 	unsigned offset = user_addr & ~PAGE_MASK;
 	int npages;
@@ -955,7 +955,7 @@ static int fuse_get_user_pages(struct fuse_req *req, const char __user *buf,
 		return 0;
 	}
 
-	nbytes = min(nbytes, (unsigned) FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT);
+	nbytes = min(nbytes, (size_t) FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT);
 	npages = (nbytes + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
 	npages = clamp(npages, 1, FUSE_MAX_PAGES_PER_REQ);
 	down_read(&current->mm->mmap_sem);