Patch "bpf: Add missed var_off setting in set_sext32_default_val()" 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: Add missed var_off setting in set_sext32_default_val()

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-add-missed-var_off-setting-in-set_sext32_default.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 d9c63b7b8c8d238d926ebd3cae858445c12a4aaf
Author: Yonghong Song <yonghong.song@xxxxxxxxx>
Date:   Sat Jun 15 10:46:26 2024 -0700

    bpf: Add missed var_off setting in set_sext32_default_val()
    
    [ Upstream commit 380d5f89a4815ff88461a45de2fb6f28533df708 ]
    
    Zac reported a verification failure and Alexei reproduced the issue
    with a simple reproducer ([1]). The verification failure is due to missed
    setting for var_off.
    
    The following is the reproducer in [1]:
      0: R1=ctx() R10=fp0
      0: (71) r3 = *(u8 *)(r10 -387)        ;
         R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=255,var_off=(0x0; 0xff)) R10=fp0
      1: (bc) w7 = (s8)w3                   ;
         R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=255,var_off=(0x0; 0xff))
         R7_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=127,var_off=(0x0; 0x7f))
      2: (36) if w7 >= 0x2533823b goto pc-3
         mark_precise: frame0: last_idx 2 first_idx 0 subseq_idx -1
         mark_precise: frame0: regs=r7 stack= before 1: (bc) w7 = (s8)w3
         mark_precise: frame0: regs=r3 stack= before 0: (71) r3 = *(u8 *)(r10 -387)
      2: R7_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=127,var_off=(0x0; 0x7f))
      3: (b4) w0 = 0                        ; R0_w=0
      4: (95) exit
    
    Note that after insn 1, the var_off for R7 is (0x0; 0x7f). This is not correct
    since upper 24 bits of w7 could be 0 or 1. So correct var_off should be
    (0x0; 0xffffffff). Missing var_off setting in set_sext32_default_val() caused later
    incorrect analysis in zext_32_to_64(dst_reg) and reg_bounds_sync(dst_reg).
    
    To fix the issue, set var_off correctly in set_sext32_default_val(). The correct
    reg state after insn 1 becomes:
      1: (bc) w7 = (s8)w3                   ;
         R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=255,var_off=(0x0; 0xff))
         R7_w=scalar(smin=0,smax=umax=0xffffffff,smin32=-128,smax32=127,var_off=(0x0; 0xffffffff))
    and at insn 2, the verifier correctly determines either branch is possible.
    
      [1] https://lore.kernel.org/bpf/CAADnVQLPU0Shz7dWV4bn2BgtGdxN3uFHPeobGBA72tpg5Xoykw@xxxxxxxxxxxxxx/
    
    Fixes: 8100928c8814 ("bpf: Support new sign-extension mov insns")
    Reported-by: Zac Ecob <zacecob@xxxxxxxxxxxxxx>
    Signed-off-by: Yonghong Song <yonghong.song@xxxxxxxxx>
    Link: https://lore.kernel.org/r/20240615174626.3994813-1-yonghong.song@xxxxxxxxx
    Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index ec0464c075bb4..291bda5ef5526 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -6159,6 +6159,7 @@ static void set_sext32_default_val(struct bpf_reg_state *reg, int size)
 	}
 	reg->u32_min_value = 0;
 	reg->u32_max_value = U32_MAX;
+	reg->var_off = tnum_subreg(tnum_unknown);
 }
 
 static void coerce_subreg_to_size_sx(struct bpf_reg_state *reg, int size)




[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