Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

This reverts commit 245f0d1c622b0183ce4f44b3e39aeacf78fae594.

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: Xin Long <lucien.xin@gmail.com>
Link: https://lore.kernel.org/CADvbK_ewub4ZZK-tZg8GBQbDFHWhd9a48C+AFXZ93pMsssCrUg@mail.gmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>

+14 -5
+14 -5
net/socket.c
··· 503 503 504 504 static int sock_map_fd(struct socket *sock, int flags) 505 505 { 506 - int fd; 507 - 508 - fd = FD_ADD(flags, sock_alloc_file(sock, flags, NULL)); 509 - if (fd < 0) 506 + struct file *newfile; 507 + int fd = get_unused_fd_flags(flags); 508 + if (unlikely(fd < 0)) { 510 509 sock_release(sock); 511 - return fd; 510 + return fd; 511 + } 512 + 513 + newfile = sock_alloc_file(sock, flags, NULL); 514 + if (!IS_ERR(newfile)) { 515 + fd_install(fd, newfile); 516 + return fd; 517 + } 518 + 519 + put_unused_fd(fd); 520 + return PTR_ERR(newfile); 512 521 } 513 522 514 523 /**