Skip to content

net/tls: Annotate lockless access to sk_prot

Jakub Sitnicki netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3net/tls: Constify base proto ops used for building tls protonet/tls/tls_main.c+2 -20 replies
2/3net/tls: Read sk_prot once when building tls proto opsnet/tls/tls_main.c+9 -80 replies
3/3net/tls: Annotate access to sk_prot with READ_ONCE/WRITE_ONCEnet/tls/tls_device.c net/tls/tls_main.c+6 -50 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH net-next 0/3] net/tls: Annotate lockless access to sk_prot

We have recently noticed that there is a case of lockless read/write to sk->sk_prot [0]. sockmap code on psock tear-down writes to sk->sk_prot, while holding sk_callback_lock. Concurrently, tcp can access it. Usually to read out the sk_prot pointer and invoke one of the ops, sk->sk_prot->handler().

The lockless write (lockless in regard to concurrent reads) happens on the following paths:

tcp_bpf_{recvmsg|sendmsg} / sock_map_unref
sk_psock_put

    sk_psock_drop
      sk_psock_restore_proto
        WRITE_ONCE(sk->sk_prot, proto)

To prevent load/store tearing [1], and to make tooling aware of intentional shared access [2], we need to annotate sites that access sk_prot with READ_ONCE/WRITE_ONCE.

This series kicks off the effort to do it. Starting with net/tls.

[0] https://lore.kernel.org/bpf/[email protected]/
[1] https://lwn.net/Articles/793253/
[2] https://github.com/google/ktsan/wiki/READ_ONCE-and-WRITE_ONCE

Jakub Sitnicki (3):
net/tls: Constify base proto ops used for building tls proto net/tls: Read sk_prot once when building tls proto ops net/tls: Annotate access to sk_prot with READ_ONCE/WRITE_ONCE

 net/tls/tls_device.c |  2 +-
 net/tls/tls_main.c   | 28 +++++++++++++++-------------
 2 files changed, 16 insertions(+), 14 deletions(-)
Signature · 1 line
2.24.1