bpf: Allow delete from sockmap/sockhash only if update is allowed

[ Upstream commit 98e948fb60d41447fd8d2d0c3b8637fc6b6dc26d ]

We have seen an influx of syzkaller reports where a BPF program attached to
a tracepoint triggers a locking rule violation by performing a map_delete
on a sockmap/sockhash.

We don't intend to support this artificial use scenario. Extend the
existing verifier allowed-program-type check for updating sockmap/sockhash
to also cover deleting from a map.

From now on only BPF programs which were previously allowed to update
sockmap/sockhash can delete from these map types.

BUG=b/349318214
TEST=presubmit
RELEASE_NOTE=Fixes CVE-2024-38662 in the Linux kernel

cos-patch: security-moderate
Fixes: ff9105993240 ("bpf, sockmap: Prevent lock inversion deadlock in map delete elem")
Reported-by: Tetsuo Handa <[email protected]>
Reported-by: [email protected]
Signed-off-by: Jakub Sitnicki <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Tested-by: [email protected]
Acked-by: John Fastabend <[email protected]>
Closes: https://syzkaller.appspot.com/bug?extid=ec941d6e24f633a59172
Link: https://lore.kernel.org/bpf/[email protected]
Signed-off-by: Sasha Levin <[email protected]>
Signed-off-by: Oleksandr Tymoshenko <[email protected]>
Change-Id: I944901e030bf05108a836c46d86683a22a036f87
Signed-off-by: Oleksandr Tymoshenko <[email protected]>
Reviewed-on: https://cos-review.googlesource.com/c/third_party/kernel/+/76182
Reviewed-by: Arnav Kansal <[email protected]>
Reviewed-by: Kevin Berry <[email protected]>
Tested-by: Cusky Presubmit Bot <[email protected]>
1 file changed