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: <ZNZcTQCDXfMA3v6O@sequoia>
Date:   Fri, 11 Aug 2023 11:53:37 -0500
From:   Tyler Hicks <code@...icks.com>
To:     Kees Cook <keescook@...omium.org>
Cc:     Petr Mladek <pmladek@...e.com>,
        Sergey Senozhatsky <senozhatsky@...omium.org>,
        Steven Rostedt <rostedt@...dmis.org>,
        John Ogness <john.ogness@...utronix.de>,
        Vijay Balakrishna <vijayb@...ux.microsoft.com>,
        stable@...r.kernel.org, Tony Luck <tony.luck@...el.com>,
        "Guilherme G. Piccoli" <gpiccoli@...lia.com>,
        "Paul E. McKenney" <paulmck@...nel.org>,
        linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH] printk: ringbuffer: Fix truncating buffer size min_t cast

On 2023-08-10 22:45:32, Kees Cook wrote:
> If an output buffer size exceeded U16_MAX, the min_t(u16, ...) cast in
> copy_data() was causing writes to truncate. This manifested as output
> bytes being skipped, seen as %NUL bytes in pstore dumps when the available
> record size was larger than 65536. Fix the cast to no longer truncate
> the calculation.
> 
> Cc: Petr Mladek <pmladek@...e.com>
> Cc: Sergey Senozhatsky <senozhatsky@...omium.org>
> Cc: Steven Rostedt <rostedt@...dmis.org>
> Cc: John Ogness <john.ogness@...utronix.de>
> Reported-by: Vijay Balakrishna <vijayb@...ux.microsoft.com>
> Closes: https://lore.kernel.org/lkml/d8bb1ec7-a4c5-43a2-9de0-9643a70b899f@linux.microsoft.com/
> Fixes: b6cf8b3f3312 ("printk: add lockless ringbuffer")
> Cc: stable@...r.kernel.org
> Signed-off-by: Kees Cook <keescook@...omium.org>

Nice find!

Reviewed-by: Tyler Hicks (Microsoft) <code@...icks.com>
Tested-by: Tyler Hicks (Microsoft) <code@...icks.com>

Verified the fix by applying it to an instrumented v6.5-rc5 kernel that
allows userspace to execute kmsg_dump(), detects NULL bytes in data
copied from the ring buffer, and warns about invalid truncation due to
the min_t(u16, ...) casting bug. Everything looks good!

Tyler

> ---
>  kernel/printk/printk_ringbuffer.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
> index 2dc4d5a1f1ff..fde338606ce8 100644
> --- a/kernel/printk/printk_ringbuffer.c
> +++ b/kernel/printk/printk_ringbuffer.c
> @@ -1735,7 +1735,7 @@ static bool copy_data(struct prb_data_ring *data_ring,
>  	if (!buf || !buf_size)
>  		return true;
>  
> -	data_size = min_t(u16, buf_size, len);
> +	data_size = min_t(unsigned int, buf_size, len);
>  
>  	memcpy(&buf[0], data, data_size); /* LMM(copy_data:A) */
>  	return true;
> -- 
> 2.34.1
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ