All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] exec: remove comparision of variable i_size of type loff_t against SIZE_MAX
@ 2020-02-27 23:31 Scott Branden
  2020-02-27 23:39 ` Eric Biggers
  2020-02-27 23:40 ` Al Viro
  0 siblings, 2 replies; 4+ messages in thread
From: Scott Branden @ 2020-02-27 23:31 UTC (permalink / raw)
  To: Alexander Viro
  Cc: linux-fsdevel, linux-kernel, bcm-kernel-feedback-list, 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).

Signed-off-by: Scott Branden <scott.branden@broadcom.com>
---
 fs/exec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/exec.c b/fs/exec.c
index db17be51b112..16c229752f74 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -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;
 	}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] exec: remove comparision of variable i_size of type loff_t against SIZE_MAX
  2020-02-27 23:31 [PATCH] exec: remove comparision of variable i_size of type loff_t against SIZE_MAX Scott Branden
@ 2020-02-27 23:39 ` Eric Biggers
  2020-02-27 23:40 ` Al Viro
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Biggers @ 2020-02-27 23:39 UTC (permalink / raw)
  To: Scott Branden
  Cc: Alexander Viro, linux-fsdevel, linux-kernel, bcm-kernel-feedback-list

On Thu, Feb 27, 2020 at 03:31:33PM -0800, Scott Branden wrote:
> 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).
> 
> Signed-off-by: Scott Branden <scott.branden@broadcom.com>
> ---
>  fs/exec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/exec.c b/fs/exec.c
> index db17be51b112..16c229752f74 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] exec: remove comparision of variable i_size of type loff_t against SIZE_MAX
  2020-02-27 23:31 [PATCH] exec: remove comparision of variable i_size of type loff_t against SIZE_MAX Scott Branden
  2020-02-27 23:39 ` Eric Biggers
@ 2020-02-27 23:40 ` Al Viro
  2020-02-27 23:49   ` Scott Branden
  1 sibling, 1 reply; 4+ messages in thread
From: Al Viro @ 2020-02-27 23:40 UTC (permalink / raw)
  To: Scott Branden; +Cc: linux-fsdevel, linux-kernel, bcm-kernel-feedback-list

On Thu, Feb 27, 2020 at 03:31:33PM -0800, Scott Branden wrote:
> 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...

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] exec: remove comparision of variable i_size of type loff_t against SIZE_MAX
  2020-02-27 23:40 ` Al Viro
@ 2020-02-27 23:49   ` Scott Branden
  0 siblings, 0 replies; 4+ messages in thread
From: Scott Branden @ 2020-02-27 23:49 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-fsdevel, linux-kernel, bcm-kernel-feedback-list



On 2020-02-27 3:40 p.m., Al Viro wrote:
> On Thu, Feb 27, 2020 at 03:31:33PM -0800, Scott Branden wrote:
>> 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?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-27 23:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27 23:31 [PATCH] exec: remove comparision of variable i_size of type loff_t against SIZE_MAX Scott Branden
2020-02-27 23:39 ` Eric Biggers
2020-02-27 23:40 ` Al Viro
2020-02-27 23:49   ` Scott Branden

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.