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  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]
Date:   Mon, 30 Nov 2020 17:30:00 -0800
From:   Jakub Kicinski <kuba@...nel.org>
To:     Denis Kirjanov <kda@...ux-powerpc.org>,
        Al Viro <viro@...iv.linux.org.uk>
Cc:     netdev@...r.kernel.org, davem@...emloft.net,
        Christoph Hellwig <hch@....de>
Subject: Re: [PATCH v2] net/af_unix: don't create a path for a binded socket

On Mon, 30 Nov 2020 16:27:47 +0300 Denis Kirjanov wrote:
> in the case of the socket which is bound to an adress
> there is no sense to create a path in the next attempts
> 
> here is a program that shows the issue:
> 
> int main()
> {
>     int s;
>     struct sockaddr_un a;
> 
>     s = socket(AF_UNIX, SOCK_STREAM, 0);
>     if (s<0)
>         perror("socket() failed\n");
> 
>     printf("First bind()\n");
> 
>     memset(&a, 0, sizeof(a));
>     a.sun_family = AF_UNIX;
>     strncpy(a.sun_path, "/tmp/.first_bind", sizeof(a.sun_path));
> 
>     if ((bind(s, (const struct sockaddr*) &a, sizeof(a))) == -1)
>         perror("bind() failed\n");
> 
>     printf("Second bind()\n");
> 
>     memset(&a, 0, sizeof(a));
>     a.sun_family = AF_UNIX;
>     strncpy(a.sun_path, "/tmp/.first_bind_failed", sizeof(a.sun_path));
> 
>     if ((bind(s, (const struct sockaddr*) &a, sizeof(a))) == -1)
>         perror("bind() failed\n");
> }
> 
> kda@...S15-SP2:~> ./test
> First bind()
> Second bind()
> bind() failed
> : Invalid argument
> 
> kda@...S15-SP2:~> ls -la /tmp/.first_bind
> .first_bind         .first_bind_failed
> 
> Signed-off-by: Denis Kirjanov <kda@...ux-powerpc.org>
> 
> v2: move a new patch creation after the address assignment check.

It is a behavior change, but IDK if anyone can reasonably depend on
current behavior for anything useful. Otherwise LGTM.

Let's CC Al Viro, and maybe Christoph to get some more capable eyes 
on this.

> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index 41c3303c3357..ff2dd1d3536b 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
> @@ -1034,6 +1034,14 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
>  		goto out;
>  	addr_len = err;
>  
> +	err = mutex_lock_interruptible(&u->bindlock);
> +	if (err)
> +		goto out_put;
> +
> +	err = -EINVAL;
> +	if (u->addr)
> +		goto out_up;
> +
>  	if (sun_path[0]) {
>  		umode_t mode = S_IFSOCK |
>  		       (SOCK_INODE(sock)->i_mode & ~current_umask());
> @@ -1045,14 +1053,6 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
>  		}
>  	}
>  
> -	err = mutex_lock_interruptible(&u->bindlock);
> -	if (err)
> -		goto out_put;
> -
> -	err = -EINVAL;
> -	if (u->addr)
> -		goto out_up;
> -
>  	err = -ENOMEM;
>  	addr = kmalloc(sizeof(*addr)+addr_len, GFP_KERNEL);
>  	if (!addr)

Powered by blists - more mailing lists