Skip to contentSkip to conversation

exec: remove comparision of variable i_size of type loff_t against SIZE_MAX

PATCH In review Scott Branden 3 participants 4 messages Feb 27, 2020

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

PATCH 1/1 exec: remove comparision of variable i_size of type loff_t against SIZE_MAX

Remove comparision of (i_size > SIZE_MAX).
i_size is of type loff_t and can not be great than SIZE_MAX (~(size_t)0).

---
 fs/exec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/exec.c +1 -1
index db17be51b112..16c229752f74 100644
@@ -919,7 +919,7 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size,
 		ret = -EINVAL;
 		goto out;
 	}
-	if (i_size > SIZE_MAX || (max_size > 0 && i_size > max_size)) {
+	if (max_size > 0 && i_size > max_size) {
 		ret = -EFBIG;
 		goto out;
 	}
Signature · 1 line
2.17.1
#1 lore raw
Quoted 13 lines · Scott Branden

Remove comparision of (i_size > SIZE_MAX).
i_size is of type loff_t and can not be great than SIZE_MAX (~(size_t)0).

---
 fs/exec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/exec.c +0 -0
index db17be51b112..16c229752f74 100644

fs/exec.c int kernel_read_file(struct file *file, void **buf, loff_t *size, · line 925

Quoted 8 lines
fs/exec.c +1 -1
@@ -919,7 +919,7 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size,
 		ret = -EINVAL;
 		goto out;
 	}
-	if (i_size > SIZE_MAX || (max_size > 0 && i_size > max_size)) {
+	if (max_size > 0 && i_size > max_size) {
 		ret = -EFBIG;
 		goto out;
 	}

Nope, loff_t is 64-bit while size_t can be 32-bit. And this check is intentional, see https://git.kernel.org/torvalds/c/691115c3513ec83e

- Eric

maintainer
#2 lore raw
In reply to Scott Branden
Quoted 2 lines · Scott Branden

Remove comparision of (i_size > SIZE_MAX).
i_size is of type loff_t and can not be great than SIZE_MAX (~(size_t)0).

include/linux/types.h:46:typedef __kernel_loff_t loff_t;
include/uapi/asm-generic/posix_types.h:88:typedef long long __kernel_loff_t;

And boxen with size_t smaller than long long do exist. Anything 32bit will qualify. Pick any such and check that yourself...

#3 lore raw
Quoted 8 lines · Al Viro
Quoted 2 lines · Scott Branden

Remove comparision of (i_size > SIZE_MAX).
i_size is of type loff_t and can not be great than SIZE_MAX (~(size_t)0).

include/linux/types.h:46:typedef __kernel_loff_t loff_t;
include/uapi/asm-generic/posix_types.h:88:typedef long long __kernel_loff_t;

And boxen with size_t smaller than long long do exist. Anything 32bit will qualify. Pick any such and check that yourself...

Thanks for the immediate responses.  I'm glad I sent this patch out to understand the check is as such. Is there some attribute we can add so such issues are not reported against static analysis tools such as coverity?