Skip to contentSkip to conversation

Fix rlimit check in precheck_file_write()

PATCH In review Jason Uhlenkott 2 participants 3 messages Dec 22, 2004 – Dec 23, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix rlimit check in precheck_file_write()

Remove a broken assumption that rlimits are 32 bits which can cause nasty things to happen on 64-bit machines if we try to write past the 2^32-1th character of a file and a larger file size limit exists.

mm/filemap.c +2 -2
@@ -3088,9 +3088,9 @@
 			send_sig(SIGXFSZ, current, 0);
 			goto out;
 		}
-		if (pos > 0xFFFFFFFFULL || *count > limit - (u32)pos) {
+		if (*count > limit - pos) {
 			/* send_sig(SIGXFSZ, current, 0); */
-			*count = limit - (u32)pos;
+			*count = limit - pos;
 		}
 	}
 
#1 lore raw
Quoted 9 lines · Jason Uhlenkott

Remove a broken assumption that rlimits are 32 bits which can cause nasty things to happen on 64-bit machines if we try to write past the 2^32-1th character of a file and a larger file size limit exists.

mm/filemap.c line 3094

Quoted 9 lines
mm/filemap.c +2 -2
@@ -3088,9 +3088,9 @@
 			send_sig(SIGXFSZ, current, 0);
 			goto out;
 		}
-		if (pos > 0xFFFFFFFFULL || *count > limit - (u32)pos) {
+		if (*count > limit - pos) {
 			/* send_sig(SIGXFSZ, current, 0); */
-			*count = limit - (u32)pos;
+			*count = limit - pos;
 		}

Are you sure this is safe for all conceivable 32bit cases as well as your 64bit one ? I don't think it is looking at the overflow cases in the if that you removed checking of.

Alan

#2 lore raw
Quoted 7 lines · Alan Cox
Quoted 6 lines · Jason Uhlenkott

Remove a broken assumption that rlimits are 32 bits which can cause nasty things to happen on 64-bit machines if we try to write past the 2^32-1th character of a file and a larger file size limit exists.

Quoted 16 lines

mm/filemap.c line 3094

Quoted 12 lines
mm/filemap.c +2 -2
@@ -3088,9 +3088,9 @@
 			send_sig(SIGXFSZ, current, 0);
 			goto out;
 		}
-		if (pos > 0xFFFFFFFFULL || *count > limit - (u32)pos) {
+		if (*count > limit - pos) {
 			/* send_sig(SIGXFSZ, current, 0); */
-			*count = limit - (u32)pos;
+			*count = limit - pos;
 		}

Are you sure this is safe for all conceivable 32bit cases as well as your 64bit one ? I don't think it is looking at the overflow cases in the if that you removed checking of.

We can't overflow -- immediately above this, we bail out if pos >= limit.