diff options
author | Stanislav Fomichev <sdf@google.com> | 2023-05-11 20:04:55 +0300 |
---|---|---|
committer | Martin KaFai Lau <martin.lau@kernel.org> | 2023-05-14 02:55:46 +0300 |
commit | e01b4a72f132c1ca63e3ed851bef9b3c62ae6149 (patch) | |
tree | 1908d1e5bc4f34dd4908561cecbaeffd738151fc /tools/testing/selftests/bpf/progs/sockopt_qos_to_cc.c | |
parent | 989a4a7dbff21399da42e808a4ae134023546f41 (diff) | |
download | linux-e01b4a72f132c1ca63e3ed851bef9b3c62ae6149.tar.xz |
selftests/bpf: Correctly handle optlen > 4096
Even though it's not relevant in selftests, the people
might still copy-paste from them. So let's take care
of optlen > 4096 cases explicitly.
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/r/20230511170456.1759459-4-sdf@google.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/sockopt_qos_to_cc.c')
-rw-r--r-- | tools/testing/selftests/bpf/progs/sockopt_qos_to_cc.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/tools/testing/selftests/bpf/progs/sockopt_qos_to_cc.c b/tools/testing/selftests/bpf/progs/sockopt_qos_to_cc.c index 1bce83b6e3a7..dbe235ede7f3 100644 --- a/tools/testing/selftests/bpf/progs/sockopt_qos_to_cc.c +++ b/tools/testing/selftests/bpf/progs/sockopt_qos_to_cc.c @@ -9,6 +9,8 @@ char _license[] SEC("license") = "GPL"; +__u32 page_size = 0; + SEC("cgroup/setsockopt") int sockopt_qos_to_cc(struct bpf_sockopt *ctx) { @@ -19,7 +21,7 @@ int sockopt_qos_to_cc(struct bpf_sockopt *ctx) char cc_cubic[TCP_CA_NAME_MAX] = "cubic"; if (ctx->level != SOL_IPV6 || ctx->optname != IPV6_TCLASS) - return 1; + goto out; if (optval + 1 > optval_end) return 0; /* EPERM, bounds check */ @@ -36,4 +38,10 @@ int sockopt_qos_to_cc(struct bpf_sockopt *ctx) return 0; } return 1; + +out: + /* optval larger than PAGE_SIZE use kernel's buffer. */ + if (ctx->optlen > page_size) + ctx->optlen = 0; + return 1; } |