No description
Find a file
Stanislav Fomichev 6c71b9b177 net: set SOCK_RCU_FREE before inserting socket into hashtable
[ Upstream commit 871019b22d ]

We've started to see the following kernel traces:

 WARNING: CPU: 83 PID: 0 at net/core/filter.c:6641 sk_lookup+0x1bd/0x1d0

 Call Trace:
  <IRQ>
  __bpf_skc_lookup+0x10d/0x120
  bpf_sk_lookup+0x48/0xd0
  bpf_sk_lookup_tcp+0x19/0x20
  bpf_prog_<redacted>+0x37c/0x16a3
  cls_bpf_classify+0x205/0x2e0
  tcf_classify+0x92/0x160
  __netif_receive_skb_core+0xe52/0xf10
  __netif_receive_skb_list_core+0x96/0x2b0
  napi_complete_done+0x7b5/0xb70
  <redacted>_poll+0x94/0xb0
  net_rx_action+0x163/0x1d70
  __do_softirq+0xdc/0x32e
  asm_call_irq_on_stack+0x12/0x20
  </IRQ>
  do_softirq_own_stack+0x36/0x50
  do_softirq+0x44/0x70

__inet_hash can race with lockless (rcu) readers on the other cpus:

  __inet_hash
    __sk_nulls_add_node_rcu
    <- (bpf triggers here)
    sock_set_flag(SOCK_RCU_FREE)

Let's move the SOCK_RCU_FREE part up a bit, before we are inserting
the socket into hashtables. Note, that the race is really harmless;
the bpf callers are handling this situation (where listener socket
doesn't have SOCK_RCU_FREE set) correctly, so the only
annoyance is a WARN_ONCE.

More details from Eric regarding SOCK_RCU_FREE timeline:

Commit 3b24d854cb ("tcp/dccp: do not touch listener sk_refcnt under
synflood") added SOCK_RCU_FREE. At that time, the precise location of
sock_set_flag(sk, SOCK_RCU_FREE) did not matter, because the thread calling
__inet_hash() owns a reference on sk. SOCK_RCU_FREE was only tested
at dismantle time.

Commit 6acc9b432e ("bpf: Add helper to retrieve socket in BPF")
started checking SOCK_RCU_FREE _after_ the lookup to infer whether
the refcount has been taken care of.

Fixes: 6acc9b432e ("bpf: Add helper to retrieve socket in BPF")
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-28 16:56:22 +00:00
arch ARM: 9320/1: fix stack depot IRQ stack filter 2023-11-28 16:56:18 +00:00
block blk-core: use pr_warn_ratelimited() in bio_check_ro() 2023-11-20 11:08:29 +01:00
certs
crypto crypto: pcrypt - Fix hungtask for PADATA_RESET 2023-11-28 16:56:18 +00:00
Documentation Documentation: sysctl: align cells in second content column 2023-10-25 11:58:54 +02:00
drivers media: cec: meson: always include meson sub-directory in Makefile 2023-11-28 16:56:21 +00:00
fs gfs2: Silence "suspicious RCU usage in gfs2_permission" warning 2023-11-28 16:56:22 +00:00
include net: inet: Retire port only listening_hash 2023-11-28 16:56:22 +00:00
init x86/mm: Initialize text poking earlier 2023-08-08 19:58:33 +02:00
io_uring io_uring/fs: remove sqe->rw_flags checking from LINKAT 2023-10-06 13:18:22 +02:00
ipc
kernel tracing/perf: Add interrupt_context_level() helper 2023-11-28 16:56:21 +00:00
lib lib/Kconfig.debug: do not enable DEBUG_PREEMPT by default 2023-10-25 11:58:54 +02:00
LICENSES
mm vfs: fix readahead(2) on block devices 2023-11-20 11:08:13 +01:00
net net: set SOCK_RCU_FREE before inserting socket into hashtable 2023-11-28 16:56:22 +00:00
samples samples/hw_breakpoint: fix building without module unloading 2023-09-23 11:10:01 +02:00
scripts modpost: fix tee MODULE_DEVICE_TABLE built on big-endian host 2023-11-20 11:08:26 +01:00
security KEYS: trusted: Remove redundant static calls usage 2023-10-19 23:05:33 +02:00
sound ASoC: ti: omap-mcbsp: Fix runtime PM underflow warnings 2023-11-28 16:56:20 +00:00
tools selftests/efivarfs: create-read: fix a resource leak 2023-11-28 16:56:17 +00:00
usr
virt KVM: Grab a reference to KVM for VM and vCPU stats file descriptors 2023-08-03 10:22:40 +02:00
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS iio: stx104: Move to addac subdirectory 2023-08-26 14:23:27 +02:00
Makefile Linux 5.15.139 2023-11-20 11:08:30 +01:00
README

Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.