Subject: Re: [PATCH v1 net] af_unix: Terminate sun_path when bind()ing pathname socket.

From: Kees Cook <[email-masked]>
Date: Wed, 26 Jul 2023 15:15:45 -0700

On Wed, Jul 26, 2023 at 12:08:28PM -0700, Kuniyuki Iwashima wrote:
> kernel test robot reported slab-out-of-bounds access in strlen(). [0]
> 
> Commit 06d4c8a80836 ("af_unix: Fix fortify_panic() in unix_bind_bsd().")
> removed unix_mkname_bsd() call in unix_bind_bsd().
> 
> If sunaddr->sun_path is not terminated by user and we don't enable
> CONFIG_INIT_STACK_ALL_ZERO=y, strlen() will do the out-of-bounds access
> during file creation.
> 
> Let's go back to strlen()-with-sockaddr_storage way and pack all 108
> trickiness into unix_mkname_bsd() with bold comments.
> 

Okay, this does at least collapse all the scary casting into a single
function. :) Thanks for navigating this!

Reviewed-by: Kees Cook <[email-masked]>

-- 
Kees Cook