Skip to content

Commit 342a9b0

Browse files
keesgregkh
authored andcommitted
net/compat: Add missing sock updates for SCM_RIGHTS
commit d953975 upstream. Add missed sock updates to compat path via a new helper, which will be used more in coming patches. (The net/core/scm.c code is left as-is here to assist with -stable backports for the compat path.) Cc: Christoph Hellwig <hch@lst.de> Cc: Sargun Dhillon <sargun@sargun.me> Cc: Jakub Kicinski <kuba@kernel.org> Cc: stable@vger.kernel.org Fixes: 48a87cc ("net: netprio: fd passed in SCM_RIGHTS datagram not set correctly") Fixes: d842950 ("net: net_cls: fd passed in SCM_RIGHTS datagram not set correctly") Acked-by: Christian Brauner <christian.brauner@ubuntu.com> Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 08d41d0 commit 342a9b0

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎include/net/sock.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,13 +890,17 @@ static inline int sk_memalloc_socks(void)
890890
{
891891
return static_branch_unlikely(&memalloc_socks_key);
892892
}
893+
894+
void __receive_sock(struct file *file);
893895
#else
894896

895897
static inline int sk_memalloc_socks(void)
896898
{
897899
return 0;
898900
}
899901

902+
static inline void __receive_sock(struct file *file)
903+
{ }
900904
#endif
901905

902906
static inline gfp_t sk_gfp_mask(const struct sock *sk, gfp_t gfp_mask)

‎net/compat.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
307307
break;
308308
}
309309
/* Bump the usage count and install the file. */
310+
__receive_sock(fp[i]);
310311
fd_install(new_fd, get_file(fp[i]));
311312
}
312313

‎net/core/sock.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,6 +2753,27 @@ int sock_no_mmap(struct file *file, struct socket *sock, struct vm_area_struct *
27532753
}
27542754
EXPORT_SYMBOL(sock_no_mmap);
27552755

2756+
/*
2757+
* When a file is received (via SCM_RIGHTS, etc), we must bump the
2758+
* various sock-based usage counts.
2759+
*/
2760+
void __receive_sock(struct file *file)
2761+
{
2762+
struct socket *sock;
2763+
int error;
2764+
2765+
/*
2766+
* The resulting value of "error" is ignored here since we only
2767+
* need to take action when the file is a socket and testing
2768+
* "sock" for NULL is sufficient.
2769+
*/
2770+
sock = sock_from_file(file, &error);
2771+
if (sock) {
2772+
sock_update_netprioidx(&sock->sk->sk_cgrp_data);
2773+
sock_update_classid(&sock->sk->sk_cgrp_data);
2774+
}
2775+
}
2776+
27562777
ssize_t sock_no_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags)
27572778
{
27582779
ssize_t res;

0 commit comments

Comments
 (0)