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] [day] [month] [year] [list]
Message-ID: <20230511052426.GH3390869@ZenIV>
Date: Thu, 11 May 2023 06:24:26 +0100
From: Al Viro <viro@...iv.linux.org.uk>
To: ye.xingchen@....com.cn
Cc: davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
	pabeni@...hat.com, netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] net: socket: Use fdget() and fdput()

On Fri, May 05, 2023 at 05:06:41PM +0800, ye.xingchen@....com.cn wrote:
> By using the fdget function, the socket object, can be quickly obtained
> from the process's file descriptor table without the need to obtain the
> file descriptor first before passing it as a parameter to the fget
> function.

>  struct socket *sockfd_lookup(int fd, int *err)
>  {
> -	struct file *file;
> +	struct fd f = fdget(fd);
>  	struct socket *sock;
> 
> -	file = fget(fd);
> -	if (!file) {
> +	if (!f.file) {
>  		*err = -EBADF;
>  		return NULL;
>  	}
> 
> -	sock = sock_from_file(file);
> +	sock = sock_from_file(f.file);
>  	if (!sock) {
>  		*err = -ENOTSOCK;
> -		fput(file);
> +		fdput(f);
>  	}
>  	return sock;

Suppose you've got that far.  If descriptor table had been shared, you've
bumped the refcount of struct file.  If it hadn't been, that refcount
had remained unchanged.  And there is no way for the caller of this
function to tell one outcome from another.

That can't work.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ