No description
Find a file
Kuniyuki Iwashima bd0b5563ec af_unix: Don't retry after unix_state_lock_nested() in unix_stream_connect().
[ Upstream commit 1ca27e0c8c ]

When a SOCK_(STREAM|SEQPACKET) socket connect()s to another one, we need
to lock the two sockets to check their states in unix_stream_connect().

We use unix_state_lock() for the server and unix_state_lock_nested() for
client with tricky sk->sk_state check to avoid deadlock.

The possible deadlock scenario are the following:

  1) Self connect()
  2) Simultaneous connect()

The former is simple, attempt to grab the same lock, and the latter is
AB-BA deadlock.

After the server's unix_state_lock(), we check the server socket's state,
and if it's not TCP_LISTEN, connect() fails with -EINVAL.

Then, we avoid the former deadlock by checking the client's state before
unix_state_lock_nested().  If its state is not TCP_LISTEN, we can make
sure that the client and the server are not identical based on the state.

Also, the latter deadlock can be avoided in the same way.  Due to the
server sk->sk_state requirement, AB-BA deadlock could happen only with
TCP_LISTEN sockets.  So, if the client's state is TCP_LISTEN, we can
give up the second lock to avoid the deadlock.

  CPU 1                 CPU 2                  CPU 3
  connect(A -> B)       connect(B -> A)        listen(A)
  ---                   ---                    ---
  unix_state_lock(B)
  B->sk_state == TCP_LISTEN
  READ_ONCE(A->sk_state) == TCP_CLOSE
                            ^^^^^^^^^
                            ok, will lock A    unix_state_lock(A)
             .--------------'                  WRITE_ONCE(A->sk_state, TCP_LISTEN)
             |                                 unix_state_unlock(A)
             |
             |          unix_state_lock(A)
             |          A->sk_sk_state == TCP_LISTEN
             |          READ_ONCE(B->sk_state) == TCP_LISTEN
             v                                    ^^^^^^^^^^
  unix_state_lock_nested(A)                       Don't lock B !!

Currently, while checking the client's state, we also check if it's
TCP_ESTABLISHED, but this is unlikely and can be checked after we know
the state is not TCP_CLOSE.

Moreover, if it happens after the second lock, we now jump to the restart
label, but it's unlikely that the server is not found during the retry,
so the jump is mostly to revist the client state check.

Let's remove the retry logic and check the state against TCP_CLOSE first.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-08-14 13:52:46 +02:00
arch x86/mm: Fix pti_clone_entry_text() for i386 2024-08-14 13:52:43 +02:00
block block: initialize integrity buffer to zero before writing it to media 2024-08-03 08:48:53 +02:00
certs
crypto crypto: aead,cipher - zeroize key buffer after use 2024-07-11 12:47:05 +02:00
Documentation dt-bindings: thermal: correct thermal zone node name limit 2024-08-03 08:49:30 +02:00
drivers net/mlx5e: SHAMPO, Fix invalid WQ linked list unlink 2024-08-14 13:52:46 +02:00
fs protect the fetch of ->fd[fd] in do_dup2() from mispredictions 2024-08-11 12:36:00 +02:00
include block: change rq_integrity_vec to respect the iterator 2024-08-14 13:52:45 +02:00
init rust: SHADOW_CALL_STACK is incompatible with Rust 2024-08-11 12:35:59 +02:00
io_uring io_uring: fix io_match_task must_hold 2024-08-03 08:49:53 +02:00
ipc sysctl: treewide: drop unused argument ctl_table_root::set_ownership(table) 2024-08-11 12:35:51 +02:00
kernel rcu: Fix rcu_barrier() VS post CPUHP_TEARDOWN_CPU invocation 2024-08-14 13:52:45 +02:00
lib kobject_uevent: Fix OOB access within zap_modalias_env() 2024-08-03 08:49:39 +02:00
LICENSES
mm mm/page_alloc: fix pcp->count race between drain_pages_zone() vs __rmqueue_pcplist() 2024-08-11 12:35:54 +02:00
net af_unix: Don't retry after unix_state_lock_nested() in unix_stream_connect(). 2024-08-14 13:52:46 +02:00
rust rust: macros: fix soundness issue in module! macro 2024-05-17 11:56:17 +02:00
samples work around gcc bugs with 'asm goto' with outputs 2024-02-23 09:12:28 +01:00
scripts kbuild: avoid build error when single DTB is turned into composite DTB 2024-08-03 08:49:48 +02:00
security apparmor: Fix null pointer deref when receiving skb during sock creation 2024-08-03 08:49:50 +02:00
sound Revert "ALSA: firewire-lib: operate for period elapse event in process context" 2024-08-11 12:36:01 +02:00
tools selftests/bpf: Fix send_signal test with nested CONFIG_PARAVIRT 2024-08-14 13:52:46 +02:00
usr
virt KVM: Fix a data race on last_boosted_vcpu in kvm_vcpu_on_spin() 2024-06-27 13:46:21 +02:00
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
.rustfmt.toml
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS MAINTAINERS: add leah to 6.1 MAINTAINERS file 2024-05-17 11:56:16 +02:00
Makefile Linux 6.1.104 2024-08-11 12:36:02 +02: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.