From 0640c843b47846bc8ac8c0fd242783f3b73f9cd4 Mon Sep 17 00:00:00 2001 From: Tomasz Jonak Date: Wed, 31 May 2023 12:31:07 +0200 Subject: [PATCH] aya-bpf: helpers::read_{kernel,user}_str_bytes additional len check Without additional check verifier fails swearing len lower bound is a negative value. Observed on v5.19/ubuntu 22.04. Signed-off-by: Tomasz Jonak --- bpf/aya-bpf/src/helpers.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bpf/aya-bpf/src/helpers.rs b/bpf/aya-bpf/src/helpers.rs index b740f4b9..715f25a2 100644 --- a/bpf/aya-bpf/src/helpers.rs +++ b/bpf/aya-bpf/src/helpers.rs @@ -430,6 +430,11 @@ pub unsafe fn bpf_probe_read_user_str_bytes( return Err(-1); } + // verifier complains if this check is missing on v5.19 + if len < 1 { + return Err(-1); + } + // len includes NULL byte Ok(&dest[..len - 1]) } @@ -583,6 +588,11 @@ pub unsafe fn bpf_probe_read_kernel_str_bytes( return Err(-1); } + // verifier complains if this check is missing on v5.19 + if len < 1 { + return Err(-1); + } + // len includes NULL byte Ok(&dest[..len - 1]) }