From: Stanislav Fomichev <sdf@google.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
martin.lau@linux.dev, song@kernel.org, yhs@fb.com,
john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com,
haoluo@google.com, jolsa@kernel.org
Subject: [PATCH bpf-next v4 0/4] bpf: Don't EFAULT for {g,s}setsockopt with wrong optlen
Date: Thu, 4 May 2023 11:43:45 -0700 [thread overview]
Message-ID: <20230504184349.3632259-1-sdf@google.com> (raw)
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).
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)
Stanislav Fomichev (4):
bpf: Don't EFAULT for {g,s}setsockopt with wrong optlen
selftests/bpf: Update EFAULT {g,s}etsockopt selftests
selftests/bpf: Correctly handle optlen > 4096
bpf: Document EFAULT changes for sockopt
Documentation/bpf/prog_cgroup_sockopt.rst | 57 ++++++++-
kernel/bpf/cgroup.c | 15 +++
.../bpf/prog_tests/cgroup_getset_retval.c | 20 ++++
.../selftests/bpf/prog_tests/sockopt.c | 103 +++++++++++++++-
.../bpf/prog_tests/sockopt_inherit.c | 59 +++-------
.../selftests/bpf/prog_tests/sockopt_multi.c | 110 +++++-------------
.../bpf/prog_tests/sockopt_qos_to_cc.c | 2 +
.../progs/cgroup_getset_retval_getsockopt.c | 13 +++
.../progs/cgroup_getset_retval_setsockopt.c | 17 +++
.../selftests/bpf/progs/sockopt_inherit.c | 18 ++-
.../selftests/bpf/progs/sockopt_multi.c | 26 ++++-
.../selftests/bpf/progs/sockopt_qos_to_cc.c | 10 +-
.../testing/selftests/bpf/progs/sockopt_sk.c | 25 ++--
13 files changed, 335 insertions(+), 140 deletions(-)
--
2.40.1.521.gf1e218fcd8-goog
next reply other threads:[~2023-05-04 18:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-04 18:43 Stanislav Fomichev [this message]
2023-05-04 18:43 ` [PATCH bpf-next v4 1/4] bpf: Don't EFAULT for {g,s}setsockopt with wrong optlen Stanislav Fomichev
2023-05-04 18:43 ` [PATCH bpf-next v4 2/4] selftests/bpf: Update EFAULT {g,s}etsockopt selftests Stanislav Fomichev
2023-05-05 21:47 ` Martin KaFai Lau
2023-05-04 18:43 ` [PATCH bpf-next v4 3/4] selftests/bpf: Correctly handle optlen > 4096 Stanislav Fomichev
2023-05-05 21:49 ` Martin KaFai Lau
2023-05-04 18:43 ` [PATCH bpf-next v4 4/4] bpf: Document EFAULT changes for sockopt Stanislav Fomichev
2023-05-05 22:00 ` [PATCH bpf-next v4 0/4] bpf: Don't EFAULT for {g,s}setsockopt with wrong optlen Martin KaFai Lau
2023-05-05 22:04 ` Stanislav Fomichev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230504184349.3632259-1-sdf@google.com \
--to=sdf@google.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=song@kernel.org \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox