lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d7c19866-6883-4f98-b178-a5ccf8726895@kernel.org>
Date: Thu, 30 May 2024 08:22:03 +0200
From: Jiri Slaby <jirislaby@...nel.org>
To: Nathan Chancellor <nathan@...nel.org>,
 Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Kees Cook <keescook@...omium.org>,
 "Gustavo A. R. Silva" <gustavoars@...nel.org>,
 Bill Wendling <morbo@...gle.com>, Justin Stitt <justinstitt@...gle.com>,
 linux-serial@...r.kernel.org, imx@...ts.linux.dev,
 linux-arm-kernel@...ts.infradead.org, linux-hardening@...r.kernel.org,
 llvm@...ts.linux.dev, patches@...ts.linux.dev, stable@...r.kernel.org
Subject: Re: [PATCH] tty: mxser: Remove __counted_by from mxser_board.ports[]

On 29. 05. 24, 23:29, Nathan Chancellor wrote:
> Work for __counted_by on generic pointers in structures (not just
> flexible array members) has started landing in Clang 19 (current tip of
> tree). During the development of this feature, a restriction was added
> to __counted_by to prevent the flexible array member's element type from
> including a flexible array member itself such as:
> 
>    struct foo {
>      int count;
>      char buf[];
>    };
> 
>    struct bar {
>      int count;
>      struct foo data[] __counted_by(count);
>    };
> 
> because the size of data cannot be calculated with the standard array
> size formula:
> 
>    sizeof(struct foo) * count
> 
> This restriction was downgraded to a warning but due to CONFIG_WERROR,
> it can still break the build. The application of __counted_by on the
> ports member of 'struct mxser_board' triggers this restriction,
> resulting in:
> 
>    drivers/tty/mxser.c:291:2: error: 'counted_by' should not be applied to an array with element of unknown size because 'struct mxser_port' is a struct type with a flexible array member.

Huh -- what am I missing:

struct mxser_port {
         struct tty_port port;
         struct mxser_board *board;

         unsigned long ioaddr;
         unsigned long opmode_ioaddr;

         u8 rx_high_water;
         u8 rx_low_water;
         int type;               /* UART type */

         u8 x_char;              /* xon/xoff character */
         u8 IER;                 /* Interrupt Enable Register */
         u8 MCR;                 /* Modem control register */
         u8 FCR;                 /* FIFO control register */

         struct async_icount icount;
         unsigned int timeout;

         u8 read_status_mask;
         u8 ignore_status_mask;
         u8 xmit_fifo_size;

         spinlock_t slock;
};

?

>  This will be an error in a future compiler version [-Werror,-Wbounds-safety-counted-by-elt-type-unknown-size]
>      291 |         struct mxser_port ports[] __counted_by(nports);
>          |         ^~~~~~~~~~~~~~~~~~~~~~~~~
>    1 error generated.
> 
> Remove this use of __counted_by to fix the warning/error. However,
> rather than remove it altogether, leave it commented, as it may be
> possible to support this in future compiler releases.

This looks like a compiler bug/deficiency.

What does gcc say BTW?

> Cc: stable@...r.kernel.org
> Closes: https://github.com/ClangBuiltLinux/linux/issues/2026
> Fixes: f34907ecca71 ("mxser: Annotate struct mxser_board with __counted_by")

I would not say "Fixes" here. It only works around a broken compiler.

> Signed-off-by: Nathan Chancellor <nathan@...nel.org>
> ---
>   drivers/tty/mxser.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
> index 458bb1280ebf..5b97e420a95f 100644
> --- a/drivers/tty/mxser.c
> +++ b/drivers/tty/mxser.c
> @@ -288,7 +288,7 @@ struct mxser_board {
>   	enum mxser_must_hwid must_hwid;
>   	speed_t max_baud;
>   
> -	struct mxser_port ports[] __counted_by(nports);
> +	struct mxser_port ports[] /* __counted_by(nports) */;
>   };
>   
>   static DECLARE_BITMAP(mxser_boards, MXSER_BOARDS);

thanks,
-- 
js
suse labs


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ