[PATCH] fuse: ioctl: fix comparison in fuse_setup_measure_verity()

Ali Nasrollahi posted 1 patch 1 month, 2 weeks ago
fs/fuse/ioctl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] fuse: ioctl: fix comparison in fuse_setup_measure_verity()
Posted by Ali Nasrollahi 1 month, 2 weeks ago
Clang reports a warning in fuse_setup_measure_verity() in
fs/fuse/ioctl.c when comparing the `__u16 digest_size` with SIZE_MAX
minus the size of `struct fsverity_digest`:

	warning: result of comparison of constant 18446744073709551611
	with expression of type '__u16' (aka 'unsigned short') is always
	false [-Wtautological-constant-out-of-range-compare]

This was first observed while building an x86_64 kernel with Clang and
W=1. Since -Werror was enabled in my build, the warning caused the build
to fail.

However, the same warning can also be reproduced with the same build
options using tinyconfig with FUSE enabled, so this is not specific to
the kernel configuration used in the original build.

The comparison is between the 16-bit digest_size and a size_t-sized
constant. Cast digest_size to size_t so that the comparison is performed
using the same type as the size calculation.

Signed-off-by: Ali Nasrollahi <A.Nasrolahi01@gmail.com>
---
 fs/fuse/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/fuse/ioctl.c b/fs/fuse/ioctl.c
index 3614ea603913..3487e30d997c 100644
--- a/fs/fuse/ioctl.c
+++ b/fs/fuse/ioctl.c
@@ -130,7 +130,7 @@ static int fuse_setup_measure_verity(unsigned long arg, struct iovec *iov)
 	if (copy_from_user(&digest_size, &uarg->digest_size, sizeof(digest_size)))
 		return -EFAULT;
 
-	if (digest_size > SIZE_MAX - sizeof(struct fsverity_digest))
+	if ((size_t)digest_size > SIZE_MAX - sizeof(struct fsverity_digest))
 		return -EINVAL;
 
 	iov->iov_len = sizeof(struct fsverity_digest) + digest_size;
-- 
2.55.0
Re: [PATCH] fuse: ioctl: fix comparison in fuse_setup_measure_verity()
Posted by Miklos Szeredi 1 month, 1 week ago
On Thu, 13 Aug 2026 at 09:07, Ali Nasrollahi <a.nasrolahi01@gmail.com> wrote:
>
> Clang reports a warning in fuse_setup_measure_verity() in
> fs/fuse/ioctl.c when comparing the `__u16 digest_size` with SIZE_MAX
> minus the size of `struct fsverity_digest`:
>
>         warning: result of comparison of constant 18446744073709551611
>         with expression of type '__u16' (aka 'unsigned short') is always
>         false [-Wtautological-constant-out-of-range-compare]

The warning is right: that condition is never going to succeed.  So
just remove it?

Thanks,
Miklos
Re: [PATCH] fuse: ioctl: fix comparison in fuse_setup_measure_verity()
Posted by Ali Nasrollahi 1 month, 1 week ago
On 26/08/18 10:53AM, Miklos Szeredi wrote:
> On Thu, 13 Aug 2026 at 09:07, Ali Nasrollahi <a.nasrolahi01@gmail.com> wrote:
> >
> > Clang reports a warning in fuse_setup_measure_verity() in
> > fs/fuse/ioctl.c when comparing the `__u16 digest_size` with SIZE_MAX
> > minus the size of `struct fsverity_digest`:
> >
> >         warning: result of comparison of constant 18446744073709551611
> >         with expression of type '__u16' (aka 'unsigned short') is always
> >         false [-Wtautological-constant-out-of-range-compare]
> 
> The warning is right: that condition is never going to succeed.  So
> just remove it?

Well, I wasn't sure why it was there in the first place, so I didn't want
to change the logic. So I'll send the v2 considering your comment.

Thanks,
    Ali