From: Rich Felker <dalias@libc.org>
To: Ismael Luceno <ismael@iodev.co.uk>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] ioctl: Fix implicit constant conversion overflow
Date: Fri, 31 May 2024 22:34:30 -0400 [thread overview]
Message-ID: <20240601023429.GJ10433@brightrain.aerifal.cx> (raw)
In-Reply-To: <20240601010328.27409-1-ismael@iodev.co.uk>
On Sat, Jun 01, 2024 at 03:03:25AM +0200, Ismael Luceno wrote:
> The last parameter (result of sizeof) to _IOC in _IOR/_IOW/_IOWR causes
> the underlying expression's value to be promoted to size_t. Casting it
> to int resolves the issue.
>
> Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
> ---
> arch/generic/bits/ioctl.h | 6 +++---
> arch/mips/bits/ioctl.h | 6 +++---
> arch/mipsn32/bits/ioctl.h | 6 +++---
> arch/powerpc/bits/ioctl.h | 6 +++---
> arch/powerpc64/bits/ioctl.h | 6 +++---
> arch/sh/bits/ioctl.h | 6 +++---
> 6 files changed, 18 insertions(+), 18 deletions(-)
>
> diff --git a/arch/generic/bits/ioctl.h b/arch/generic/bits/ioctl.h
> index 60ae8b850b17..16541d547f68 100644
> --- a/arch/generic/bits/ioctl.h
> +++ b/arch/generic/bits/ioctl.h
> @@ -4,9 +4,9 @@
> #define _IOC_READ 2U
>
> #define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0)
> -#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c))
> -#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c))
> -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
> +#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),(int)sizeof(c))
> +#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),(int)sizeof(c))
> +#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),(int)sizeof(c))
I don't see how this helps with the warning you're trying to suppress,
since _IOC_{READ,WRITE} already have unsigned type. If you changed
that, you would then have *real overflows* (undefined behavior)
instead of the well-defined, valid implicit conversions -Werror is
complaining about.
There may be a way to improve on the situation here but it's not so
simple.
Rich
next prev parent reply other threads:[~2024-06-01 2:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-01 1:03 Ismael Luceno
2024-06-01 2:34 ` Rich Felker [this message]
2024-06-02 3:01 ` Ismael Luceno
2024-06-02 22:50 ` Rich Felker
2024-06-03 1:57 ` Ismael Luceno
2024-06-10 16:04 ` Rich Felker
2024-06-11 19:02 ` Ismael Luceno
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240601023429.GJ10433@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=ismael@iodev.co.uk \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).