kernel_samsung_a53x/include/net
Eric Dumazet 8fd57cfe08 tcp: properly terminate timers for kernel sockets
[ Upstream commit 151c9c724d05d5b0dd8acd3e11cb69ef1f2dbada ]

We had various syzbot reports about tcp timers firing after
the corresponding netns has been dismantled.

Fortunately Josef Bacik could trigger the issue more often,
and could test a patch I wrote two years ago.

When TCP sockets are closed, we call inet_csk_clear_xmit_timers()
to 'stop' the timers.

inet_csk_clear_xmit_timers() can be called from any context,
including when socket lock is held.
This is the reason it uses sk_stop_timer(), aka del_timer().
This means that ongoing timers might finish much later.

For user sockets, this is fine because each running timer
holds a reference on the socket, and the user socket holds
a reference on the netns.

For kernel sockets, we risk that the netns is freed before
timer can complete, because kernel sockets do not hold
reference on the netns.

This patch adds inet_csk_clear_xmit_timers_sync() function
that using sk_stop_timer_sync() to make sure all timers
are terminated before the kernel socket is released.
Modules using kernel sockets close them in their netns exit()
handler.

Also add sock_not_owned_by_me() helper to get LOCKDEP
support : inet_csk_clear_xmit_timers_sync() must not be called
while socket lock is held.

It is very possible we can revert in the future commit
3a58f13a881e ("net: rds: acquire refcount on TCP sockets")
which attempted to solve the issue in rds only.
(net/smc/af_smc.c and net/mptcp/subflow.c have similar code)

We probably can remove the check_net() tests from
tcp_out_of_resources() and __tcp_close() in the future.

Reported-by: Josef Bacik <josef@toxicpanda.com>
Closes: https://lore.kernel.org/netdev/20240314210740.GA2823176@perftesting/
Fixes: 26abe14379f8 ("net: Modify sk_alloc to not reference count the netns of kernel sockets.")
Fixes: 8a68173691f0 ("net: sk_clone_lock() should only do get_net() if the parent is not a kernel socket")
Link: https://lore.kernel.org/bpf/CANn89i+484ffqb93aQm1N-tjxxvb3WDKX0EbD7318RwRgsatjw@mail.gmail.com/
Signed-off-by: Eric Dumazet <edumazet@google.com>
Tested-by: Josef Bacik <josef@toxicpanda.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Link: https://lore.kernel.org/r/20240322135732.1535772-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-19 09:22:44 +01:00
..
9p Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bluetooth Bluetooth: Fix bogus check for re-auth no supported with non-ssp 2024-11-18 12:12:38 +01:00
caif Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
iucv Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
netfilter netfilter: nf_tables: fix pointer math issue in nft_byteorder_eval() 2024-11-18 12:13:40 +01:00
netns Revert "xfrm: fix a data-race in xfrm_gen_index()" 2024-11-17 19:38:56 +01:00
nfc Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
phonet Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sctp Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tc_act Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
6lowpan.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
act_api.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
addrconf.h net: ipv6: support reporting otherwise unknown prefix flags in RTM_NEWPREFIX 2024-11-18 12:11:48 +01:00
af_ieee802154.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
af_rxrpc.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
af_unix.h af_unix: fix lockdep positive in sk_diag_dump_icons() 2024-11-18 12:13:23 +01:00
af_vsock.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ah.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
arp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
atmclip.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ax25.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ax88796.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bareudp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bond_3ad.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bond_alb.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bond_options.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bonding.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bpf_sk_storage.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
busy_poll.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
calipso.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cfg80211-wext.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cfg80211.h Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
cfg802154.h mac802154: fix llsec key resources release in mac802154_llsec_key_del 2024-11-19 09:22:33 +01:00
checksum.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cipso_ipv4.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cls_cgroup.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cnss2.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cnss_nl.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cnss_prealloc.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cnss_utils.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
codel.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
codel_impl.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
codel_qdisc.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
compat.h net/ipv4/ipv6: Replace one-element arraya with flexible-array members 2024-11-19 08:44:49 +01:00
datalink.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dcbevent.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dcbnl.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
devlink.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dropdump.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dsa.h Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
dsfield.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dst.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dst_cache.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dst_metadata.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dst_ops.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
erspan.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
esp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
espintcp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ethoc.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
failover.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fib_notifier.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fib_rules.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
firewire.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
flow.h inet: shrink struct flowi_common 2024-11-18 11:43:07 +01:00
flow_dissector.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
flow_offload.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fou.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fq.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fq_impl.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
garp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
gen_stats.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
genetlink.h drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group 2024-11-18 12:11:46 +01:00
geneve.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
gre.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
gro_cells.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
gtp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
gue.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hwbm.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
icmp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ieee80211_radiotap.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ieee802154_netdev.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
if_inet6.h net: ipv6: support reporting otherwise unknown prefix flags in RTM_NEWPREFIX 2024-11-18 12:11:48 +01:00
ife.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ila.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
inet6_connection_sock.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
inet6_hashtables.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
inet_common.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
inet_connection_sock.h tcp: properly terminate timers for kernel sockets 2024-11-19 09:22:44 +01:00
inet_ecn.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
inet_frag.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
inet_hashtables.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
inet_sock.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
inet_timewait_sock.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
inetpeer.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ip.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ip6_checksum.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ip6_fib.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ip6_route.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ip6_tunnel.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ip_fib.h ipv4/fib: send notify when delete source address routes 2024-11-08 11:26:17 +01:00
ip_tunnels.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ip_vs.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ipcomp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ipconfig.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ipv6.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ipv6_frag.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ipv6_stubs.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ipx.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
iw_handler.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kcm.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
l3mdev.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lag.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lapb.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lib80211.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
llc.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
llc_c_ac.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
llc_c_ev.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
llc_c_st.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
llc_conn.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
llc_if.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
llc_pdu.h llc: Drop support for ETH_P_TR_802_2. 2024-11-18 12:13:00 +01:00
llc_s_ac.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
llc_s_ev.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
llc_s_st.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
llc_sap.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lwtunnel.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mac80211.h Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
mac802154.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
macsec.h net: macsec: indicate next pn update when offloading 2024-11-08 11:25:46 +01:00
mip6.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mld.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mpls.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mpls_iptunnel.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mptcp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mrp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ncm.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ncsi.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ndisc.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
neighbour.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
net_failover.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
net_namespace.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
net_ratelimit.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
netevent.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
netlabel.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
netlink.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
netprio_cgroup.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
netrom.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nexthop.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nl802154.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nsh.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
p8022.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
page_pool.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pie.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ping.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pkt_cls.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pkt_sched.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pptp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
protocol.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
psample.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
psnap.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
raw.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rawv6.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
red.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
regulatory.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
request_sock.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rose.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
route.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rpl.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rsi_91x.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rtnetlink.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rtnh.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sch_generic.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
scm.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
secure_seq.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
seg6.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
seg6_hmac.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
seg6_local.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
skb_tracer.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
slhc_vj.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
smc.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
snmp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sock.h tcp: properly terminate timers for kernel sockets 2024-11-19 09:22:44 +01:00
sock_reuseport.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Space.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
stp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
strparser.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
switchdev.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tcp.h mptcp: fix lockless access in subflow ULP diag 2024-11-18 22:25:39 +01:00
tcp_states.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
TEST_MAPPING Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
timewait_sock.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tipc.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tls.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tls_toe.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
transp_v6.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tso.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tun_proto.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
udp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
udp_tunnel.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
udplite.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
virt_wifi.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vsock_addr.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vxlan.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
wext.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
wimax.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
x25.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
x25device.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
xdp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
xdp_priv.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
xdp_sock.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
xdp_sock_drv.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
xfrm.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
xsk_buff_pool.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00