Skip to contentSkip to conversation

sendfile: several fixes

PATCH In review [email protected] 5 participants 7 messages Aug 6, 2009 – Aug 7, 2009 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 9/12 sendfile: several fixes

From: Mandeep Singh Baines <[email protected]>

Three fixes for sendfile, mostly related to sending large files from pseudo filesystems:

- Fix sendfile for offsets > 300G. This can happen with pseudo filesystems. This happens because the overflow check is using inode->i_sb->s_maxbytes and not the superblock of the backing device's s_maxbytes. For a regular file these are interchangible but for a special file these are different and you want the latter.

- Don't compare against the max of the out_inode's superblock. Doesn't make sense.

- For pseudo and other filesystems with s_maxbytes set to ~0ULL, max ends up holding a negative number as it is signed. Check for and correct that.

---

 fs/read_write.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
fs/read_write.c renamed from fs/read_write.c~sendfile-several-fixes +9 -2
diff -puN fs/read_write.c~sendfile-several-fixes fs/read_write.c
@@ -835,8 +835,15 @@ static ssize_t do_sendfile(int out_fd, i
 		goto fput_out;
 	count = retval;
 
-	if (!max)
-		max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
+	if (!max) {
+		max = in_inode->i_mapping->host->i_sb->s_maxbytes;
+		/*
+		 * For psuedo filesystems, s_maxbytes is ~0ULL. When converted
+		 * to loff_t, it can go negative. So we check for and fix that.
+		 */
+		if (max < 0)
+			max = LLONG_MAX;
+	}
 
 	pos = *ppos;
 	retval = -EINVAL;

_

#1 lore raw
Quoted 11 lines · On Thu, Aug 06, 2009 at 04:10:15PM -0700, [email protected] wrote:

From: Mandeep Singh Baines <[email protected]>

Three fixes for sendfile, mostly related to sending large files from pseudo filesystems:

- Fix sendfile for offsets > 300G. This can happen with pseudo filesystems. This happens because the overflow check is using inode->i_sb->s_maxbytes and not the superblock of the backing device's s_maxbytes. For a regular file these are interchangible but for a special file these are different and you want the latter.

Quoted 5 lines

- Don't compare against the max of the out_inode's superblock. Doesn't make sense.

- For pseudo and other filesystems with s_maxbytes set to ~0ULL, max ends up holding a negative number as it is signed. Check for and correct that.

The right fix is to not set s_maxbytes to ~0ULL. Jeff Layton has sent some patches for that recently.

#2 lore raw
Quoted 2 lines · Christoph Hellwig

The right fix is to not set s_maxbytes to ~0ULL.  Jeff Layton has sent some patches for that recently.

I agree.

I still think this check is worthwhile, given the signed/unsigned mismatch.

Robert
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 8 lines · Robert Love
Quoted 2 lines · Christoph Hellwig

The right fix is to not set s_maxbytes to ~0ULL. ?Jeff Layton has sent some patches for that recently.

I agree.

I still think this check is worthwhile, given the signed/unsigned mismatch.

I think the plan is to change s_maxbytes to be an loff_t which would eliminate this. I'm not sure if Jeff has sent that patch already.

#4 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Robert Love
Quoted 2 lines · Christoph Hellwig

The right fix is to not set s_maxbytes to ~0ULL. ?Jeff Layton has sent some patches for that recently.

Yeah, found it here:

http://lkml.org/lkml/2009/7/22/178

Quoted 7 lines
Quoted 3 lines

I agree.

I still think this check is worthwhile, given the signed/unsigned mismatch.

I think the plan is to change s_maxbytes to be an loff_t which would eliminate this. I'm not sure if Jeff has sent that patch already.

Yeah, found the discussion here:

http://lkml.org/lkml/2009/7/22/241

Cool. Didn't really like this check. It would be nice to remove the check and comment from the next version of this patch.

#5 lore raw
Quoted 20 lines · On Thu, 6 Aug 2009 23:12:17 -0700 Mandeep Singh Baines <[email protected]> wrote:
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Robert Love
Quoted 2 lines · Christoph Hellwig

The right fix is to not set s_maxbytes to ~0ULL. ?Jeff Layton has sent some patches for that recently.

Yeah, found it here:

http://lkml.org/lkml/2009/7/22/178

Quoted 7 lines
Quoted 3 lines

I agree.

I still think this check is worthwhile, given the signed/unsigned mismatch.

I think the plan is to change s_maxbytes to be an loff_t which would eliminate this. I'm not sure if Jeff has sent that patch already.

Quoted 6 lines

Yeah, found the discussion here:

http://lkml.org/lkml/2009/7/22/241

Cool. Didn't really like this check. It would be nice to remove the check and comment from the next version of this patch.

Jeff, can you please redo/refresh/review/resend that stuff?

Thanks.

#6 lore raw
Quoted 22 lines · On Thu, 6 Aug 2009 23:26:55 -0700 Andrew Morton <[email protected]>…
Quoted 20 lines · On Thu, 6 Aug 2009 23:12:17 -0700 Mandeep Singh Baines <[email protected]> wrote:
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Robert Love
Quoted 2 lines · Christoph Hellwig

The right fix is to not set s_maxbytes to ~0ULL. ?Jeff Layton has sent some patches for that recently.

Yeah, found it here:

http://lkml.org/lkml/2009/7/22/178

Quoted 7 lines
Quoted 3 lines

I agree.

I still think this check is worthwhile, given the signed/unsigned mismatch.

I think the plan is to change s_maxbytes to be an loff_t which would eliminate this. I'm not sure if Jeff has sent that patch already.

Quoted 9 lines
Quoted 6 lines

Yeah, found the discussion here:

http://lkml.org/lkml/2009/7/22/241

Cool. Didn't really like this check. It would be nice to remove the check and comment from the next version of this patch.

Jeff, can you please redo/refresh/review/resend that stuff?

Yep. I'll try to have something next week. The tricky part here is checking all of the existing filesystems and making sure that changing s_maxbytes to loff_t won't break anything.

I also want to clean up the checks in do_sendfile like Johannes suggested, though I still have some questions about that...

Signature · 1 line
Jeff Layton <[email protected]>