[patch 2/6][RFC] Allow FIBMAP to return EFBIG on large filesystems.

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-fsdevel@...>
Cc: <linux-kernel@...>, Mike Waychison <mikew@...>
Date: Friday, October 26, 2007 - 7:37 pm

Propagate an error (EFBIG) to userspace if the physical block is too large to return in a 32bit int instead of truncating it.

Signed-off-by: Mike Waychison <mikew@google.com>

 fs/ioctl.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Index: linux-2.6.23/fs/ioctl.c
===================================================================
--- linux-2.6.23.orig/fs/ioctl.c	2007-10-26 15:26:10.000000000 -0700
+++ linux-2.6.23/fs/ioctl.c	2007-10-26 16:16:28.000000000 -0700
@@ -52,6 +52,7 @@ static int file_ioctl(struct file *filp,
 		case FIBMAP:
 		{
 			struct address_space *mapping = filp->f_mapping;
+			sector_t phys_block;
 			int res;
 			/* do we support this mess? */
 			if (!mapping->a_ops->bmap)
@@ -64,8 +65,15 @@ static int file_ioctl(struct file *filp,
 				return -EINVAL;
 
 			lock_kernel();
-			res = mapping->a_ops->bmap(mapping, block);
+			phys_block = mapping->a_ops->bmap(mapping, block);
 			unlock_kernel();
+
+			/* Make sure that the return value fits in the
+			 * user's buffer. */
+			if ((u32)phys_block < phys_block)
+				return -EFBIG;
+
+			res = phys_block;
 			return put_user(res, p);
 		}
 		case FIGETBSZ:

--
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch 2/6][RFC] Allow FIBMAP to return EFBIG on large files..., Mike Waychison, (Fri Oct 26, 7:37 pm)