Ubuntu-focal-kernel/net
Florian Westphal e1858dedad inet: inet_defrag: prevent sk release while still in use
ip_local_out() and other functions can pass skb->sk as function argument.

If the skb is a fragment and reassembly happens before such function call
returns, the sk must not be released.

This affects skb fragments reassembled via netfilter or similar
modules, e.g. openvswitch or ct_act.c, when run as part of tx pipeline.

Eric Dumazet made an initial analysis of this bug.  Quoting Eric:
  Calling ip_defrag() in output path is also implying skb_orphan(),
  which is buggy because output path relies on sk not disappearing.

  A relevant old patch about the issue was :
  8282f27449 ("inet: frag: Always orphan skbs inside ip_defrag()")

  [..]

  net/ipv4/ip_output.c depends on skb->sk being set, and probably to an
  inet socket, not an arbitrary one.

  If we orphan the packet in ipvlan, then downstream things like FQ
  packet scheduler will not work properly.

  We need to change ip_defrag() to only use skb_orphan() when really
  needed, ie whenever frag_list is going to be used.

Eric suggested to stash sk in fragment queue and made an initial patch.
However there is a problem with this:

If skb is refragmented again right after, ip_do_fragment() will copy
head->sk to the new fragments, and sets up destructor to sock_wfree.
IOW, we have no choice but to fix up sk_wmem accouting to reflect the
fully reassembled skb, else wmem will underflow.

This change moves the orphan down into the core, to last possible moment.
As ip_defrag_offset is aliased with sk_buff->sk member, we must move the
offset into the FRAG_CB, else skb->sk gets clobbered.

This allows to delay the orphaning long enough to learn if the skb has
to be queued or if the skb is completing the reasm queue.

In the former case, things work as before, skb is orphaned.  This is
safe because skb gets queued/stolen and won't continue past reasm engine.

In the latter case, we will steal the skb->sk reference, reattach it to
the head skb, and fix up wmem accouting when inet_frag inflates truesize.

Fixes: 7026b1ddb6 ("netfilter: Pass socket pointer down through okfn().")
Diagnosed-by: Eric Dumazet <edumazet@google.com>
Reported-by: xingwei lee <xrivendell7@gmail.com>
Reported-by: yue sun <samsun1006219@gmail.com>
Reported-by: syzbot+e5167d7144a62715044c@syzkaller.appspotmail.com
Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20240326101845.30836-1-fw@strlen.de
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
(backported from commit 18685451fc4e546fc0e718580d32df3c0e5c8272)
[vpeixoto: missing commits 2e47eece158a ("ipv4: remove unnecessary
type castings") and 8672406eb5d7 ("net: ip: Handle delivery_time in ip
defrag") introduce context conflicts but are irrelevant to the fix,
so a manual backport is appropriate.]
CVE-2024-26921
Signed-off-by: Vinicius Peixoto <vinicius.peixoto@canonical.com>
Acked-by: Manuel Diewald <manuel.diewald@canonical.com>
Acked-by: Kevin Becker <kevin.becker@canonical.com>
Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com>
2024-08-02 16:16:08 +02:00
..
6lowpan
9p net/9p: fix uninit-value in p9_client_rpc() 2024-07-05 10:52:03 +02:00
802
8021q
appletalk
atm
ax25
batman-adv batman-adv: Avoid infinite loop trying to resize local TT 2024-06-07 15:01:42 +02:00
bluetooth Bluetooth: Fix atomicity violation in {min, max}_key_size_set 2024-08-02 16:16:06 +02:00
bpf
bpfilter
bridge net: bridge: fix corrupted ethernet header on multicast-to-unicast 2024-07-05 10:51:53 +02:00
caif
can
ceph
core skb_expand_head() adjust skb->truesize incorrectly 2024-08-02 16:16:08 +02:00
dcb
dccp
decnet
dns_resolver
dsa
ethernet ethernet: Add helper for assigning packet type when dest address does not match device address 2024-06-07 15:01:47 +02:00
hsr hsr: Handle failures in module init 2024-06-07 15:01:31 +02:00
ieee802154
ife
ipv4 inet: inet_defrag: prevent sk release while still in use 2024-08-02 16:16:08 +02:00
ipv6 inet: inet_defrag: prevent sk release while still in use 2024-08-02 16:16:08 +02:00
iucv net/iucv: fix the allocation size of iucv_path_table array 2024-06-07 15:01:23 +02:00
kcm net: kcm: fix incorrect parameter validation in the kcm_getsockopt) function 2024-06-07 15:01:27 +02:00
key
l2tp net l2tp: drop flow hash on forward 2024-07-05 10:51:51 +02:00
l3mdev
lapb
llc
mac80211 wifi: mac80211: fix ieee80211_bss_*_flags kernel-doc 2024-07-05 10:51:52 +02:00
mac802154
mpls
ncsi
netfilter netfilter: nfnetlink_queue: acquire rcu_read_lock() in instance_destroy_rcu() 2024-07-05 10:52:01 +02:00
netlabel
netlink
netrom netrom: fix possible dead-lock in nr_rt_ioctl() 2024-07-05 10:51:59 +02:00
nfc nfc: nci: Fix handling of zero-length payload packets in nci_rx_work() 2024-07-05 10:52:01 +02:00
nsh nsh: Restore skb->{protocol,data,mac_header} for outer header in nsh_gso_segment(). 2024-07-05 10:51:51 +02:00
openvswitch openvswitch: Set the skbuff pkt_type for proper pmtud support. 2024-07-05 10:52:01 +02:00
packet af_packet: do not call packet_read_pending() from tpacket_destruct_skb() 2024-07-05 10:51:59 +02:00
phonet phonet: fix rtm_phonet_notify() skb allocation 2024-07-05 10:51:53 +02:00
psample
qrtr
rds net/rds: fix possible cp null dereference 2024-06-07 15:01:38 +02:00
rfkill
rose
rxrpc
sched net/sched: act_skbmod: prevent kernel-infoleak 2024-06-07 15:01:39 +02:00
sctp
smc
strparser
sunrpc SUNRPC: Fix loop termination condition in gss_free_in_token_pages() 2024-07-05 10:52:02 +02:00
switchdev
tipc tipc: fix UAF in error path 2024-07-05 10:51:54 +02:00
tls tls: fix race between tx work scheduling and socket close 2024-07-05 10:51:50 +02:00
unix af_unix: Fix data races in unix_release_sock/unix_stream_sendmsg 2024-07-05 10:51:58 +02:00
vmw_vsock
wimax
wireless wifi: cfg80211: fix the order of arguments for trace events of the tx_rx_evt class 2024-07-05 10:51:55 +02:00
x25 net/x25: fix incorrect parameter validation in the x25_getsockopt() function 2024-06-07 15:01:27 +02:00
xdp xsk: validate user input for XDP_{UMEM|COMPLETION}_FILL_RING 2024-07-05 10:52:03 +02:00
xfrm net: fix __dst_negative_advice() race 2024-07-05 10:52:03 +02:00
Kconfig
Makefile
compat.c
socket.c
sysctl_net.c