Unverified Commit afb9917d authored by Christian Brauner's avatar Christian Brauner
Browse files

Revert "net/socket: convert sock_map_fd() to FD_ADD()"



This reverts commit 245f0d1c.

When allocating a file sock_alloc_file() consumes the socket reference
unconditionally which isn't correctly handled in the conversion. This
can be fixed by massaging this appropriately but this is best left for
next cycle.

Reported-by: default avatarXin Long <lucien.xin@gmail.com>
Link: https://lore.kernel.org/CADvbK_ewub4ZZK-tZg8GBQbDFHWhd9a48C+AFXZ93pMsssCrUg@mail.gmail.com


Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent b6cb3cce
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -503,14 +503,23 @@ EXPORT_SYMBOL(sock_alloc_file);

static int sock_map_fd(struct socket *sock, int flags)
{
	int fd;

	fd = FD_ADD(flags, sock_alloc_file(sock, flags, NULL));
	if (fd < 0)
	struct file *newfile;
	int fd = get_unused_fd_flags(flags);
	if (unlikely(fd < 0)) {
		sock_release(sock);
		return fd;
	}

	newfile = sock_alloc_file(sock, flags, NULL);
	if (!IS_ERR(newfile)) {
		fd_install(fd, newfile);
		return fd;
	}

	put_unused_fd(fd);
	return PTR_ERR(newfile);
}

/**
 *	sock_from_file - Return the &socket bounded to @file.
 *	@file: file