From 84418d728622f4ce34b6e4db0fbeec1c3f2433dd Mon Sep 17 00:00:00 2001 From: Oskar Viljasaar <oskar.viljasaar@iopsys.eu> Date: Tue, 19 Jan 2021 10:47:11 +0100 Subject: [PATCH] Import openwrt hack patch 901-debloat_sock_diag.patch --- net/Kconfig | 3 +++ net/core/Makefile | 3 ++- net/core/sock.c | 14 ++++++++++++++ net/core/sock_diag.c | 12 ------------ net/ipv4/Kconfig | 1 + net/netlink/Kconfig | 1 + net/packet/Kconfig | 1 + net/unix/Kconfig | 1 + 8 files changed, 23 insertions(+), 13 deletions(-) diff --git a/net/Kconfig b/net/Kconfig index d79219fa53..e2a52376d1 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -98,6 +98,9 @@ source "net/netlabel/Kconfig" endif # if INET +config SOCK_DIAG + bool + config NETWORK_SECMARK bool "Security Marking" help diff --git a/net/core/Makefile b/net/core/Makefile index 80175e6a2e..8aa31e739a 100644 --- a/net/core/Makefile +++ b/net/core/Makefile @@ -10,9 +10,10 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.o obj-y += dev.o ethtool.o dev_addr_lists.o dst.o netevent.o \ neighbour.o rtnetlink.o utils.o link_watch.o filter.o \ - sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \ + dev_ioctl.o tso.o sock_reuseport.o \ fib_notifier.o xdp.o +obj-$(CONFIG_SOCK_DIAG) += sock_diag.o obj-y += net-sysfs.o obj-$(CONFIG_PAGE_POOL) += page_pool.o obj-$(CONFIG_PROC_FS) += net-procfs.o diff --git a/net/core/sock.c b/net/core/sock.c index e6cbe137cb..787dfbb446 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -490,6 +490,18 @@ int __sk_receive_skb(struct sock *sk, struct sk_buff *skb, } EXPORT_SYMBOL(__sk_receive_skb); +u64 sock_gen_cookie(struct sock *sk) +{ + while (1) { + u64 res = atomic64_read(&sk->sk_cookie); + + if (res) + return res; + res = atomic64_inc_return(&sock_net(sk)->cookie_gen); + atomic64_cmpxchg(&sk->sk_cookie, 0, res); + } +} + struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie) { struct dst_entry *dst = __sk_dst_get(sk); @@ -1604,9 +1616,11 @@ static void __sk_free(struct sock *sk) if (likely(sk->sk_net_refcnt)) sock_inuse_add(sock_net(sk), -1); +#ifdef CONFIG_SOCK_DIAG if (unlikely(sk->sk_net_refcnt && sock_diag_has_destroy_listeners(sk))) sock_diag_broadcast_destroy(sk); else +#endif sk_destruct(sk); } diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c index 3312a5849a..8cd45bc053 100644 --- a/net/core/sock_diag.c +++ b/net/core/sock_diag.c @@ -20,18 +20,6 @@ static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh); static DEFINE_MUTEX(sock_diag_table_mutex); static struct workqueue_struct *broadcast_wq; -u64 sock_gen_cookie(struct sock *sk) -{ - while (1) { - u64 res = atomic64_read(&sk->sk_cookie); - - if (res) - return res; - res = atomic64_inc_return(&sock_net(sk)->cookie_gen); - atomic64_cmpxchg(&sk->sk_cookie, 0, res); - } -} - int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie) { u64 res; diff --git a/net/ipv4/Kconfig b/net/ipv4/Kconfig index 2e12f84820..ed98021240 100644 --- a/net/ipv4/Kconfig +++ b/net/ipv4/Kconfig @@ -426,6 +426,7 @@ config INET_XFRM_MODE_BEET config INET_DIAG tristate "INET: socket monitoring interface" + select SOCK_DIAG default y ---help--- Support for INET (TCP, DCCP, etc) socket monitoring interface used by diff --git a/net/netlink/Kconfig b/net/netlink/Kconfig index 5d6e8c05b3..8a2696d66c 100644 --- a/net/netlink/Kconfig +++ b/net/netlink/Kconfig @@ -4,6 +4,7 @@ config NETLINK_DIAG tristate "NETLINK: socket monitoring interface" + select SOCK_DIAG default n ---help--- Support for NETLINK socket monitoring interface used by the ss tool. diff --git a/net/packet/Kconfig b/net/packet/Kconfig index cc55b35f80..9a83c86f54 100644 --- a/net/packet/Kconfig +++ b/net/packet/Kconfig @@ -18,6 +18,7 @@ config PACKET config PACKET_DIAG tristate "Packet: sockets monitoring interface" depends on PACKET + select SOCK_DIAG default n ---help--- Support for PF_PACKET sockets monitoring interface used by the ss tool. diff --git a/net/unix/Kconfig b/net/unix/Kconfig index 8b31ab85d0..6548cf3ea7 100644 --- a/net/unix/Kconfig +++ b/net/unix/Kconfig @@ -22,6 +22,7 @@ config UNIX config UNIX_DIAG tristate "UNIX: socket monitoring interface" depends on UNIX + select SOCK_DIAG default n ---help--- Support for UNIX socket monitoring interface used by the ss tool. -- GitLab