Merge branch 'bpf: Don't EFAULT for {g,s}setsockopt with wrong optlen'
authorMartin KaFai Lau <martin.lau@kernel.org>
Sat, 13 May 2023 23:20:16 +0000 (16:20 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Sun, 14 May 2023 00:00:47 +0000 (17:00 -0700)
commit79b3604d6221220770fb52619e1f55ee04b2c1b7
treea9447b5600d3d980f8445bb223db5cbab058042b
parentbdeeed3498c7871c17465bb4f11d1bc67f9098af
parent6b6a23d5d8e857e0dda1bbe5043cf4d5e9c711d3
Merge branch 'bpf: Don't EFAULT for {g,s}setsockopt with wrong optlen'

Stanislav Fomichev says:

====================
optval larger than PAGE_SIZE leads to EFAULT if the BPF program
isn't careful enough. This is often overlooked and might break
completely unrelated socket options. Instead of EFAULT,
let's ignore BPF program buffer changes. See the first patch for
more info.

In addition, clearly document this corner case and reset optlen
in our selftests (in case somebody copy-pastes from them).

v6:
- no changes; resending due to screwing up v5 series with the unrelated
  patch

v5:
- goto in the selftest (Martin)
- set IP_TOS to zero to avoid endianness complications (Martin)

v4:
- ignore retval as well when optlen > PAGE_SIZE (Martin)

v3:
- don't hard-code PAGE_SIZE (Martin)
- reset orig_optlen in getsockopt when kernel part succeeds (Martin)
====================

Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>