Patch "bpf, arm64: fix bug in BPF_LDX_MEMSX" has been added to the 6.8-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, arm64: fix bug in BPF_LDX_MEMSX

to the 6.8-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-arm64-fix-bug-in-bpf_ldx_memsx.patch
and it can be found in the queue-6.8 subdirectory.

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



commit 7f52e93297963c67cd767f0d0ee48c8c11ccf309
Author: Puranjay Mohan <puranjay12@xxxxxxxxx>
Date:   Tue Mar 12 23:59:17 2024 +0000

    bpf, arm64: fix bug in BPF_LDX_MEMSX
    
    [ Upstream commit 114b5b3b4bde7358624437be2f12cde1b265224e ]
    
    A64_LDRSW() takes three registers: Xt, Xn, Xm as arguments and it loads
    and sign extends the value at address Xn + Xm into register Xt.
    
    Currently, the offset is being directly used in place of the tmp
    register which has the offset already loaded by the last emitted
    instruction.
    
    This will cause JIT failures. The easiest way to reproduce this is to
    test the following code through test_bpf module:
    
    {
            "BPF_LDX_MEMSX | BPF_W",
            .u.insns_int = {
                    BPF_LD_IMM64(R1, 0x00000000deadbeefULL),
                    BPF_LD_IMM64(R2, 0xffffffffdeadbeefULL),
                    BPF_STX_MEM(BPF_DW, R10, R1, -7),
                    BPF_LDX_MEMSX(BPF_W, R0, R10, -7),
                    BPF_JMP_REG(BPF_JNE, R0, R2, 1),
                    BPF_ALU64_IMM(BPF_MOV, R0, 0),
                    BPF_EXIT_INSN(),
            },
            INTERNAL,
            { },
            { { 0, 0 } },
            .stack_depth = 7,
    },
    
    We need to use the offset as -7 to trigger this code path, there could
    be other valid ways to trigger this from proper BPF programs as well.
    
    This code is rejected by the JIT because -7 is passed to A64_LDRSW() but
    it expects a valid register (0 - 31).
    
     roott@pjy:~# modprobe test_bpf test_name="BPF_LDX_MEMSX | BPF_W"
     [11300.490371] test_bpf: test_bpf: set 'test_bpf' as the default test_suite.
     [11300.491750] test_bpf: #345 BPF_LDX_MEMSX | BPF_W
     [11300.493179] aarch64_insn_encode_register: unknown register encoding -7
     [11300.494133] aarch64_insn_encode_register: unknown register encoding -7
     [11300.495292] FAIL to select_runtime err=-524
     [11300.496804] test_bpf: Summary: 0 PASSED, 1 FAILED, [0/0 JIT'ed]
     modprobe: ERROR: could not insert 'test_bpf': Invalid argument
    
    Applying this patch fixes the issue.
    
     root@pjy:~# modprobe test_bpf test_name="BPF_LDX_MEMSX | BPF_W"
     [  292.837436] test_bpf: test_bpf: set 'test_bpf' as the default test_suite.
     [  292.839416] test_bpf: #345 BPF_LDX_MEMSX | BPF_W jited:1 156 PASS
     [  292.844794] test_bpf: Summary: 1 PASSED, 0 FAILED, [1/1 JIT'ed]
    
    Fixes: cc88f540da52 ("bpf, arm64: Support sign-extension load instructions")
    Signed-off-by: Puranjay Mohan <puranjay12@xxxxxxxxx>
    Message-ID: <20240312235917.103626-1-puranjay12@xxxxxxxxx>
    Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 8955da5c47cf7..582c4c2491edc 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -1189,7 +1189,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
 			} else {
 				emit_a64_mov_i(1, tmp, off, ctx);
 				if (sign_extend)
-					emit(A64_LDRSW(dst, src_adj, off_adj), ctx);
+					emit(A64_LDRSW(dst, src, tmp), ctx);
 				else
 					emit(A64_LDR32(dst, src, tmp), ctx);
 			}




[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