Patch "bpf: Fix a verifier bug due to incorrect branch offset comparison with cpu=v4" has been added to the 6.6-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    bpf: Fix a verifier bug due to incorrect branch offset comparison with cpu=v4

to the 6.6-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     bpf-fix-a-verifier-bug-due-to-incorrect-branch-offse.patch
and it can be found in the queue-6.6 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 478166d775bc5a9125f13720d0f4031f5a26497e
Author: Yonghong Song <yonghong.song@xxxxxxxxx>
Date:   Thu Nov 30 18:46:40 2023 -0800

    bpf: Fix a verifier bug due to incorrect branch offset comparison with cpu=v4
    
    [ Upstream commit dfce9cb3140592b886838e06f3e0c25fea2a9cae ]
    
    Bpf cpu=v4 support is introduced in [1] and Commit 4cd58e9af8b9
    ("bpf: Support new 32bit offset jmp instruction") added support for new
    32bit offset jmp instruction. Unfortunately, in function
    bpf_adj_delta_to_off(), for new branch insn with 32bit offset, the offset
    (plus/minor a small delta) compares to 16-bit offset bound
    [S16_MIN, S16_MAX], which caused the following verification failure:
      $ ./test_progs-cpuv4 -t verif_scale_pyperf180
      ...
      insn 10 cannot be patched due to 16-bit range
      ...
      libbpf: failed to load object 'pyperf180.bpf.o'
      scale_test:FAIL:expect_success unexpected error: -12 (errno 12)
      #405     verif_scale_pyperf180:FAIL
    
    Note that due to recent llvm18 development, the patch [2] (already applied
    in bpf-next) needs to be applied to bpf tree for testing purpose.
    
    The fix is rather simple. For 32bit offset branch insn, the adjusted
    offset compares to [S32_MIN, S32_MAX] and then verification succeeded.
    
      [1] https://lore.kernel.org/all/20230728011143.3710005-1-yonghong.song@xxxxxxxxx
      [2] https://lore.kernel.org/bpf/20231110193644.3130906-1-yonghong.song@xxxxxxxxx
    
    Fixes: 4cd58e9af8b9 ("bpf: Support new 32bit offset jmp instruction")
    Signed-off-by: Yonghong Song <yonghong.song@xxxxxxxxx>
    Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
    Link: https://lore.kernel.org/bpf/20231201024640.3417057-1-yonghong.song@xxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 64fcd81ad3da4..5d1efe5200ba3 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -371,14 +371,18 @@ static int bpf_adj_delta_to_imm(struct bpf_insn *insn, u32 pos, s32 end_old,
 static int bpf_adj_delta_to_off(struct bpf_insn *insn, u32 pos, s32 end_old,
 				s32 end_new, s32 curr, const bool probe_pass)
 {
-	const s32 off_min = S16_MIN, off_max = S16_MAX;
+	s64 off_min, off_max, off;
 	s32 delta = end_new - end_old;
-	s32 off;
 
-	if (insn->code == (BPF_JMP32 | BPF_JA))
+	if (insn->code == (BPF_JMP32 | BPF_JA)) {
 		off = insn->imm;
-	else
+		off_min = S32_MIN;
+		off_max = S32_MAX;
+	} else {
 		off = insn->off;
+		off_min = S16_MIN;
+		off_max = S16_MAX;
+	}
 
 	if (curr < pos && curr + off + 1 >= end_old)
 		off += delta;




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux