Skip to content

Commit d953975

Browse files
committed
net/compat: Add missing sock updates for SCM_RIGHTS
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 <[email protected]> Cc: Sargun Dhillon <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: [email protected] 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 <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent 11eb004 commit d953975

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

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
@@ -309,6 +309,7 @@ void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
309309
break;
310310
}
311311
/* Bump the usage count and install the file. */
312+
__receive_sock(fp[i]);
312313
fd_install(new_fd, get_file(fp[i]));
313314
}
314315

net/core/sock.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,6 +2840,27 @@ int sock_no_mmap(struct file *file, struct socket *sock, struct vm_area_struct *
28402840
}
28412841
EXPORT_SYMBOL(sock_no_mmap);
28422842

2843+
/*
2844+
* When a file is received (via SCM_RIGHTS, etc), we must bump the
2845+
* various sock-based usage counts.
2846+
*/
2847+
void __receive_sock(struct file *file)
2848+
{
2849+
struct socket *sock;
2850+
int error;
2851+
2852+
/*
2853+
* The resulting value of "error" is ignored here since we only
2854+
* need to take action when the file is a socket and testing
2855+
* "sock" for NULL is sufficient.
2856+
*/
2857+
sock = sock_from_file(file, &error);
2858+
if (sock) {
2859+
sock_update_netprioidx(&sock->sk->sk_cgrp_data);
2860+
sock_update_classid(&sock->sk->sk_cgrp_data);
2861+
}
2862+
}
2863+
28432864
ssize_t sock_no_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags)
28442865
{
28452866
ssize_t res;

0 commit comments

Comments
 (0)