| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/23 04:24 | flow | patch-triage |
2mArgs:null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"emit_hmul_aux",
"scalar_min_max_uhmul",
"scalar_min_max_shmul",
"check_hmul_jit",
"bpf_jit_supports_hmul",
"adjust_scalar_min_max_vals",
"check_alu_fields"
],
"KMSANReasoning": "The patch introduces support for 64-bit unsigned high-half multiplication (UHMUL) and signed high-half multiplication (SHMUL) instructions across the BPF verifier, interpreter, and JIT compilers (x86_64, arm64, riscv64).\n\n1. No kernel structures or memory buffers copied to userspace are introduced or modified.\n2. The patch only alters arithmetic ALU64 instruction execution, JIT code emission, and verifier constant/scalar tracking (marking non-constant hmul results unknown, and disallowing pointers such as arena pointers).\n3. No stack or heap allocations, uninitialized variable usage, or kernel info-leaks are introduced.\n4. Any potential issues with JIT code generation or verifier bounds analysis would manifest as functional errors, crashes, or out-of-bounds accesses, which are covered by standard testing and KASAN rather than KMSAN.\n\nTherefore, a dedicated KMSAN session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch introduces new eBPF 64-bit high-half multiplication instructions (UHMUL and SHMUL) across the BPF verifier, BPF interpreter, and architecture JIT compilers (including x86_64). The changes directly affect instruction validation, scalar min/max value tracking, arena pointer checks, and JIT assembly generation (including RAX/RDX push/pop and mul/imul execution). This reachable, security-critical code in a core subsystem is accessible via the bpf() syscall and warrants fuzzing for verifier/JIT desynchronization, register clobbering, or integer arithmetic edge cases.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/23 04:24 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 6d6c77985c9242ff63faeda7fbb06058ee652429\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Fri Oct 23 04:23:59 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/Documentation/bpf/standardization/instruction-set.rst b/Documentation/bpf/standardization/instruction-set.rst\nindex 39c74611752b6..6f3cb6bcaa1a6 100644\n--- a/Documentation/bpf/standardization/instruction-set.rst\n+++ b/Documentation/bpf/standardization/instruction-set.rst\n@@ -142,8 +142,9 @@ This document defines the following conformance groups:\n * atomic32: includes 32-bit atomic operation instructions (see `Atomic operations`_).\n * atomic64: includes atomic32, plus 64-bit atomic operation instructions.\n * divmul32: includes 32-bit division, multiplication, and modulo instructions.\n-* divmul64: includes divmul32, plus 64-bit division, multiplication,\n+* divmul64: includes divmul32, plus 64-bit division, low-half multiplication,\n and modulo instructions.\n+* divmul64v2: includes divmul64, plus high-half multiplication instructions.\n * packet: deprecated packet access instructions.\n \n Instruction encoding\n@@ -330,6 +331,8 @@ register.\n ADD 0x0 0 dst += src\n SUB 0x1 0 dst -= src\n MUL 0x2 0 dst \\*= src\n+ UHMUL 0x2 1 ``dst uh*= src`` (unsigned high half, ``ALU64`` only)\n+ SHMUL 0x2 2 ``dst sh*= src`` (signed high half, ``ALU64`` only)\n DIV 0x3 0 dst = (src != 0) ? (dst / src) : 0\n SDIV 0x3 1 dst = (src == 0) ? 0 : ((src == -1 \u0026\u0026 dst == LLONG_MIN) ? LLONG_MIN : (dst s/ src))\n OR 0x4 0 dst \\|= src\n@@ -379,13 +382,33 @@ where '(u32)' indicates that the upper 32 bits are zeroed.\n \n dst = dst ^ imm\n \n-Note that most arithmetic instructions have 'offset' set to 0. Only three instructions\n-(``SDIV``, ``SMOD``, ``MOVSX``) have a non-zero 'offset'.\n+Note that most arithmetic instructions have 'offset' set to 0. The following\n+instructions may have a non-zero 'offset':\n+\n+* ``SDIV`` and ``SMOD``: ``offset == 1`` selects the signed variant.\n+* ``MOVSX``: ``offset`` selects the source operand width.\n+* ``MUL``: ``offset`` selects the multiplication variant (see below).\n+\n+Division, low-half multiplication (``MUL`` with ``offset == 0``), and\n+modulo operations for ``ALU`` are part of the \"divmul32\" conformance\n+group, and their ``ALU64`` variants are part of the \"divmul64\"\n+conformance group.\n+\n+For ``ALU64`` multiplication, ``offset == 1`` selects unsigned\n+high-half multiplication (``UHMUL``), and ``offset == 2`` selects\n+signed high-half multiplication (``SHMUL``). Both instructions belong\n+to the \"divmul64v2\" conformance group.\n+\n+For ``X`` mode, ``src64`` is the 64-bit value in ``src_reg``. For\n+``K`` mode, ``src64`` is ``imm`` sign-extended from 32 to 64 bits.\n+The operations are::\n+\n+ UHMUL: dst = (u64)(((u128)dst * (u128)(u64)src64) \u003e\u003e 64)\n+ SHMUL: dst = (u64)(((s128)(s64)dst * (s128)(s64)src64) \u003e\u003e 64)\n+\n+For ``ALU`` multiplication, only ``offset == 0`` is valid. For ``ALU64``\n+multiplication, offset values other than 0, 1, and 2 are reserved.\n \n-Division, multiplication, and modulo operations for ``ALU`` are part\n-of the \"divmul32\" conformance group, and division, multiplication, and\n-modulo operations for ``ALU64`` are part of the \"divmul64\" conformance\n-group.\n The division and modulo operations support both unsigned and signed flavors.\n \n For unsigned operations (``DIV`` and ``MOD``), for ``ALU``,\ndiff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h\nindex 1ce75a4426387..f38738fa54a27 100644\n--- a/arch/arm64/include/asm/insn.h\n+++ b/arch/arm64/include/asm/insn.h\n@@ -247,6 +247,8 @@ enum aarch64_insn_data2_type {\n enum aarch64_insn_data3_type {\n \tAARCH64_INSN_DATA3_MADD,\n \tAARCH64_INSN_DATA3_MSUB,\n+\tAARCH64_INSN_DATA3_SMULH,\n+\tAARCH64_INSN_DATA3_UMULH,\n };\n \n enum aarch64_insn_logic_type {\n@@ -396,6 +398,8 @@ __AARCH64_INSN_FUNCS(sub_ext,\t0x7FE00000, 0x4B200000)\n __AARCH64_INSN_FUNCS(subs_ext,\t0x7FE00000, 0x6B200000)\n __AARCH64_INSN_FUNCS(madd,\t0x7FE08000, 0x1B000000)\n __AARCH64_INSN_FUNCS(msub,\t0x7FE08000, 0x1B008000)\n+__AARCH64_INSN_FUNCS(smulh,\t0x7FE0FC00, 0x1B407C00)\n+__AARCH64_INSN_FUNCS(umulh,\t0x7FE0FC00, 0x1BC07C00)\n __AARCH64_INSN_FUNCS(udiv,\t0x7FE0FC00, 0x1AC00800)\n __AARCH64_INSN_FUNCS(sdiv,\t0x7FE0FC00, 0x1AC00C00)\n __AARCH64_INSN_FUNCS(lslv,\t0x7FE0FC00, 0x1AC02000)\ndiff --git a/arch/arm64/lib/insn.c b/arch/arm64/lib/insn.c\nindex e70ac02385153..dc483d1b8bd54 100644\n--- a/arch/arm64/lib/insn.c\n+++ b/arch/arm64/lib/insn.c\n@@ -1155,6 +1155,12 @@ u32 aarch64_insn_gen_data3(enum aarch64_insn_register dst,\n \tcase AARCH64_INSN_DATA3_MSUB:\n \t\tinsn = aarch64_insn_get_msub_value();\n \t\tbreak;\n+\tcase AARCH64_INSN_DATA3_SMULH:\n+\t\tinsn = aarch64_insn_get_smulh_value();\n+\t\tbreak;\n+\tcase AARCH64_INSN_DATA3_UMULH:\n+\t\tinsn = aarch64_insn_get_umulh_value();\n+\t\tbreak;\n \tdefault:\n \t\tpr_err(\"%s: unknown data3 encoding %d\\n\", __func__, type);\n \t\treturn AARCH64_BREAK_FAULT;\ndiff --git a/arch/arm64/net/bpf_jit.h b/arch/arm64/net/bpf_jit.h\nindex b2fe6e6dcf447..70fc329c661db 100644\n--- a/arch/arm64/net/bpf_jit.h\n+++ b/arch/arm64/net/bpf_jit.h\n@@ -281,6 +281,12 @@\n \tA64_VARIANT(sf), AARCH64_INSN_DATA3_MSUB)\n /* Rd = Rn * Rm */\n #define A64_MUL(sf, Rd, Rn, Rm) A64_MADD(sf, Rd, A64_ZR, Rn, Rm)\n+/* Rd = high 64 bits of signed Rn * Rm */\n+#define A64_SMULH(Rd, Rn, Rm) aarch64_insn_gen_data3(Rd, A64_ZR, Rn, Rm, \\\n+\tAARCH64_INSN_VARIANT_64BIT, AARCH64_INSN_DATA3_SMULH)\n+/* Rd = high 64 bits of unsigned Rn * Rm */\n+#define A64_UMULH(Rd, Rn, Rm) aarch64_insn_gen_data3(Rd, A64_ZR, Rn, Rm, \\\n+\tAARCH64_INSN_VARIANT_64BIT, AARCH64_INSN_DATA3_UMULH)\n \n /* Logical (shifted register) */\n #define A64_LOGIC_SREG(sf, Rd, Rn, Rm, type) \\\ndiff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c\nindex 326e9e1dea0a7..3b4793092c1a4 100644\n--- a/arch/arm64/net/bpf_jit_comp.c\n+++ b/arch/arm64/net/bpf_jit_comp.c\n@@ -144,6 +144,17 @@ static inline void emit_a64_mov_i(const int is64, const int reg,\n \t}\n }\n \n+static inline void emit_a64_mul(const bool is64, const u8 dst, const u8 src,\n+\t\t\t\tconst s16 off, struct jit_ctx *ctx)\n+{\n+\tif (is64 \u0026\u0026 off == BPF_UHMUL)\n+\t\temit(A64_UMULH(dst, dst, src), ctx);\n+\telse if (is64 \u0026\u0026 off == BPF_SHMUL)\n+\t\temit(A64_SMULH(dst, dst, src), ctx);\n+\telse\n+\t\temit(A64_MUL(is64, dst, dst, src), ctx);\n+}\n+\n static int i64_i16_blocks(const u64 val, bool inverse)\n {\n \treturn (((val \u003e\u003e 0) \u0026 0xffff) != (inverse ? 0xffff : 0x0000)) +\n@@ -1531,7 +1542,7 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn\n \t\tbreak;\n \tcase BPF_ALU | BPF_MUL | BPF_X:\n \tcase BPF_ALU64 | BPF_MUL | BPF_X:\n-\t\temit(A64_MUL(is64, dst, dst, src), ctx);\n+\t\temit_a64_mul(is64, dst, src, off, ctx);\n \t\tbreak;\n \tcase BPF_ALU | BPF_DIV | BPF_X:\n \tcase BPF_ALU64 | BPF_DIV | BPF_X:\n@@ -1660,7 +1671,7 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn\n \tcase BPF_ALU | BPF_MUL | BPF_K:\n \tcase BPF_ALU64 | BPF_MUL | BPF_K:\n \t\temit_a64_mov_i(is64, tmp, imm, ctx);\n-\t\temit(A64_MUL(is64, dst, dst, tmp), ctx);\n+\t\temit_a64_mul(is64, dst, tmp, off, ctx);\n \t\tbreak;\n \tcase BPF_ALU | BPF_DIV | BPF_K:\n \tcase BPF_ALU64 | BPF_DIV | BPF_K:\n@@ -2595,6 +2606,11 @@ bool bpf_jit_supports_callx(void)\n \treturn true;\n }\n \n+bool bpf_jit_supports_hmul(void)\n+{\n+\treturn true;\n+}\n+\n bool bpf_jit_supports_large_stack(void)\n {\n \treturn true;\ndiff --git a/arch/riscv/net/bpf_jit.h b/arch/riscv/net/bpf_jit.h\nindex 5c4f53060c918..21a190a6a6d99 100644\n--- a/arch/riscv/net/bpf_jit.h\n+++ b/arch/riscv/net/bpf_jit.h\n@@ -436,6 +436,11 @@ static inline u32 rv_mul(u8 rd, u8 rs1, u8 rs2)\n \treturn rv_r_insn(1, rs2, rs1, 0, rd, 0x33);\n }\n \n+static inline u32 rv_mulh(u8 rd, u8 rs1, u8 rs2)\n+{\n+\treturn rv_r_insn(1, rs2, rs1, 1, rd, 0x33);\n+}\n+\n static inline u32 rv_mulhu(u8 rd, u8 rs1, u8 rs2)\n {\n \treturn rv_r_insn(1, rs2, rs1, 3, rd, 0x33);\ndiff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c\nindex 788fcc21fd5b8..371405598faa7 100644\n--- a/arch/riscv/net/bpf_jit_comp64.c\n+++ b/arch/riscv/net/bpf_jit_comp64.c\n@@ -197,6 +197,19 @@ static void emit_imm(u8 rd, s64 val, struct rv_jit_context *ctx)\n \t\temit_addi(rd, rd, lower, ctx);\n }\n \n+static void emit_mul(u8 rd, u8 rs, bool is64, s16 off,\n+\t\t struct rv_jit_context *ctx)\n+{\n+\tif (!is64)\n+\t\temit(rv_mulw(rd, rd, rs), ctx);\n+\telse if (off == BPF_UHMUL)\n+\t\temit(rv_mulhu(rd, rd, rs), ctx);\n+\telse if (off == BPF_SHMUL)\n+\t\temit(rv_mulh(rd, rd, rs), ctx);\n+\telse\n+\t\temit(rv_mul(rd, rd, rs), ctx);\n+}\n+\n static void __build_epilogue(bool is_tail_call, struct rv_jit_context *ctx)\n {\n \tint stack_adjust = ctx-\u003estack_size, store_offset = stack_adjust - 8;\n@@ -1526,7 +1539,7 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,\n \t\tbreak;\n \tcase BPF_ALU | BPF_MUL | BPF_X:\n \tcase BPF_ALU64 | BPF_MUL | BPF_X:\n-\t\temit(is64 ? rv_mul(rd, rd, rs) : rv_mulw(rd, rd, rs), ctx);\n+\t\temit_mul(rd, rs, is64, off, ctx);\n \t\tif (!is64 \u0026\u0026 !aux-\u003everifier_zext)\n \t\t\temit_zextw(rd, rd, ctx);\n \t\tbreak;\n@@ -1662,8 +1675,7 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,\n \tcase BPF_ALU | BPF_MUL | BPF_K:\n \tcase BPF_ALU64 | BPF_MUL | BPF_K:\n \t\temit_imm(RV_REG_T1, imm, ctx);\n-\t\temit(is64 ? rv_mul(rd, rd, RV_REG_T1) :\n-\t\t rv_mulw(rd, rd, RV_REG_T1), ctx);\n+\t\temit_mul(rd, RV_REG_T1, is64, off, ctx);\n \t\tif (!is64 \u0026\u0026 !aux-\u003everifier_zext)\n \t\t\temit_zextw(rd, rd, ctx);\n \t\tbreak;\n@@ -2303,3 +2315,8 @@ bool bpf_jit_supports_callx(void)\n {\n \treturn true;\n }\n+\n+bool bpf_jit_supports_hmul(void)\n+{\n+\treturn true;\n+}\ndiff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c\nindex 6a2fe3d0039d3..2707e8fb97994 100644\n--- a/arch/x86/net/bpf_jit_comp.c\n+++ b/arch/x86/net/bpf_jit_comp.c\n@@ -1378,6 +1378,38 @@ static int emit_kasan_check(struct bpf_verifier_env *env, u8 **pprog,\n \treturn 0;\n }\n \n+/*\n+ * The one-operand x86 mul/imul forms use RAX as the implicit first\n+ * operand and store the 128-bit product in RDX:RAX.\n+ * The JIT uses AUX_REG as the explicit second operand.\n+ */\n+static void emit_hmul_aux(u8 **pprog, u32 dst_reg, bool is_signed)\n+{\n+\tu8 *prog = *pprog;\n+\tbool save_rax = dst_reg != BPF_REG_0;\n+\tbool save_rdx = dst_reg != BPF_REG_3;\n+\tu8 mul_modrm_base = is_signed ? 0xE8 : 0xE0; /* imul /5 or mul /4 */\n+\n+\tif (save_rax)\n+\t\tEMIT1(0x50); /* push rax */\n+\tif (save_rdx)\n+\t\tEMIT1(0x52); /* push rdx */\n+\n+\tif (save_rax)\n+\t\temit_mov_reg(\u0026prog, true, BPF_REG_0, dst_reg);\n+\tmaybe_emit_1mod(\u0026prog, AUX_REG, true);\n+\tEMIT2(0xF7, add_1reg(mul_modrm_base, AUX_REG));\n+\tif (save_rdx)\n+\t\temit_mov_reg(\u0026prog, true, dst_reg, BPF_REG_3);\n+\n+\tif (save_rdx)\n+\t\tEMIT1(0x5A); /* pop rdx */\n+\tif (save_rax)\n+\t\tEMIT1(0x58); /* pop rax */\n+\n+\t*pprog = prog;\n+}\n+\n /* LDX: dst_reg = *(u8*)(src_reg + off) */\n static void emit_ldx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)\n {\n@@ -2916,6 +2948,14 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *\n \n \t\tcase BPF_ALU | BPF_MUL | BPF_K:\n \t\tcase BPF_ALU64 | BPF_MUL | BPF_K:\n+\t\t\tif (bpf_insn_is_hmul(insn)) {\n+\t\t\t\t/* imul/mul use AUX_REG as src. */\n+\t\t\t\temit_mov_imm32(\u0026prog, true, AUX_REG, imm32);\n+\t\t\t\temit_hmul_aux(\u0026prog, dst_reg,\n+\t\t\t\t\t insn-\u003eoff == BPF_SHMUL);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n \t\t\t/*\n \t\t\t * lea for 3, 5 and 9, which LLVM leaves as a\n \t\t\t * multiplication, but not for r13, which needs a\n@@ -2951,6 +2991,14 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *\n \n \t\tcase BPF_ALU | BPF_MUL | BPF_X:\n \t\tcase BPF_ALU64 | BPF_MUL | BPF_X:\n+\t\t\tif (bpf_insn_is_hmul(insn)) {\n+\t\t\t\t/* imul/mul use AUX_REG as src. */\n+\t\t\t\temit_mov_reg(\u0026prog, true, AUX_REG, src_reg);\n+\t\t\t\temit_hmul_aux(\u0026prog, dst_reg,\n+\t\t\t\t\t insn-\u003eoff == BPF_SHMUL);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n \t\t\tmaybe_emit_mod(\u0026prog, src_reg, dst_reg,\n \t\t\t\t BPF_CLASS(insn-\u003ecode) == BPF_ALU64);\n \n@@ -5126,6 +5174,11 @@ bool bpf_jit_supports_unwind(void)\n \treturn true;\n }\n \n+bool bpf_jit_supports_hmul(void)\n+{\n+\treturn true;\n+}\n+\n const struct bpf_jit_arg_abi *bpf_jit_arg_abi(void)\n {\n \treturn \u0026x86_arg_abi;\ndiff --git a/include/linux/filter.h b/include/linux/filter.h\nindex e0218e677a1dc..2a2101fb01684 100644\n--- a/include/linux/filter.h\n+++ b/include/linux/filter.h\n@@ -23,6 +23,7 @@\n #include \u003clinux/sockptr.h\u003e\n #include \u003clinux/static_call.h\u003e\n #include \u003clinux/u64_stats_sync.h\u003e\n+#include \u003clinux/math64.h\u003e\n \n #include \u003cnet/sch_generic.h\u003e\n \n@@ -152,6 +153,38 @@ struct ctl_table_header;\n #define BPF_ALU32_IMM(OP, DST, IMM)\t\t\t\t\\\n \tBPF_ALU32_IMM_OFF(OP, DST, IMM, 0)\n \n+static inline u64 bpf_uhmul64(u64 a, u64 b)\n+{\n+\treturn mul_u64_u64_shr(a, b, 64);\n+}\n+\n+static inline u64 bpf_shmul64(s64 a, s64 b)\n+{\n+\tu64 ua = a, ub = b;\n+\tu64 hi = bpf_uhmul64(ua, ub);\n+\n+\t/*\n+\t * Let M = 2^64, sa = (a \u003c 0), and sb = (b \u003c 0). Then:\n+\t *\n+\t * a * b = (ua - sa * M) * (ub - sb * M)\n+\t * = ua * ub - sa * M * ub - sb * M * ua + sa * sb * M^2\n+\t *\n+\t * Therefore, signed_hi = unsigned_hi - sa * ub - sb * ua (mod M).\n+\t */\n+\tif (a \u003c 0)\n+\t\thi -= ub;\n+\tif (b \u003c 0)\n+\t\thi -= ua;\n+\treturn hi;\n+}\n+\n+static inline bool bpf_insn_is_hmul(const struct bpf_insn *insn)\n+{\n+\treturn BPF_CLASS(insn-\u003ecode) == BPF_ALU64 \u0026\u0026\n+\t BPF_OP(insn-\u003ecode) == BPF_MUL \u0026\u0026\n+\t (insn-\u003eoff == BPF_UHMUL || insn-\u003eoff == BPF_SHMUL);\n+}\n+\n /* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */\n \n #define BPF_ENDIAN(TYPE, DST, LEN)\t\t\t\t\\\n@@ -1281,6 +1314,7 @@ bool bpf_jit_supports_kfunc_call(void);\n bool bpf_jit_supports_callx(void);\n bool bpf_jit_supports_kfunc_ret_reg_pair(void);\n bool bpf_jit_supports_unwind(void);\n+bool bpf_jit_supports_hmul(void);\n bool bpf_jit_supports_stack_args(void);\n bool bpf_jit_supports_arena_args(void);\n bool bpf_jit_supports_far_kfunc_call(void);\ndiff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h\nindex f29b0aad440cb..90c30e5d790b9 100644\n--- a/include/uapi/linux/bpf.h\n+++ b/include/uapi/linux/bpf.h\n@@ -34,6 +34,12 @@\n #define BPF_FROM_LE\tBPF_TO_LE\n #define BPF_FROM_BE\tBPF_TO_BE\n \n+/* BPF_MUL off values for high-half multiplication; BPF_ALU64 only. */\n+enum bpf_mul_variant {\n+\tBPF_UHMUL = 1,\n+\tBPF_SHMUL = 2,\n+};\n+\n /* jmp encodings */\n #define BPF_JNE\t\t0x50\t/* jump != */\n #define BPF_JLT\t\t0xa0\t/* LT is unsigned, '\u003c' */\ndiff --git a/kernel/bpf/core.c b/kernel/bpf/core.c\nindex 3030beb531d99..8600c93842175 100644\n--- a/kernel/bpf/core.c\n+++ b/kernel/bpf/core.c\n@@ -1943,7 +1943,46 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)\n \tALU(AND, \u0026)\n \tALU(OR, |)\n \tALU(XOR, ^)\n-\tALU(MUL, *)\n+\t/*\n+\t * MUL needs explicit handlers because ALU64 insn-\u003eoff selects\n+\t * low-half, unsigned high-half, or signed high-half multiplication.\n+\t */\n+\tALU64_MUL_X:\n+\t\tswitch (OFF) {\n+\t\tcase 0:\n+\t\t\tDST = DST * SRC;\n+\t\t\tbreak;\n+\t\tcase BPF_UHMUL:\n+\t\t\tDST = bpf_uhmul64(DST, SRC);\n+\t\t\tbreak;\n+\t\tcase BPF_SHMUL:\n+\t\t\tDST = bpf_shmul64((s64)DST, (s64)SRC);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tgoto default_label;\n+\t\t}\n+\t\tCONT;\n+\tALU_MUL_X:\n+\t\tDST = (u32) DST * (u32) SRC;\n+\t\tCONT;\n+\tALU64_MUL_K:\n+\t\tswitch (OFF) {\n+\t\tcase 0:\n+\t\t\tDST = DST * IMM;\n+\t\t\tbreak;\n+\t\tcase BPF_UHMUL:\n+\t\t\tDST = bpf_uhmul64(DST, (u64)IMM);\n+\t\t\tbreak;\n+\t\tcase BPF_SHMUL:\n+\t\t\tDST = bpf_shmul64((s64)DST, (s32)IMM);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tgoto default_label;\n+\t\t}\n+\t\tCONT;\n+\tALU_MUL_K:\n+\t\tDST = (u32) DST * (u32) IMM;\n+\t\tCONT;\n \tSHT(LSH, \u003c\u003c)\n \tSHT(RSH, \u003e\u003e)\n #undef SHT\n@@ -3405,6 +3444,12 @@ bool __weak bpf_jit_supports_unwind(void)\n \treturn false;\n }\n \n+/* uhmul and shmul */\n+bool __weak bpf_jit_supports_hmul(void)\n+{\n+\treturn false;\n+}\n+\n /*\n * How this arch places a by-value kfunc argument, or NULL for one that has\n * not opted in and so only takes an argument of a single eightbyte, which\ndiff --git a/kernel/bpf/disasm.c b/kernel/bpf/disasm.c\nindex 889fc074496f1..0b1bbb27e9e4e 100644\n--- a/kernel/bpf/disasm.c\n+++ b/kernel/bpf/disasm.c\n@@ -163,6 +163,22 @@ static bool is_sdiv_smod(const struct bpf_insn *insn)\n \t insn-\u003eoff == 1;\n }\n \n+/* Return the UHMUL or SHMUL operator string, or NULL for all other encodings. */\n+static const char *hmul_op_string(const struct bpf_insn *insn)\n+{\n+\tif (BPF_CLASS(insn-\u003ecode) != BPF_ALU64 ||\n+\t BPF_OP(insn-\u003ecode) != BPF_MUL)\n+\t\treturn NULL;\n+\tswitch (insn-\u003eoff) {\n+\tcase BPF_UHMUL:\n+\t\treturn \"uh*=\";\n+\tcase BPF_SHMUL:\n+\t\treturn \"sh*=\";\n+\tdefault:\n+\t\treturn NULL;\n+\t}\n+}\n+\n static bool is_movsx(const struct bpf_insn *insn)\n {\n \treturn BPF_OP(insn-\u003ecode) == BPF_MOV \u0026\u0026\n@@ -215,6 +231,7 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs,\n \t\t\tverbose(cbs-\u003eprivate_data, \"(%02x) %c%d %s %s%c%d\",\n \t\t\t\tinsn-\u003ecode, class == BPF_ALU ? 'w' : 'r',\n \t\t\t\tinsn-\u003edst_reg,\n+\t\t\t\thmul_op_string(insn) ?:\n \t\t\t\tis_sdiv_smod(insn) ? bpf_alu_sign_string[BPF_OP(insn-\u003ecode) \u003e\u003e 4]\n \t\t\t\t\t\t : bpf_alu_string[BPF_OP(insn-\u003ecode) \u003e\u003e 4],\n \t\t\t\tis_movsx(insn) ? bpf_movsx_string[(insn-\u003eoff \u003e\u003e 3) - 1] : \"\",\n@@ -224,6 +241,7 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs,\n \t\t\tverbose(cbs-\u003eprivate_data, \"(%02x) %c%d %s %d\",\n \t\t\t\tinsn-\u003ecode, class == BPF_ALU ? 'w' : 'r',\n \t\t\t\tinsn-\u003edst_reg,\n+\t\t\t\thmul_op_string(insn) ?:\n \t\t\t\tis_sdiv_smod(insn) ? bpf_alu_sign_string[BPF_OP(insn-\u003ecode) \u003e\u003e 4]\n \t\t\t\t\t\t : bpf_alu_string[BPF_OP(insn-\u003ecode) \u003e\u003e 4],\n \t\t\t\tinsn-\u003eimm);\ndiff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c\nindex 5601d20562186..ac7974038eaa3 100644\n--- a/kernel/bpf/verifier.c\n+++ b/kernel/bpf/verifier.c\n@@ -16664,6 +16664,24 @@ static void scalar_min_max_mul(struct bpf_reg_state *dst_reg,\n \t\t\t\t\tcnum64_from_srange(smin, smax));\n }\n \n+static void scalar_min_max_uhmul(struct bpf_reg_state *dst_reg,\n+\t\t\t\t struct bpf_reg_state *src_reg)\n+{\n+\tu64 dst = reg_const_value(dst_reg, false);\n+\tu64 src = reg_const_value(src_reg, false);\n+\n+\t___mark_reg_known(dst_reg, bpf_uhmul64(dst, src));\n+}\n+\n+static void scalar_min_max_shmul(struct bpf_reg_state *dst_reg,\n+\t\t\t\t struct bpf_reg_state *src_reg)\n+{\n+\ts64 dst = reg_const_value(dst_reg, false);\n+\ts64 src = reg_const_value(src_reg, false);\n+\n+\t___mark_reg_known(dst_reg, bpf_shmul64(dst, src));\n+}\n+\n static void scalar32_min_max_udiv(struct bpf_reg_state *dst_reg,\n \t\t\t\t struct bpf_reg_state *src_reg)\n {\n@@ -17364,6 +17382,25 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,\n \t\treg_step_reset(dst_reg);\n \t\tbreak;\n \tcase BPF_MUL:\n+\t\t/*\n+\t\t * Range analysis for UHMUL/SHMUL is not implemented yet.\n+\t\t * Compute an exact result only when both operands are constants.\n+\t\t * Ordinary low-half MUL continues to use the analysis below.\n+\t\t */\n+\t\tif (bpf_insn_is_hmul(insn) \u0026\u0026\n+\t\t (!is_reg_const(dst_reg, false) ||\n+\t\t !is_reg_const(\u0026src_reg, false))) {\n+\t\t\t__mark_reg_unknown(env, dst_reg);\n+\t\t\tbreak;\n+\t\t}\n+\t\tif (!alu32 \u0026\u0026 insn-\u003eoff == BPF_UHMUL) {\n+\t\t\tscalar_min_max_uhmul(dst_reg, \u0026src_reg);\n+\t\t\tbreak;\n+\t\t}\n+\t\tif (!alu32 \u0026\u0026 insn-\u003eoff == BPF_SHMUL) {\n+\t\t\tscalar_min_max_shmul(dst_reg, \u0026src_reg);\n+\t\t\tbreak;\n+\t\t}\n \t\tscalar_step_mul(dst_reg, \u0026src_reg);\n \t\tdst_reg-\u003evar_off = tnum_mul(dst_reg-\u003evar_off, src_reg.var_off);\n \t\tscalar32_min_max_mul(dst_reg, \u0026src_reg);\n@@ -17499,6 +17536,11 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,\n \t/* Case where at least one operand is an arena. */\n \tif (dst_reg-\u003etype == PTR_TO_ARENA || (src_reg \u0026\u0026 src_reg-\u003etype == PTR_TO_ARENA)) {\n \n+\t\tif (bpf_insn_is_hmul(insn)) {\n+\t\t\tverbose(env, \"UHMUL/SHMUL with arena pointers are not supported\\n\");\n+\t\t\treturn -EOPNOTSUPP;\n+\t\t}\n+\n \t\tif (dst_reg-\u003etype != PTR_TO_ARENA)\n \t\t\t*dst_reg = *src_reg;\n \n@@ -21194,6 +21236,31 @@ static int fd_array_get_map_idx(struct bpf_verifier_env *env, u32 idx)\n \treturn -EPROTO;\n }\n \n+static bool is_valid_alu_variant(const struct bpf_insn *insn)\n+{\n+\tswitch (BPF_OP(insn-\u003ecode)) {\n+\tcase BPF_MUL:\n+\t\treturn insn-\u003eoff == 0 || bpf_insn_is_hmul(insn);\n+\tcase BPF_DIV:\n+\tcase BPF_MOD:\n+\t\t/* off == 1 selects SDIV/SMOD. */\n+\t\treturn insn-\u003eoff == 0 || insn-\u003eoff == 1;\n+\tdefault:\n+\t\treturn insn-\u003eoff == 0;\n+\t}\n+}\n+\n+/* The interpreter supports uhmul and shmul. JITs opt in. */\n+static int check_hmul_jit(struct bpf_verifier_env *env)\n+{\n+\tif (bpf_prog_is_offloaded(env-\u003eprog-\u003eaux) ||\n+\t (env-\u003eprog-\u003ejit_requested \u0026\u0026 !bpf_jit_supports_hmul())) {\n+\t\tverbose(env, \"JIT doesn't support uhmul and shmul\\n\");\n+\t\treturn -EOPNOTSUPP;\n+\t}\n+\treturn 0;\n+}\n+\n static int check_alu_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)\n {\n \tu8 class = BPF_CLASS(insn-\u003ecode);\n@@ -21249,18 +21316,14 @@ static int check_alu_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)\n \tcase BPF_MUL:\n \tcase BPF_DIV:\n \tcase BPF_MOD:\n-\t\tif (BPF_SRC(insn-\u003ecode) == BPF_X) {\n-\t\t\tif (insn-\u003eimm != 0 || (insn-\u003eoff != 0 \u0026\u0026 insn-\u003eoff != 1) ||\n-\t\t\t (insn-\u003eoff == 1 \u0026\u0026 opcode != BPF_MOD \u0026\u0026 opcode != BPF_DIV)) {\n-\t\t\t\tverbose(env, \"BPF_ALU uses reserved fields\\n\");\n-\t\t\t\treturn -EINVAL;\n-\t\t\t}\n-\t\t} else if (insn-\u003esrc_reg != BPF_REG_0 ||\n-\t\t\t (insn-\u003eoff != 0 \u0026\u0026 insn-\u003eoff != 1) ||\n-\t\t\t (insn-\u003eoff == 1 \u0026\u0026 opcode != BPF_MOD \u0026\u0026 opcode != BPF_DIV)) {\n+\t\tif (!is_valid_alu_variant(insn) ||\n+\t\t (BPF_SRC(insn-\u003ecode) == BPF_X \u0026\u0026 insn-\u003eimm != 0) ||\n+\t\t (BPF_SRC(insn-\u003ecode) == BPF_K \u0026\u0026 insn-\u003esrc_reg != BPF_REG_0)) {\n \t\t\tverbose(env, \"BPF_ALU uses reserved fields\\n\");\n \t\t\treturn -EINVAL;\n \t\t}\n+\t\tif (bpf_insn_is_hmul(insn))\n+\t\t\treturn check_hmul_jit(env);\n \t\treturn 0;\n \tdefault:\n \t\tverbose(env, \"invalid BPF_ALU opcode %x\\n\", opcode);\ndiff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h\nindex f29b0aad440cb..90c30e5d790b9 100644\n--- a/tools/include/uapi/linux/bpf.h\n+++ b/tools/include/uapi/linux/bpf.h\n@@ -34,6 +34,12 @@\n #define BPF_FROM_LE\tBPF_TO_LE\n #define BPF_FROM_BE\tBPF_TO_BE\n \n+/* BPF_MUL off values for high-half multiplication; BPF_ALU64 only. */\n+enum bpf_mul_variant {\n+\tBPF_UHMUL = 1,\n+\tBPF_SHMUL = 2,\n+};\n+\n /* jmp encodings */\n #define BPF_JNE\t\t0x50\t/* jump != */\n #define BPF_JLT\t\t0xa0\t/* LT is unsigned, '\u003c' */\ndiff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c\nindex 04740ba37e918..795c3e56c23e0 100644\n--- a/tools/testing/selftests/bpf/prog_tests/verifier.c\n+++ b/tools/testing/selftests/bpf/prog_tests/verifier.c\n@@ -59,6 +59,7 @@\n #include \"verifier_helper_packet_access.skel.h\"\n #include \"verifier_helper_restricted.skel.h\"\n #include \"verifier_helper_value_access.skel.h\"\n+#include \"verifier_hmul.skel.h\"\n #include \"verifier_idoms.skel.h\"\n #include \"verifier_int_ptr.skel.h\"\n #include \"verifier_iterating_callbacks.skel.h\"\n@@ -251,6 +252,7 @@ void test_verifier_helper_access_var_len(void) { RUN(verifier_helper_access_var_\n void test_verifier_helper_packet_access(void) { RUN(verifier_helper_packet_access); }\n void test_verifier_helper_restricted(void) { RUN(verifier_helper_restricted); }\n void test_verifier_helper_value_access(void) { RUN(verifier_helper_value_access); }\n+void test_verifier_hmul(void) { RUN(verifier_hmul); }\n void test_verifier_idoms(void) { RUN(verifier_idoms); }\n void test_verifier_int_ptr(void) { RUN(verifier_int_ptr); }\n void test_verifier_iterating_callbacks(void) { RUN(verifier_iterating_callbacks); }\ndiff --git a/tools/testing/selftests/bpf/prog_tests/verifier_hmul_arena.c b/tools/testing/selftests/bpf/prog_tests/verifier_hmul_arena.c\nnew file mode 100644\nindex 0000000000000..f9cd7b7b9781a\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/prog_tests/verifier_hmul_arena.c\n@@ -0,0 +1,19 @@\n+// SPDX-License-Identifier: GPL-2.0\n+\n+#include \u003ctest_progs.h\u003e\n+#include \"verifier_hmul_arena.skel.h\"\n+\n+void test_verifier_hmul_arena(void)\n+{\n+\tint ret;\n+\n+\t/* Arena support can depend on CPU features, such as Zacas on RV64. */\n+\tret = libbpf_probe_bpf_map_type(BPF_MAP_TYPE_ARENA, NULL);\n+\tif (!ASSERT_GE(ret, 0, \"probe_arena\"))\n+\t\treturn;\n+\tif (!ret) {\n+\t\ttest__skip();\n+\t\treturn;\n+\t}\n+\tRUN_TESTS(verifier_hmul_arena);\n+}\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_hmul.c b/tools/testing/selftests/bpf/progs/verifier_hmul.c\nnew file mode 100644\nindex 0000000000000..acd92355c6365\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/verifier_hmul.c\n@@ -0,0 +1,235 @@\n+// SPDX-License-Identifier: GPL-2.0\n+\n+#include \u003clinux/bpf.h\u003e\n+#include \u003climits.h\u003e\n+#include \u003cbpf/bpf_helpers.h\u003e\n+#include \"bpf_misc.h\"\n+#include \"../../../include/linux/filter.h\"\n+\n+#define BPF_UHMUL64_REG(DST, SRC) \\\n+\tBPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_X, DST, SRC, BPF_UHMUL, 0)\n+\n+#define BPF_UHMUL64_IMM(DST, IMM) \\\n+\tBPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, BPF_UHMUL, IMM)\n+\n+#define BPF_SHMUL64_REG(DST, SRC) \\\n+\tBPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_X, DST, SRC, BPF_SHMUL, 0)\n+\n+#define BPF_SHMUL64_IMM(DST, IMM) \\\n+\tBPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, BPF_SHMUL, IMM)\n+\n+/*\n+ * Inject UHMUL/SHMUL as raw instructions so these tests do not require\n+ * assembler support for the new mnemonics. All surrounding instructions use\n+ * existing BPF assembly syntax supported by the baseline selftests toolchain.\n+ */\n+\n+#if defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || \\\n+\t(defined(__TARGET_ARCH_riscv) \u0026\u0026 __riscv_xlen == 64)\n+\n+/*\n+ * BPF_PROG_TEST_RUN reports a 32-bit retval. Fold both halves of\n+ * (actual ^ expected) into w0 so retval == 0 checks the full 64-bit result.\n+ */\n+\n+SEC(\"socket\")\n+__description(\"UHMUL64, U64_MAX * U64_MAX, register source\")\n+__success __success_unpriv __retval(0)\n+__naked void uhmul64_max_reg(void)\n+{\n+\tasm volatile (\n+\t\"r0 = -1;\"\n+\t\"r1 = -1;\"\n+\t\".8byte %[hmul];\"\n+\t\"r2 = -2;\"\n+\t\"r0 ^= r2;\"\n+\t\"r2 = r0;\"\n+\t\"r2 \u003e\u003e= 32;\"\n+\t\"w0 |= w2;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm_insn(hmul, BPF_UHMUL64_REG(BPF_REG_0, BPF_REG_1))\n+\t: __clobber_all);\n+}\n+\n+SEC(\"socket\")\n+__description(\"UHMUL64, (1ULL \u003c\u003c 63) * 2, register source\")\n+__success __success_unpriv __retval(0)\n+__naked void uhmul64_pow2_reg(void)\n+{\n+\tasm volatile (\n+\t\"r0 = 2;\"\n+\t\"r1 = %[llong_min] ll;\"\n+\t\".8byte %[hmul];\"\n+\t\"r0 = r1;\"\n+\t\"r2 = 1;\"\n+\t\"r0 ^= r2;\"\n+\t\"r2 = r0;\"\n+\t\"r2 \u003e\u003e= 32;\"\n+\t\"w0 |= w2;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm_const(llong_min, LLONG_MIN),\n+\t __imm_insn(hmul, BPF_UHMUL64_REG(BPF_REG_1, BPF_REG_0))\n+\t: __clobber_all);\n+}\n+\n+SEC(\"socket\")\n+__description(\"UHMUL64, (1ULL \u003c\u003c 63) * 2, R3 destination\")\n+__success __success_unpriv __retval(0)\n+__naked void uhmul64_r3_dst(void)\n+{\n+\tasm volatile (\n+\t\"r3 = %[llong_min] ll;\"\n+\t\"r0 = 2;\"\n+\t\".8byte %[hmul];\"\n+\t\"r2 = 1;\"\n+\t\"r3 ^= r2;\"\n+\t\"r2 = r3;\"\n+\t\"r2 \u003e\u003e= 32;\"\n+\t\"w3 |= w2;\"\n+\t\"r0 = r3;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm_const(llong_min, LLONG_MIN),\n+\t __imm_insn(hmul, BPF_UHMUL64_REG(BPF_REG_3, BPF_REG_0))\n+\t: __clobber_all);\n+}\n+\n+SEC(\"socket\")\n+__description(\"UHMUL64, (1ULL \u003c\u003c 63) * 2, immediate source\")\n+__success __success_unpriv __retval(0)\n+__naked void uhmul64_pow2_imm(void)\n+{\n+\tasm volatile (\n+\t\"r0 = %[llong_min] ll;\"\n+\t\".8byte %[hmul];\"\n+\t\"r2 = 1;\"\n+\t\"r0 ^= r2;\"\n+\t\"r2 = r0;\"\n+\t\"r2 \u003e\u003e= 32;\"\n+\t\"w0 |= w2;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm_const(llong_min, LLONG_MIN),\n+\t __imm_insn(hmul, BPF_UHMUL64_IMM(BPF_REG_0, 2))\n+\t: __clobber_all);\n+}\n+\n+SEC(\"socket\")\n+__description(\"UHMUL64, (1ULL \u003c\u003c 63) * -2, immediate source\")\n+__success __success_unpriv __retval(0)\n+__naked void uhmul64_neg_imm(void)\n+{\n+\tasm volatile (\n+\t\"r0 = %[llong_min] ll;\"\n+\t\".8byte %[hmul];\"\n+\t\"r2 = %[llong_max] ll;\"\n+\t\"r0 ^= r2;\"\n+\t\"r2 = r0;\"\n+\t\"r2 \u003e\u003e= 32;\"\n+\t\"w0 |= w2;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm_const(llong_min, LLONG_MIN),\n+\t __imm_const(llong_max, LLONG_MAX),\n+\t __imm_insn(hmul, BPF_UHMUL64_IMM(BPF_REG_0, -2))\n+\t: __clobber_all);\n+}\n+\n+SEC(\"socket\")\n+__description(\"SHMUL64, INT64_MAX * INT64_MAX, register source\")\n+__success __success_unpriv __retval(0)\n+__naked void shmul64_max_reg(void)\n+{\n+\tasm volatile (\n+\t\"r0 = %[llong_max] ll;\"\n+\t\"r1 = %[llong_max] ll;\"\n+\t\".8byte %[hmul];\"\n+\t\"r2 = %[expected] ll;\"\n+\t\"r0 ^= r2;\"\n+\t\"r2 = r0;\"\n+\t\"r2 \u003e\u003e= 32;\"\n+\t\"w0 |= w2;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm_const(expected, 0x3fffffffffffffffULL),\n+\t __imm_const(llong_max, LLONG_MAX),\n+\t __imm_insn(hmul, BPF_SHMUL64_REG(BPF_REG_0, BPF_REG_1))\n+\t: __clobber_all);\n+}\n+\n+SEC(\"socket\")\n+__description(\"SHMUL64, INT64_MIN * -2, register source\")\n+__success __success_unpriv __retval(0)\n+__naked void shmul64_min_neg2_reg(void)\n+{\n+\tasm volatile (\n+\t\"r0 = %[llong_min] ll;\"\n+\t\"r1 = -2;\"\n+\t\".8byte %[hmul];\"\n+\t\"r2 = 1;\"\n+\t\"r0 ^= r2;\"\n+\t\"r2 = r0;\"\n+\t\"r2 \u003e\u003e= 32;\"\n+\t\"w0 |= w2;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm_const(llong_min, LLONG_MIN),\n+\t __imm_insn(hmul, BPF_SHMUL64_REG(BPF_REG_0, BPF_REG_1))\n+\t: __clobber_all);\n+}\n+\n+SEC(\"socket\")\n+__description(\"SHMUL64, 1 * -2, immediate source\")\n+__success __success_unpriv __retval(0)\n+__naked void shmul64_neg_imm(void)\n+{\n+\tasm volatile (\n+\t\"r0 = 1;\"\n+\t\".8byte %[hmul];\"\n+\t\"r2 = -1;\"\n+\t\"r0 ^= r2;\"\n+\t\"r2 = r0;\"\n+\t\"r2 \u003e\u003e= 32;\"\n+\t\"w0 |= w2;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm_insn(hmul, BPF_SHMUL64_IMM(BPF_REG_0, -2))\n+\t: __clobber_all);\n+}\n+\n+SEC(\"socket\")\n+__description(\"SHMUL64, INT64_MIN * 2, immediate source\")\n+__success __success_unpriv __retval(0)\n+__naked void shmul64_min_imm(void)\n+{\n+\tasm volatile (\n+\t\"r0 = %[llong_min] ll;\"\n+\t\".8byte %[hmul];\"\n+\t\"r2 = -1;\"\n+\t\"r0 ^= r2;\"\n+\t\"r2 = r0;\"\n+\t\"r2 \u003e\u003e= 32;\"\n+\t\"w0 |= w2;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm_const(llong_min, LLONG_MIN),\n+\t __imm_insn(hmul, BPF_SHMUL64_IMM(BPF_REG_0, 2))\n+\t: __clobber_all);\n+}\n+\n+#else\n+\n+SEC(\"socket\")\n+__description(\"UHMUL/SHMUL are not supported by this JIT, use a dummy test\")\n+__skip(\"UHMUL/SHMUL are not supported by this jit\")\n+__success\n+int dummy_test(void)\n+{\n+\treturn 0;\n+}\n+\n+#endif\n+\n+char _license[] SEC(\"license\") = \"GPL\";\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_hmul_arena.c b/tools/testing/selftests/bpf/progs/verifier_hmul_arena.c\nnew file mode 100644\nindex 0000000000000..a8709ec447aa8\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/verifier_hmul_arena.c\n@@ -0,0 +1,74 @@\n+// SPDX-License-Identifier: GPL-2.0\n+\n+#include \u003clinux/bpf.h\u003e\n+#include \u003cbpf/bpf_helpers.h\u003e\n+#include \"bpf_misc.h\"\n+#include \"../../../include/linux/filter.h\"\n+\n+#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)\n+\n+#define BPF_UHMUL64_IMM(DST, IMM) \\\n+\tBPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, BPF_UHMUL, IMM)\n+\n+#define BPF_SHMUL64_REG(DST, SRC) \\\n+\tBPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_X, DST, SRC, BPF_SHMUL, 0)\n+\n+struct {\n+\t__uint(type, BPF_MAP_TYPE_ARENA);\n+\t__uint(map_flags, BPF_F_MMAPABLE);\n+\t__uint(max_entries, 1);\n+} arena SEC(\".maps\");\n+\n+SEC(\"syscall\")\n+__description(\"UHMUL64 with arena pointer dst\")\n+__failure __msg(\"UHMUL/SHMUL with arena pointers are not supported\")\n+__arch_x86_64 __arch_arm64 __arch_riscv64\n+__load_if_JITed()\n+__naked void uhmul64_arena_ptr(void)\n+{\n+\tasm volatile (\n+\t\"r1 = %[arena] ll;\"\n+\t\"r0 = 1;\"\n+\t\"r0 = addr_space_cast(r0, 0x0, 0x1);\"\n+\t\".8byte %[hmul];\"\n+\t\"exit;\"\n+\t:\n+\t: __imm_addr(arena),\n+\t __imm_insn(hmul, BPF_UHMUL64_IMM(BPF_REG_0, 2))\n+\t: __clobber_all);\n+}\n+\n+SEC(\"syscall\")\n+__description(\"SHMUL64 with arena pointer src\")\n+__failure __msg(\"UHMUL/SHMUL with arena pointers are not supported\")\n+__arch_x86_64 __arch_arm64 __arch_riscv64\n+__load_if_JITed()\n+__naked void shmul64_arena_ptr(void)\n+{\n+\tasm volatile (\n+\t\"r1 = %[arena] ll;\"\n+\t\"r1 = 1;\"\n+\t\"r1 = addr_space_cast(r1, 0x0, 0x1);\"\n+\t\"r0 = 2;\"\n+\t\".8byte %[hmul];\"\n+\t\"exit;\"\n+\t:\n+\t: __imm_addr(arena),\n+\t __imm_insn(hmul, BPF_SHMUL64_REG(BPF_REG_0, BPF_REG_1))\n+\t: __clobber_all);\n+}\n+\n+#else\n+\n+SEC(\"socket\")\n+__description(\"HMUL arena tests require compiler support for addr_space_cast\")\n+__skip(\"compiler doesn't support addr_space_cast\")\n+__success\n+int dummy_test(void)\n+{\n+\treturn 0;\n+}\n+\n+#endif\n+\n+char _license[] SEC(\"license\") = \"GPL\";\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c\nindex 31663338866d3..209d5be551555 100644\n--- a/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c\n+++ b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c\n@@ -367,7 +367,8 @@ __naked void flow_keys_illegal_variable_offset_alu(void)\n \n /*\n * Offset fields of 0 and 1 are legal for BPF_{DIV,MOD} instructions.\n- * Offset fields of 0 are legal for the rest of ALU instructions.\n+ * Offset fields of 0, 1 and 2 are legal for BPF_ALU64 | BPF_MUL.\n+ * Only offset 0 is legal for BPF_ALU | BPF_MUL.\n * Test that error is reported for illegal offsets, assuming that tests\n * for legal offsets exist.\n */\n@@ -377,5 +378,9 @@ DEFINE_BAD_OFFSET_TEST(bad_offset_addx, BPF_ALU64 | BPF_ADD | BPF_X, -1, 0)\n DEFINE_BAD_OFFSET_TEST(bad_offset_divx2, BPF_ALU64 | BPF_DIV | BPF_X, 2, 0)\n DEFINE_BAD_OFFSET_TEST(bad_offset_modk2, BPF_ALU64 | BPF_MOD | BPF_K, 2, 1)\n DEFINE_BAD_OFFSET_TEST(bad_offset_addx2, BPF_ALU64 | BPF_ADD | BPF_X, 1, 0)\n+DEFINE_BAD_OFFSET_TEST(bad_offset_mulx, BPF_ALU64 | BPF_MUL | BPF_X, -1, 0)\n+DEFINE_BAD_OFFSET_TEST(bad_offset_mulk, BPF_ALU64 | BPF_MUL | BPF_K, 3, 0)\n+DEFINE_BAD_OFFSET_TEST(bad_uhmul32_x, BPF_ALU | BPF_MUL | BPF_X, BPF_UHMUL, 0)\n+DEFINE_BAD_OFFSET_TEST(bad_shmul32_k, BPF_ALU | BPF_MUL | BPF_K, BPF_SHMUL, 0)\n \n char _license[] SEC(\"license\") = \"GPL\";\n"
} |
| 2/1 | 2026/10/23 04:24 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"emit_hmul_aux",
"scalar_min_max_uhmul",
"scalar_min_max_shmul",
"check_hmul_jit",
"bpf_jit_supports_hmul",
"adjust_scalar_min_max_vals",
"check_alu_fields"
],
"Reasoning": "The patch introduces new eBPF 64-bit high-half multiplication instructions (UHMUL and SHMUL) across the BPF verifier, BPF interpreter, and architecture JIT compilers (including x86_64). The changes directly affect instruction validation, scalar min/max value tracking, arena pointer checks, and JIT assembly generation (including RAX/RDX push/pop and mul/imul execution). This reachable, security-critical code in a core subsystem is accessible via the bpf() syscall and warrants fuzzing for verifier/JIT desynchronization, register clobbering, or integer arithmetic edge cases.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 6d6c77985c9242ff63faeda7fbb06058ee652429
Author: syz-cluster <triage@syzkaller.com>
Date: Fri Oct 23 04:23:59 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/bpf/standardization/instruction-set.rst b/Documentation/bpf/standardization/instruction-set.rst
index 39c74611752b6..6f3cb6bcaa1a6 100644
--- a/Documentation/bpf/standardization/instruction-set.rst
+++ b/Documentation/bpf/standardization/instruction-set.rst
@@ -142,8 +142,9 @@ This document defines the following conformance groups:
* atomic32: includes 32-bit atomic operation instructions (see `Atomic operations`_).
* atomic64: includes atomic32, plus 64-bit atomic operation instructions.
* divmul32: includes 32-bit division, multiplication, and modulo instructions.
-* divmul64: includes divmul32, plus 64-bit division, multiplication,
+* divmul64: includes divmul32, plus 64-bit division, low-half multiplication,
and modulo instructions.
+* divmul64v2: includes divmul64, plus high-half multiplication instructions.
* packet: deprecated packet access instructions.
Instruction encoding
@@ -330,6 +331,8 @@ register.
ADD 0x0 0 dst += src
SUB 0x1 0 dst -= src
MUL 0x2 0 dst \*= src
+ UHMUL 0x2 1 ``dst uh*= src`` (unsigned high half, ``ALU64`` only)
+ SHMUL 0x2 2 ``dst sh*= src`` (signed high half, ``ALU64`` only)
DIV 0x3 0 dst = (src != 0) ? (dst / src) : 0
SDIV 0x3 1 dst = (src == 0) ? 0 : ((src == -1 && dst == LLONG_MIN) ? LLONG_MIN : (dst s/ src))
OR 0x4 0 dst \|= src
@@ -379,13 +382,33 @@ where '(u32)' indicates that the upper 32 bits are zeroed.
dst = dst ^ imm
-Note that most arithmetic instructions have 'offset' set to 0. Only three instructions
-(``SDIV``, ``SMOD``, ``MOVSX``) have a non-zero 'offset'.
+Note that most arithmetic instructions have 'offset' set to 0. The following
+instructions may have a non-zero 'offset':
+
+* ``SDIV`` and ``SMOD``: ``offset == 1`` selects the signed variant.
+* ``MOVSX``: ``offset`` selects the source operand width.
+* ``MUL``: ``offset`` selects the multiplication variant (see below).
+
+Division, low-half multiplication (``MUL`` with ``offset == 0``), and
+modulo operations for ``ALU`` are part of the "divmul32" conformance
+group, and their ``ALU64`` variants are part of the "divmul64"
+conformance group.
+
+For ``ALU64`` multiplication, ``offset == 1`` selects unsigned
+high-half multiplication (``UHMUL``), and ``offset == 2`` selects
+signed high-half multiplication (``SHMUL``). Both instructions belong
+to the "divmul64v2" conformance group.
+
+For ``X`` mode, ``src64`` is the 64-bit value in ``src_reg``. For
+``K`` mode, ``src64`` is ``imm`` sign-extended from 32 to 64 bits.
+The operations are::
+
+ UHMUL: dst = (u64)(((u128)dst * (u128)(u64)src64) >> 64)
+ SHMUL: dst = (u64)(((s128)(s64)dst * (s128)(s64)src64) >> 64)
+
+For ``ALU`` multiplication, only ``offset == 0`` is valid. For ``ALU64``
+multiplication, offset values other than 0, 1, and 2 are reserved.
-Division, multiplication, and modulo operations for ``ALU`` are part
-of the "divmul32" conformance group, and division, multiplication, and
-modulo operations for ``ALU64`` are part of the "divmul64" conformance
-group.
The division and modulo operations support both unsigned and signed flavors.
For unsigned operations (``DIV`` and ``MOD``), for ``ALU``,
diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h
index 1ce75a4426387..f38738fa54a27 100644
--- a/arch/arm64/include/asm/insn.h
+++ b/arch/arm64/include/asm/insn.h
@@ -247,6 +247,8 @@ enum aarch64_insn_data2_type {
enum aarch64_insn_data3_type {
AARCH64_INSN_DATA3_MADD,
AARCH64_INSN_DATA3_MSUB,
+ AARCH64_INSN_DATA3_SMULH,
+ AARCH64_INSN_DATA3_UMULH,
};
enum aarch64_insn_logic_type {
@@ -396,6 +398,8 @@ __AARCH64_INSN_FUNCS(sub_ext, 0x7FE00000, 0x4B200000)
__AARCH64_INSN_FUNCS(subs_ext, 0x7FE00000, 0x6B200000)
__AARCH64_INSN_FUNCS(madd, 0x7FE08000, 0x1B000000)
__AARCH64_INSN_FUNCS(msub, 0x7FE08000, 0x1B008000)
+__AARCH64_INSN_FUNCS(smulh, 0x7FE0FC00, 0x1B407C00)
+__AARCH64_INSN_FUNCS(umulh, 0x7FE0FC00, 0x1BC07C00)
__AARCH64_INSN_FUNCS(udiv, 0x7FE0FC00, 0x1AC00800)
__AARCH64_INSN_FUNCS(sdiv, 0x7FE0FC00, 0x1AC00C00)
__AARCH64_INSN_FUNCS(lslv, 0x7FE0FC00, 0x1AC02000)
diff --git a/arch/arm64/lib/insn.c b/arch/arm64/lib/insn.c
index e70ac02385153..dc483d1b8bd54 100644
--- a/arch/arm64/lib/insn.c
+++ b/arch/arm64/lib/insn.c
@@ -1155,6 +1155,12 @@ u32 aarch64_insn_gen_data3(enum aarch64_insn_register dst,
case AARCH64_INSN_DATA3_MSUB:
insn = aarch64_insn_get_msub_value();
break;
+ case AARCH64_INSN_DATA3_SMULH:
+ insn = aarch64_insn_get_smulh_value();
+ break;
+ case AARCH64_INSN_DATA3_UMULH:
+ insn = aarch64_insn_get_umulh_value();
+ break;
default:
pr_err("%s: unknown data3 encoding %d\n", __func__, type);
return AARCH64_BREAK_FAULT;
diff --git a/arch/arm64/net/bpf_jit.h b/arch/arm64/net/bpf_jit.h
index b2fe6e6dcf447..70fc329c661db 100644
--- a/arch/arm64/net/bpf_jit.h
+++ b/arch/arm64/net/bpf_jit.h
@@ -281,6 +281,12 @@
A64_VARIANT(sf), AARCH64_INSN_DATA3_MSUB)
/* Rd = Rn * Rm */
#define A64_MUL(sf, Rd, Rn, Rm) A64_MADD(sf, Rd, A64_ZR, Rn, Rm)
+/* Rd = high 64 bits of signed Rn * Rm */
+#define A64_SMULH(Rd, Rn, Rm) aarch64_insn_gen_data3(Rd, A64_ZR, Rn, Rm, \
+ AARCH64_INSN_VARIANT_64BIT, AARCH64_INSN_DATA3_SMULH)
+/* Rd = high 64 bits of unsigned Rn * Rm */
+#define A64_UMULH(Rd, Rn, Rm) aarch64_insn_gen_data3(Rd, A64_ZR, Rn, Rm, \
+ AARCH64_INSN_VARIANT_64BIT, AARCH64_INSN_DATA3_UMULH)
/* Logical (shifted register) */
#define A64_LOGIC_SREG(sf, Rd, Rn, Rm, type) \
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 326e9e1dea0a7..3b4793092c1a4 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -144,6 +144,17 @@ static inline void emit_a64_mov_i(const int is64, const int reg,
}
}
+static inline void emit_a64_mul(const bool is64, const u8 dst, const u8 src,
+ const s16 off, struct jit_ctx *ctx)
+{
+ if (is64 && off == BPF_UHMUL)
+ emit(A64_UMULH(dst, dst, src), ctx);
+ else if (is64 && off == BPF_SHMUL)
+ emit(A64_SMULH(dst, dst, src), ctx);
+ else
+ emit(A64_MUL(is64, dst, dst, src), ctx);
+}
+
static int i64_i16_blocks(const u64 val, bool inverse)
{
return (((val >> 0) & 0xffff) != (inverse ? 0xffff : 0x0000)) +
@@ -1531,7 +1542,7 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn
break;
case BPF_ALU | BPF_MUL | BPF_X:
case BPF_ALU64 | BPF_MUL | BPF_X:
- emit(A64_MUL(is64, dst, dst, src), ctx);
+ emit_a64_mul(is64, dst, src, off, ctx);
break;
case BPF_ALU | BPF_DIV | BPF_X:
case BPF_ALU64 | BPF_DIV | BPF_X:
@@ -1660,7 +1671,7 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn
case BPF_ALU | BPF_MUL | BPF_K:
case BPF_ALU64 | BPF_MUL | BPF_K:
emit_a64_mov_i(is64, tmp, imm, ctx);
- emit(A64_MUL(is64, dst, dst, tmp), ctx);
+ emit_a64_mul(is64, dst, tmp, off, ctx);
break;
case BPF_ALU | BPF_DIV | BPF_K:
case BPF_ALU64 | BPF_DIV | BPF_K:
@@ -2595,6 +2606,11 @@ bool bpf_jit_supports_callx(void)
return true;
}
+bool bpf_jit_supports_hmul(void)
+{
+ return true;
+}
+
bool bpf_jit_supports_large_stack(void)
{
return true;
diff --git a/arch/riscv/net/bpf_jit.h b/arch/riscv/net/bpf_jit.h
index 5c4f53060c918..21a190a6a6d99 100644
--- a/arch/riscv/net/bpf_jit.h
+++ b/arch/riscv/net/bpf_jit.h
@@ -436,6 +436,11 @@ static inline u32 rv_mul(u8 rd, u8 rs1, u8 rs2)
return rv_r_insn(1, rs2, rs1, 0, rd, 0x33);
}
+static inline u32 rv_mulh(u8 rd, u8 rs1, u8 rs2)
+{
+ return rv_r_insn(1, rs2, rs1, 1, rd, 0x33);
+}
+
static inline u32 rv_mulhu(u8 rd, u8 rs1, u8 rs2)
{
return rv_r_insn(1, rs2, rs1, 3, rd, 0x33);
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index 788fcc21fd5b8..371405598faa7 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -197,6 +197,19 @@ static void emit_imm(u8 rd, s64 val, struct rv_jit_context *ctx)
emit_addi(rd, rd, lower, ctx);
}
+static void emit_mul(u8 rd, u8 rs, bool is64, s16 off,
+ struct rv_jit_context *ctx)
+{
+ if (!is64)
+ emit(rv_mulw(rd, rd, rs), ctx);
+ else if (off == BPF_UHMUL)
+ emit(rv_mulhu(rd, rd, rs), ctx);
+ else if (off == BPF_SHMUL)
+ emit(rv_mulh(rd, rd, rs), ctx);
+ else
+ emit(rv_mul(rd, rd, rs), ctx);
+}
+
static void __build_epilogue(bool is_tail_call, struct rv_jit_context *ctx)
{
int stack_adjust = ctx->stack_size, store_offset = stack_adjust - 8;
@@ -1526,7 +1539,7 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
break;
case BPF_ALU | BPF_MUL | BPF_X:
case BPF_ALU64 | BPF_MUL | BPF_X:
- emit(is64 ? rv_mul(rd, rd, rs) : rv_mulw(rd, rd, rs), ctx);
+ emit_mul(rd, rs, is64, off, ctx);
if (!is64 && !aux->verifier_zext)
emit_zextw(rd, rd, ctx);
break;
@@ -1662,8 +1675,7 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
case BPF_ALU | BPF_MUL | BPF_K:
case BPF_ALU64 | BPF_MUL | BPF_K:
emit_imm(RV_REG_T1, imm, ctx);
- emit(is64 ? rv_mul(rd, rd, RV_REG_T1) :
- rv_mulw(rd, rd, RV_REG_T1), ctx);
+ emit_mul(rd, RV_REG_T1, is64, off, ctx);
if (!is64 && !aux->verifier_zext)
emit_zextw(rd, rd, ctx);
break;
@@ -2303,3 +2315,8 @@ bool bpf_jit_supports_callx(void)
{
return true;
}
+
+bool bpf_jit_supports_hmul(void)
+{
+ return true;
+}
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 6a2fe3d0039d3..2707e8fb97994 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -1378,6 +1378,38 @@ static int emit_kasan_check(struct bpf_verifier_env *env, u8 **pprog,
return 0;
}
+/*
+ * The one-operand x86 mul/imul forms use RAX as the implicit first
+ * operand and store the 128-bit product in RDX:RAX.
+ * The JIT uses AUX_REG as the explicit second operand.
+ */
+static void emit_hmul_aux(u8 **pprog, u32 dst_reg, bool is_signed)
+{
+ u8 *prog = *pprog;
+ bool save_rax = dst_reg != BPF_REG_0;
+ bool save_rdx = dst_reg != BPF_REG_3;
+ u8 mul_modrm_base = is_signed ? 0xE8 : 0xE0; /* imul /5 or mul /4 */
+
+ if (save_rax)
+ EMIT1(0x50); /* push rax */
+ if (save_rdx)
+ EMIT1(0x52); /* push rdx */
+
+ if (save_rax)
+ emit_mov_reg(&prog, true, BPF_REG_0, dst_reg);
+ maybe_emit_1mod(&prog, AUX_REG, true);
+ EMIT2(0xF7, add_1reg(mul_modrm_base, AUX_REG));
+ if (save_rdx)
+ emit_mov_reg(&prog, true, dst_reg, BPF_REG_3);
+
+ if (save_rdx)
+ EMIT1(0x5A); /* pop rdx */
+ if (save_rax)
+ EMIT1(0x58); /* pop rax */
+
+ *pprog = prog;
+}
+
/* LDX: dst_reg = *(u8*)(src_reg + off) */
static void emit_ldx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
{
@@ -2916,6 +2948,14 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
case BPF_ALU | BPF_MUL | BPF_K:
case BPF_ALU64 | BPF_MUL | BPF_K:
+ if (bpf_insn_is_hmul(insn)) {
+ /* imul/mul use AUX_REG as src. */
+ emit_mov_imm32(&prog, true, AUX_REG, imm32);
+ emit_hmul_aux(&prog, dst_reg,
+ insn->off == BPF_SHMUL);
+ break;
+ }
+
/*
* lea for 3, 5 and 9, which LLVM leaves as a
* multiplication, but not for r13, which needs a
@@ -2951,6 +2991,14 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
case BPF_ALU | BPF_MUL | BPF_X:
case BPF_ALU64 | BPF_MUL | BPF_X:
+ if (bpf_insn_is_hmul(insn)) {
+ /* imul/mul use AUX_REG as src. */
+ emit_mov_reg(&prog, true, AUX_REG, src_reg);
+ emit_hmul_aux(&prog, dst_reg,
+ insn->off == BPF_SHMUL);
+ break;
+ }
+
maybe_emit_mod(&prog, src_reg, dst_reg,
BPF_CLASS(insn->code) == BPF_ALU64);
@@ -5126,6 +5174,11 @@ bool bpf_jit_supports_unwind(void)
return true;
}
+bool bpf_jit_supports_hmul(void)
+{
+ return true;
+}
+
const struct bpf_jit_arg_abi *bpf_jit_arg_abi(void)
{
return &x86_arg_abi;
diff --git a/include/linux/filter.h b/include/linux/filter.h
index e0218e677a1dc..2a2101fb01684 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -23,6 +23,7 @@
#include <linux/sockptr.h>
#include <linux/static_call.h>
#include <linux/u64_stats_sync.h>
+#include <linux/math64.h>
#include <net/sch_generic.h>
@@ -152,6 +153,38 @@ struct ctl_table_header;
#define BPF_ALU32_IMM(OP, DST, IMM) \
BPF_ALU32_IMM_OFF(OP, DST, IMM, 0)
+static inline u64 bpf_uhmul64(u64 a, u64 b)
+{
+ return mul_u64_u64_shr(a, b, 64);
+}
+
+static inline u64 bpf_shmul64(s64 a, s64 b)
+{
+ u64 ua = a, ub = b;
+ u64 hi = bpf_uhmul64(ua, ub);
+
+ /*
+ * Let M = 2^64, sa = (a < 0), and sb = (b < 0). Then:
+ *
+ * a * b = (ua - sa * M) * (ub - sb * M)
+ * = ua * ub - sa * M * ub - sb * M * ua + sa * sb * M^2
+ *
+ * Therefore, signed_hi = unsigned_hi - sa * ub - sb * ua (mod M).
+ */
+ if (a < 0)
+ hi -= ub;
+ if (b < 0)
+ hi -= ua;
+ return hi;
+}
+
+static inline bool bpf_insn_is_hmul(const struct bpf_insn *insn)
+{
+ return BPF_CLASS(insn->code) == BPF_ALU64 &&
+ BPF_OP(insn->code) == BPF_MUL &&
+ (insn->off == BPF_UHMUL || insn->off == BPF_SHMUL);
+}
+
/* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */
#define BPF_ENDIAN(TYPE, DST, LEN) \
@@ -1281,6 +1314,7 @@ bool bpf_jit_supports_kfunc_call(void);
bool bpf_jit_supports_callx(void);
bool bpf_jit_supports_kfunc_ret_reg_pair(void);
bool bpf_jit_supports_unwind(void);
+bool bpf_jit_supports_hmul(void);
bool bpf_jit_supports_stack_args(void);
bool bpf_jit_supports_arena_args(void);
bool bpf_jit_supports_far_kfunc_call(void);
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index f29b0aad440cb..90c30e5d790b9 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -34,6 +34,12 @@
#define BPF_FROM_LE BPF_TO_LE
#define BPF_FROM_BE BPF_TO_BE
+/* BPF_MUL off values for high-half multiplication; BPF_ALU64 only. */
+enum bpf_mul_variant {
+ BPF_UHMUL = 1,
+ BPF_SHMUL = 2,
+};
+
/* jmp encodings */
#define BPF_JNE 0x50 /* jump != */
#define BPF_JLT 0xa0 /* LT is unsigned, '<' */
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 3030beb531d99..8600c93842175 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1943,7 +1943,46 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)
ALU(AND, &)
ALU(OR, |)
ALU(XOR, ^)
- ALU(MUL, *)
+ /*
+ * MUL needs explicit handlers because ALU64 insn->off selects
+ * low-half, unsigned high-half, or signed high-half multiplication.
+ */
+ ALU64_MUL_X:
+ switch (OFF) {
+ case 0:
+ DST = DST * SRC;
+ break;
+ case BPF_UHMUL:
+ DST = bpf_uhmul64(DST, SRC);
+ break;
+ case BPF_SHMUL:
+ DST = bpf_shmul64((s64)DST, (s64)SRC);
+ break;
+ default:
+ goto default_label;
+ }
+ CONT;
+ ALU_MUL_X:
+ DST = (u32) DST * (u32) SRC;
+ CONT;
+ ALU64_MUL_K:
+ switch (OFF) {
+ case 0:
+ DST = DST * IMM;
+ break;
+ case BPF_UHMUL:
+ DST = bpf_uhmul64(DST, (u64)IMM);
+ break;
+ case BPF_SHMUL:
+ DST = bpf_shmul64((s64)DST, (s32)IMM);
+ break;
+ default:
+ goto default_label;
+ }
+ CONT;
+ ALU_MUL_K:
+ DST = (u32) DST * (u32) IMM;
+ CONT;
SHT(LSH, <<)
SHT(RSH, >>)
#undef SHT
@@ -3405,6 +3444,12 @@ bool __weak bpf_jit_supports_unwind(void)
return false;
}
+/* uhmul and shmul */
+bool __weak bpf_jit_supports_hmul(void)
+{
+ return false;
+}
+
/*
* How this arch places a by-value kfunc argument, or NULL for one that has
* not opted in and so only takes an argument of a single eightbyte, which
diff --git a/kernel/bpf/disasm.c b/kernel/bpf/disasm.c
index 889fc074496f1..0b1bbb27e9e4e 100644
--- a/kernel/bpf/disasm.c
+++ b/kernel/bpf/disasm.c
@@ -163,6 +163,22 @@ static bool is_sdiv_smod(const struct bpf_insn *insn)
insn->off == 1;
}
+/* Return the UHMUL or SHMUL operator string, or NULL for all other encodings. */
+static const char *hmul_op_string(const struct bpf_insn *insn)
+{
+ if (BPF_CLASS(insn->code) != BPF_ALU64 ||
+ BPF_OP(insn->code) != BPF_MUL)
+ return NULL;
+ switch (insn->off) {
+ case BPF_UHMUL:
+ return "uh*=";
+ case BPF_SHMUL:
+ return "sh*=";
+ default:
+ return NULL;
+ }
+}
+
static bool is_movsx(const struct bpf_insn *insn)
{
return BPF_OP(insn->code) == BPF_MOV &&
@@ -215,6 +231,7 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs,
verbose(cbs->private_data, "(%02x) %c%d %s %s%c%d",
insn->code, class == BPF_ALU ? 'w' : 'r',
insn->dst_reg,
+ hmul_op_string(insn) ?:
is_sdiv_smod(insn) ? bpf_alu_sign_string[BPF_OP(insn->code) >> 4]
: bpf_alu_string[BPF_OP(insn->code) >> 4],
is_movsx(insn) ? bpf_movsx_string[(insn->off >> 3) - 1] : "",
@@ -224,6 +241,7 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs,
verbose(cbs->private_data, "(%02x) %c%d %s %d",
insn->code, class == BPF_ALU ? 'w' : 'r',
insn->dst_reg,
+ hmul_op_string(insn) ?:
is_sdiv_smod(insn) ? bpf_alu_sign_string[BPF_OP(insn->code) >> 4]
: bpf_alu_string[BPF_OP(insn->code) >> 4],
insn->imm);
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 5601d20562186..ac7974038eaa3 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -16664,6 +16664,24 @@ static void scalar_min_max_mul(struct bpf_reg_state *dst_reg,
cnum64_from_srange(smin, smax));
}
+static void scalar_min_max_uhmul(struct bpf_reg_state *dst_reg,
+ struct bpf_reg_state *src_reg)
+{
+ u64 dst = reg_const_value(dst_reg, false);
+ u64 src = reg_const_value(src_reg, false);
+
+ ___mark_reg_known(dst_reg, bpf_uhmul64(dst, src));
+}
+
+static void scalar_min_max_shmul(struct bpf_reg_state *dst_reg,
+ struct bpf_reg_state *src_reg)
+{
+ s64 dst = reg_const_value(dst_reg, false);
+ s64 src = reg_const_value(src_reg, false);
+
+ ___mark_reg_known(dst_reg, bpf_shmul64(dst, src));
+}
+
static void scalar32_min_max_udiv(struct bpf_reg_state *dst_reg,
struct bpf_reg_state *src_reg)
{
@@ -17364,6 +17382,25 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,
reg_step_reset(dst_reg);
break;
case BPF_MUL:
+ /*
+ * Range analysis for UHMUL/SHMUL is not implemented yet.
+ * Compute an exact result only when both operands are constants.
+ * Ordinary low-half MUL continues to use the analysis below.
+ */
+ if (bpf_insn_is_hmul(insn) &&
+ (!is_reg_const(dst_reg, false) ||
+ !is_reg_const(&src_reg, false))) {
+ __mark_reg_unknown(env, dst_reg);
+ break;
+ }
+ if (!alu32 && insn->off == BPF_UHMUL) {
+ scalar_min_max_uhmul(dst_reg, &src_reg);
+ break;
+ }
+ if (!alu32 && insn->off == BPF_SHMUL) {
+ scalar_min_max_shmul(dst_reg, &src_reg);
+ break;
+ }
scalar_step_mul(dst_reg, &src_reg);
dst_reg->var_off = tnum_mul(dst_reg->var_off, src_reg.var_off);
scalar32_min_max_mul(dst_reg, &src_reg);
@@ -17499,6 +17536,11 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
/* Case where at least one operand is an arena. */
if (dst_reg->type == PTR_TO_ARENA || (src_reg && src_reg->type == PTR_TO_ARENA)) {
+ if (bpf_insn_is_hmul(insn)) {
+ verbose(env, "UHMUL/SHMUL with arena pointers are not supported\n");
+ return -EOPNOTSUPP;
+ }
+
if (dst_reg->type != PTR_TO_ARENA)
*dst_reg = *src_reg;
@@ -21194,6 +21236,31 @@ static int fd_array_get_map_idx(struct bpf_verifier_env *env, u32 idx)
return -EPROTO;
}
+static bool is_valid_alu_variant(const struct bpf_insn *insn)
+{
+ switch (BPF_OP(insn->code)) {
+ case BPF_MUL:
+ return insn->off == 0 || bpf_insn_is_hmul(insn);
+ case BPF_DIV:
+ case BPF_MOD:
+ /* off == 1 selects SDIV/SMOD. */
+ return insn->off == 0 || insn->off == 1;
+ default:
+ return insn->off == 0;
+ }
+}
+
+/* The interpreter supports uhmul and shmul. JITs opt in. */
+static int check_hmul_jit(struct bpf_verifier_env *env)
+{
+ if (bpf_prog_is_offloaded(env->prog->aux) ||
+ (env->prog->jit_requested && !bpf_jit_supports_hmul())) {
+ verbose(env, "JIT doesn't support uhmul and shmul\n");
+ return -EOPNOTSUPP;
+ }
+ return 0;
+}
+
static int check_alu_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)
{
u8 class = BPF_CLASS(insn->code);
@@ -21249,18 +21316,14 @@ static int check_alu_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)
case BPF_MUL:
case BPF_DIV:
case BPF_MOD:
- if (BPF_SRC(insn->code) == BPF_X) {
- if (insn->imm != 0 || (insn->off != 0 && insn->off != 1) ||
- (insn->off == 1 && opcode != BPF_MOD && opcode != BPF_DIV)) {
- verbose(env, "BPF_ALU uses reserved fields\n");
- return -EINVAL;
- }
- } else if (insn->src_reg != BPF_REG_0 ||
- (insn->off != 0 && insn->off != 1) ||
- (insn->off == 1 && opcode != BPF_MOD && opcode != BPF_DIV)) {
+ if (!is_valid_alu_variant(insn) ||
+ (BPF_SRC(insn->code) == BPF_X && insn->imm != 0) ||
+ (BPF_SRC(insn->code) == BPF_K && insn->src_reg != BPF_REG_0)) {
verbose(env, "BPF_ALU uses reserved fields\n");
return -EINVAL;
}
+ if (bpf_insn_is_hmul(insn))
+ return check_hmul_jit(env);
return 0;
default:
verbose(env, "invalid BPF_ALU opcode %x\n", opcode);
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index f29b0aad440cb..90c30e5d790b9 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -34,6 +34,12 @@
#define BPF_FROM_LE BPF_TO_LE
#define BPF_FROM_BE BPF_TO_BE
+/* BPF_MUL off values for high-half multiplication; BPF_ALU64 only. */
+enum bpf_mul_variant {
+ BPF_UHMUL = 1,
+ BPF_SHMUL = 2,
+};
+
/* jmp encodings */
#define BPF_JNE 0x50 /* jump != */
#define BPF_JLT 0xa0 /* LT is unsigned, '<' */
diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c
index 04740ba37e918..795c3e56c23e0 100644
--- a/tools/testing/selftests/bpf/prog_tests/verifier.c
+++ b/tools/testing/selftests/bpf/prog_tests/verifier.c
@@ -59,6 +59,7 @@
#include "verifier_helper_packet_access.skel.h"
#include "verifier_helper_restricted.skel.h"
#include "verifier_helper_value_access.skel.h"
+#include "verifier_hmul.skel.h"
#include "verifier_idoms.skel.h"
#include "verifier_int_ptr.skel.h"
#include "verifier_iterating_callbacks.skel.h"
@@ -251,6 +252,7 @@ void test_verifier_helper_access_var_len(void) { RUN(verifier_helper_access_var_
void test_verifier_helper_packet_access(void) { RUN(verifier_helper_packet_access); }
void test_verifier_helper_restricted(void) { RUN(verifier_helper_restricted); }
void test_verifier_helper_value_access(void) { RUN(verifier_helper_value_access); }
+void test_verifier_hmul(void) { RUN(verifier_hmul); }
void test_verifier_idoms(void) { RUN(verifier_idoms); }
void test_verifier_int_ptr(void) { RUN(verifier_int_ptr); }
void test_verifier_iterating_callbacks(void) { RUN(verifier_iterating_callbacks); }
diff --git a/tools/testing/selftests/bpf/prog_tests/verifier_hmul_arena.c b/tools/testing/selftests/bpf/prog_tests/verifier_hmul_arena.c
new file mode 100644
index 0000000000000..f9cd7b7b9781a
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/verifier_hmul_arena.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <test_progs.h>
+#include "verifier_hmul_arena.skel.h"
+
+void test_verifier_hmul_arena(void)
+{
+ int ret;
+
+ /* Arena support can depend on CPU features, such as Zacas on RV64. */
+ ret = libbpf_probe_bpf_map_type(BPF_MAP_TYPE_ARENA, NULL);
+ if (!ASSERT_GE(ret, 0, "probe_arena"))
+ return;
+ if (!ret) {
+ test__skip();
+ return;
+ }
+ RUN_TESTS(verifier_hmul_arena);
+}
diff --git a/tools/testing/selftests/bpf/progs/verifier_hmul.c b/tools/testing/selftests/bpf/progs/verifier_hmul.c
new file mode 100644
index 0000000000000..acd92355c6365
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/verifier_hmul.c
@@ -0,0 +1,235 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/bpf.h>
+#include <limits.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+#include "../../../include/linux/filter.h"
+
+#define BPF_UHMUL64_REG(DST, SRC) \
+ BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_X, DST, SRC, BPF_UHMUL, 0)
+
+#define BPF_UHMUL64_IMM(DST, IMM) \
+ BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, BPF_UHMUL, IMM)
+
+#define BPF_SHMUL64_REG(DST, SRC) \
+ BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_X, DST, SRC, BPF_SHMUL, 0)
+
+#define BPF_SHMUL64_IMM(DST, IMM) \
+ BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, BPF_SHMUL, IMM)
+
+/*
+ * Inject UHMUL/SHMUL as raw instructions so these tests do not require
+ * assembler support for the new mnemonics. All surrounding instructions use
+ * existing BPF assembly syntax supported by the baseline selftests toolchain.
+ */
+
+#if defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || \
+ (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)
+
+/*
+ * BPF_PROG_TEST_RUN reports a 32-bit retval. Fold both halves of
+ * (actual ^ expected) into w0 so retval == 0 checks the full 64-bit result.
+ */
+
+SEC("socket")
+__description("UHMUL64, U64_MAX * U64_MAX, register source")
+__success __success_unpriv __retval(0)
+__naked void uhmul64_max_reg(void)
+{
+ asm volatile (
+ "r0 = -1;"
+ "r1 = -1;"
+ ".8byte %[hmul];"
+ "r2 = -2;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_insn(hmul, BPF_UHMUL64_REG(BPF_REG_0, BPF_REG_1))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("UHMUL64, (1ULL << 63) * 2, register source")
+__success __success_unpriv __retval(0)
+__naked void uhmul64_pow2_reg(void)
+{
+ asm volatile (
+ "r0 = 2;"
+ "r1 = %[llong_min] ll;"
+ ".8byte %[hmul];"
+ "r0 = r1;"
+ "r2 = 1;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_const(llong_min, LLONG_MIN),
+ __imm_insn(hmul, BPF_UHMUL64_REG(BPF_REG_1, BPF_REG_0))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("UHMUL64, (1ULL << 63) * 2, R3 destination")
+__success __success_unpriv __retval(0)
+__naked void uhmul64_r3_dst(void)
+{
+ asm volatile (
+ "r3 = %[llong_min] ll;"
+ "r0 = 2;"
+ ".8byte %[hmul];"
+ "r2 = 1;"
+ "r3 ^= r2;"
+ "r2 = r3;"
+ "r2 >>= 32;"
+ "w3 |= w2;"
+ "r0 = r3;"
+ "exit;"
+ :
+ : __imm_const(llong_min, LLONG_MIN),
+ __imm_insn(hmul, BPF_UHMUL64_REG(BPF_REG_3, BPF_REG_0))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("UHMUL64, (1ULL << 63) * 2, immediate source")
+__success __success_unpriv __retval(0)
+__naked void uhmul64_pow2_imm(void)
+{
+ asm volatile (
+ "r0 = %[llong_min] ll;"
+ ".8byte %[hmul];"
+ "r2 = 1;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_const(llong_min, LLONG_MIN),
+ __imm_insn(hmul, BPF_UHMUL64_IMM(BPF_REG_0, 2))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("UHMUL64, (1ULL << 63) * -2, immediate source")
+__success __success_unpriv __retval(0)
+__naked void uhmul64_neg_imm(void)
+{
+ asm volatile (
+ "r0 = %[llong_min] ll;"
+ ".8byte %[hmul];"
+ "r2 = %[llong_max] ll;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_const(llong_min, LLONG_MIN),
+ __imm_const(llong_max, LLONG_MAX),
+ __imm_insn(hmul, BPF_UHMUL64_IMM(BPF_REG_0, -2))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("SHMUL64, INT64_MAX * INT64_MAX, register source")
+__success __success_unpriv __retval(0)
+__naked void shmul64_max_reg(void)
+{
+ asm volatile (
+ "r0 = %[llong_max] ll;"
+ "r1 = %[llong_max] ll;"
+ ".8byte %[hmul];"
+ "r2 = %[expected] ll;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_const(expected, 0x3fffffffffffffffULL),
+ __imm_const(llong_max, LLONG_MAX),
+ __imm_insn(hmul, BPF_SHMUL64_REG(BPF_REG_0, BPF_REG_1))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("SHMUL64, INT64_MIN * -2, register source")
+__success __success_unpriv __retval(0)
+__naked void shmul64_min_neg2_reg(void)
+{
+ asm volatile (
+ "r0 = %[llong_min] ll;"
+ "r1 = -2;"
+ ".8byte %[hmul];"
+ "r2 = 1;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_const(llong_min, LLONG_MIN),
+ __imm_insn(hmul, BPF_SHMUL64_REG(BPF_REG_0, BPF_REG_1))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("SHMUL64, 1 * -2, immediate source")
+__success __success_unpriv __retval(0)
+__naked void shmul64_neg_imm(void)
+{
+ asm volatile (
+ "r0 = 1;"
+ ".8byte %[hmul];"
+ "r2 = -1;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_insn(hmul, BPF_SHMUL64_IMM(BPF_REG_0, -2))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("SHMUL64, INT64_MIN * 2, immediate source")
+__success __success_unpriv __retval(0)
+__naked void shmul64_min_imm(void)
+{
+ asm volatile (
+ "r0 = %[llong_min] ll;"
+ ".8byte %[hmul];"
+ "r2 = -1;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_const(llong_min, LLONG_MIN),
+ __imm_insn(hmul, BPF_SHMUL64_IMM(BPF_REG_0, 2))
+ : __clobber_all);
+}
+
+#else
+
+SEC("socket")
+__description("UHMUL/SHMUL are not supported by this JIT, use a dummy test")
+__skip("UHMUL/SHMUL are not supported by this jit")
+__success
+int dummy_test(void)
+{
+ return 0;
+}
+
+#endif
+
+char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/verifier_hmul_arena.c b/tools/testing/selftests/bpf/progs/verifier_hmul_arena.c
new file mode 100644
index 0000000000000..a8709ec447aa8
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/verifier_hmul_arena.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+#include "../../../include/linux/filter.h"
+
+#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
+
+#define BPF_UHMUL64_IMM(DST, IMM) \
+ BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, BPF_UHMUL, IMM)
+
+#define BPF_SHMUL64_REG(DST, SRC) \
+ BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_X, DST, SRC, BPF_SHMUL, 0)
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARENA);
+ __uint(map_flags, BPF_F_MMAPABLE);
+ __uint(max_entries, 1);
+} arena SEC(".maps");
+
+SEC("syscall")
+__description("UHMUL64 with arena pointer dst")
+__failure __msg("UHMUL/SHMUL with arena pointers are not supported")
+__arch_x86_64 __arch_arm64 __arch_riscv64
+__load_if_JITed()
+__naked void uhmul64_arena_ptr(void)
+{
+ asm volatile (
+ "r1 = %[arena] ll;"
+ "r0 = 1;"
+ "r0 = addr_space_cast(r0, 0x0, 0x1);"
+ ".8byte %[hmul];"
+ "exit;"
+ :
+ : __imm_addr(arena),
+ __imm_insn(hmul, BPF_UHMUL64_IMM(BPF_REG_0, 2))
+ : __clobber_all);
+}
+
+SEC("syscall")
+__description("SHMUL64 with arena pointer src")
+__failure __msg("UHMUL/SHMUL with arena pointers are not supported")
+__arch_x86_64 __arch_arm64 __arch_riscv64
+__load_if_JITed()
+__naked void shmul64_arena_ptr(void)
+{
+ asm volatile (
+ "r1 = %[arena] ll;"
+ "r1 = 1;"
+ "r1 = addr_space_cast(r1, 0x0, 0x1);"
+ "r0 = 2;"
+ ".8byte %[hmul];"
+ "exit;"
+ :
+ : __imm_addr(arena),
+ __imm_insn(hmul, BPF_SHMUL64_REG(BPF_REG_0, BPF_REG_1))
+ : __clobber_all);
+}
+
+#else
+
+SEC("socket")
+__description("HMUL arena tests require compiler support for addr_space_cast")
+__skip("compiler doesn't support addr_space_cast")
+__success
+int dummy_test(void)
+{
+ return 0;
+}
+
+#endif
+
+char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
index 31663338866d3..209d5be551555 100644
--- a/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
+++ b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
@@ -367,7 +367,8 @@ __naked void flow_keys_illegal_variable_offset_alu(void)
/*
* Offset fields of 0 and 1 are legal for BPF_{DIV,MOD} instructions.
- * Offset fields of 0 are legal for the rest of ALU instructions.
+ * Offset fields of 0, 1 and 2 are legal for BPF_ALU64 | BPF_MUL.
+ * Only offset 0 is legal for BPF_ALU | BPF_MUL.
* Test that error is reported for illegal offsets, assuming that tests
* for legal offsets exist.
*/
@@ -377,5 +378,9 @@ DEFINE_BAD_OFFSET_TEST(bad_offset_addx, BPF_ALU64 | BPF_ADD | BPF_X, -1, 0)
DEFINE_BAD_OFFSET_TEST(bad_offset_divx2, BPF_ALU64 | BPF_DIV | BPF_X, 2, 0)
DEFINE_BAD_OFFSET_TEST(bad_offset_modk2, BPF_ALU64 | BPF_MOD | BPF_K, 2, 1)
DEFINE_BAD_OFFSET_TEST(bad_offset_addx2, BPF_ALU64 | BPF_ADD | BPF_X, 1, 0)
+DEFINE_BAD_OFFSET_TEST(bad_offset_mulx, BPF_ALU64 | BPF_MUL | BPF_X, -1, 0)
+DEFINE_BAD_OFFSET_TEST(bad_offset_mulk, BPF_ALU64 | BPF_MUL | BPF_K, 3, 0)
+DEFINE_BAD_OFFSET_TEST(bad_uhmul32_x, BPF_ALU | BPF_MUL | BPF_X, BPF_UHMUL, 0)
+DEFINE_BAD_OFFSET_TEST(bad_shmul32_k, BPF_ALU | BPF_MUL | BPF_K, BPF_SHMUL, 0)
char _license[] SEC("license") = "GPL";
|
| 3/2 | 2026/10/23 04:24 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 18307 output: 34 thoughts: 1796 Thoughts: **Syzkaller Fuzzing Potential: BPF High-Half Multiplication** Okay, let's break this down. I've got a patch series here introducing new eBPF instructions for high-half multiplication (UHMUL64 and SHMUL64). My initial gut feeling is that this *screams* "syzkaller candidate." It touches core subsystems, namely the BPF verifier, the interpreter, and the JIT compilers for x86-64, arm64, and RISC-V. BPF is a hotbed of bugs, and new instructions always mean new attack vectors. Specifically, I'm thinking verification bypasses, JIT codegen errors, range tracking issues, and potential register clobbering. This is classic syzkaller territory. Now, let's get into the nitty-gritty. Since the target architecture is amd64, I'm most interested in the x86 JIT implementation, starting with `arch/x86/net/bpf_jit_comp.c`. I'm especially interested in the `emit_hmul_aux` function. Okay, here's what I'm seeing. `emit_hmul_aux` handles the actual instruction emission, and I immediately spot a potential register-clobbering issue with the RAX and RDX registers. It looks like we have different codepaths depending on whether the destination register (`dst_reg`) is RAX (BPF_REG_0) or RDX (BPF_REG_3) and that we could clobber the values on RAX and RDX with certain choices. Specifically, I'm digging into `emit_hmul_aux`: * If `dst_reg` is RAX (BPF_REG_0), and if the destination register is not RDX (BPF_REG_3), we are pushing RDX and copying RAX into RDX after the multiplication is done. But RAX has already been modified by the multiplication. This is strange! * If `dst_reg` is RDX (BPF_REG_3), RAX is pushed, then RDX is copied into RAX *before* the multiplication. I also need to understand where `AUX_REG` comes from. This is crucial. It appears that the source register is copied to AUX_REG *before* the `emit_hmul_aux` function is called. My hypothesis here is that a carefully crafted BPF program could lead to register clobbering in these cases, potentially allowing for out-of-bounds reads/writes or even control-flow hijacking. I'm going to start by confirming this by analyzing the possible register dependencies in `do_jit`. I will focus my syzkaller fuzzer on the BPF verifier, JIT compilers, and interpreter, specifically targeting programs utilizing these new high-half multiplication instructions. I'll need to figure out appropriate configs and focus symbols to target these potential issues, focusing on the x86-64 JIT implementation first. |
| 4/2 | 2026/10/23 04:24 | tool | grepper |
0mArgs:{
"Expression": "#define AUX_REG",
"PathPrefixes": [
"arch/x86/net/"
]
}Results: {
"Output": "arch/x86/net/bpf_jit_comp.c=167=static int bpf_size_to_x86_bytes(int bpf_size)\n--\narch/x86/net/bpf_jit_comp.c-196-/* Pick a register outside of BPF range for JIT internal work */\narch/x86/net/bpf_jit_comp.c:197:#define AUX_REG (MAX_BPF_JIT_REG + 1)\narch/x86/net/bpf_jit_comp.c-198-#define X86_REG_R9 (MAX_BPF_JIT_REG + 2)\n"
} |
| 5/2 | 2026/10/23 04:24 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20964 output: 47 thoughts: 377 Thoughts: **Investigating Register State During Multiplication in BPF** Okay, so I'm thinking through some edge cases related to multiplication operations in BPF, specifically how the destination register (`dst_reg`) behaves when it's either `BPF_REG_0` or `BPF_REG_3`, or if there's an issue with stack alignment. My mind immediately jumps to x86-64 and how pushing `rax` or `rdx` modifies `RSP`. I need to be sure that in the BPF JIT, pushing and popping on `RSP` doesn't throw off stack alignment or cause problems during unwinding. What if there are exceptions or tail calls? That's definitely something to consider. I need to dive into the verifier logic now. Let's see... looking at the `scalar_min_max_uhmul` and `scalar_min_max_shmul` functions, I see they're doing a signed/unsigned multiplication by grabbing constant values from the registers. Wait! Looking closer at `scalar_min_max_shmul`, I see `s64 dst = reg_const_value(dst_reg, false);`. This gets my attention; what does `reg_const_value` actually return? That's the crux of understanding how the values are being handled. I need to go and analyze the `reg_const_value` function's behavior to understand this. |
| 6/2 | 2026/10/23 04:24 | tool | grepper |
0mArgs:{
"Expression": "reg_const_value",
"PathPrefixes": [
"kernel/bpf/verifier.c",
"include/linux/bpf_verifier.h"
]
}Results: {
"Output": "kernel/bpf/verifier.c=3789=static bool is_reg_const(struct bpf_reg_state *reg, bool subreg32)\n--\nkernel/bpf/verifier.c-3795-/* assuming is_reg_const() is true, return constant value of a register */\nkernel/bpf/verifier.c:3796:static u64 reg_const_value(struct bpf_reg_state *reg, bool subreg32)\nkernel/bpf/verifier.c-3797-{\n--\nkernel/bpf/verifier.c=16667=static void scalar_min_max_uhmul(struct bpf_reg_state *dst_reg,\n--\nkernel/bpf/verifier.c-16669-{\nkernel/bpf/verifier.c:16670:\tu64 dst = reg_const_value(dst_reg, false);\nkernel/bpf/verifier.c:16671:\tu64 src = reg_const_value(src_reg, false);\nkernel/bpf/verifier.c-16672-\n--\nkernel/bpf/verifier.c=16676=static void scalar_min_max_shmul(struct bpf_reg_state *dst_reg,\n--\nkernel/bpf/verifier.c-16678-{\nkernel/bpf/verifier.c:16679:\ts64 dst = reg_const_value(dst_reg, false);\nkernel/bpf/verifier.c:16680:\ts64 src = reg_const_value(src_reg, false);\nkernel/bpf/verifier.c-16681-\n--\nkernel/bpf/verifier.c=17518=static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-17668-\t !(BPF_SRC(insn-\u003ecode) == BPF_X \u0026\u0026 insn-\u003esrc_reg == insn-\u003edst_reg)) {\nkernel/bpf/verifier.c:17669:\t\tu64 val = reg_const_value(src_reg, alu32);\nkernel/bpf/verifier.c-17670-\t\ts32 off;\n--\nkernel/bpf/verifier.c=18348=static int is_branch_taken(struct bpf_verifier_env *env, struct bpf_reg_state *reg1,\n--\nkernel/bpf/verifier.c-18378-\t\t */\nkernel/bpf/verifier.c:18379:\t\tval = reg_const_value(reg2, is_jmp32);\nkernel/bpf/verifier.c-18380-\t\tif (val != 0)\n--\nkernel/bpf/verifier.c=18423=static void regs_refine_cond_op(struct bpf_reg_state *reg1, struct bpf_reg_state *reg2,\n--\nkernel/bpf/verifier.c-18467-\t\t */\nkernel/bpf/verifier.c:18468:\t\tval = reg_const_value(reg2, is_jmp32);\nkernel/bpf/verifier.c-18469-\t\tif (is_jmp32) {\n--\nkernel/bpf/verifier.c-18481-\t\t\tbreak;\nkernel/bpf/verifier.c:18482:\t\tval = reg_const_value(reg2, is_jmp32);\nkernel/bpf/verifier.c-18483-\t\t/* BPF_JSET (i.e., TRUE branch, *not* BPF_JSET | BPF_X)\n--\nkernel/bpf/verifier.c-18506-\t\t\tbreak;\nkernel/bpf/verifier.c:18507:\t\tval = reg_const_value(reg2, is_jmp32);\nkernel/bpf/verifier.c-18508-\t\t/* Forget the ranges before narrowing tnums, to avoid invariant\n"
} |
| 7/2 | 2026/10/23 04:24 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22715 output: 35 thoughts: 816 Thoughts: **Analyzing BPF MUL Instruction Handling** Okay, let's break down how the BPF verifier handles multiplication instructions (`BPF_MUL`) and its variants. I'm focusing on the intricacies of the `MUL` instruction and how it interacts with the range analysis and pointer arithmetic. First, let's look at `check_alu_fields`: I see that `is_valid_alu_variant` is crucial, especially for handling variants like `SDIV`, `SMOD` (which use `off == 1`), and the standard `MUL`. It seems that the verifier checks if the instruction uses reserved fields (e.g., non-zero `imm` when source is immediate, or a non-zero source register when source is a constant), if `is_valid_alu_variant` indicates valid use, and if `hmul` special cases are valid. It appears we're also dealing with `hmul` instructions (high multiplication), that may need further validation via `check_hmul_jit`. Now, let's dig into how the range analysis works in `adjust_scalar_min_max_vals`. Specifically for `MUL` instructions. If operands are constants, we attempt to compute the result exactly. However, for `UHMUL` and `SHMUL`, if either operand is *not* a constant, we mark the destination register as unknown. It then uses special functions, like `scalar_min_max_uhmul` or `scalar_min_max_shmul` to adjust ranges. But wait a minute... what happens if `dst_reg` is a pointer? That's the critical question. The problem comes to light in `adjust_reg_min_max_vals`, which is called from `adjust_scalar_min_max_vals`! *That's* where we find the check for arena pointers, which is a pointer. It explicitly *disallows* UHMUL/SHMUL with arena pointers, but what about other pointer types like `PTR_TO_STACK` or `PTR_TO_MAP_VALUE`? Is multiplication *even* allowed on pointers in the BPF verifier? This is a point that needs more investigation, and I need to check `kernel/bpf/verifier.c` to understand the limitations on multiplication involving registers that could be pointers. I'll need to check how the BPF verifier handles pointer arithmetic in general, specifically if a MUL instruction is allowed on pointers, and if so, what are the restrictions and range analysis implications of doing so. |
| 8/2 | 2026/10/23 04:24 | tool | grepper |
0mArgs:{
"Expression": "case BPF_MUL:",
"PathPrefixes": [
"kernel/bpf/verifier.c"
]
}Results: {
"Output": "kernel/bpf/verifier.c=17245=static bool is_safe_to_compute_dst_reg_range(struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-17269-\tcase BPF_OR:\nkernel/bpf/verifier.c:17270:\tcase BPF_MUL:\nkernel/bpf/verifier.c-17271-\tcase BPF_END:\n--\nkernel/bpf/verifier.c=17328=static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-17383-\t\tbreak;\nkernel/bpf/verifier.c:17384:\tcase BPF_MUL:\nkernel/bpf/verifier.c-17385-\t\t/*\n--\nkernel/bpf/verifier.c=21239=static bool is_valid_alu_variant(const struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-21241-\tswitch (BPF_OP(insn-\u003ecode)) {\nkernel/bpf/verifier.c:21242:\tcase BPF_MUL:\nkernel/bpf/verifier.c-21243-\t\treturn insn-\u003eoff == 0 || bpf_insn_is_hmul(insn);\n--\nkernel/bpf/verifier.c=21264=static int check_alu_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-21315-\tcase BPF_ARSH:\nkernel/bpf/verifier.c:21316:\tcase BPF_MUL:\nkernel/bpf/verifier.c-21317-\tcase BPF_DIV:\n"
} |
| 9/2 | 2026/10/23 04:24 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24583 output: 42 thoughts: 19 Thoughts: Okay, let's dive into this. Here's my thought process on this function: **Checking `is_safe_to_compute_dst_reg_range`** Right, so we need to assess the safety of a destination register range for a computation. Essentially, I need to ensure that whatever computation we're about to perform won't clobber any data we shouldn't be touching. This probably involves a bunch of checks, likely related to memory access permissions, register aliasing, and the current execution context. The name suggests this is about protecting against overwriting critical memory locations or causing unexpected behavior due to register conflicts. I expect this function to be a critical gatekeeper, preventing potentially catastrophic errors. The implementation details are key here, but my main focus is on the *why* - safeguarding the integrity of our data and the stability of the computation. |
| 10/2 | 2026/10/23 04:24 | tool | grepper |
0mArgs:{
"Expression": "is_safe_to_compute_dst_reg_range",
"PathPrefixes": [
"kernel/bpf/verifier.c"
]
}Results: {
"Output": "kernel/bpf/verifier.c=17195=static void scalar_byte_swap(struct bpf_reg_state *dst_reg, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-17244-\nkernel/bpf/verifier.c:17245:static bool is_safe_to_compute_dst_reg_range(struct bpf_insn *insn,\nkernel/bpf/verifier.c-17246-\t\t\t\t\t const struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c=17328=static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-17337-\nkernel/bpf/verifier.c:17338:\tif (!is_safe_to_compute_dst_reg_range(insn, \u0026src_reg)) {\nkernel/bpf/verifier.c-17339-\t\t__mark_reg_unknown(env, dst_reg);\n"
} |
| 11/2 | 2026/10/23 04:24 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25105 output: 38 thoughts: 19 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and presented as if it were my own internal monologue: **Analyzing `is_safe_to_compute_dst_reg_range`** Alright, let's dive into this `is_safe_to_compute_dst_reg_range` function. Immediately, my mind is already processing the implications. I'm thinking about the register allocation context; what's the goal here? It's clearly a safety check, but what kind? Is it to prevent register conflicts, out-of-bounds access, or perhaps to ensure data integrity during a computation's destination register range? I'm rapidly considering potential scenarios: overlapping ranges, read-after-write hazards, potential for aliasing... The naming convention suggests a focus on the destination registers, which usually means ensuring their availability and preventing unintended side effects. My experience tells me this is likely embedded in a larger system, maybe a compiler or a runtime environment. I'm keen to understand the specific criteria the function employs to determine "safety". Are there resource limits? Are there architectural constraints at play? This calls for a deep dive into the code's implementation, especially how it interacts with the register allocation process. What level of abstraction are we dealing with? Does it take the register range, some context about existing allocations, and the "safety" means specific conditions? Is it dealing with virtual registers or physical ones? Let's get to the specifics. |
| 12/2 | 2026/10/23 04:25 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 17244,
"LineCount": 40
}Results: {
"Contents": "17244:\t\n17245:\tstatic bool is_safe_to_compute_dst_reg_range(struct bpf_insn *insn,\n17246:\t\t\t\t\t\t const struct bpf_reg_state *src_reg)\n17247:\t{\n17248:\t\tbool src_is_const = false;\n17249:\t\tu64 insn_bitness = (BPF_CLASS(insn-\u003ecode) == BPF_ALU64) ? 64 : 32;\n17250:\t\n17251:\t\tif (insn_bitness == 32) {\n17252:\t\t\tif (tnum_subreg_is_const(src_reg-\u003evar_off)\n17253:\t\t\t \u0026\u0026 reg_s32_min(src_reg) == reg_s32_max(src_reg)\n17254:\t\t\t \u0026\u0026 reg_u32_min(src_reg) == reg_u32_max(src_reg))\n17255:\t\t\t\tsrc_is_const = true;\n17256:\t\t} else {\n17257:\t\t\tif (tnum_is_const(src_reg-\u003evar_off)\n17258:\t\t\t \u0026\u0026 reg_smin(src_reg) == reg_smax(src_reg)\n17259:\t\t\t \u0026\u0026 reg_umin(src_reg) == reg_umax(src_reg))\n17260:\t\t\t\tsrc_is_const = true;\n17261:\t\t}\n17262:\t\n17263:\t\tswitch (BPF_OP(insn-\u003ecode)) {\n17264:\t\tcase BPF_ADD:\n17265:\t\tcase BPF_SUB:\n17266:\t\tcase BPF_NEG:\n17267:\t\tcase BPF_AND:\n17268:\t\tcase BPF_XOR:\n17269:\t\tcase BPF_OR:\n17270:\t\tcase BPF_MUL:\n17271:\t\tcase BPF_END:\n17272:\t\t\treturn true;\n17273:\t\n17274:\t\t/*\n17275:\t\t * Division and modulo operators range is only safe to compute when the\n17276:\t\t * divisor is a constant.\n17277:\t\t */\n17278:\t\tcase BPF_DIV:\n17279:\t\tcase BPF_MOD:\n17280:\t\t\treturn src_is_const;\n17281:\t\n17282:\t\t/* Shift operators range is only computable if shift dimension operand\n17283:\t\t * is a constant. Shifts greater than 31 or 63 are undefined. This\n"
} |
| 13/2 | 2026/10/23 04:25 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26194 output: 38 thoughts: 219 Thoughts: **Analyzing BPF Multiplication Instructions**
Okay, here's what I'm seeing: when the BPF instruction is identified as a high-multiply (`bpf_insn_is_hmul(insn)` is true) but the operands aren't constant, the code marks the destination register (`dst_reg`) as unknown. Makes sense; without constants, we can't reliably determine the result's range. The code snippet clearly shows this:
```c
if (bpf_insn_is_hmul(insn) &&
(!is_reg_const(dst_reg, false) ||
!is_reg_const(&src_reg, false))) {
__mark_reg_unknown(env, dst_reg);
break;
}
```
However, if both operands *are* constant, then the function `scalar_min_max_uhmul` or `scalar_min_max_shmul` is called. These functions compute the exact constant and importantly, they mark the destination register as known! That's the key difference. The JIT (just-in-time compiler) knows what the answer will be, which avoids unknown ranges. This is clever.
Now, let's look at the bigger picture. I need to understand what configurations are required for this code path to even be active. BPF functionality is controlled by `CONFIG_BPF_SYSCALL` – that's the base enabling option. `CONFIG_BPF_JIT` (for Just in Time compilation) is also probably required. I need to look at kernel/bpf/Kconfig to confirm those dependencies and get a clearer understanding of the BPF configuration landscape.
|
| 14/2 | 2026/10/23 04:25 | tool | grepper |
0mArgs:{
"Expression": "config BPF_SYSCALL",
"PathPrefixes": [
"kernel/bpf/",
"init/"
]
}Results: {
"Output": "kernel/bpf/Kconfig=29=menu \"BPF subsystem\"\nkernel/bpf/Kconfig-30-\nkernel/bpf/Kconfig:31:config BPF_SYSCALL\nkernel/bpf/Kconfig-32-\tbool \"Enable bpf() system call\"\n"
} |
| 15/2 | 2026/10/23 04:25 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26903 output: 41 thoughts: 14 Thoughts: Okay, let's dive into this. Here's my summary, presented as my own thought process, assuming I'm an expert in this field: **Considering the `BPF_JIT` Implications** Alright, we've gone through the main aspects, but I have a nagging feeling we're overlooking something potentially significant. I need to explicitly account for the Just-In-Time compilation aspect, especially within the context of the Berkeley Packet Filter (BPF). We haven't explicitly mentioned `BPF_JIT` yet. What are the specific implications for the current analysis and the points we've already covered if the JIT compiler is involved? How might it optimize (or potentially hinder) the performance or security characteristics we are concerned with? Are there subtle variations in behaviour we need to account for? I need to quickly recall the typical usage patterns of `BPF_JIT`, and how the specifics relate to the problem at hand, to ensure we have a truly complete understanding. That seems like the next logical step. |
| 16/2 | 2026/10/23 04:25 | tool | grepper |
0mArgs:{
"Expression": "config BPF_JIT",
"PathPrefixes": [
"kernel/bpf/",
"arch/x86/"
]
}Results: {
"Output": "kernel/bpf/Kconfig=31=config BPF_SYSCALL\n--\nkernel/bpf/Kconfig-45-\nkernel/bpf/Kconfig:46:config BPF_JIT\nkernel/bpf/Kconfig-47-\tbool \"Enable BPF Just In Time compiler\"\n--\nkernel/bpf/Kconfig-61-\nkernel/bpf/Kconfig:62:config BPF_JIT_ALWAYS_ON\nkernel/bpf/Kconfig-63-\tbool \"Permanently enable BPF JIT and remove BPF interpreter\"\n--\nkernel/bpf/Kconfig-72-\nkernel/bpf/Kconfig:73:config BPF_JIT_DEFAULT_ON\nkernel/bpf/Kconfig-74-\tdef_bool ARCH_WANT_DEFAULT_BPF_JIT || BPF_JIT_ALWAYS_ON\n--\nkernel/bpf/Kconfig=105=config BPF_LSM\n--\nkernel/bpf/Kconfig-116-\nkernel/bpf/Kconfig:117:config BPF_JIT_KASAN\nkernel/bpf/Kconfig-118-\tbool\n"
} |
| 17/2 | 2026/10/23 04:25 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27472 output: 47 thoughts: 33 Thoughts: Okay, let's dive into this. Here's how I'd approach this task, as if these were my internal thoughts: **Investigating Compilation Dependencies for Affected Files** Alright, I need to understand the compilation flow for these recently modified files. The changes likely involve BPF or x86 networking code, and I need to see how they're being built into the kernel. My initial thought is to check the relevant Makefiles. Specifically, I should look at `kernel/bpf/Makefile` because the changes could be affecting BPF-related components. I also need to verify this with `arch/x86/net/Makefile` because the touched files could be dependent on the x86 architecture. By examining these Makefiles, I should be able to trace how these files are compiled, any special flags used, and how they relate to other parts of the kernel. This will give me a solid understanding of where these pieces fit into the bigger picture and what the implications of these changes might be. |
| 18/2 | 2026/10/23 04:25 | tool | grepper |
0mArgs:{
"Expression": "verifier|bpf_jit_comp",
"PathPrefixes": [
"kernel/bpf/Makefile",
"arch/x86/net/Makefile"
]
}Results: {
"Output": "arch/x86/net/Makefile=6=ifeq ($(CONFIG_X86_32),y)\narch/x86/net/Makefile:7: obj-$(CONFIG_BPF_JIT) += bpf_jit_comp32.o\narch/x86/net/Makefile-8-else\narch/x86/net/Makefile:9: obj-$(CONFIG_BPF_JIT) += bpf_jit_comp.o bpf_timed_may_goto.o\narch/x86/net/Makefile-10-endif\n--\nkernel/bpf/Makefile=7=CFLAGS_core.o += -Wno-override-init $(cflags-nogcse-yy)\nkernel/bpf/Makefile-8-\nkernel/bpf/Makefile:9:obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o cnum.o log.o token.o liveness.o const_fold.o diagnostics.o loops.o scev.o\nkernel/bpf/Makefile-10-obj-$(CONFIG_BPF_SYSCALL) += bpf_iter.o map_iter.o task_iter.o prog_iter.o link_iter.o\n"
} |
| 19/2 | 2026/10/23 04:25 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28075 output: 36 thoughts: 45 Thoughts: Here's my thought process, summarized as you requested: **Assessing BPF Configuration Options** Okay, so I'm diving into the BPF configuration landscape. My initial hunch is that `CONFIG_BPF_SYSCALL` and `CONFIG_BPF_JIT` are the key settings I need to focus on. They seem like the most likely candidates for enabling the core BPF functionality and the Just-In-Time compiler, which is crucial for performance. But, before I get too far down that path, let me just quickly confirm that there isn't a more overarching configuration option that I'm overlooking. I should probably double-check if `CONFIG_BPF` itself is a valid configuration option. It could act as a broader toggle, and if that's not enabled, the others are moot. It's always best to start with the fundamentals. |
| 20/2 | 2026/10/23 04:25 | tool | grepper |
0mArgs:{
"Expression": "config BPF\\b",
"PathPrefixes": [
"init/",
"kernel/bpf/"
]
}Results: {
"Output": "kernel/bpf/Kconfig-3-# BPF interpreter that, for example, classic socket filters depend on.\nkernel/bpf/Kconfig:4:config BPF\nkernel/bpf/Kconfig-5-\tbool\n"
} |
| 21/2 | 2026/10/23 04:25 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28405 output: 34 thoughts: 1033 Thoughts: **Fuzzing Target Identification: BPF High-Half Multiplication** Okay, let's break this down. First, this looks promising for fuzzing. We're dealing with new BPF instructions (UHMUL, SHMUL) for high-half multiplication (ALU64), which immediately flags potential issues. The fact that the BPF verifier and JIT compiler are being modified is a big red flag – these are core components, directly exposed via the `bpf()` syscall and socket filters. Arithmetic operations and JIT are a well-known minefield for security vulnerabilities. Range tracking and register management in the JIT compiler, especially things like pushing/popping registers for multiplication and handling signed vs. unsigned 128-bit operations, are prime targets for desynchronization bugs and potential privilege escalation. Now, for specific functions to focus on, and this is where it gets interesting. The instructions specifically guide me to be careful, and avoid ubiquitous lifecycle functions. I need to pinpoint the *specific* feature logic and entrypoints. So, let's see. The changes are spread across `kernel/bpf/verifier.c`, `kernel/bpf/core.c`, and `arch/x86/net/bpf_jit_comp.c`. First, I need to know which of those functions are static or non-static in the kernel image, vmlinux. Let's go through the functions affected and see. In `kernel/bpf/verifier.c`: * `scalar_min_max_uhmul` (static) * `scalar_min_max_shmul` (static) * `adjust_scalar_min_max_vals` (static) * `check_alu_fields` (static) * `check_hmul_jit` (static) * `is_valid_alu_variant` (static) Looks like everything in verifier.c is static! I can't target the static helpers directly, since they lack distinct symbol addresses and are likely inlined. I need to find the non-static functions that *call* these. Which means I need to go back and check the code, and look for callers of `check_alu_fields`. |
| 22/2 | 2026/10/23 04:25 | tool | grepper |
0mArgs:{
"Expression": "check_alu_fields",
"PathPrefixes": [
"kernel/bpf/verifier.c"
]
}Results: {
"Output": "kernel/bpf/verifier.c=21254=static int check_hmul_jit(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-21263-\nkernel/bpf/verifier.c:21264:static int check_alu_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)\nkernel/bpf/verifier.c-21265-{\n--\nkernel/bpf/verifier.c=21400=static int check_insn_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-21404-\tcase BPF_ALU64:\nkernel/bpf/verifier.c:21405:\t\treturn check_alu_fields(env, insn);\nkernel/bpf/verifier.c-21406-\tcase BPF_LDX:\n"
} |
| 23/2 | 2026/10/23 04:25 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 30207 output: 35 thoughts: 43 Thoughts: Okay, here's my assessment of the situation: **Investigating BPF Instruction Verification** Right, so I need to understand how we're validating BPF instructions. My initial instinct is to go directly to `bpf_check`. I want to see how the overall instruction verification is structured, so the first question is, does `bpf_check` *itself* call a routine like `check_insn_fields`, or something similar that actually digs into the instruction details? If so, great. If not, I'll need to broaden the scope. If `bpf_check` *does* delegate to a low level function, then the next step would be to examine the callers of the function such as `check_insn_fields`. This might reveal the relationships between those components. This should give me a better handle on the verification flow, and where any potential issues might be stemming from. |
| 24/2 | 2026/10/23 04:25 | tool | grepper |
0mArgs:{
"Expression": "check_insn_fields",
"PathPrefixes": [
"kernel/bpf/verifier.c"
]
}Results: {
"Output": "kernel/bpf/verifier.c=21334=static int check_jmp_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-21399-\nkernel/bpf/verifier.c:21400:static int check_insn_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)\nkernel/bpf/verifier.c-21401-{\n--\nkernel/bpf/verifier.c=21460=static int check_and_resolve_insns(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-21590-\nkernel/bpf/verifier.c:21591:\t\terr = check_insn_fields(env, insn);\nkernel/bpf/verifier.c-21592-\t\tif (err)\n"
} |
| 25/2 | 2026/10/23 04:25 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 30722 output: 37 thoughts: 758 Thoughts: **My BPF Verification & JIT Analysis** Okay, so I'm tracing the data flow here in the BPF verifier and JIT compilation process. I see that `check_insn_fields` is called within `bpf_check`, the main verifier entry point, during the instruction checking phase. That's straightforward. Now, where does `adjust_scalar_min_max_vals` fit in? Ah, it's called by `adjust_reg_min_max_vals`, which is, in turn, called by `check_alu_op`. `check_alu_op` itself is called within `do_check`. This tells me the verifier is using these functions to propagate and refine min/max value ranges, especially for ALU operations. Now, let's cast a wider net and look at some files. I'm interested in the functions in `arch/x86/net/bpf_jit_comp.c`: I see `emit_hmul_aux`, `do_jit`, and `bpf_jit_supports_hmul` as key players there. `bpf_int_jit_compile` seems to be the entrypoint for x86 JIT compilation. In `kernel/bpf/core.c`, the interpreter is `___bpf_prog_run`. Also there is a weak symbol for `bpf_jit_supports_hmul` in core.c, and over in `kernel/bpf/verifier.c` where I started, I see `adjust_scalar_min_max_vals`, `scalar_min_max_uhmul`, `scalar_min_max_shmul`, `check_alu_fields`, `check_hmul_jit`, and the main `bpf_check` entry point. I need to quickly assess if the min/max value functions like `adjust_scalar_min_max_vals`, `scalar_min_max_uhmul`, and `scalar_min_max_shmul` are inlined or separate. My experience suggests they are often large and preserved as distinct symbols, which makes them easier to target. I want to build a mental map of what I can target for specific analysis. Now, can I create a list of functions to FocusSymbols? Okay, I want to include `check_alu_fields`, `adjust_scalar_min_max_vals`, `emit_hmul_aux`, `do_jit`, `___bpf_prog_run`, and `bpf_jit_supports_hmul` and see where they are used. Hold on, I see that `___bpf_prog_run` is specific to the interpreter, which is used when JIT is disabled or before JIT is enabled. So it is specific to BPF. I need to keep in mind where each is used. Thinking about it more, `emit_hmul_aux` is clearly about generating code for the high-half multiplication instruction in the x86 JIT, and `bpf_jit_supports_hmul` tells me if the JIT supports this instruction. In `kernel/bpf/verifier.c`, it seems that `check_alu_fields`, `check_hmul_jit`, `adjust_scalar_min_max_vals`, `scalar_min_max_uhmul`, and `scalar_min_max_shmul` are directly implementing or modifying the verification logic for these specific instructions. Also, `do_jit` in `arch/x86/net/bpf_jit_comp.c` is what handles emitting the JIT code. Finally, I need to check if `scalar_min_max_mul` is a separate symbol or if there are other similar symbols in the `verifier.c` file. I'll just grep for `scalar_min_max_` there and build up a mental model from there. |
| 26/2 | 2026/10/23 04:25 | tool | grepper |
0mArgs:{
"Expression": "^static void scalar.*min_max",
"PathPrefixes": [
"kernel/bpf/verifier.c"
]
}Results: {
"Output": "kernel/bpf/verifier.c=223=static const char *non_sleepable_context_description(struct bpf_verifier_env *env);\nkernel/bpf/verifier.c:224:static void scalar32_min_max_add(struct bpf_reg_state *dst_reg, struct bpf_reg_state *src_reg);\nkernel/bpf/verifier.c:225:static void scalar_min_max_add(struct bpf_reg_state *dst_reg, struct bpf_reg_state *src_reg);\nkernel/bpf/verifier.c-226-\n--\nkernel/bpf/verifier.c=16287=static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-16580-\nkernel/bpf/verifier.c:16581:static void scalar32_min_max_add(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16582-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16586-\nkernel/bpf/verifier.c:16587:static void scalar_min_max_add(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16588-\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16592-\nkernel/bpf/verifier.c:16593:static void scalar32_min_max_sub(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16594-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16598-\nkernel/bpf/verifier.c:16599:static void scalar_min_max_sub(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16600-\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16604-\nkernel/bpf/verifier.c:16605:static void scalar32_min_max_mul(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16606-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16635-\nkernel/bpf/verifier.c:16636:static void scalar_min_max_mul(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16637-\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16666-\nkernel/bpf/verifier.c:16667:static void scalar_min_max_uhmul(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16668-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16675-\nkernel/bpf/verifier.c:16676:static void scalar_min_max_shmul(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16677-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16684-\nkernel/bpf/verifier.c:16685:static void scalar32_min_max_udiv(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16686-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16696-\nkernel/bpf/verifier.c:16697:static void scalar_min_max_udiv(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16698-\t\t\t\tstruct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16708-\nkernel/bpf/verifier.c:16709:static void scalar32_min_max_sdiv(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16710-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16744-\nkernel/bpf/verifier.c:16745:static void scalar_min_max_sdiv(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16746-\t\t\t\tstruct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16780-\nkernel/bpf/verifier.c:16781:static void scalar32_min_max_umod(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16782-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16799-\nkernel/bpf/verifier.c:16800:static void scalar_min_max_umod(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16801-\t\t\t\tstruct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16818-\nkernel/bpf/verifier.c:16819:static void scalar32_min_max_smod(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16820-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16857-\nkernel/bpf/verifier.c:16858:static void scalar_min_max_smod(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16859-\t\t\t\tstruct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16896-\nkernel/bpf/verifier.c:16897:static void scalar32_min_max_and(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16898-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16917-\nkernel/bpf/verifier.c:16918:static void scalar_min_max_and(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16919-\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16940-\nkernel/bpf/verifier.c:16941:static void scalar32_min_max_or(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16942-\t\t\t\tstruct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16961-\nkernel/bpf/verifier.c:16962:static void scalar_min_max_or(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16963-\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-16984-\nkernel/bpf/verifier.c:16985:static void scalar32_min_max_xor(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-16986-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-17000-\nkernel/bpf/verifier.c:17001:static void scalar_min_max_xor(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-17002-\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c=17019=static void __scalar32_min_max_lsh(struct bpf_reg_state *dst_reg,\n--\nkernel/bpf/verifier.c-17032-\nkernel/bpf/verifier.c:17033:static void scalar32_min_max_lsh(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-17034-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c=17051=static void __scalar64_min_max_lsh(struct bpf_reg_state *dst_reg,\n--\nkernel/bpf/verifier.c-17076-\nkernel/bpf/verifier.c:17077:static void scalar_min_max_lsh(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-17078-\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-17091-\nkernel/bpf/verifier.c:17092:static void scalar32_min_max_rsh(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-17093-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-17121-\nkernel/bpf/verifier.c:17122:static void scalar_min_max_rsh(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-17123-\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-17153-\nkernel/bpf/verifier.c:17154:static void scalar32_min_max_arsh(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-17155-\t\t\t\t struct bpf_reg_state *src_reg)\n--\nkernel/bpf/verifier.c-17173-\nkernel/bpf/verifier.c:17174:static void scalar_min_max_arsh(struct bpf_reg_state *dst_reg,\nkernel/bpf/verifier.c-17175-\t\t\t\tstruct bpf_reg_state *src_reg)\n"
} |
| 27/2 | 2026/10/23 04:25 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35088 output: 252 thoughts: 1373 Thoughts: **Analysis of BPF Multiplication Instruction Addition for Fuzzing Focus** Okay, let's break this down. First, the naming scheme for `scalar_min_max_uhmul` and `scalar_min_max_shmul` directly aligns with the `verifier.c` scalar operations, which is good for consistency. I see a bunch of symbols related to the new high-multiply instructions (UHMUL/SHMUL) and their integration, including verifier components, JIT compilation, and the interpreter. I need to figure out the right *FocusSymbols* for fuzzing this. I've scanned the relevant files. Looks like we have additions in `include/linux/filter.h` (inline helpers like `bpf_uhmul64`, `bpf_shmul64`, etc.), some new string in `kernel/bpf/disasm.c`, and a bunch of JIT-related stuff in `arch/x86/net/bpf_jit_comp.c`. That gives me a good overview of the code landscape. Now, let's think about the *FocusSymbols* according to the guidelines. I need to avoid ubiquitous functions, which means no general memory allocators or core synchronization primitives. I need to *TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS*. The key is to find functions that *specifically* implement the logic being added or altered, or are direct API entrypoints. Considering that, and the inline nature of some functions in the headers, I believe the best *FocusSymbols* are: * `emit_hmul_aux` (JIT emission) * `scalar_min_max_uhmul` (Verifier function) * `scalar_min_max_shmul` (Verifier function) * `check_hmul_jit` (JIT check) * `bpf_jit_supports_hmul` (JIT capability check) * `adjust_scalar_min_max_vals` (Verifier - range adjustment) * `check_alu_fields` (Verifier - ALU field check) Now, what about `___bpf_prog_run`? It *is* the interpreter entrypoint, crucial for ALU64\_MUL\_X and ALU64\_MUL\_K evaluation when the JIT isn't used. But is it too generic? While it's only executed when interpreting BPF programs, is it *ubiquitous* in interpreted execution? The verifier and JIT functions listed above are very specific to BPF program loading, verification, and JIT. I think it's still good to include, as it's the core of the new logic, even without JIT. I need to confirm the required kernel configs. `CONFIG_BPF_SYSCALL` is essential for loading eBPF programs via the `bpf()` syscall and running the verifier. `CONFIG_BPF_JIT` is required for the JIT compiler. I know `BPF_SYSCALL` depends on `BPF`, and enabling `BPF_SYSCALL` automatically takes care of `BPF`. When enabling in syzkaller configs, I can see that `BPF_SYSCALL` and `BPF_JIT` are standard. So those seem to be the required minimal configurations. It appears that the required kernel configs for the set results are: `["BPF_SYSCALL", "BPF_JIT"]`. Alright, let's verify everything before calling the fuzzing setup. This patch introduces UHMUL and SHMUL, modifying the verifier, interpreter, and x86-64 JIT. The verifier changes include instruction field validation, JIT capability, scalar min/max tracking and pointer operand checks. The interpreter change involves evaluating 64-bit high multiplication for register and immediate operands. The JIT section involves emitting 64-bit `mul` and `imul` instructions using RAX and RDX with register spilling/restoration. These changes are definitely in core, security-critical paths accessed via the `bpf()` syscall. This means they're perfect for fuzzing. I need to check for issues like verifier range tracking discrepancies, JIT register clobbering, or mismatches between JIT and the interpreter. Okay, I'm confident in this. Let's call `set-results`! |
| 28/2 | 2026/10/23 04:26 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"emit_hmul_aux",
"scalar_min_max_uhmul",
"scalar_min_max_shmul",
"check_hmul_jit",
"bpf_jit_supports_hmul",
"adjust_scalar_min_max_vals",
"check_alu_fields"
],
"Reasoning": "The patch introduces new eBPF 64-bit high-half multiplication instructions (UHMUL and SHMUL) across the BPF verifier, BPF interpreter, and architecture JIT compilers (including x86_64). The changes directly affect instruction validation, scalar min/max value tracking, arena pointer checks, and JIT assembly generation (including RAX/RDX push/pop and mul/imul execution). This reachable, security-critical code in a core subsystem is accessible via the bpf() syscall and warrants fuzzing for verifier/JIT desynchronization, register clobbering, or integer arithmetic edge cases.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"emit_hmul_aux",
"scalar_min_max_uhmul",
"scalar_min_max_shmul",
"check_hmul_jit",
"bpf_jit_supports_hmul",
"adjust_scalar_min_max_vals",
"check_alu_fields"
],
"Reasoning": "The patch introduces new eBPF 64-bit high-half multiplication instructions (UHMUL and SHMUL) across the BPF verifier, BPF interpreter, and architecture JIT compilers (including x86_64). The changes directly affect instruction validation, scalar min/max value tracking, arena pointer checks, and JIT assembly generation (including RAX/RDX push/pop and mul/imul execution). This reachable, security-critical code in a core subsystem is accessible via the bpf() syscall and warrants fuzzing for verifier/JIT desynchronization, register clobbering, or integer arithmetic edge cases.",
"WorthFuzzing": true
} |
| 29/1 | 2026/10/23 04:26 | action | If |
0mArgs:{
"WorthFuzzing": true
}Results: null |
| 30/2 | 2026/10/23 04:26 | agent | kmsan-evaluator |
0mModel:core Args: null Results: {
"KMSANReasoning": "The patch introduces support for 64-bit unsigned high-half multiplication (UHMUL) and signed high-half multiplication (SHMUL) instructions across the BPF verifier, interpreter, and JIT compilers (x86_64, arm64, riscv64).\n\n1. No kernel structures or memory buffers copied to userspace are introduced or modified.\n2. The patch only alters arithmetic ALU64 instruction execution, JIT code emission, and verifier constant/scalar tracking (marking non-constant hmul results unknown, and disallowing pointers such as arena pointers).\n3. No stack or heap allocations, uninitialized variable usage, or kernel info-leaks are introduced.\n4. Any potential issues with JIT code generation or verifier bounds analysis would manifest as functional errors, crashes, or out-of-bounds accesses, which are covered by standard testing and KASAN rather than KMSAN.\n\nTherefore, a dedicated KMSAN session is not warranted.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 6d6c77985c9242ff63faeda7fbb06058ee652429
Author: syz-cluster <triage@syzkaller.com>
Date: Fri Oct 23 04:23:59 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/bpf/standardization/instruction-set.rst b/Documentation/bpf/standardization/instruction-set.rst
index 39c74611752b6..6f3cb6bcaa1a6 100644
--- a/Documentation/bpf/standardization/instruction-set.rst
+++ b/Documentation/bpf/standardization/instruction-set.rst
@@ -142,8 +142,9 @@ This document defines the following conformance groups:
* atomic32: includes 32-bit atomic operation instructions (see `Atomic operations`_).
* atomic64: includes atomic32, plus 64-bit atomic operation instructions.
* divmul32: includes 32-bit division, multiplication, and modulo instructions.
-* divmul64: includes divmul32, plus 64-bit division, multiplication,
+* divmul64: includes divmul32, plus 64-bit division, low-half multiplication,
and modulo instructions.
+* divmul64v2: includes divmul64, plus high-half multiplication instructions.
* packet: deprecated packet access instructions.
Instruction encoding
@@ -330,6 +331,8 @@ register.
ADD 0x0 0 dst += src
SUB 0x1 0 dst -= src
MUL 0x2 0 dst \*= src
+ UHMUL 0x2 1 ``dst uh*= src`` (unsigned high half, ``ALU64`` only)
+ SHMUL 0x2 2 ``dst sh*= src`` (signed high half, ``ALU64`` only)
DIV 0x3 0 dst = (src != 0) ? (dst / src) : 0
SDIV 0x3 1 dst = (src == 0) ? 0 : ((src == -1 && dst == LLONG_MIN) ? LLONG_MIN : (dst s/ src))
OR 0x4 0 dst \|= src
@@ -379,13 +382,33 @@ where '(u32)' indicates that the upper 32 bits are zeroed.
dst = dst ^ imm
-Note that most arithmetic instructions have 'offset' set to 0. Only three instructions
-(``SDIV``, ``SMOD``, ``MOVSX``) have a non-zero 'offset'.
+Note that most arithmetic instructions have 'offset' set to 0. The following
+instructions may have a non-zero 'offset':
+
+* ``SDIV`` and ``SMOD``: ``offset == 1`` selects the signed variant.
+* ``MOVSX``: ``offset`` selects the source operand width.
+* ``MUL``: ``offset`` selects the multiplication variant (see below).
+
+Division, low-half multiplication (``MUL`` with ``offset == 0``), and
+modulo operations for ``ALU`` are part of the "divmul32" conformance
+group, and their ``ALU64`` variants are part of the "divmul64"
+conformance group.
+
+For ``ALU64`` multiplication, ``offset == 1`` selects unsigned
+high-half multiplication (``UHMUL``), and ``offset == 2`` selects
+signed high-half multiplication (``SHMUL``). Both instructions belong
+to the "divmul64v2" conformance group.
+
+For ``X`` mode, ``src64`` is the 64-bit value in ``src_reg``. For
+``K`` mode, ``src64`` is ``imm`` sign-extended from 32 to 64 bits.
+The operations are::
+
+ UHMUL: dst = (u64)(((u128)dst * (u128)(u64)src64) >> 64)
+ SHMUL: dst = (u64)(((s128)(s64)dst * (s128)(s64)src64) >> 64)
+
+For ``ALU`` multiplication, only ``offset == 0`` is valid. For ``ALU64``
+multiplication, offset values other than 0, 1, and 2 are reserved.
-Division, multiplication, and modulo operations for ``ALU`` are part
-of the "divmul32" conformance group, and division, multiplication, and
-modulo operations for ``ALU64`` are part of the "divmul64" conformance
-group.
The division and modulo operations support both unsigned and signed flavors.
For unsigned operations (``DIV`` and ``MOD``), for ``ALU``,
diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h
index 1ce75a4426387..f38738fa54a27 100644
--- a/arch/arm64/include/asm/insn.h
+++ b/arch/arm64/include/asm/insn.h
@@ -247,6 +247,8 @@ enum aarch64_insn_data2_type {
enum aarch64_insn_data3_type {
AARCH64_INSN_DATA3_MADD,
AARCH64_INSN_DATA3_MSUB,
+ AARCH64_INSN_DATA3_SMULH,
+ AARCH64_INSN_DATA3_UMULH,
};
enum aarch64_insn_logic_type {
@@ -396,6 +398,8 @@ __AARCH64_INSN_FUNCS(sub_ext, 0x7FE00000, 0x4B200000)
__AARCH64_INSN_FUNCS(subs_ext, 0x7FE00000, 0x6B200000)
__AARCH64_INSN_FUNCS(madd, 0x7FE08000, 0x1B000000)
__AARCH64_INSN_FUNCS(msub, 0x7FE08000, 0x1B008000)
+__AARCH64_INSN_FUNCS(smulh, 0x7FE0FC00, 0x1B407C00)
+__AARCH64_INSN_FUNCS(umulh, 0x7FE0FC00, 0x1BC07C00)
__AARCH64_INSN_FUNCS(udiv, 0x7FE0FC00, 0x1AC00800)
__AARCH64_INSN_FUNCS(sdiv, 0x7FE0FC00, 0x1AC00C00)
__AARCH64_INSN_FUNCS(lslv, 0x7FE0FC00, 0x1AC02000)
diff --git a/arch/arm64/lib/insn.c b/arch/arm64/lib/insn.c
index e70ac02385153..dc483d1b8bd54 100644
--- a/arch/arm64/lib/insn.c
+++ b/arch/arm64/lib/insn.c
@@ -1155,6 +1155,12 @@ u32 aarch64_insn_gen_data3(enum aarch64_insn_register dst,
case AARCH64_INSN_DATA3_MSUB:
insn = aarch64_insn_get_msub_value();
break;
+ case AARCH64_INSN_DATA3_SMULH:
+ insn = aarch64_insn_get_smulh_value();
+ break;
+ case AARCH64_INSN_DATA3_UMULH:
+ insn = aarch64_insn_get_umulh_value();
+ break;
default:
pr_err("%s: unknown data3 encoding %d\n", __func__, type);
return AARCH64_BREAK_FAULT;
diff --git a/arch/arm64/net/bpf_jit.h b/arch/arm64/net/bpf_jit.h
index b2fe6e6dcf447..70fc329c661db 100644
--- a/arch/arm64/net/bpf_jit.h
+++ b/arch/arm64/net/bpf_jit.h
@@ -281,6 +281,12 @@
A64_VARIANT(sf), AARCH64_INSN_DATA3_MSUB)
/* Rd = Rn * Rm */
#define A64_MUL(sf, Rd, Rn, Rm) A64_MADD(sf, Rd, A64_ZR, Rn, Rm)
+/* Rd = high 64 bits of signed Rn * Rm */
+#define A64_SMULH(Rd, Rn, Rm) aarch64_insn_gen_data3(Rd, A64_ZR, Rn, Rm, \
+ AARCH64_INSN_VARIANT_64BIT, AARCH64_INSN_DATA3_SMULH)
+/* Rd = high 64 bits of unsigned Rn * Rm */
+#define A64_UMULH(Rd, Rn, Rm) aarch64_insn_gen_data3(Rd, A64_ZR, Rn, Rm, \
+ AARCH64_INSN_VARIANT_64BIT, AARCH64_INSN_DATA3_UMULH)
/* Logical (shifted register) */
#define A64_LOGIC_SREG(sf, Rd, Rn, Rm, type) \
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 326e9e1dea0a7..3b4793092c1a4 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -144,6 +144,17 @@ static inline void emit_a64_mov_i(const int is64, const int reg,
}
}
+static inline void emit_a64_mul(const bool is64, const u8 dst, const u8 src,
+ const s16 off, struct jit_ctx *ctx)
+{
+ if (is64 && off == BPF_UHMUL)
+ emit(A64_UMULH(dst, dst, src), ctx);
+ else if (is64 && off == BPF_SHMUL)
+ emit(A64_SMULH(dst, dst, src), ctx);
+ else
+ emit(A64_MUL(is64, dst, dst, src), ctx);
+}
+
static int i64_i16_blocks(const u64 val, bool inverse)
{
return (((val >> 0) & 0xffff) != (inverse ? 0xffff : 0x0000)) +
@@ -1531,7 +1542,7 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn
break;
case BPF_ALU | BPF_MUL | BPF_X:
case BPF_ALU64 | BPF_MUL | BPF_X:
- emit(A64_MUL(is64, dst, dst, src), ctx);
+ emit_a64_mul(is64, dst, src, off, ctx);
break;
case BPF_ALU | BPF_DIV | BPF_X:
case BPF_ALU64 | BPF_DIV | BPF_X:
@@ -1660,7 +1671,7 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn
case BPF_ALU | BPF_MUL | BPF_K:
case BPF_ALU64 | BPF_MUL | BPF_K:
emit_a64_mov_i(is64, tmp, imm, ctx);
- emit(A64_MUL(is64, dst, dst, tmp), ctx);
+ emit_a64_mul(is64, dst, tmp, off, ctx);
break;
case BPF_ALU | BPF_DIV | BPF_K:
case BPF_ALU64 | BPF_DIV | BPF_K:
@@ -2595,6 +2606,11 @@ bool bpf_jit_supports_callx(void)
return true;
}
+bool bpf_jit_supports_hmul(void)
+{
+ return true;
+}
+
bool bpf_jit_supports_large_stack(void)
{
return true;
diff --git a/arch/riscv/net/bpf_jit.h b/arch/riscv/net/bpf_jit.h
index 5c4f53060c918..21a190a6a6d99 100644
--- a/arch/riscv/net/bpf_jit.h
+++ b/arch/riscv/net/bpf_jit.h
@@ -436,6 +436,11 @@ static inline u32 rv_mul(u8 rd, u8 rs1, u8 rs2)
return rv_r_insn(1, rs2, rs1, 0, rd, 0x33);
}
+static inline u32 rv_mulh(u8 rd, u8 rs1, u8 rs2)
+{
+ return rv_r_insn(1, rs2, rs1, 1, rd, 0x33);
+}
+
static inline u32 rv_mulhu(u8 rd, u8 rs1, u8 rs2)
{
return rv_r_insn(1, rs2, rs1, 3, rd, 0x33);
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index 788fcc21fd5b8..371405598faa7 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -197,6 +197,19 @@ static void emit_imm(u8 rd, s64 val, struct rv_jit_context *ctx)
emit_addi(rd, rd, lower, ctx);
}
+static void emit_mul(u8 rd, u8 rs, bool is64, s16 off,
+ struct rv_jit_context *ctx)
+{
+ if (!is64)
+ emit(rv_mulw(rd, rd, rs), ctx);
+ else if (off == BPF_UHMUL)
+ emit(rv_mulhu(rd, rd, rs), ctx);
+ else if (off == BPF_SHMUL)
+ emit(rv_mulh(rd, rd, rs), ctx);
+ else
+ emit(rv_mul(rd, rd, rs), ctx);
+}
+
static void __build_epilogue(bool is_tail_call, struct rv_jit_context *ctx)
{
int stack_adjust = ctx->stack_size, store_offset = stack_adjust - 8;
@@ -1526,7 +1539,7 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
break;
case BPF_ALU | BPF_MUL | BPF_X:
case BPF_ALU64 | BPF_MUL | BPF_X:
- emit(is64 ? rv_mul(rd, rd, rs) : rv_mulw(rd, rd, rs), ctx);
+ emit_mul(rd, rs, is64, off, ctx);
if (!is64 && !aux->verifier_zext)
emit_zextw(rd, rd, ctx);
break;
@@ -1662,8 +1675,7 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
case BPF_ALU | BPF_MUL | BPF_K:
case BPF_ALU64 | BPF_MUL | BPF_K:
emit_imm(RV_REG_T1, imm, ctx);
- emit(is64 ? rv_mul(rd, rd, RV_REG_T1) :
- rv_mulw(rd, rd, RV_REG_T1), ctx);
+ emit_mul(rd, RV_REG_T1, is64, off, ctx);
if (!is64 && !aux->verifier_zext)
emit_zextw(rd, rd, ctx);
break;
@@ -2303,3 +2315,8 @@ bool bpf_jit_supports_callx(void)
{
return true;
}
+
+bool bpf_jit_supports_hmul(void)
+{
+ return true;
+}
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 6a2fe3d0039d3..2707e8fb97994 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -1378,6 +1378,38 @@ static int emit_kasan_check(struct bpf_verifier_env *env, u8 **pprog,
return 0;
}
+/*
+ * The one-operand x86 mul/imul forms use RAX as the implicit first
+ * operand and store the 128-bit product in RDX:RAX.
+ * The JIT uses AUX_REG as the explicit second operand.
+ */
+static void emit_hmul_aux(u8 **pprog, u32 dst_reg, bool is_signed)
+{
+ u8 *prog = *pprog;
+ bool save_rax = dst_reg != BPF_REG_0;
+ bool save_rdx = dst_reg != BPF_REG_3;
+ u8 mul_modrm_base = is_signed ? 0xE8 : 0xE0; /* imul /5 or mul /4 */
+
+ if (save_rax)
+ EMIT1(0x50); /* push rax */
+ if (save_rdx)
+ EMIT1(0x52); /* push rdx */
+
+ if (save_rax)
+ emit_mov_reg(&prog, true, BPF_REG_0, dst_reg);
+ maybe_emit_1mod(&prog, AUX_REG, true);
+ EMIT2(0xF7, add_1reg(mul_modrm_base, AUX_REG));
+ if (save_rdx)
+ emit_mov_reg(&prog, true, dst_reg, BPF_REG_3);
+
+ if (save_rdx)
+ EMIT1(0x5A); /* pop rdx */
+ if (save_rax)
+ EMIT1(0x58); /* pop rax */
+
+ *pprog = prog;
+}
+
/* LDX: dst_reg = *(u8*)(src_reg + off) */
static void emit_ldx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
{
@@ -2916,6 +2948,14 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
case BPF_ALU | BPF_MUL | BPF_K:
case BPF_ALU64 | BPF_MUL | BPF_K:
+ if (bpf_insn_is_hmul(insn)) {
+ /* imul/mul use AUX_REG as src. */
+ emit_mov_imm32(&prog, true, AUX_REG, imm32);
+ emit_hmul_aux(&prog, dst_reg,
+ insn->off == BPF_SHMUL);
+ break;
+ }
+
/*
* lea for 3, 5 and 9, which LLVM leaves as a
* multiplication, but not for r13, which needs a
@@ -2951,6 +2991,14 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
case BPF_ALU | BPF_MUL | BPF_X:
case BPF_ALU64 | BPF_MUL | BPF_X:
+ if (bpf_insn_is_hmul(insn)) {
+ /* imul/mul use AUX_REG as src. */
+ emit_mov_reg(&prog, true, AUX_REG, src_reg);
+ emit_hmul_aux(&prog, dst_reg,
+ insn->off == BPF_SHMUL);
+ break;
+ }
+
maybe_emit_mod(&prog, src_reg, dst_reg,
BPF_CLASS(insn->code) == BPF_ALU64);
@@ -5126,6 +5174,11 @@ bool bpf_jit_supports_unwind(void)
return true;
}
+bool bpf_jit_supports_hmul(void)
+{
+ return true;
+}
+
const struct bpf_jit_arg_abi *bpf_jit_arg_abi(void)
{
return &x86_arg_abi;
diff --git a/include/linux/filter.h b/include/linux/filter.h
index e0218e677a1dc..2a2101fb01684 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -23,6 +23,7 @@
#include <linux/sockptr.h>
#include <linux/static_call.h>
#include <linux/u64_stats_sync.h>
+#include <linux/math64.h>
#include <net/sch_generic.h>
@@ -152,6 +153,38 @@ struct ctl_table_header;
#define BPF_ALU32_IMM(OP, DST, IMM) \
BPF_ALU32_IMM_OFF(OP, DST, IMM, 0)
+static inline u64 bpf_uhmul64(u64 a, u64 b)
+{
+ return mul_u64_u64_shr(a, b, 64);
+}
+
+static inline u64 bpf_shmul64(s64 a, s64 b)
+{
+ u64 ua = a, ub = b;
+ u64 hi = bpf_uhmul64(ua, ub);
+
+ /*
+ * Let M = 2^64, sa = (a < 0), and sb = (b < 0). Then:
+ *
+ * a * b = (ua - sa * M) * (ub - sb * M)
+ * = ua * ub - sa * M * ub - sb * M * ua + sa * sb * M^2
+ *
+ * Therefore, signed_hi = unsigned_hi - sa * ub - sb * ua (mod M).
+ */
+ if (a < 0)
+ hi -= ub;
+ if (b < 0)
+ hi -= ua;
+ return hi;
+}
+
+static inline bool bpf_insn_is_hmul(const struct bpf_insn *insn)
+{
+ return BPF_CLASS(insn->code) == BPF_ALU64 &&
+ BPF_OP(insn->code) == BPF_MUL &&
+ (insn->off == BPF_UHMUL || insn->off == BPF_SHMUL);
+}
+
/* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */
#define BPF_ENDIAN(TYPE, DST, LEN) \
@@ -1281,6 +1314,7 @@ bool bpf_jit_supports_kfunc_call(void);
bool bpf_jit_supports_callx(void);
bool bpf_jit_supports_kfunc_ret_reg_pair(void);
bool bpf_jit_supports_unwind(void);
+bool bpf_jit_supports_hmul(void);
bool bpf_jit_supports_stack_args(void);
bool bpf_jit_supports_arena_args(void);
bool bpf_jit_supports_far_kfunc_call(void);
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index f29b0aad440cb..90c30e5d790b9 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -34,6 +34,12 @@
#define BPF_FROM_LE BPF_TO_LE
#define BPF_FROM_BE BPF_TO_BE
+/* BPF_MUL off values for high-half multiplication; BPF_ALU64 only. */
+enum bpf_mul_variant {
+ BPF_UHMUL = 1,
+ BPF_SHMUL = 2,
+};
+
/* jmp encodings */
#define BPF_JNE 0x50 /* jump != */
#define BPF_JLT 0xa0 /* LT is unsigned, '<' */
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 3030beb531d99..8600c93842175 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1943,7 +1943,46 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)
ALU(AND, &)
ALU(OR, |)
ALU(XOR, ^)
- ALU(MUL, *)
+ /*
+ * MUL needs explicit handlers because ALU64 insn->off selects
+ * low-half, unsigned high-half, or signed high-half multiplication.
+ */
+ ALU64_MUL_X:
+ switch (OFF) {
+ case 0:
+ DST = DST * SRC;
+ break;
+ case BPF_UHMUL:
+ DST = bpf_uhmul64(DST, SRC);
+ break;
+ case BPF_SHMUL:
+ DST = bpf_shmul64((s64)DST, (s64)SRC);
+ break;
+ default:
+ goto default_label;
+ }
+ CONT;
+ ALU_MUL_X:
+ DST = (u32) DST * (u32) SRC;
+ CONT;
+ ALU64_MUL_K:
+ switch (OFF) {
+ case 0:
+ DST = DST * IMM;
+ break;
+ case BPF_UHMUL:
+ DST = bpf_uhmul64(DST, (u64)IMM);
+ break;
+ case BPF_SHMUL:
+ DST = bpf_shmul64((s64)DST, (s32)IMM);
+ break;
+ default:
+ goto default_label;
+ }
+ CONT;
+ ALU_MUL_K:
+ DST = (u32) DST * (u32) IMM;
+ CONT;
SHT(LSH, <<)
SHT(RSH, >>)
#undef SHT
@@ -3405,6 +3444,12 @@ bool __weak bpf_jit_supports_unwind(void)
return false;
}
+/* uhmul and shmul */
+bool __weak bpf_jit_supports_hmul(void)
+{
+ return false;
+}
+
/*
* How this arch places a by-value kfunc argument, or NULL for one that has
* not opted in and so only takes an argument of a single eightbyte, which
diff --git a/kernel/bpf/disasm.c b/kernel/bpf/disasm.c
index 889fc074496f1..0b1bbb27e9e4e 100644
--- a/kernel/bpf/disasm.c
+++ b/kernel/bpf/disasm.c
@@ -163,6 +163,22 @@ static bool is_sdiv_smod(const struct bpf_insn *insn)
insn->off == 1;
}
+/* Return the UHMUL or SHMUL operator string, or NULL for all other encodings. */
+static const char *hmul_op_string(const struct bpf_insn *insn)
+{
+ if (BPF_CLASS(insn->code) != BPF_ALU64 ||
+ BPF_OP(insn->code) != BPF_MUL)
+ return NULL;
+ switch (insn->off) {
+ case BPF_UHMUL:
+ return "uh*=";
+ case BPF_SHMUL:
+ return "sh*=";
+ default:
+ return NULL;
+ }
+}
+
static bool is_movsx(const struct bpf_insn *insn)
{
return BPF_OP(insn->code) == BPF_MOV &&
@@ -215,6 +231,7 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs,
verbose(cbs->private_data, "(%02x) %c%d %s %s%c%d",
insn->code, class == BPF_ALU ? 'w' : 'r',
insn->dst_reg,
+ hmul_op_string(insn) ?:
is_sdiv_smod(insn) ? bpf_alu_sign_string[BPF_OP(insn->code) >> 4]
: bpf_alu_string[BPF_OP(insn->code) >> 4],
is_movsx(insn) ? bpf_movsx_string[(insn->off >> 3) - 1] : "",
@@ -224,6 +241,7 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs,
verbose(cbs->private_data, "(%02x) %c%d %s %d",
insn->code, class == BPF_ALU ? 'w' : 'r',
insn->dst_reg,
+ hmul_op_string(insn) ?:
is_sdiv_smod(insn) ? bpf_alu_sign_string[BPF_OP(insn->code) >> 4]
: bpf_alu_string[BPF_OP(insn->code) >> 4],
insn->imm);
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 5601d20562186..ac7974038eaa3 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -16664,6 +16664,24 @@ static void scalar_min_max_mul(struct bpf_reg_state *dst_reg,
cnum64_from_srange(smin, smax));
}
+static void scalar_min_max_uhmul(struct bpf_reg_state *dst_reg,
+ struct bpf_reg_state *src_reg)
+{
+ u64 dst = reg_const_value(dst_reg, false);
+ u64 src = reg_const_value(src_reg, false);
+
+ ___mark_reg_known(dst_reg, bpf_uhmul64(dst, src));
+}
+
+static void scalar_min_max_shmul(struct bpf_reg_state *dst_reg,
+ struct bpf_reg_state *src_reg)
+{
+ s64 dst = reg_const_value(dst_reg, false);
+ s64 src = reg_const_value(src_reg, false);
+
+ ___mark_reg_known(dst_reg, bpf_shmul64(dst, src));
+}
+
static void scalar32_min_max_udiv(struct bpf_reg_state *dst_reg,
struct bpf_reg_state *src_reg)
{
@@ -17364,6 +17382,25 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,
reg_step_reset(dst_reg);
break;
case BPF_MUL:
+ /*
+ * Range analysis for UHMUL/SHMUL is not implemented yet.
+ * Compute an exact result only when both operands are constants.
+ * Ordinary low-half MUL continues to use the analysis below.
+ */
+ if (bpf_insn_is_hmul(insn) &&
+ (!is_reg_const(dst_reg, false) ||
+ !is_reg_const(&src_reg, false))) {
+ __mark_reg_unknown(env, dst_reg);
+ break;
+ }
+ if (!alu32 && insn->off == BPF_UHMUL) {
+ scalar_min_max_uhmul(dst_reg, &src_reg);
+ break;
+ }
+ if (!alu32 && insn->off == BPF_SHMUL) {
+ scalar_min_max_shmul(dst_reg, &src_reg);
+ break;
+ }
scalar_step_mul(dst_reg, &src_reg);
dst_reg->var_off = tnum_mul(dst_reg->var_off, src_reg.var_off);
scalar32_min_max_mul(dst_reg, &src_reg);
@@ -17499,6 +17536,11 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
/* Case where at least one operand is an arena. */
if (dst_reg->type == PTR_TO_ARENA || (src_reg && src_reg->type == PTR_TO_ARENA)) {
+ if (bpf_insn_is_hmul(insn)) {
+ verbose(env, "UHMUL/SHMUL with arena pointers are not supported\n");
+ return -EOPNOTSUPP;
+ }
+
if (dst_reg->type != PTR_TO_ARENA)
*dst_reg = *src_reg;
@@ -21194,6 +21236,31 @@ static int fd_array_get_map_idx(struct bpf_verifier_env *env, u32 idx)
return -EPROTO;
}
+static bool is_valid_alu_variant(const struct bpf_insn *insn)
+{
+ switch (BPF_OP(insn->code)) {
+ case BPF_MUL:
+ return insn->off == 0 || bpf_insn_is_hmul(insn);
+ case BPF_DIV:
+ case BPF_MOD:
+ /* off == 1 selects SDIV/SMOD. */
+ return insn->off == 0 || insn->off == 1;
+ default:
+ return insn->off == 0;
+ }
+}
+
+/* The interpreter supports uhmul and shmul. JITs opt in. */
+static int check_hmul_jit(struct bpf_verifier_env *env)
+{
+ if (bpf_prog_is_offloaded(env->prog->aux) ||
+ (env->prog->jit_requested && !bpf_jit_supports_hmul())) {
+ verbose(env, "JIT doesn't support uhmul and shmul\n");
+ return -EOPNOTSUPP;
+ }
+ return 0;
+}
+
static int check_alu_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)
{
u8 class = BPF_CLASS(insn->code);
@@ -21249,18 +21316,14 @@ static int check_alu_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)
case BPF_MUL:
case BPF_DIV:
case BPF_MOD:
- if (BPF_SRC(insn->code) == BPF_X) {
- if (insn->imm != 0 || (insn->off != 0 && insn->off != 1) ||
- (insn->off == 1 && opcode != BPF_MOD && opcode != BPF_DIV)) {
- verbose(env, "BPF_ALU uses reserved fields\n");
- return -EINVAL;
- }
- } else if (insn->src_reg != BPF_REG_0 ||
- (insn->off != 0 && insn->off != 1) ||
- (insn->off == 1 && opcode != BPF_MOD && opcode != BPF_DIV)) {
+ if (!is_valid_alu_variant(insn) ||
+ (BPF_SRC(insn->code) == BPF_X && insn->imm != 0) ||
+ (BPF_SRC(insn->code) == BPF_K && insn->src_reg != BPF_REG_0)) {
verbose(env, "BPF_ALU uses reserved fields\n");
return -EINVAL;
}
+ if (bpf_insn_is_hmul(insn))
+ return check_hmul_jit(env);
return 0;
default:
verbose(env, "invalid BPF_ALU opcode %x\n", opcode);
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index f29b0aad440cb..90c30e5d790b9 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -34,6 +34,12 @@
#define BPF_FROM_LE BPF_TO_LE
#define BPF_FROM_BE BPF_TO_BE
+/* BPF_MUL off values for high-half multiplication; BPF_ALU64 only. */
+enum bpf_mul_variant {
+ BPF_UHMUL = 1,
+ BPF_SHMUL = 2,
+};
+
/* jmp encodings */
#define BPF_JNE 0x50 /* jump != */
#define BPF_JLT 0xa0 /* LT is unsigned, '<' */
diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c
index 04740ba37e918..795c3e56c23e0 100644
--- a/tools/testing/selftests/bpf/prog_tests/verifier.c
+++ b/tools/testing/selftests/bpf/prog_tests/verifier.c
@@ -59,6 +59,7 @@
#include "verifier_helper_packet_access.skel.h"
#include "verifier_helper_restricted.skel.h"
#include "verifier_helper_value_access.skel.h"
+#include "verifier_hmul.skel.h"
#include "verifier_idoms.skel.h"
#include "verifier_int_ptr.skel.h"
#include "verifier_iterating_callbacks.skel.h"
@@ -251,6 +252,7 @@ void test_verifier_helper_access_var_len(void) { RUN(verifier_helper_access_var_
void test_verifier_helper_packet_access(void) { RUN(verifier_helper_packet_access); }
void test_verifier_helper_restricted(void) { RUN(verifier_helper_restricted); }
void test_verifier_helper_value_access(void) { RUN(verifier_helper_value_access); }
+void test_verifier_hmul(void) { RUN(verifier_hmul); }
void test_verifier_idoms(void) { RUN(verifier_idoms); }
void test_verifier_int_ptr(void) { RUN(verifier_int_ptr); }
void test_verifier_iterating_callbacks(void) { RUN(verifier_iterating_callbacks); }
diff --git a/tools/testing/selftests/bpf/prog_tests/verifier_hmul_arena.c b/tools/testing/selftests/bpf/prog_tests/verifier_hmul_arena.c
new file mode 100644
index 0000000000000..f9cd7b7b9781a
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/verifier_hmul_arena.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <test_progs.h>
+#include "verifier_hmul_arena.skel.h"
+
+void test_verifier_hmul_arena(void)
+{
+ int ret;
+
+ /* Arena support can depend on CPU features, such as Zacas on RV64. */
+ ret = libbpf_probe_bpf_map_type(BPF_MAP_TYPE_ARENA, NULL);
+ if (!ASSERT_GE(ret, 0, "probe_arena"))
+ return;
+ if (!ret) {
+ test__skip();
+ return;
+ }
+ RUN_TESTS(verifier_hmul_arena);
+}
diff --git a/tools/testing/selftests/bpf/progs/verifier_hmul.c b/tools/testing/selftests/bpf/progs/verifier_hmul.c
new file mode 100644
index 0000000000000..acd92355c6365
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/verifier_hmul.c
@@ -0,0 +1,235 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/bpf.h>
+#include <limits.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+#include "../../../include/linux/filter.h"
+
+#define BPF_UHMUL64_REG(DST, SRC) \
+ BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_X, DST, SRC, BPF_UHMUL, 0)
+
+#define BPF_UHMUL64_IMM(DST, IMM) \
+ BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, BPF_UHMUL, IMM)
+
+#define BPF_SHMUL64_REG(DST, SRC) \
+ BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_X, DST, SRC, BPF_SHMUL, 0)
+
+#define BPF_SHMUL64_IMM(DST, IMM) \
+ BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, BPF_SHMUL, IMM)
+
+/*
+ * Inject UHMUL/SHMUL as raw instructions so these tests do not require
+ * assembler support for the new mnemonics. All surrounding instructions use
+ * existing BPF assembly syntax supported by the baseline selftests toolchain.
+ */
+
+#if defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || \
+ (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)
+
+/*
+ * BPF_PROG_TEST_RUN reports a 32-bit retval. Fold both halves of
+ * (actual ^ expected) into w0 so retval == 0 checks the full 64-bit result.
+ */
+
+SEC("socket")
+__description("UHMUL64, U64_MAX * U64_MAX, register source")
+__success __success_unpriv __retval(0)
+__naked void uhmul64_max_reg(void)
+{
+ asm volatile (
+ "r0 = -1;"
+ "r1 = -1;"
+ ".8byte %[hmul];"
+ "r2 = -2;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_insn(hmul, BPF_UHMUL64_REG(BPF_REG_0, BPF_REG_1))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("UHMUL64, (1ULL << 63) * 2, register source")
+__success __success_unpriv __retval(0)
+__naked void uhmul64_pow2_reg(void)
+{
+ asm volatile (
+ "r0 = 2;"
+ "r1 = %[llong_min] ll;"
+ ".8byte %[hmul];"
+ "r0 = r1;"
+ "r2 = 1;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_const(llong_min, LLONG_MIN),
+ __imm_insn(hmul, BPF_UHMUL64_REG(BPF_REG_1, BPF_REG_0))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("UHMUL64, (1ULL << 63) * 2, R3 destination")
+__success __success_unpriv __retval(0)
+__naked void uhmul64_r3_dst(void)
+{
+ asm volatile (
+ "r3 = %[llong_min] ll;"
+ "r0 = 2;"
+ ".8byte %[hmul];"
+ "r2 = 1;"
+ "r3 ^= r2;"
+ "r2 = r3;"
+ "r2 >>= 32;"
+ "w3 |= w2;"
+ "r0 = r3;"
+ "exit;"
+ :
+ : __imm_const(llong_min, LLONG_MIN),
+ __imm_insn(hmul, BPF_UHMUL64_REG(BPF_REG_3, BPF_REG_0))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("UHMUL64, (1ULL << 63) * 2, immediate source")
+__success __success_unpriv __retval(0)
+__naked void uhmul64_pow2_imm(void)
+{
+ asm volatile (
+ "r0 = %[llong_min] ll;"
+ ".8byte %[hmul];"
+ "r2 = 1;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_const(llong_min, LLONG_MIN),
+ __imm_insn(hmul, BPF_UHMUL64_IMM(BPF_REG_0, 2))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("UHMUL64, (1ULL << 63) * -2, immediate source")
+__success __success_unpriv __retval(0)
+__naked void uhmul64_neg_imm(void)
+{
+ asm volatile (
+ "r0 = %[llong_min] ll;"
+ ".8byte %[hmul];"
+ "r2 = %[llong_max] ll;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_const(llong_min, LLONG_MIN),
+ __imm_const(llong_max, LLONG_MAX),
+ __imm_insn(hmul, BPF_UHMUL64_IMM(BPF_REG_0, -2))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("SHMUL64, INT64_MAX * INT64_MAX, register source")
+__success __success_unpriv __retval(0)
+__naked void shmul64_max_reg(void)
+{
+ asm volatile (
+ "r0 = %[llong_max] ll;"
+ "r1 = %[llong_max] ll;"
+ ".8byte %[hmul];"
+ "r2 = %[expected] ll;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_const(expected, 0x3fffffffffffffffULL),
+ __imm_const(llong_max, LLONG_MAX),
+ __imm_insn(hmul, BPF_SHMUL64_REG(BPF_REG_0, BPF_REG_1))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("SHMUL64, INT64_MIN * -2, register source")
+__success __success_unpriv __retval(0)
+__naked void shmul64_min_neg2_reg(void)
+{
+ asm volatile (
+ "r0 = %[llong_min] ll;"
+ "r1 = -2;"
+ ".8byte %[hmul];"
+ "r2 = 1;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_const(llong_min, LLONG_MIN),
+ __imm_insn(hmul, BPF_SHMUL64_REG(BPF_REG_0, BPF_REG_1))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("SHMUL64, 1 * -2, immediate source")
+__success __success_unpriv __retval(0)
+__naked void shmul64_neg_imm(void)
+{
+ asm volatile (
+ "r0 = 1;"
+ ".8byte %[hmul];"
+ "r2 = -1;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_insn(hmul, BPF_SHMUL64_IMM(BPF_REG_0, -2))
+ : __clobber_all);
+}
+
+SEC("socket")
+__description("SHMUL64, INT64_MIN * 2, immediate source")
+__success __success_unpriv __retval(0)
+__naked void shmul64_min_imm(void)
+{
+ asm volatile (
+ "r0 = %[llong_min] ll;"
+ ".8byte %[hmul];"
+ "r2 = -1;"
+ "r0 ^= r2;"
+ "r2 = r0;"
+ "r2 >>= 32;"
+ "w0 |= w2;"
+ "exit;"
+ :
+ : __imm_const(llong_min, LLONG_MIN),
+ __imm_insn(hmul, BPF_SHMUL64_IMM(BPF_REG_0, 2))
+ : __clobber_all);
+}
+
+#else
+
+SEC("socket")
+__description("UHMUL/SHMUL are not supported by this JIT, use a dummy test")
+__skip("UHMUL/SHMUL are not supported by this jit")
+__success
+int dummy_test(void)
+{
+ return 0;
+}
+
+#endif
+
+char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/verifier_hmul_arena.c b/tools/testing/selftests/bpf/progs/verifier_hmul_arena.c
new file mode 100644
index 0000000000000..a8709ec447aa8
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/verifier_hmul_arena.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+#include "../../../include/linux/filter.h"
+
+#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
+
+#define BPF_UHMUL64_IMM(DST, IMM) \
+ BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, BPF_UHMUL, IMM)
+
+#define BPF_SHMUL64_REG(DST, SRC) \
+ BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_X, DST, SRC, BPF_SHMUL, 0)
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARENA);
+ __uint(map_flags, BPF_F_MMAPABLE);
+ __uint(max_entries, 1);
+} arena SEC(".maps");
+
+SEC("syscall")
+__description("UHMUL64 with arena pointer dst")
+__failure __msg("UHMUL/SHMUL with arena pointers are not supported")
+__arch_x86_64 __arch_arm64 __arch_riscv64
+__load_if_JITed()
+__naked void uhmul64_arena_ptr(void)
+{
+ asm volatile (
+ "r1 = %[arena] ll;"
+ "r0 = 1;"
+ "r0 = addr_space_cast(r0, 0x0, 0x1);"
+ ".8byte %[hmul];"
+ "exit;"
+ :
+ : __imm_addr(arena),
+ __imm_insn(hmul, BPF_UHMUL64_IMM(BPF_REG_0, 2))
+ : __clobber_all);
+}
+
+SEC("syscall")
+__description("SHMUL64 with arena pointer src")
+__failure __msg("UHMUL/SHMUL with arena pointers are not supported")
+__arch_x86_64 __arch_arm64 __arch_riscv64
+__load_if_JITed()
+__naked void shmul64_arena_ptr(void)
+{
+ asm volatile (
+ "r1 = %[arena] ll;"
+ "r1 = 1;"
+ "r1 = addr_space_cast(r1, 0x0, 0x1);"
+ "r0 = 2;"
+ ".8byte %[hmul];"
+ "exit;"
+ :
+ : __imm_addr(arena),
+ __imm_insn(hmul, BPF_SHMUL64_REG(BPF_REG_0, BPF_REG_1))
+ : __clobber_all);
+}
+
+#else
+
+SEC("socket")
+__description("HMUL arena tests require compiler support for addr_space_cast")
+__skip("compiler doesn't support addr_space_cast")
+__success
+int dummy_test(void)
+{
+ return 0;
+}
+
+#endif
+
+char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
index 31663338866d3..209d5be551555 100644
--- a/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
+++ b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
@@ -367,7 +367,8 @@ __naked void flow_keys_illegal_variable_offset_alu(void)
/*
* Offset fields of 0 and 1 are legal for BPF_{DIV,MOD} instructions.
- * Offset fields of 0 are legal for the rest of ALU instructions.
+ * Offset fields of 0, 1 and 2 are legal for BPF_ALU64 | BPF_MUL.
+ * Only offset 0 is legal for BPF_ALU | BPF_MUL.
* Test that error is reported for illegal offsets, assuming that tests
* for legal offsets exist.
*/
@@ -377,5 +378,9 @@ DEFINE_BAD_OFFSET_TEST(bad_offset_addx, BPF_ALU64 | BPF_ADD | BPF_X, -1, 0)
DEFINE_BAD_OFFSET_TEST(bad_offset_divx2, BPF_ALU64 | BPF_DIV | BPF_X, 2, 0)
DEFINE_BAD_OFFSET_TEST(bad_offset_modk2, BPF_ALU64 | BPF_MOD | BPF_K, 2, 1)
DEFINE_BAD_OFFSET_TEST(bad_offset_addx2, BPF_ALU64 | BPF_ADD | BPF_X, 1, 0)
+DEFINE_BAD_OFFSET_TEST(bad_offset_mulx, BPF_ALU64 | BPF_MUL | BPF_X, -1, 0)
+DEFINE_BAD_OFFSET_TEST(bad_offset_mulk, BPF_ALU64 | BPF_MUL | BPF_K, 3, 0)
+DEFINE_BAD_OFFSET_TEST(bad_uhmul32_x, BPF_ALU | BPF_MUL | BPF_X, BPF_UHMUL, 0)
+DEFINE_BAD_OFFSET_TEST(bad_shmul32_k, BPF_ALU | BPF_MUL | BPF_K, BPF_SHMUL, 0)
char _license[] SEC("license") = "GPL";
|
| 31/3 | 2026/10/23 04:26 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17519 output: 35 thoughts: 908 Thoughts: **KMSAN Evaluation for eBPF High-Half Multiplication Support** Okay, I need to decide if this patch series warrants a KMSAN run. Let's break this down systematically. First, I'll analyze the patch itself. It's adding support for `UHMUL` and `SHMUL` instructions in eBPF. The changes span several areas: documentation, JIT support for AArch64, RISC-V, and x86, helper functions, enum definitions, interpreter modifications, disassembler updates, and, crucially, verifier updates. The verifier changes include functions like `scalar_min_max_uhmul`, `scalar_min_max_shmul`, and adjustments to min/max value handling for these new instructions. It also covers things like disallowing arena pointers and adding instruction validation. And, of course, there's a selftest update. Now, I need to keep in mind the difference between KASAN and KMSAN. KASAN is all about out-of-bounds access, use-after-free, etc., and KMSAN deals with reads of *uninitialized* memory and kernel-to-user info leaks. I'm focusing on the latter here. The rule of thumb is: no KMSAN if KASAN or standard bug detectors would catch the issue. I'll need KMSAN if the patch: 1. Touches kernel structures that are sent to user space where uninitialized fields are possible. 2. Involves conditional logic or branching based on potentially uninitialized variables. 3. Allocates/initializes complex data structures, where uninitialized fields could be read later. 4. Modifies bounds checks in a way that risks uninitialized reads. Conversely, I *don't* need KMSAN if: * The code risks only out-of-bounds access, overflows, null dereferences, or use-after-free (KASAN catches these). * All touched structures are *fully* initialized. * The patch doesn't introduce *any* risk of uninitialized memory usage or info-leaks. Let's dive into the code changes to look for potential KMSAN issues. I'll start with the verifier, particularly the `scalar_min_max_uhmul` and `scalar_min_max_shmul` functions. They use `___mark_reg_known`. That looks interesting, so I need to check how the destination register (`dst_reg`) is initialized, or if `___mark_reg_known` itself introduces any. I'll do a quick grep for `___mark_reg_known` within `kernel/bpf/verifier.c` to understand what's happening. Based on how `dst_reg` is handled, that should shed some light on the need for KMSAN. |
| 32/3 | 2026/10/23 04:26 | tool | grepper |
0mArgs:{
"Expression": "___mark_reg_known",
"PathPrefixes": [
"kernel/bpf/verifier.c"
]
}Results: {
"Output": "kernel/bpf/verifier.c=2057=static void reg_step_check_unsigned(struct bpf_reg_state *reg, u32 bits)\n--\nkernel/bpf/verifier.c-2063-/* This helper doesn't clear reg-\u003eid */\nkernel/bpf/verifier.c:2064:static void ___mark_reg_known(struct bpf_reg_state *reg, u64 imm)\nkernel/bpf/verifier.c-2065-{\n--\nkernel/bpf/verifier.c=2075=static void __mark_reg_known(struct bpf_reg_state *reg, u64 imm)\n--\nkernel/bpf/verifier.c-2082-\treg-\u003emap_uid = 0;\nkernel/bpf/verifier.c:2083:\t___mark_reg_known(reg, imm);\nkernel/bpf/verifier.c-2084-}\n--\nkernel/bpf/verifier.c=2267=static void __update_reg64_bounds(struct bpf_reg_state *reg)\n--\nkernel/bpf/verifier.c-2282-\t\t */\nkernel/bpf/verifier.c:2283:\t\t___mark_reg_known(reg, reg_umin(reg));\nkernel/bpf/verifier.c-2284-\t} else if (!umin_in_tnum \u0026\u0026 tnum_next == tmax) {\n--\nkernel/bpf/verifier.c-2289-\t\t */\nkernel/bpf/verifier.c:2290:\t\t___mark_reg_known(reg, tmax);\nkernel/bpf/verifier.c-2291-\t} else if (!umin_in_tnum \u0026\u0026 tnum_next \u003c= reg_umax(reg) \u0026\u0026\n--\nkernel/bpf/verifier.c-2297-\t\t */\nkernel/bpf/verifier.c:2298:\t\t___mark_reg_known(reg, tnum_next);\nkernel/bpf/verifier.c-2299-\t}\n--\nkernel/bpf/verifier.c=16667=static void scalar_min_max_uhmul(struct bpf_reg_state *dst_reg,\n--\nkernel/bpf/verifier.c-16672-\nkernel/bpf/verifier.c:16673:\t___mark_reg_known(dst_reg, bpf_uhmul64(dst, src));\nkernel/bpf/verifier.c-16674-}\n--\nkernel/bpf/verifier.c=16676=static void scalar_min_max_shmul(struct bpf_reg_state *dst_reg,\n--\nkernel/bpf/verifier.c-16681-\nkernel/bpf/verifier.c:16682:\t___mark_reg_known(dst_reg, bpf_shmul64(dst, src));\nkernel/bpf/verifier.c-16683-}\n--\nkernel/bpf/verifier.c=17328=static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-17411-\t\tif ((alu32 \u0026\u0026 reg_u32_min(\u0026src_reg) == 0) || (!alu32 \u0026\u0026 reg_umin(\u0026src_reg) == 0)) {\nkernel/bpf/verifier.c:17412:\t\t\t___mark_reg_known(dst_reg, 0);\nkernel/bpf/verifier.c-17413-\t\t\tbreak;\n"
} |
| 33/3 | 2026/10/23 04:26 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 19968 output: 37 thoughts: 64 Thoughts: Here's my summary, as if I were thinking it: **Verifying Constant Scalar Results in BPF** Okay, so I'm thinking about how we handle constant results during scalar operations, specifically when using `adjust_scalar_min_max_vals`. The common pattern, the one I'm used to seeing, is employing `___mark_reg_known(dst_reg, ...)` when we know the result is a constant. Seems straightforward enough. Now, I need to jog my memory and see how the verifier specifically deals with this. I know this is handled by the BPF verifier in the kernel. Let's drill down into `kernel/bpf/verifier.c` and take a look, I'll start around line 2064 and use `read-file` to get the context I need. Time to refresh my understanding of the exact logic. |
| 34/3 | 2026/10/23 04:26 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 2060,
"LineCount": 35
}Results: {
"Contents": "2060:\t\t\treg_step_reset(reg);\n2061:\t}\n2062:\t\n2063:\t/* This helper doesn't clear reg-\u003eid */\n2064:\tstatic void ___mark_reg_known(struct bpf_reg_state *reg, u64 imm)\n2065:\t{\n2066:\t\treg-\u003evar_off = tnum_const(imm);\n2067:\t\treg-\u003er64 = cnum64_from_urange(imm, imm);\n2068:\t\treg-\u003er32 = cnum32_from_urange((u32)imm, (u32)imm);\n2069:\t\treg_step_reset(reg);\n2070:\t}\n2071:\t\n2072:\t/* Mark the unknown part of a register (variable offset or scalar value) as\n2073:\t * known to have the value @imm.\n2074:\t */\n2075:\tstatic void __mark_reg_known(struct bpf_reg_state *reg, u64 imm)\n2076:\t{\n2077:\t\t/* Clear off and union(map_ptr, range) */\n2078:\t\tmemset(((u8 *)reg) + sizeof(reg-\u003etype), 0,\n2079:\t\t offsetof(struct bpf_reg_state, var_off) - sizeof(reg-\u003etype));\n2080:\t\treg-\u003eid = 0;\n2081:\t\treg-\u003eparent_id = 0;\n2082:\t\treg-\u003emap_uid = 0;\n2083:\t\t___mark_reg_known(reg, imm);\n2084:\t}\n2085:\t\n2086:\tvoid bpf_mark_reg_known_scalar(struct bpf_reg_state *reg, u64 imm)\n2087:\t{\n2088:\t\t__mark_reg_known(reg, imm);\n2089:\t\treg-\u003etype = SCALAR_VALUE;\n2090:\t}\n2091:\t\n2092:\tstatic void __mark_reg32_known(struct bpf_reg_state *reg, u64 imm)\n2093:\t{\n2094:\t\treg-\u003evar_off = tnum_const_subreg(reg-\u003evar_off, imm);\n"
} |
| 35/3 | 2026/10/23 04:26 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20870 output: 232 thoughts: 2300 Thoughts: **KMSAN Assessment for BPF UHMUL/SHMUL Implementation** Okay, let's break this down. My initial focus is on the `adjust_scalar_min_max_vals` function and how it handles the new `BPF_UHMUL` and `BPF_SHMUL` instructions. The key here is the range analysis. The code clearly states that range analysis for these instructions isn't fully implemented yet, so the verifier falls back to exact computation *only* when both operands are constant. Otherwise, it conservatively marks the destination register as "unknown" using `__mark_reg_unknown()`. This sounds correct, and `adjust_reg_min_max_vals` would have already handled the initial `SCALAR_VALUE` check. Next, I look at the interpreter implementation in `kernel/bpf/core.c`. It shows the `DST = bpf_uhmul64/shmul64(DST, SRC/IMM)` calculations. These are straightforward, but I have to verify the JIT compiler for the x86 architecture. Diving into `arch/x86/net/bpf_jit_comp.c`, specifically `emit_hmul_aux`, is where things get interesting. I have to ensure correct register usage. The code's logic of pushing and popping registers (RAX and RDX) around the `mul` or `imul` instructions looks sound. The cases where `dst_reg` is `BPF_REG_0` (RAX) or `BPF_REG_3` (RDX) are handled correctly: `push`, `mul`, `pop`, and the register is left with the correct high part of the result, with the correct stack and register balance. The logic for other registers seems also correct. I need to confirm there's no risk of reading uninitialized memory. There's no use of uninitialized memory in the kernel, and the only memory operations are pushing and popping known registers. I have to carefully assess if the introduction of these instructions could somehow lead to an uninitialized memory read or leak *through* a verifier flaw, such as an out-of-bounds access. But the verifier specifically makes the destination register "unknown" if the inputs aren't constants, so potential errors in range analysis would not read from uninitialized memory. Also, the arena check (`bpf_insn_is_hmul`) makes sure it doesn't support UH/SHMUL with pointers. Furthermore, the verifier tracks all BPF registers and will flag any attempted reads of uninitialized values. Finally, any out-of-bounds access in the kernel would be caught by KASAN. So, in conclusion, based on my understanding of the verifier, interpreter, and JIT compiler for these new BPF instructions and the surrounding code, there is *no* risk of an uninitialized memory read. The conservative approach to range analysis, the explicit marking of registers as unknown, and the existing memory safety checks (verifier and KASAN) cover all potential issues. As the KMSAN guidance indicates, if the bug can be caught by KASAN, then KMSAN is not necessary. Therefore, `NeedsKMSAN=false`. |
| 36/3 | 2026/10/23 04:26 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch introduces support for 64-bit unsigned high-half multiplication (UHMUL) and signed high-half multiplication (SHMUL) instructions across the BPF verifier, interpreter, and JIT compilers (x86_64, arm64, riscv64).\n\n1. No kernel structures or memory buffers copied to userspace are introduced or modified.\n2. The patch only alters arithmetic ALU64 instruction execution, JIT code emission, and verifier constant/scalar tracking (marking non-constant hmul results unknown, and disallowing pointers such as arena pointers).\n3. No stack or heap allocations, uninitialized variable usage, or kernel info-leaks are introduced.\n4. Any potential issues with JIT code generation or verifier bounds analysis would manifest as functional errors, crashes, or out-of-bounds accesses, which are covered by standard testing and KASAN rather than KMSAN.\n\nTherefore, a dedicated KMSAN session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch introduces support for 64-bit unsigned high-half multiplication (UHMUL) and signed high-half multiplication (SHMUL) instructions across the BPF verifier, interpreter, and JIT compilers (x86_64, arm64, riscv64).\n\n1. No kernel structures or memory buffers copied to userspace are introduced or modified.\n2. The patch only alters arithmetic ALU64 instruction execution, JIT code emission, and verifier constant/scalar tracking (marking non-constant hmul results unknown, and disallowing pointers such as arena pointers).\n3. No stack or heap allocations, uninitialized variable usage, or kernel info-leaks are introduced.\n4. Any potential issues with JIT code generation or verifier bounds analysis would manifest as functional errors, crashes, or out-of-bounds accesses, which are covered by standard testing and KASAN rather than KMSAN.\n\nTherefore, a dedicated KMSAN session is not warranted.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|