AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/18 20:53 flow patch-triage
1m Args:
null

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "BPF_JIT"
  ],
  "FocusSymbols": [
    "check_alu_fields",
    "adjust_scalar_min_max_vals",
    "adjust_reg_min_max_vals",
    "scalar_min_max_uhmul",
    "scalar_min_max_shmul",
    "check_alu_op",
    "do_jit",
    "bpf_int_jit_compile",
    "___bpf_prog_run"
  ],
  "KMSANReasoning": "The patch series implements support for BPF 64-bit high-half multiplication instructions (UHMUL and SHMUL) across the BPF interpreter, BPF verifier, disassembler, and JIT compilers (x86, arm64, riscv) while returning -EOPNOTSUPP on other architectures.\n\nThe changes involve:\n1. Pure scalar arithmetic routines (bpf_uhmul64, bpf_shmul64) operating on register values passed by value.\n2. Verifier scalar range/state tracking updates using standard register marking functions (__mark_reg_unknown, ___mark_reg_known).\n3. JIT compiler instruction emissions for the new ALU operations.\n4. Validation of instruction fields (BPF_MUL variants) in check_alu_fields().\n\nNo new heap/stack allocations, memory copying routines, kernel-to-user copy operations (e.g., copy_to_user, ioctl outputs, struct padding), or buffer length manipulations are introduced. Potential bugs in this patch would involve mathematical logic flaws, verifier state tracking inconsistencies, or JIT assembly generation errors (which could cause memory corruption detectable by KASAN/fault handlers), none of which represent uninitialized memory usage or information leaks detectable only by KMSAN. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch implements two new BPF instructions (UHMUL and SHMUL for 64-bit unsigned and signed high-half multiplication) across the BPF verifier, interpreter, and JIT compilers (including x86-64). This touches core reachable kernel paths reachable via the bpf() syscall. Fuzzing is warranted to test verifier bounds tracking, instruction validation, and x86 JIT code generation (such as register preservation for RAX/RDX around mul/imul instructions).",
  "WorthFuzzing": true
}

1/1 2026/09/18 20:53 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 07f3ca6345148982e2a8fbc63d6d227638cb9458\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Fri Sep 18 20:53:37 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..3c2cde11fa234 100644\n--- a/Documentation/bpf/standardization/instruction-set.rst\n+++ b/Documentation/bpf/standardization/instruction-set.rst\n@@ -330,6 +330,8 @@ register.\n   ADD    0x0    0        dst += src\n   SUB    0x1    0        dst -= src\n   MUL    0x2    0        dst \\*= src\n+  UHMUL  0x2    1        unsigned high-half multiplication (``ALU64`` only)\n+  SHMUL  0x2    2        signed high-half multiplication (``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 +381,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, 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+\n+For ``ALU64`` multiplication, ``offset == 1`` selects unsigned\n+high-half multiplication (``UHMUL``), and ``offset == 2`` selects\n+signed high-half multiplication (``SHMUL``).\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\n+``ALU64`` multiplication, offset values other than 0, 1, and 2 are\n+reserved.\n+\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/arc/net/bpf_jit_core.c b/arch/arc/net/bpf_jit_core.c\nindex 639a2736f029e..78b1819cee5a6 100644\n--- a/arch/arc/net/bpf_jit_core.c\n+++ b/arch/arc/net/bpf_jit_core.c\n@@ -734,6 +734,9 @@ static int handle_insn(struct jit_context *ctx, u32 idx)\n \tu8  len = 0;\n \tint ret = 0;\n \n+\tif (bpf_insn_is_hmul(insn))\n+\t\treturn -EOPNOTSUPP;\n+\n \tswitch (code) {\n \t/* dst += src (32-bit) */\n \tcase BPF_ALU | BPF_ADD | BPF_X:\ndiff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c\nindex 9ede81afbc50e..aa466fc79d964 100644\n--- a/arch/arm/net/bpf_jit_32.c\n+++ b/arch/arm/net/bpf_jit_32.c\n@@ -1611,6 +1611,9 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)\n } while (0)\n #define check_imm24(imm) check_imm(24, imm)\n \n+\tif (bpf_insn_is_hmul(insn))\n+\t\tgoto notyet;\n+\n \tswitch (code) {\n \t/* ALU operations */\n \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 6c04fee468766..054c38775dd22 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_MUL_VARIANT_UHMUL)\n+\t\temit(A64_UMULH(dst, dst, src), ctx);\n+\telse if (is64 \u0026\u0026 off == BPF_MUL_VARIANT_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@@ -1454,7 +1465,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@@ -1583,7 +1594,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:\ndiff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c\nindex 4da2789009383..7bb3813fda8e9 100644\n--- a/arch/loongarch/net/bpf_jit.c\n+++ b/arch/loongarch/net/bpf_jit.c\n@@ -709,6 +709,9 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext\n \tconst s32 imm = insn-\u003eimm;\n \tconst bool is32 = BPF_CLASS(insn-\u003ecode) == BPF_ALU || BPF_CLASS(insn-\u003ecode) == BPF_JMP32;\n \n+\tif (bpf_insn_is_hmul(insn))\n+\t\treturn -EOPNOTSUPP;\n+\n \tswitch (code) {\n \t/* dst = src */\n \tcase BPF_ALU | BPF_MOV | BPF_X:\ndiff --git a/arch/mips/net/bpf_jit_comp32.c b/arch/mips/net/bpf_jit_comp32.c\nindex 40a878b672f5d..1afe15162af20 100644\n--- a/arch/mips/net/bpf_jit_comp32.c\n+++ b/arch/mips/net/bpf_jit_comp32.c\n@@ -1472,6 +1472,9 @@ int build_insn(const struct bpf_insn *insn, struct jit_context *ctx)\n \ts32 val, rel;\n \tu8 alu, jmp;\n \n+\tif (bpf_insn_is_hmul(insn))\n+\t\tgoto notyet;\n+\n \tswitch (code) {\n \t/* ALU operations */\n \t/* dst = imm */\ndiff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c\nindex fa7e9aa37f498..a9765ea252824 100644\n--- a/arch/mips/net/bpf_jit_comp64.c\n+++ b/arch/mips/net/bpf_jit_comp64.c\n@@ -643,6 +643,9 @@ int build_insn(const struct bpf_insn *insn, struct jit_context *ctx)\n \ts32 val, rel;\n \tu8 alu, jmp;\n \n+\tif (bpf_insn_is_hmul(insn))\n+\t\tgoto notyet;\n+\n \tswitch (code) {\n \t/* ALU operations */\n \t/* dst = imm */\ndiff --git a/arch/parisc/net/bpf_jit_comp32.c b/arch/parisc/net/bpf_jit_comp32.c\nindex 5ff0cf925fe95..6bf72d04855ba 100644\n--- a/arch/parisc/net/bpf_jit_comp32.c\n+++ b/arch/parisc/net/bpf_jit_comp32.c\n@@ -1133,6 +1133,9 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct hppa_jit_context *ctx,\n \t\tBPF_CLASS(code), code, (code \u0026 BPF_ALU64) ? 1:0, BPF_SIZE(code),\n \t\tBPF_OP(code), insn-\u003esrc_reg, insn-\u003edst_reg);\n \n+\tif (bpf_insn_is_hmul(insn))\n+\t\treturn -EOPNOTSUPP;\n+\n \tswitch (code) {\n \t/* dst = src */\n \tcase BPF_ALU64 | BPF_MOV | BPF_X:\ndiff --git a/arch/parisc/net/bpf_jit_comp64.c b/arch/parisc/net/bpf_jit_comp64.c\nindex 54b0d5e25e024..36b6078a146f8 100644\n--- a/arch/parisc/net/bpf_jit_comp64.c\n+++ b/arch/parisc/net/bpf_jit_comp64.c\n@@ -603,6 +603,9 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct hppa_jit_context *ctx,\n \n \tinit_regs(\u0026rd, \u0026rs, insn, ctx);\n \n+\tif (bpf_insn_is_hmul(insn))\n+\t\treturn -EOPNOTSUPP;\n+\n \tswitch (code) {\n \t/* dst = src */\n \tcase BPF_ALU | BPF_MOV | BPF_X:\ndiff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c\nindex bfdc50740da8e..6bfc97a029d73 100644\n--- a/arch/powerpc/net/bpf_jit_comp32.c\n+++ b/arch/powerpc/net/bpf_jit_comp32.c\n@@ -349,6 +349,9 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code\n \t\tu32 true_cond;\n \t\tu32 tmp_idx;\n \n+\t\tif (bpf_insn_is_hmul(\u0026insn[i]))\n+\t\t\treturn -EOPNOTSUPP;\n+\n \t\tif (i \u0026\u0026 (BPF_CLASS(code) == BPF_ALU64 || BPF_CLASS(code) == BPF_ALU) \u0026\u0026\n \t\t    (BPF_CLASS(prevcode) == BPF_ALU64 || BPF_CLASS(prevcode) == BPF_ALU) \u0026\u0026\n \t\t    BPF_OP(prevcode) == BPF_MOV \u0026\u0026 BPF_SRC(prevcode) == BPF_X \u0026\u0026\ndiff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c\nindex fc9db691e8203..192c96e0ed34a 100644\n--- a/arch/powerpc/net/bpf_jit_comp64.c\n+++ b/arch/powerpc/net/bpf_jit_comp64.c\n@@ -992,6 +992,9 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code\n \t\tu32 tmp_idx;\n \t\tu32 jmp_off;\n \n+\t\tif (bpf_insn_is_hmul(\u0026insn[i]))\n+\t\t\treturn -EOPNOTSUPP;\n+\n \t\t/*\n \t\t * addrs[] maps a BPF bytecode address into a real offset from\n \t\t * the start of the body code.\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_comp32.c b/arch/riscv/net/bpf_jit_comp32.c\nindex a9e0bd5cc81d2..64bc6779d25c7 100644\n--- a/arch/riscv/net/bpf_jit_comp32.c\n+++ b/arch/riscv/net/bpf_jit_comp32.c\n@@ -1014,6 +1014,9 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,\n \tconst s8 *tmp1 = bpf2rv32[TMP_REG_1];\n \tconst s8 *tmp2 = bpf2rv32[TMP_REG_2];\n \n+\tif (bpf_insn_is_hmul(insn))\n+\t\tgoto notsupported;\n+\n \tswitch (code) {\n \tcase BPF_ALU64 | BPF_MOV | BPF_X:\n \t\tif (insn-\u003eoff != 0) {\ndiff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c\nindex ed0a6f871deac..a773506a92093 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_MUL_VARIANT_UHMUL)\n+\t\temit(rv_mulhu(rd, rd, rs), ctx);\n+\telse if (off == BPF_MUL_VARIANT_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@@ -1498,7 +1511,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@@ -1634,8 +1647,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;\ndiff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c\nindex c4b47070bb590..9e5c865d5ea8c 100644\n--- a/arch/s390/net/bpf_jit_comp.c\n+++ b/arch/s390/net/bpf_jit_comp.c\n@@ -985,6 +985,9 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,\n \n \tbpf_jit_probe_init(\u0026probe);\n \n+\tif (bpf_insn_is_hmul(insn))\n+\t\treturn -EOPNOTSUPP;\n+\n \tswitch (insn-\u003ecode) {\n \t/*\n \t * BPF_MOV\ndiff --git a/arch/sparc/net/bpf_jit_comp_64.c b/arch/sparc/net/bpf_jit_comp_64.c\nindex 2fa0e93751276..1154ddc515b0f 100644\n--- a/arch/sparc/net/bpf_jit_comp_64.c\n+++ b/arch/sparc/net/bpf_jit_comp_64.c\n@@ -901,6 +901,9 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)\n \tconst s16 off = insn-\u003eoff;\n \tconst s32 imm = insn-\u003eimm;\n \n+\tif (bpf_insn_is_hmul(insn))\n+\t\treturn -EOPNOTSUPP;\n+\n \tif (insn-\u003esrc_reg == BPF_REG_FP)\n \t\tctx-\u003esaw_frame_pointer = true;\n \ndiff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c\nindex d4a980140b48d..645d0ac4db040 100644\n--- a/arch/x86/net/bpf_jit_comp.c\n+++ b/arch/x86/net/bpf_jit_comp.c\n@@ -1225,6 +1225,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@@ -2332,6 +2364,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_MUL_VARIANT_SHMUL);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n \t\t\tmaybe_emit_mod(\u0026prog, dst_reg, dst_reg,\n \t\t\t\t       BPF_CLASS(insn-\u003ecode) == BPF_ALU64);\n \n@@ -2348,6 +2388,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_MUL_VARIANT_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 \ndiff --git a/arch/x86/net/bpf_jit_comp32.c b/arch/x86/net/bpf_jit_comp32.c\nindex 852baf2e4db4d..11ed65130d1e5 100644\n--- a/arch/x86/net/bpf_jit_comp32.c\n+++ b/arch/x86/net/bpf_jit_comp32.c\n@@ -1683,6 +1683,9 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,\n \t\tint ilen;\n \t\tu8 *func;\n \n+\t\tif (bpf_insn_is_hmul(insn))\n+\t\t\tgoto notyet;\n+\n \t\tswitch (code) {\n \t\t/* ALU operations */\n \t\t/* dst = src */\ndiff --git a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c\nindex 1caa87da72b51..effce27f3b88e 100644\n--- a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c\n+++ b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c\n@@ -3,6 +3,7 @@\n \n #include \u003clinux/bpf.h\u003e\n #include \u003clinux/bpf_verifier.h\u003e\n+#include \u003clinux/filter.h\u003e\n #include \u003clinux/kernel.h\u003e\n #include \u003clinux/netdevice.h\u003e\n #include \u003clinux/pkt_cls.h\u003e\n@@ -561,6 +562,11 @@ nfp_bpf_check_alu(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta,\n \tconst struct bpf_reg_state *dreg =\n \t\tcur_regs(env) + meta-\u003einsn.dst_reg;\n \n+\tif (bpf_insn_is_hmul(\u0026meta-\u003einsn)) {\n+\t\tpr_vlog(env, \"UHMUL/SHMUL are not supported\\n\");\n+\t\treturn -EOPNOTSUPP;\n+\t}\n+\n \tmeta-\u003eumin_src = min(meta-\u003eumin_src, reg_umin(sreg));\n \tmeta-\u003eumax_src = max(meta-\u003eumax_src, reg_umax(sreg));\n \tmeta-\u003eumin_dst = min(meta-\u003eumin_dst, reg_umin(dreg));\ndiff --git a/include/linux/filter.h b/include/linux/filter.h\nindex b17222db2efc3..b6dc4b968a9cd 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@@ -147,6 +148,44 @@ 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_is_hmul_variant(s16 off)\n+{\n+\treturn off == BPF_MUL_VARIANT_UHMUL ||\n+\t       off == BPF_MUL_VARIANT_SHMUL;\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       bpf_is_hmul_variant(insn-\u003eoff);\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\\\ndiff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h\nindex 732b35cc08d1c..845eee5361986 100644\n--- a/include/uapi/linux/bpf.h\n+++ b/include/uapi/linux/bpf.h\n@@ -34,6 +34,16 @@\n #define BPF_FROM_LE\tBPF_TO_LE\n #define BPF_FROM_BE\tBPF_TO_BE\n \n+/*\n+ * BPF_MUL variants selected by the off field.\n+ * UHMUL and SHMUL are only valid for BPF_ALU64.\n+ */\n+enum bpf_mul_variant {\n+\tBPF_MUL_VARIANT_LO    = 0,\n+\tBPF_MUL_VARIANT_UHMUL = 1,\n+\tBPF_MUL_VARIANT_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 4e208cc94752f..4f746973481b9 100644\n--- a/kernel/bpf/core.c\n+++ b/kernel/bpf/core.c\n@@ -1931,7 +1931,50 @@ 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 BPF_MUL_VARIANT_LO:\n+\t\t\tDST = DST * SRC;\n+\t\t\tbreak;\n+\t\tcase BPF_MUL_VARIANT_UHMUL:\n+\t\t\tDST = bpf_uhmul64(DST, SRC);\n+\t\t\tbreak;\n+\t\tcase BPF_MUL_VARIANT_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\tif (OFF != BPF_MUL_VARIANT_LO)\n+\t\t\tgoto default_label;\n+\t\tDST = (u32) DST * (u32) SRC;\n+\t\tCONT;\n+\tALU64_MUL_K:\n+\t\tswitch (OFF) {\n+\t\tcase BPF_MUL_VARIANT_LO:\n+\t\t\tDST = DST * IMM;\n+\t\t\tbreak;\n+\t\tcase BPF_MUL_VARIANT_UHMUL:\n+\t\t\tDST = bpf_uhmul64(DST, (u64)IMM);\n+\t\t\tbreak;\n+\t\tcase BPF_MUL_VARIANT_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\tif (OFF != BPF_MUL_VARIANT_LO)\n+\t\t\tgoto default_label;\n+\t\tDST = (u32) DST * (u32) IMM;\n+\t\tCONT;\n \tSHT(LSH, \u003c\u003c)\n \tSHT(RSH, \u003e\u003e)\n #undef SHT\ndiff --git a/kernel/bpf/disasm.c b/kernel/bpf/disasm.c\nindex 3ce8d74b0e400..03f22845e1692 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_MUL_VARIANT_UHMUL:\n+\t\treturn \"uh*=\";\n+\tcase BPF_MUL_VARIANT_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 6c6b8d8520cdf..92603a6a030ba 100644\n--- a/kernel/bpf/verifier.c\n+++ b/kernel/bpf/verifier.c\n@@ -15238,6 +15238,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@@ -15934,6 +15952,25 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,\n \t\tdst_reg-\u003evar_off = tnum_neg(env-\u003efake_reg[0].var_off);\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_MUL_VARIANT_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_MUL_VARIANT_SHMUL) {\n+\t\t\tscalar_min_max_shmul(dst_reg, \u0026src_reg);\n+\t\t\tbreak;\n+\t\t}\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 \t\tscalar_min_max_mul(dst_reg, \u0026src_reg);\n@@ -16059,6 +16096,11 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,\n \tif (dst_reg-\u003etype == PTR_TO_ARENA || (src_reg \u0026\u0026 src_reg-\u003etype == PTR_TO_ARENA)) {\n \t\tstruct bpf_insn_aux_data *aux = cur_aux(env);\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@@ -19338,6 +19380,21 @@ 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 == BPF_MUL_VARIANT_LO ||\n+\t\t       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 static int check_alu_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)\n {\n \tu8 class = BPF_CLASS(insn-\u003ecode);\n@@ -19393,15 +19450,9 @@ 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}\ndiff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h\nindex 732b35cc08d1c..845eee5361986 100644\n--- a/tools/include/uapi/linux/bpf.h\n+++ b/tools/include/uapi/linux/bpf.h\n@@ -34,6 +34,16 @@\n #define BPF_FROM_LE\tBPF_TO_LE\n #define BPF_FROM_BE\tBPF_TO_BE\n \n+/*\n+ * BPF_MUL variants selected by the off field.\n+ * UHMUL and SHMUL are only valid for BPF_ALU64.\n+ */\n+enum bpf_mul_variant {\n+\tBPF_MUL_VARIANT_LO    = 0,\n+\tBPF_MUL_VARIANT_UHMUL = 1,\n+\tBPF_MUL_VARIANT_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 7732df9bc8701..bf5d9b140c45a 100644\n--- a/tools/testing/selftests/bpf/prog_tests/verifier.c\n+++ b/tools/testing/selftests/bpf/prog_tests/verifier.c\n@@ -51,6 +51,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_int_ptr.skel.h\"\n #include \"verifier_iterating_callbacks.skel.h\"\n #include \"verifier_jeq_infer_not_null.skel.h\"\n@@ -217,6 +218,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_int_ptr(void)              { RUN(verifier_int_ptr); }\n void test_verifier_iterating_callbacks(void)  { RUN(verifier_iterating_callbacks); }\n void test_verifier_jeq_infer_not_null(void)   { RUN(verifier_jeq_infer_not_null); }\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..197ceac3b7980\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/verifier_hmul.c\n@@ -0,0 +1,284 @@\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, \\\n+\t\t     BPF_MUL_VARIANT_UHMUL, 0)\n+\n+#define BPF_UHMUL64_IMM(DST, IMM) \\\n+\tBPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, \\\n+\t\t     BPF_MUL_VARIANT_UHMUL, IMM)\n+\n+#define BPF_SHMUL64_REG(DST, SRC) \\\n+\tBPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_X, DST, SRC, \\\n+\t\t     BPF_MUL_VARIANT_SHMUL, 0)\n+\n+#define BPF_SHMUL64_IMM(DST, IMM) \\\n+\tBPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, \\\n+\t\t     BPF_MUL_VARIANT_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(__BPF_FEATURE_ADDR_SPACE_CAST)\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+__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+__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+#endif\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_value_illegal_alu.c b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c\nindex 4d8273c258d51..d7fb6b71b2061 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@@ -202,7 +202,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@@ -212,5 +213,11 @@ 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,\n+\t\t       BPF_MUL_VARIANT_UHMUL, 0)\n+DEFINE_BAD_OFFSET_TEST(bad_shmul32_k, BPF_ALU | BPF_MUL | BPF_K,\n+\t\t       BPF_MUL_VARIANT_SHMUL, 0)\n \n char _license[] SEC(\"license\") = \"GPL\";\n"
}

2/1 2026/09/18 20:53 agent patch-evaluator
0m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "BPF_JIT"
  ],
  "FocusSymbols": [
    "check_alu_fields",
    "adjust_scalar_min_max_vals",
    "adjust_reg_min_max_vals",
    "scalar_min_max_uhmul",
    "scalar_min_max_shmul",
    "check_alu_op",
    "do_jit",
    "bpf_int_jit_compile",
    "___bpf_prog_run"
  ],
  "Reasoning": "The patch implements two new BPF instructions (UHMUL and SHMUL for 64-bit unsigned and signed high-half multiplication) across the BPF verifier, interpreter, and JIT compilers (including x86-64). This touches core reachable kernel paths reachable via the bpf() syscall. Fuzzing is warranted to test verifier bounds tracking, instruction validation, and x86 JIT code generation (such as register preservation for RAX/RDX around mul/imul instructions).",
  "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 07f3ca6345148982e2a8fbc63d6d227638cb9458
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Sep 18 20:53:37 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..3c2cde11fa234 100644
--- a/Documentation/bpf/standardization/instruction-set.rst
+++ b/Documentation/bpf/standardization/instruction-set.rst
@@ -330,6 +330,8 @@ register.
   ADD    0x0    0        dst += src
   SUB    0x1    0        dst -= src
   MUL    0x2    0        dst \*= src
+  UHMUL  0x2    1        unsigned high-half multiplication (``ALU64`` only)
+  SHMUL  0x2    2        signed high-half multiplication (``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 +381,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, 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.
+
+For ``ALU64`` multiplication, ``offset == 1`` selects unsigned
+high-half multiplication (``UHMUL``), and ``offset == 2`` selects
+signed high-half multiplication (``SHMUL``).
+
+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.
+
 The division and modulo operations support both unsigned and signed flavors.
 
 For unsigned operations (``DIV`` and ``MOD``), for ``ALU``,
diff --git a/arch/arc/net/bpf_jit_core.c b/arch/arc/net/bpf_jit_core.c
index 639a2736f029e..78b1819cee5a6 100644
--- a/arch/arc/net/bpf_jit_core.c
+++ b/arch/arc/net/bpf_jit_core.c
@@ -734,6 +734,9 @@ static int handle_insn(struct jit_context *ctx, u32 idx)
 	u8  len = 0;
 	int ret = 0;
 
+	if (bpf_insn_is_hmul(insn))
+		return -EOPNOTSUPP;
+
 	switch (code) {
 	/* dst += src (32-bit) */
 	case BPF_ALU | BPF_ADD | BPF_X:
diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
index 9ede81afbc50e..aa466fc79d964 100644
--- a/arch/arm/net/bpf_jit_32.c
+++ b/arch/arm/net/bpf_jit_32.c
@@ -1611,6 +1611,9 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
 } while (0)
 #define check_imm24(imm) check_imm(24, imm)
 
+	if (bpf_insn_is_hmul(insn))
+		goto notyet;
+
 	switch (code) {
 	/* ALU operations */
 
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 6c04fee468766..054c38775dd22 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_MUL_VARIANT_UHMUL)
+		emit(A64_UMULH(dst, dst, src), ctx);
+	else if (is64 && off == BPF_MUL_VARIANT_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)) +
@@ -1454,7 +1465,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:
@@ -1583,7 +1594,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:
diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
index 4da2789009383..7bb3813fda8e9 100644
--- a/arch/loongarch/net/bpf_jit.c
+++ b/arch/loongarch/net/bpf_jit.c
@@ -709,6 +709,9 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
 	const s32 imm = insn->imm;
 	const bool is32 = BPF_CLASS(insn->code) == BPF_ALU || BPF_CLASS(insn->code) == BPF_JMP32;
 
+	if (bpf_insn_is_hmul(insn))
+		return -EOPNOTSUPP;
+
 	switch (code) {
 	/* dst = src */
 	case BPF_ALU | BPF_MOV | BPF_X:
diff --git a/arch/mips/net/bpf_jit_comp32.c b/arch/mips/net/bpf_jit_comp32.c
index 40a878b672f5d..1afe15162af20 100644
--- a/arch/mips/net/bpf_jit_comp32.c
+++ b/arch/mips/net/bpf_jit_comp32.c
@@ -1472,6 +1472,9 @@ int build_insn(const struct bpf_insn *insn, struct jit_context *ctx)
 	s32 val, rel;
 	u8 alu, jmp;
 
+	if (bpf_insn_is_hmul(insn))
+		goto notyet;
+
 	switch (code) {
 	/* ALU operations */
 	/* dst = imm */
diff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c
index fa7e9aa37f498..a9765ea252824 100644
--- a/arch/mips/net/bpf_jit_comp64.c
+++ b/arch/mips/net/bpf_jit_comp64.c
@@ -643,6 +643,9 @@ int build_insn(const struct bpf_insn *insn, struct jit_context *ctx)
 	s32 val, rel;
 	u8 alu, jmp;
 
+	if (bpf_insn_is_hmul(insn))
+		goto notyet;
+
 	switch (code) {
 	/* ALU operations */
 	/* dst = imm */
diff --git a/arch/parisc/net/bpf_jit_comp32.c b/arch/parisc/net/bpf_jit_comp32.c
index 5ff0cf925fe95..6bf72d04855ba 100644
--- a/arch/parisc/net/bpf_jit_comp32.c
+++ b/arch/parisc/net/bpf_jit_comp32.c
@@ -1133,6 +1133,9 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct hppa_jit_context *ctx,
 		BPF_CLASS(code), code, (code & BPF_ALU64) ? 1:0, BPF_SIZE(code),
 		BPF_OP(code), insn->src_reg, insn->dst_reg);
 
+	if (bpf_insn_is_hmul(insn))
+		return -EOPNOTSUPP;
+
 	switch (code) {
 	/* dst = src */
 	case BPF_ALU64 | BPF_MOV | BPF_X:
diff --git a/arch/parisc/net/bpf_jit_comp64.c b/arch/parisc/net/bpf_jit_comp64.c
index 54b0d5e25e024..36b6078a146f8 100644
--- a/arch/parisc/net/bpf_jit_comp64.c
+++ b/arch/parisc/net/bpf_jit_comp64.c
@@ -603,6 +603,9 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct hppa_jit_context *ctx,
 
 	init_regs(&rd, &rs, insn, ctx);
 
+	if (bpf_insn_is_hmul(insn))
+		return -EOPNOTSUPP;
+
 	switch (code) {
 	/* dst = src */
 	case BPF_ALU | BPF_MOV | BPF_X:
diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c
index bfdc50740da8e..6bfc97a029d73 100644
--- a/arch/powerpc/net/bpf_jit_comp32.c
+++ b/arch/powerpc/net/bpf_jit_comp32.c
@@ -349,6 +349,9 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
 		u32 true_cond;
 		u32 tmp_idx;
 
+		if (bpf_insn_is_hmul(&insn[i]))
+			return -EOPNOTSUPP;
+
 		if (i && (BPF_CLASS(code) == BPF_ALU64 || BPF_CLASS(code) == BPF_ALU) &&
 		    (BPF_CLASS(prevcode) == BPF_ALU64 || BPF_CLASS(prevcode) == BPF_ALU) &&
 		    BPF_OP(prevcode) == BPF_MOV && BPF_SRC(prevcode) == BPF_X &&
diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c
index fc9db691e8203..192c96e0ed34a 100644
--- a/arch/powerpc/net/bpf_jit_comp64.c
+++ b/arch/powerpc/net/bpf_jit_comp64.c
@@ -992,6 +992,9 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
 		u32 tmp_idx;
 		u32 jmp_off;
 
+		if (bpf_insn_is_hmul(&insn[i]))
+			return -EOPNOTSUPP;
+
 		/*
 		 * addrs[] maps a BPF bytecode address into a real offset from
 		 * the start of the body code.
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_comp32.c b/arch/riscv/net/bpf_jit_comp32.c
index a9e0bd5cc81d2..64bc6779d25c7 100644
--- a/arch/riscv/net/bpf_jit_comp32.c
+++ b/arch/riscv/net/bpf_jit_comp32.c
@@ -1014,6 +1014,9 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
 	const s8 *tmp1 = bpf2rv32[TMP_REG_1];
 	const s8 *tmp2 = bpf2rv32[TMP_REG_2];
 
+	if (bpf_insn_is_hmul(insn))
+		goto notsupported;
+
 	switch (code) {
 	case BPF_ALU64 | BPF_MOV | BPF_X:
 		if (insn->off != 0) {
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index ed0a6f871deac..a773506a92093 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_MUL_VARIANT_UHMUL)
+		emit(rv_mulhu(rd, rd, rs), ctx);
+	else if (off == BPF_MUL_VARIANT_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;
@@ -1498,7 +1511,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;
@@ -1634,8 +1647,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;
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index c4b47070bb590..9e5c865d5ea8c 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -985,6 +985,9 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
 
 	bpf_jit_probe_init(&probe);
 
+	if (bpf_insn_is_hmul(insn))
+		return -EOPNOTSUPP;
+
 	switch (insn->code) {
 	/*
 	 * BPF_MOV
diff --git a/arch/sparc/net/bpf_jit_comp_64.c b/arch/sparc/net/bpf_jit_comp_64.c
index 2fa0e93751276..1154ddc515b0f 100644
--- a/arch/sparc/net/bpf_jit_comp_64.c
+++ b/arch/sparc/net/bpf_jit_comp_64.c
@@ -901,6 +901,9 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
 	const s16 off = insn->off;
 	const s32 imm = insn->imm;
 
+	if (bpf_insn_is_hmul(insn))
+		return -EOPNOTSUPP;
+
 	if (insn->src_reg == BPF_REG_FP)
 		ctx->saw_frame_pointer = true;
 
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index d4a980140b48d..645d0ac4db040 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -1225,6 +1225,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)
 {
@@ -2332,6 +2364,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_MUL_VARIANT_SHMUL);
+				break;
+			}
+
 			maybe_emit_mod(&prog, dst_reg, dst_reg,
 				       BPF_CLASS(insn->code) == BPF_ALU64);
 
@@ -2348,6 +2388,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_MUL_VARIANT_SHMUL);
+				break;
+			}
+
 			maybe_emit_mod(&prog, src_reg, dst_reg,
 				       BPF_CLASS(insn->code) == BPF_ALU64);
 
diff --git a/arch/x86/net/bpf_jit_comp32.c b/arch/x86/net/bpf_jit_comp32.c
index 852baf2e4db4d..11ed65130d1e5 100644
--- a/arch/x86/net/bpf_jit_comp32.c
+++ b/arch/x86/net/bpf_jit_comp32.c
@@ -1683,6 +1683,9 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
 		int ilen;
 		u8 *func;
 
+		if (bpf_insn_is_hmul(insn))
+			goto notyet;
+
 		switch (code) {
 		/* ALU operations */
 		/* dst = src */
diff --git a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
index 1caa87da72b51..effce27f3b88e 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
@@ -3,6 +3,7 @@
 
 #include <linux/bpf.h>
 #include <linux/bpf_verifier.h>
+#include <linux/filter.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>
 #include <linux/pkt_cls.h>
@@ -561,6 +562,11 @@ nfp_bpf_check_alu(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta,
 	const struct bpf_reg_state *dreg =
 		cur_regs(env) + meta->insn.dst_reg;
 
+	if (bpf_insn_is_hmul(&meta->insn)) {
+		pr_vlog(env, "UHMUL/SHMUL are not supported\n");
+		return -EOPNOTSUPP;
+	}
+
 	meta->umin_src = min(meta->umin_src, reg_umin(sreg));
 	meta->umax_src = max(meta->umax_src, reg_umax(sreg));
 	meta->umin_dst = min(meta->umin_dst, reg_umin(dreg));
diff --git a/include/linux/filter.h b/include/linux/filter.h
index b17222db2efc3..b6dc4b968a9cd 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>
 
@@ -147,6 +148,44 @@ 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_is_hmul_variant(s16 off)
+{
+	return off == BPF_MUL_VARIANT_UHMUL ||
+	       off == BPF_MUL_VARIANT_SHMUL;
+}
+
+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 &&
+	       bpf_is_hmul_variant(insn->off);
+}
+
 /* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */
 
 #define BPF_ENDIAN(TYPE, DST, LEN)				\
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 732b35cc08d1c..845eee5361986 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -34,6 +34,16 @@
 #define BPF_FROM_LE	BPF_TO_LE
 #define BPF_FROM_BE	BPF_TO_BE
 
+/*
+ * BPF_MUL variants selected by the off field.
+ * UHMUL and SHMUL are only valid for BPF_ALU64.
+ */
+enum bpf_mul_variant {
+	BPF_MUL_VARIANT_LO    = 0,
+	BPF_MUL_VARIANT_UHMUL = 1,
+	BPF_MUL_VARIANT_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 4e208cc94752f..4f746973481b9 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1931,7 +1931,50 @@ 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 BPF_MUL_VARIANT_LO:
+			DST = DST * SRC;
+			break;
+		case BPF_MUL_VARIANT_UHMUL:
+			DST = bpf_uhmul64(DST, SRC);
+			break;
+		case BPF_MUL_VARIANT_SHMUL:
+			DST = bpf_shmul64((s64)DST, (s64)SRC);
+			break;
+		default:
+			goto default_label;
+		}
+		CONT;
+	ALU_MUL_X:
+		if (OFF != BPF_MUL_VARIANT_LO)
+			goto default_label;
+		DST = (u32) DST * (u32) SRC;
+		CONT;
+	ALU64_MUL_K:
+		switch (OFF) {
+		case BPF_MUL_VARIANT_LO:
+			DST = DST * IMM;
+			break;
+		case BPF_MUL_VARIANT_UHMUL:
+			DST = bpf_uhmul64(DST, (u64)IMM);
+			break;
+		case BPF_MUL_VARIANT_SHMUL:
+			DST = bpf_shmul64((s64)DST, (s32)IMM);
+			break;
+		default:
+			goto default_label;
+		}
+		CONT;
+	ALU_MUL_K:
+		if (OFF != BPF_MUL_VARIANT_LO)
+			goto default_label;
+		DST = (u32) DST * (u32) IMM;
+		CONT;
 	SHT(LSH, <<)
 	SHT(RSH, >>)
 #undef SHT
diff --git a/kernel/bpf/disasm.c b/kernel/bpf/disasm.c
index 3ce8d74b0e400..03f22845e1692 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_MUL_VARIANT_UHMUL:
+		return "uh*=";
+	case BPF_MUL_VARIANT_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 6c6b8d8520cdf..92603a6a030ba 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -15238,6 +15238,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)
 {
@@ -15934,6 +15952,25 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,
 		dst_reg->var_off = tnum_neg(env->fake_reg[0].var_off);
 		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_MUL_VARIANT_UHMUL) {
+			scalar_min_max_uhmul(dst_reg, &src_reg);
+			break;
+		}
+		if (!alu32 && insn->off == BPF_MUL_VARIANT_SHMUL) {
+			scalar_min_max_shmul(dst_reg, &src_reg);
+			break;
+		}
 		dst_reg->var_off = tnum_mul(dst_reg->var_off, src_reg.var_off);
 		scalar32_min_max_mul(dst_reg, &src_reg);
 		scalar_min_max_mul(dst_reg, &src_reg);
@@ -16059,6 +16096,11 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
 	if (dst_reg->type == PTR_TO_ARENA || (src_reg && src_reg->type == PTR_TO_ARENA)) {
 		struct bpf_insn_aux_data *aux = cur_aux(env);
 
+		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;
 
@@ -19338,6 +19380,21 @@ 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 == BPF_MUL_VARIANT_LO ||
+		       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;
+	}
+}
+
 static int check_alu_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)
 {
 	u8 class = BPF_CLASS(insn->code);
@@ -19393,15 +19450,9 @@ 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;
 		}
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 732b35cc08d1c..845eee5361986 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -34,6 +34,16 @@
 #define BPF_FROM_LE	BPF_TO_LE
 #define BPF_FROM_BE	BPF_TO_BE
 
+/*
+ * BPF_MUL variants selected by the off field.
+ * UHMUL and SHMUL are only valid for BPF_ALU64.
+ */
+enum bpf_mul_variant {
+	BPF_MUL_VARIANT_LO    = 0,
+	BPF_MUL_VARIANT_UHMUL = 1,
+	BPF_MUL_VARIANT_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 7732df9bc8701..bf5d9b140c45a 100644
--- a/tools/testing/selftests/bpf/prog_tests/verifier.c
+++ b/tools/testing/selftests/bpf/prog_tests/verifier.c
@@ -51,6 +51,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_int_ptr.skel.h"
 #include "verifier_iterating_callbacks.skel.h"
 #include "verifier_jeq_infer_not_null.skel.h"
@@ -217,6 +218,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_int_ptr(void)              { RUN(verifier_int_ptr); }
 void test_verifier_iterating_callbacks(void)  { RUN(verifier_iterating_callbacks); }
 void test_verifier_jeq_infer_not_null(void)   { RUN(verifier_jeq_infer_not_null); }
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..197ceac3b7980
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/verifier_hmul.c
@@ -0,0 +1,284 @@
+// 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_MUL_VARIANT_UHMUL, 0)
+
+#define BPF_UHMUL64_IMM(DST, IMM) \
+	BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, \
+		     BPF_MUL_VARIANT_UHMUL, IMM)
+
+#define BPF_SHMUL64_REG(DST, SRC) \
+	BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_X, DST, SRC, \
+		     BPF_MUL_VARIANT_SHMUL, 0)
+
+#define BPF_SHMUL64_IMM(DST, IMM) \
+	BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, \
+		     BPF_MUL_VARIANT_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(__BPF_FEATURE_ADDR_SPACE_CAST)
+
+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")
+__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")
+__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);
+}
+
+#endif
+
+#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_value_illegal_alu.c b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
index 4d8273c258d51..d7fb6b71b2061 100644
--- a/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
+++ b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
@@ -202,7 +202,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.
  */
@@ -212,5 +213,11 @@ 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_MUL_VARIANT_UHMUL, 0)
+DEFINE_BAD_OFFSET_TEST(bad_shmul32_k, BPF_ALU | BPF_MUL | BPF_K,
+		       BPF_MUL_VARIANT_SHMUL, 0)
 
 char _license[] SEC("license") = "GPL";

3/2 2026/09/18 20:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 20473
							output: 31
							thoughts: 907
						

Thoughts:
**Syzkaller Fuzzing Evaluation: BPF High-Half Multiplication Instructions**

Okay, let's break this down. The patch introduces new BPF instructions, `UHMUL` and `SHMUL`, for unsigned and signed high-half 64-bit multiplication. Seems pretty straightforward, adding multiplication operations. Now, let's see where this touches.

The patch's changes document the new instructions, but the real meat is in the architecture-specific JIT compilers and the core BPF components. It *implements* `SMULH`/`UMULH` for ARM64 and RISC-V. The x86_64 JIT compiler also gets an implementation, with `emit_hmul_aux` handling for `BPF_ALU64 | BPF_MUL` and the new `hmul`. Other architectures reject the new instruction. There's also changes in the BPF verifier (with new scalar min/max helpers and related adjustments), interpreter support, disassembler, and a selftest suite. It also includes new definitions for these instructions in several header files.

Crucially, this modification directly impacts the BPF verifier, the interpreter, and the x86_64 JIT compiler. All of these components are accessible via the `bpf()` syscall. This is a big flashing sign that screams "fuzz me!" The BPF verifier's range tracking logic, the JIT code generation, particularly with x86 stack manipulation and register saving and restoring, and the interpreter logic are all potential areas with subtle bugs and edge cases that fuzzing could unearth.

Looking at the evaluation criteria, this clearly falls into "Any logic modifications in... BPF..." which means this is **definitely** worth fuzzing. We have new instructions that have been added to the instruction set and implemented in critical parts of the BPF ecosystem.

Now, we need to check the Kconfig options. We'll need to enable BPF, BPF_SYSCALL, and BPF_JIT for this to be properly tested by Syzkaller.



4/2 2026/09/18 20:53 tool grepper
0m Args:
{
  "Expression": "config BPF_JIT",
  "PathPrefix": "kernel/bpf/"
}

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=96=config BPF_LSM\n--\nkernel/bpf/Kconfig-107-\nkernel/bpf/Kconfig:108:config BPF_JIT_KASAN\nkernel/bpf/Kconfig-109-\tbool\n"
}

5/2 2026/09/18 20:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22152
							output: 34
							thoughts: 30
						

Thoughts:
Okay, here's my take on those thoughts, framed as an expert's internal monologue:

**Checking BPF Configuration Options**

Alright, time to dive into the kernel configuration. I need to refresh my memory on the interplay between `BPF_SYSCALL` and `BPF_JIT` within `kernel/bpf/Kconfig`. These two are fundamental to how BPF works, and I want to make sure I've got the latest understanding of their dependencies and implications. My concern is around any recent changes that might influence their behavior or how they are used together. I'm especially interested in whether any new configurations or default settings have been introduced or if there are any subtle conflicts. I'm going to look for any hidden dependencies, conditionals, or warnings around these symbols to make sure I am working with an accurate and up-to-date representation of how the system expects these parameters to work. It's time to dig in and reacquaint myself with the details.



6/2 2026/09/18 20:53 tool read-file
0m Args:
{
  "File": "kernel/bpf/Kconfig",
  "FirstLine": 25,
  "LineCount": 40
}

Results:
{
  "Contents": "  25:\t# default for kernels that were compiled with BPF JIT support.\n  26:\tconfig ARCH_WANT_DEFAULT_BPF_JIT\n  27:\t\tbool\n  28:\t\n  29:\tmenu \"BPF subsystem\"\n  30:\t\n  31:\tconfig BPF_SYSCALL\n  32:\t\tbool \"Enable bpf() system call\"\n  33:\t\tselect BPF\n  34:\t\tselect IRQ_WORK\n  35:\t\tselect NEED_TASKS_RCU\n  36:\t\tselect TASKS_TRACE_RCU\n  37:\t\tselect BINARY_PRINTF\n  38:\t\tselect NET_SOCK_MSG if NET\n  39:\t\tselect NET_XGRESS if NET\n  40:\t\tselect PAGE_POOL if NET\n  41:\t\tdefault n\n  42:\t\thelp\n  43:\t\t  Enable the bpf() system call that allows to manipulate BPF programs\n  44:\t\t  and maps via file descriptors.\n  45:\t\n  46:\tconfig BPF_JIT\n  47:\t\tbool \"Enable BPF Just In Time compiler\"\n  48:\t\tdepends on BPF\n  49:\t\tdepends on HAVE_CBPF_JIT || HAVE_EBPF_JIT\n  50:\t\tselect EXECMEM\n  51:\t\thelp\n  52:\t\t  BPF programs are normally handled by a BPF interpreter. This option\n  53:\t\t  allows the kernel to generate native code when a program is loaded\n  54:\t\t  into the kernel. This will significantly speed-up processing of BPF\n  55:\t\t  programs.\n  56:\t\n  57:\t\t  Note, an admin should enable this feature changing:\n  58:\t\t  /proc/sys/net/core/bpf_jit_enable\n  59:\t\t  /proc/sys/net/core/bpf_jit_harden   (optional)\n  60:\t\t  /proc/sys/net/core/bpf_jit_kallsyms (optional)\n  61:\t\n  62:\tconfig BPF_JIT_ALWAYS_ON\n  63:\t\tbool \"Permanently enable BPF JIT and remove BPF interpreter\"\n  64:\t\tdepends on BPF_SYSCALL \u0026\u0026 HAVE_EBPF_JIT \u0026\u0026 BPF_JIT\n"
}

7/2 2026/09/18 20:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23010
							output: 36
							thoughts: 123
						

Thoughts:
**My BPF Implementation Overview**

Okay, so I need to get a clear picture of how this BPF stuff works, and where all the pieces are. Right, so first off, the `BPF_SYSCALL` is *critical*. That's the gateway, the system call needed to actually load BPF programs and, crucially, to run the verifier. That verifier is in `kernel/bpf/verifier.c`.  I *know* I need to keep that in mind.

Then we've got the JIT compiler. `BPF_JIT` enables the x86 BPF JIT compiler – always good to speed things up – and that lives in `arch/x86/net/bpf_jit_comp.c`. Of course, this only applies to x86.

And then, just to round things out, I need to know where the *interpreter* lives. `___bpf_prog_run`, that core logic for actually *executing* the BPF bytecode, is in `kernel/bpf/core.c`.  I should make a note of that, so I can find it later when I need to.

Now, I think I need to dig into the Makefiles. I'll take a quick look at the `kernel/bpf/` and `arch/x86/net/` Makefiles, just to make sure I'm not missing anything obvious and to understand the build process.



8/2 2026/09/18 20:53 tool grepper
0m Args:
{
  "Expression": "bpf_jit_comp\\.o",
  "PathPrefix": "arch/x86/net/"
}

Results:
{
  "Output": "arch/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"
}

9/2 2026/09/18 20:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23568
							output: 28
							thoughts: 12
						

Thoughts:
Here's my take on those thoughts, tailored for an expert audience:

**Diving into the BPF Makefile**

Alright, time to get my hands dirty. My initial thought is to zero in on `kernel/bpf/Makefile`. That's where I need to start. I know all the BPF magic is orchestrated from within the kernel, and the Makefile, in this specific subdirectory, is going to be the heart of the build process for the BPF infrastructure. It's the key to understanding how everything fits together – the compilation of helper functions, the linking of various BPF programs, the generation of the necessary headers, and how they ultimately get integrated. I need to understand the dependencies and build rules in that file. That file contains crucial information, and this is where I would hope to find the build configuration. What are the dependencies? How are various BPF programs compiled and linked? Are there any compiler flags that need attention? It's time to dig in and see what secrets it holds.



10/2 2026/09/18 20:53 tool grepper
0m Args:
{
  "Expression": "verifier\\.o",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/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\nkernel/bpf/Makefile-10-obj-$(CONFIG_BPF_SYSCALL) += bpf_iter.o map_iter.o task_iter.o prog_iter.o link_iter.o\n"
}

11/2 2026/09/18 20:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23984
							output: 36
							thoughts: 163
						

Thoughts:
**Analyzing BPF JIT Compilation on x86-64**

Okay, so I'm diving into this BPF JIT compilation setup, and it looks like `CONFIG_BPF_SYSCALL` and `CONFIG_BPF_JIT` are the critical kernel configurations to keep in mind. I need to get a handle on what's going on with the `FocusSymbols`, so I'll start by examining the functions that were either introduced or changed within the reachable amd64 code.

Let me take another look at the diff... right, let's start with `arch/x86/net/bpf_jit_comp.c`. I see `emit_hmul_aux`, which is *static* within that file. That means it's only called within `bpf_jit_comp.c`, specifically by `do_jit`. I'll want to focus on this, and then check any *non-static* entrypoints within `arch/x86/net/bpf_jit_comp.c` to see if there's anything else important to understand.



12/2 2026/09/18 20:53 tool grepper
0m Args:
{
  "Expression": "bpf_int_jit_compile",
  "PathPrefix": "arch/x86/net/"
}

Results:
{
  "Output": "arch/x86/net/bpf_jit_comp.c=4261=struct x64_jit_data {\n--\narch/x86/net/bpf_jit_comp.c-4272-\narch/x86/net/bpf_jit_comp.c:4273:struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)\narch/x86/net/bpf_jit_comp.c-4274-{\n--\narch/x86/net/bpf_jit_comp32.c=2519=bool bpf_jit_needs_zext(void)\n--\narch/x86/net/bpf_jit_comp32.c-2523-\narch/x86/net/bpf_jit_comp32.c:2524:struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)\narch/x86/net/bpf_jit_comp32.c-2525-{\n"
}

13/2 2026/09/18 20:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24719
							output: 32
							thoughts: 30
						

Thoughts:
Here's a summary of my immediate thought process:

**Static or Dynamic? The JIT Question**

Okay, so I'm digging into this `do_jit` function. The first thing I need to figure out is whether it's statically compiled or dynamically generated. To do that, I'll need to go straight to the source. Specifically, I should look at `arch/x86/net/bpf_jit_comp.c`. That's where the x86 BPF JIT compilation likely lives, and it'll almost certainly contain the implementation or declaration of `do_jit`. I'm hoping to understand its compilation characteristics by inspecting the code directly.



14/2 2026/09/18 20:53 tool grepper
0m Args:
{
  "Expression": "do_jit\\(",
  "PathPrefix": "arch/x86/net/"
}

Results:
{
  "Output": "arch/x86/net/bpf_jit_comp.c=1955=static int emit_kfunc_arena_args(struct bpf_prog *bpf_prog,\n--\narch/x86/net/bpf_jit_comp.c-1993-\narch/x86/net/bpf_jit_comp.c:1994:static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *addrs, u8 *image,\narch/x86/net/bpf_jit_comp.c-1995-\t\t  u8 *rw_image, int oldproglen, struct jit_context *ctx, bool jmp_padding)\n--\narch/x86/net/bpf_jit_comp.c=4273=struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)\n--\narch/x86/net/bpf_jit_comp.c-4350-\t\t\tpadding = true;\narch/x86/net/bpf_jit_comp.c:4351:\t\tproglen = do_jit(env, prog, addrs, image, rw_image, oldproglen,\narch/x86/net/bpf_jit_comp.c-4352-\t\t\t\t \u0026ctx, padding);\n--\narch/x86/net/bpf_jit_comp32.c=1569=static int emit_kfunc_call(const struct bpf_prog *bpf_prog, u8 *end_addr,\n--\narch/x86/net/bpf_jit_comp32.c-1658-\narch/x86/net/bpf_jit_comp32.c:1659:static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,\narch/x86/net/bpf_jit_comp32.c-1660-\t\t  int oldproglen, struct jit_context *ctx)\n--\narch/x86/net/bpf_jit_comp32.c=2524=struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)\n--\narch/x86/net/bpf_jit_comp32.c-2557-\tfor (pass = 0; pass \u003c 20 || image; pass++) {\narch/x86/net/bpf_jit_comp32.c:2558:\t\tproglen = do_jit(prog, addrs, image, oldproglen, \u0026ctx);\narch/x86/net/bpf_jit_comp32.c-2559-\t\tif (proglen \u003c= 0) {\n"
}

15/2 2026/09/18 20:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 25645
							output: 33
							thoughts: 191
						

Thoughts:
**Analyzing BPF Verifier Changes**

Okay, so `do_jit` is a bit of an interesting case. It's declared as static, which *should* mean it's local to its compilation unit, but the compiler's inlining decisions could change things. It could very well end up embedded within `bpf_int_jit_compile`. I need to confirm this.

Alright, let's dive into the `kernel/bpf/verifier.c` file. I need to get a handle on the changes. Right away, I see a bunch of new or modified functions: `scalar_min_max_uhmul`, `scalar_min_max_shmul`, `adjust_scalar_min_max_vals`, `adjust_reg_min_max_vals`, `is_valid_alu_variant`, and `check_alu_fields`. All static, which is typical for helper functions within a verifier.

Now, I want to trace the call paths and relationships here. Specifically, I need to know who's calling `adjust_scalar_min_max_vals` and `check_alu_fields`. And it's important to understand whether those callers are static functions, meaning they are contained within `verifier.c`, or are they global functions. This is key to understanding the scope of the changes and how they impact the overall BPF verification process. This will help inform whether these new functions introduce any new verification logic or just refactor existing code.



16/2 2026/09/18 20:54 tool grepper
0m Args:
{
  "Expression": "check_alu_fields",
  "PathPrefix": "kernel/bpf/verifier.c"
}

Results:
{
  "Output": "kernel/bpf/verifier.c=19383=static bool is_valid_alu_variant(const struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-19397-\nkernel/bpf/verifier.c:19398:static int check_alu_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)\nkernel/bpf/verifier.c-19399-{\n--\nkernel/bpf/verifier.c=19524=static int check_insn_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-19528-\tcase BPF_ALU64:\nkernel/bpf/verifier.c:19529:\t\treturn check_alu_fields(env, insn);\nkernel/bpf/verifier.c-19530-\tcase BPF_LDX:\n"
}

17/2 2026/09/18 20:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 26438
							output: 37
							thoughts: 38
						

Thoughts:
Okay, let's break this down.

**Investigating Function Call Relationships**

Right, so I'm trying to trace the data flow here. I see that `check_alu_fields` is definitely being invoked by `check_insn_fields`. That gives me a starting point. Now, the next logical question is: where does this `adjust_reg_min_max_vals` function come into play? I need to figure out what calls *it*. Understanding that will give me a better handle on how all these validation and adjustment functions are interconnected within the larger architecture. This is key to ensuring the integrity of the register state.



18/2 2026/09/18 20:54 tool grepper
0m Args:
{
  "Expression": "adjust_reg_min_max_vals",
  "PathPrefix": "kernel/bpf/verifier.c"
}

Results:
{
  "Output": "kernel/bpf/verifier.c=15901=static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-16077- */\nkernel/bpf/verifier.c:16078:static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-16079-\t\t\t\t   struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c=16250=static int check_alu_op(struct bpf_verifier_env *env, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-16425-\t\terr = check_reg_arg(env, insn-\u003edst_reg, DST_OP_NO_MARK);\nkernel/bpf/verifier.c:16426:\t\terr = err ?: adjust_reg_min_max_vals(env, insn);\nkernel/bpf/verifier.c-16427-\t\tif (err)\n"
}

19/2 2026/09/18 20:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 26930
							output: 33
							thoughts: 46
						

Thoughts:
**Analyzing the ALU Operation Checker**

Okay, so `check_alu_op` is a crucial function, and it looks like it gets called from a few important places: `do_check`, `do_check_subprogs`, and `bpf_check`. My expertise tells me these are all parts of the broader eBPF verification process. Right now, I need to understand how `check_alu_op` fits into the bigger picture. Therefore, I need to map out where all it is called to accurately gauge its impact and purpose. Let's see exactly what's triggering this function; this is key to understanding its role in ensuring the integrity and safety of the eBPF code.



20/2 2026/09/18 20:54 tool grepper
0m Args:
{
  "Expression": "check_alu_op",
  "PathPrefix": "kernel/bpf/verifier.c"
}

Results:
{
  "Output": "kernel/bpf/verifier.c=16078=static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-16249-/* check validity of 32-bit and 64-bit arithmetic operations */\nkernel/bpf/verifier.c:16250:static int check_alu_op(struct bpf_verifier_env *env, struct bpf_insn *insn)\nkernel/bpf/verifier.c-16251-{\n--\nkernel/bpf/verifier.c=18628=static int do_check_insn(struct bpf_verifier_env *env, bool *do_print_state)\n--\nkernel/bpf/verifier.c-18636-\tcase BPF_ALU64:\nkernel/bpf/verifier.c:18637:\t\treturn check_alu_op(env, insn);\nkernel/bpf/verifier.c-18638-\n"
}

21/2 2026/09/18 20:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 27421
							output: 35
							thoughts: 51
						

Thoughts:
Here's my thought process, as an expert in the field:

**Diving into the BPF Interpreter**

Okay, so I'm digging into the BPF implementation, specifically in `kernel/bpf/core.c`. My focus is zeroing in on `___bpf_prog_run`. Right, that's the interpreter itself – the heart of executing those BPF programs. I need to confirm something critical here. I need to make sure `___bpf_prog_run` is actually present as a symbol within `vmlinux`. That confirmation will inform the next stages of my investigation. Let's start there.



22/2 2026/09/18 20:54 tool grepper
0m Args:
{
  "Expression": "___bpf_prog_run",
  "PathPrefix": "kernel/bpf/core.c"
}

Results:
{
  "Output": "kernel/bpf/core.c=1848=static u64 (*interpreters_args[])(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5,\n--\nkernel/bpf/core.c-1851-/**\nkernel/bpf/core.c:1852: *\t___bpf_prog_run - run eBPF program on a given context\nkernel/bpf/core.c-1853- *\t@regs: is the array of MAX_BPF_EXT_REG eBPF pseudo-registers\n--\nkernel/bpf/core.c-1859- */\nkernel/bpf/core.c:1860:static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)\nkernel/bpf/core.c-1861-{\n--\nkernel/bpf/core.c=2452=static unsigned int PROG_NAME(stack_size)(const void *ctx, const struct bpf_insn *insn) \\\n--\nkernel/bpf/core.c-2459-\tARG1 = (u64) (unsigned long) ctx; \\\nkernel/bpf/core.c:2460:\treturn ___bpf_prog_run(regs, insn); \\\nkernel/bpf/core.c-2461-}\n--\nkernel/bpf/core.c=2465=static u64 PROG_NAME_ARGS(stack_size)(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5, \\\n--\nkernel/bpf/core.c-2477-\tBPF_R5 = r5; \\\nkernel/bpf/core.c:2478:\treturn ___bpf_prog_run(regs, insn); \\\nkernel/bpf/core.c-2479-}\n"
}

23/2 2026/09/18 20:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 28140
							output: 34
							thoughts: 22
						

Thoughts:
Here's a summary of my thought process, as if I were the one thinking it:

**Diving into the BPF Verifier**

Okay, so I'm digging into this BPF verifier code again. Specifically, I'm focusing on the `bpf_check` function within `kernel/bpf/verifier.c`. This is the core of the validation process, and I know from experience that this is where the interesting stuff happens. I need to refresh my understanding of the control flow analysis this function performs. I suspect there are nuances with register allocation and stack access checking that I'd like to revisit. I want to pay particularly close attention to how it handles potential overflows. I'm also going to see if any optimization strategies are applied during verification. I want to check for any potential weaknesses, especially those that have been exploited in the past, and see if the checks have been improved in recent kernels. Essentially, I'm looking for the most fundamental aspects of verifying BPF programs. My goal is to solidify my understanding of the core logic and be prepared for more complex analyses or potential debugging scenarios.



24/2 2026/09/18 20:54 tool grepper
0m Args:
{
  "Expression": "int bpf_check\\(",
  "PathPrefix": "kernel/bpf/verifier.c"
}

Results:
{
  "Output": "kernel/bpf/verifier.c=21438=static int bpf_prog_verify_signature(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-21561-\nkernel/bpf/verifier.c:21562:int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,\nkernel/bpf/verifier.c-21563-\t      struct bpf_log_attr *attr_log)\n"
}

25/2 2026/09/18 20:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 28572
							output: 32
							thoughts: 71
						

Thoughts:
**Dissecting the BPF Disassembly Modification**

Alright, let's dive into this. The first step is clear: I need to check `kernel/bpf/disasm.c`. That's where any changes to the disassembly process are likely to reside. Ah, I see, they've touched `print_bpf_insn`. Now, the critical question is, what's the role of `print_bpf_insn`? Is it a general-purpose entry point, or something specific to a particular feature or use case within the BPF subsystem? *Wait, of course!* It's the verifier log disassembler! That makes complete sense. Given that context, I need to understand *how* it was modified and what those changes imply for the verifier logs. Time to meticulously dissect the `print_bpf_insn` function itself.



26/2 2026/09/18 20:54 tool grepper
0m Args:
{
  "Expression": "print_bpf_insn",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/diagnostics.c=608=static void format_disasm_line(struct bpf_verifier_env *env, int insn_idx,\n--\nkernel/bpf/diagnostics.c-632-\nkernel/bpf/diagnostics.c:633:\tprint_bpf_insn(\u0026cbs, insn, env-\u003eallow_ptr_leaks);\nkernel/bpf/diagnostics.c-634-\tseq_buf_str(\u0026ctx.seq);\n--\nkernel/bpf/disasm.c=200=static inline bool is_mov_percpu_addr(const struct bpf_insn *insn)\n--\nkernel/bpf/disasm.c-204-\nkernel/bpf/disasm.c:205:void print_bpf_insn(const struct bpf_insn_cbs *cbs,\nkernel/bpf/disasm.c-206-\t\t    const struct bpf_insn *insn,\n--\nkernel/bpf/disasm.h=30=struct bpf_insn_cbs {\n--\nkernel/bpf/disasm.h-36-\nkernel/bpf/disasm.h:37:void print_bpf_insn(const struct bpf_insn_cbs *cbs,\nkernel/bpf/disasm.h-38-\t\t    const struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c=3395=void bpf_verbose_insn(struct bpf_verifier_env *env, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-3402-\nkernel/bpf/verifier.c:3403:\tprint_bpf_insn(\u0026cbs, insn, env-\u003eallow_ptr_leaks);\nkernel/bpf/verifier.c-3404-}\n"
}

27/2 2026/09/18 20:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29344
							output: 39
							thoughts: 410
						

Thoughts:
**Analyzing BPF Function Calls**

Okay, let's dive into this. My first thought is to zero in on these functions and their context. We're talking BPF, so the verifier is a key starting point. `bpf_check` in `kernel/bpf/verifier.c` is the top-level verification function, which, while important, is likely not the only function involved in BPF.

Now, let's get granular. I need to understand the relationship between `bpf_check` and its constituents. Digging deeper, I see functions such as `check_alu_op`, `adjust_scalar_min_max_vals`, `adjust_reg_min_max_vals`, `scalar_min_max_uhmul`, `scalar_min_max_shmul`, and `check_alu_fields` within `kernel/bpf/verifier.c`. These are crucial for handling arithmetic logic unit (ALU) operations and adjusting scalar/register minimum and maximum values.

Next, I need to see if there is any other context these functions appear in. Shifting gears slightly, there's `arch/x86/net/bpf_jit_comp.c`, which contains functions related to JIT compilation like `emit_hmul_aux`, `do_jit`, and `bpf_int_jit_compile`. Also, `___bpf_prog_run` in `kernel/bpf/core.c` and `print_bpf_insn` in `kernel/bpf/disasm.c` are notable.

Now, a critical question: Are these functions inlined or are they actual symbols? Considering the typical kernel structure, functions like `adjust_scalar_min_max_vals`, `check_alu_op`, `adjust_reg_min_max_vals`, `do_jit`, `check_alu_fields`, and `bpf_int_jit_compile` are almost certainly *not* inlined. They're typically substantial, often involving large switch statements or complex logic. These functions will be present in kallsyms unless inlined which is unlikely. So, I need to check how long the function `adjust_scalar_min_max_vals` is, to confirm this hypothesis.



28/2 2026/09/18 20:54 tool grepper
0m Args:
{
  "Expression": "static int adjust_scalar_min_max_vals",
  "PathPrefix": "kernel/bpf/verifier.c"
}

Results:
{
  "Output": "kernel/bpf/verifier.c=15868=static int maybe_fork_scalars(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-15900- */\nkernel/bpf/verifier.c:15901:static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-15902-\t\t\t\t      struct bpf_insn *insn,\n"
}

29/2 2026/09/18 20:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30421
							output: 240
							thoughts: 1391
						

Thoughts:
**Analysis of BPF UHMUL/SHMUL Instruction Patch for Fuzzing**

Okay, let's break this down. We have a "WorthFuzzing=true" situation, which means we need a focused fuzzing strategy. The core of this patch introduces support for the UHMUL and SHMUL (unsigned and signed high-half multiplication) instructions within the BPF subsystem. This involves changes across the verifier, interpreter, and JIT compiler.

First, I identified the key functions to target.  `adjust_scalar_min_max_vals`, `check_alu_op`, and `check_alu_fields` are crucial for the verifier, particularly handling the new multiplication instructions. `do_jit` is a significant function for the JIT compiler, and `bpf_int_jit_compile` is also relevant. Also, we have functions in the core.c file: `___bpf_prog_run`, and static functions in filter.h like `bpf_uhmul64` and `bpf_shmul64`.  Given the guidelines, I made sure to prioritize feature-specific functions while avoiding ubiquitous ones.  Specifically, I've avoided generic memory allocators etc.

The critical functions from a fuzzing perspective appear to be: `check_alu_fields`, `adjust_scalar_min_max_vals`, `adjust_reg_min_max_vals`, `scalar_min_max_uhmul`, `scalar_min_max_shmul`, `check_alu_op`, `do_jit`, `bpf_int_jit_compile`, and `___bpf_prog_run`. These should provide excellent coverage for the new logic.

Next, I looked at dependencies and configurations. The `bpf_uhmul64` and `bpf_shmul64` static inline functions in `filter.h` do not introduce additional config requirements beyond standard kernel headers. The relevant configurations are `BPF_SYSCALL` and `BPF_JIT`.  The `Kconfig` confirms `BPF_SYSCALL` selects `BPF`, and `BPF_JIT` depends on `BPF`, so these are standard and sufficient.

In summary, the patch introduces new BPF instructions (UHMUL/SHMUL) and implements their support in the BPF verifier, interpreter, and JIT compiler. The instructions are reachable by the bpf(BPF_PROG_LOAD, ...) syscall. This makes it an ideal target for fuzzing. Potential issues could be in scalar range tracking, register clobbering, or arithmetic edge cases.

I'm now confident that the `FocusSymbols` and configurations are accurate and should guide the fuzzer effectively. Ready to call `set-results`.



30/2 2026/09/18 20:54 tool set-results
0m Args:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "BPF_JIT"
  ],
  "FocusSymbols": [
    "check_alu_fields",
    "adjust_scalar_min_max_vals",
    "adjust_reg_min_max_vals",
    "scalar_min_max_uhmul",
    "scalar_min_max_shmul",
    "check_alu_op",
    "do_jit",
    "bpf_int_jit_compile",
    "___bpf_prog_run"
  ],
  "Reasoning": "The patch implements two new BPF instructions (UHMUL and SHMUL for 64-bit unsigned and signed high-half multiplication) across the BPF verifier, interpreter, and JIT compilers (including x86-64). This touches core reachable kernel paths reachable via the bpf() syscall. Fuzzing is warranted to test verifier bounds tracking, instruction validation, and x86 JIT code generation (such as register preservation for RAX/RDX around mul/imul instructions).",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "BPF_JIT"
  ],
  "FocusSymbols": [
    "check_alu_fields",
    "adjust_scalar_min_max_vals",
    "adjust_reg_min_max_vals",
    "scalar_min_max_uhmul",
    "scalar_min_max_shmul",
    "check_alu_op",
    "do_jit",
    "bpf_int_jit_compile",
    "___bpf_prog_run"
  ],
  "Reasoning": "The patch implements two new BPF instructions (UHMUL and SHMUL for 64-bit unsigned and signed high-half multiplication) across the BPF verifier, interpreter, and JIT compilers (including x86-64). This touches core reachable kernel paths reachable via the bpf() syscall. Fuzzing is warranted to test verifier bounds tracking, instruction validation, and x86 JIT code generation (such as register preservation for RAX/RDX around mul/imul instructions).",
  "WorthFuzzing": true
}

31/1 2026/09/18 20:54 action If
0m Args:
{
  "WorthFuzzing": true
}

Results:
null

32/2 2026/09/18 20:54 agent kmsan-evaluator
0m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch series implements support for BPF 64-bit high-half multiplication instructions (UHMUL and SHMUL) across the BPF interpreter, BPF verifier, disassembler, and JIT compilers (x86, arm64, riscv) while returning -EOPNOTSUPP on other architectures.\n\nThe changes involve:\n1. Pure scalar arithmetic routines (bpf_uhmul64, bpf_shmul64) operating on register values passed by value.\n2. Verifier scalar range/state tracking updates using standard register marking functions (__mark_reg_unknown, ___mark_reg_known).\n3. JIT compiler instruction emissions for the new ALU operations.\n4. Validation of instruction fields (BPF_MUL variants) in check_alu_fields().\n\nNo new heap/stack allocations, memory copying routines, kernel-to-user copy operations (e.g., copy_to_user, ioctl outputs, struct padding), or buffer length manipulations are introduced. Potential bugs in this patch would involve mathematical logic flaws, verifier state tracking inconsistencies, or JIT assembly generation errors (which could cause memory corruption detectable by KASAN/fault handlers), none of which represent uninitialized memory usage or information leaks detectable only by KMSAN. Therefore, a dedicated KMSAN fuzzing 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 07f3ca6345148982e2a8fbc63d6d227638cb9458
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Sep 18 20:53:37 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..3c2cde11fa234 100644
--- a/Documentation/bpf/standardization/instruction-set.rst
+++ b/Documentation/bpf/standardization/instruction-set.rst
@@ -330,6 +330,8 @@ register.
   ADD    0x0    0        dst += src
   SUB    0x1    0        dst -= src
   MUL    0x2    0        dst \*= src
+  UHMUL  0x2    1        unsigned high-half multiplication (``ALU64`` only)
+  SHMUL  0x2    2        signed high-half multiplication (``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 +381,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, 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.
+
+For ``ALU64`` multiplication, ``offset == 1`` selects unsigned
+high-half multiplication (``UHMUL``), and ``offset == 2`` selects
+signed high-half multiplication (``SHMUL``).
+
+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.
+
 The division and modulo operations support both unsigned and signed flavors.
 
 For unsigned operations (``DIV`` and ``MOD``), for ``ALU``,
diff --git a/arch/arc/net/bpf_jit_core.c b/arch/arc/net/bpf_jit_core.c
index 639a2736f029e..78b1819cee5a6 100644
--- a/arch/arc/net/bpf_jit_core.c
+++ b/arch/arc/net/bpf_jit_core.c
@@ -734,6 +734,9 @@ static int handle_insn(struct jit_context *ctx, u32 idx)
 	u8  len = 0;
 	int ret = 0;
 
+	if (bpf_insn_is_hmul(insn))
+		return -EOPNOTSUPP;
+
 	switch (code) {
 	/* dst += src (32-bit) */
 	case BPF_ALU | BPF_ADD | BPF_X:
diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
index 9ede81afbc50e..aa466fc79d964 100644
--- a/arch/arm/net/bpf_jit_32.c
+++ b/arch/arm/net/bpf_jit_32.c
@@ -1611,6 +1611,9 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
 } while (0)
 #define check_imm24(imm) check_imm(24, imm)
 
+	if (bpf_insn_is_hmul(insn))
+		goto notyet;
+
 	switch (code) {
 	/* ALU operations */
 
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 6c04fee468766..054c38775dd22 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_MUL_VARIANT_UHMUL)
+		emit(A64_UMULH(dst, dst, src), ctx);
+	else if (is64 && off == BPF_MUL_VARIANT_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)) +
@@ -1454,7 +1465,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:
@@ -1583,7 +1594,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:
diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
index 4da2789009383..7bb3813fda8e9 100644
--- a/arch/loongarch/net/bpf_jit.c
+++ b/arch/loongarch/net/bpf_jit.c
@@ -709,6 +709,9 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
 	const s32 imm = insn->imm;
 	const bool is32 = BPF_CLASS(insn->code) == BPF_ALU || BPF_CLASS(insn->code) == BPF_JMP32;
 
+	if (bpf_insn_is_hmul(insn))
+		return -EOPNOTSUPP;
+
 	switch (code) {
 	/* dst = src */
 	case BPF_ALU | BPF_MOV | BPF_X:
diff --git a/arch/mips/net/bpf_jit_comp32.c b/arch/mips/net/bpf_jit_comp32.c
index 40a878b672f5d..1afe15162af20 100644
--- a/arch/mips/net/bpf_jit_comp32.c
+++ b/arch/mips/net/bpf_jit_comp32.c
@@ -1472,6 +1472,9 @@ int build_insn(const struct bpf_insn *insn, struct jit_context *ctx)
 	s32 val, rel;
 	u8 alu, jmp;
 
+	if (bpf_insn_is_hmul(insn))
+		goto notyet;
+
 	switch (code) {
 	/* ALU operations */
 	/* dst = imm */
diff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c
index fa7e9aa37f498..a9765ea252824 100644
--- a/arch/mips/net/bpf_jit_comp64.c
+++ b/arch/mips/net/bpf_jit_comp64.c
@@ -643,6 +643,9 @@ int build_insn(const struct bpf_insn *insn, struct jit_context *ctx)
 	s32 val, rel;
 	u8 alu, jmp;
 
+	if (bpf_insn_is_hmul(insn))
+		goto notyet;
+
 	switch (code) {
 	/* ALU operations */
 	/* dst = imm */
diff --git a/arch/parisc/net/bpf_jit_comp32.c b/arch/parisc/net/bpf_jit_comp32.c
index 5ff0cf925fe95..6bf72d04855ba 100644
--- a/arch/parisc/net/bpf_jit_comp32.c
+++ b/arch/parisc/net/bpf_jit_comp32.c
@@ -1133,6 +1133,9 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct hppa_jit_context *ctx,
 		BPF_CLASS(code), code, (code & BPF_ALU64) ? 1:0, BPF_SIZE(code),
 		BPF_OP(code), insn->src_reg, insn->dst_reg);
 
+	if (bpf_insn_is_hmul(insn))
+		return -EOPNOTSUPP;
+
 	switch (code) {
 	/* dst = src */
 	case BPF_ALU64 | BPF_MOV | BPF_X:
diff --git a/arch/parisc/net/bpf_jit_comp64.c b/arch/parisc/net/bpf_jit_comp64.c
index 54b0d5e25e024..36b6078a146f8 100644
--- a/arch/parisc/net/bpf_jit_comp64.c
+++ b/arch/parisc/net/bpf_jit_comp64.c
@@ -603,6 +603,9 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct hppa_jit_context *ctx,
 
 	init_regs(&rd, &rs, insn, ctx);
 
+	if (bpf_insn_is_hmul(insn))
+		return -EOPNOTSUPP;
+
 	switch (code) {
 	/* dst = src */
 	case BPF_ALU | BPF_MOV | BPF_X:
diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c
index bfdc50740da8e..6bfc97a029d73 100644
--- a/arch/powerpc/net/bpf_jit_comp32.c
+++ b/arch/powerpc/net/bpf_jit_comp32.c
@@ -349,6 +349,9 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
 		u32 true_cond;
 		u32 tmp_idx;
 
+		if (bpf_insn_is_hmul(&insn[i]))
+			return -EOPNOTSUPP;
+
 		if (i && (BPF_CLASS(code) == BPF_ALU64 || BPF_CLASS(code) == BPF_ALU) &&
 		    (BPF_CLASS(prevcode) == BPF_ALU64 || BPF_CLASS(prevcode) == BPF_ALU) &&
 		    BPF_OP(prevcode) == BPF_MOV && BPF_SRC(prevcode) == BPF_X &&
diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c
index fc9db691e8203..192c96e0ed34a 100644
--- a/arch/powerpc/net/bpf_jit_comp64.c
+++ b/arch/powerpc/net/bpf_jit_comp64.c
@@ -992,6 +992,9 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
 		u32 tmp_idx;
 		u32 jmp_off;
 
+		if (bpf_insn_is_hmul(&insn[i]))
+			return -EOPNOTSUPP;
+
 		/*
 		 * addrs[] maps a BPF bytecode address into a real offset from
 		 * the start of the body code.
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_comp32.c b/arch/riscv/net/bpf_jit_comp32.c
index a9e0bd5cc81d2..64bc6779d25c7 100644
--- a/arch/riscv/net/bpf_jit_comp32.c
+++ b/arch/riscv/net/bpf_jit_comp32.c
@@ -1014,6 +1014,9 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
 	const s8 *tmp1 = bpf2rv32[TMP_REG_1];
 	const s8 *tmp2 = bpf2rv32[TMP_REG_2];
 
+	if (bpf_insn_is_hmul(insn))
+		goto notsupported;
+
 	switch (code) {
 	case BPF_ALU64 | BPF_MOV | BPF_X:
 		if (insn->off != 0) {
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index ed0a6f871deac..a773506a92093 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_MUL_VARIANT_UHMUL)
+		emit(rv_mulhu(rd, rd, rs), ctx);
+	else if (off == BPF_MUL_VARIANT_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;
@@ -1498,7 +1511,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;
@@ -1634,8 +1647,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;
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index c4b47070bb590..9e5c865d5ea8c 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -985,6 +985,9 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
 
 	bpf_jit_probe_init(&probe);
 
+	if (bpf_insn_is_hmul(insn))
+		return -EOPNOTSUPP;
+
 	switch (insn->code) {
 	/*
 	 * BPF_MOV
diff --git a/arch/sparc/net/bpf_jit_comp_64.c b/arch/sparc/net/bpf_jit_comp_64.c
index 2fa0e93751276..1154ddc515b0f 100644
--- a/arch/sparc/net/bpf_jit_comp_64.c
+++ b/arch/sparc/net/bpf_jit_comp_64.c
@@ -901,6 +901,9 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
 	const s16 off = insn->off;
 	const s32 imm = insn->imm;
 
+	if (bpf_insn_is_hmul(insn))
+		return -EOPNOTSUPP;
+
 	if (insn->src_reg == BPF_REG_FP)
 		ctx->saw_frame_pointer = true;
 
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index d4a980140b48d..645d0ac4db040 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -1225,6 +1225,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)
 {
@@ -2332,6 +2364,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_MUL_VARIANT_SHMUL);
+				break;
+			}
+
 			maybe_emit_mod(&prog, dst_reg, dst_reg,
 				       BPF_CLASS(insn->code) == BPF_ALU64);
 
@@ -2348,6 +2388,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_MUL_VARIANT_SHMUL);
+				break;
+			}
+
 			maybe_emit_mod(&prog, src_reg, dst_reg,
 				       BPF_CLASS(insn->code) == BPF_ALU64);
 
diff --git a/arch/x86/net/bpf_jit_comp32.c b/arch/x86/net/bpf_jit_comp32.c
index 852baf2e4db4d..11ed65130d1e5 100644
--- a/arch/x86/net/bpf_jit_comp32.c
+++ b/arch/x86/net/bpf_jit_comp32.c
@@ -1683,6 +1683,9 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
 		int ilen;
 		u8 *func;
 
+		if (bpf_insn_is_hmul(insn))
+			goto notyet;
+
 		switch (code) {
 		/* ALU operations */
 		/* dst = src */
diff --git a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
index 1caa87da72b51..effce27f3b88e 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
@@ -3,6 +3,7 @@
 
 #include <linux/bpf.h>
 #include <linux/bpf_verifier.h>
+#include <linux/filter.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>
 #include <linux/pkt_cls.h>
@@ -561,6 +562,11 @@ nfp_bpf_check_alu(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta,
 	const struct bpf_reg_state *dreg =
 		cur_regs(env) + meta->insn.dst_reg;
 
+	if (bpf_insn_is_hmul(&meta->insn)) {
+		pr_vlog(env, "UHMUL/SHMUL are not supported\n");
+		return -EOPNOTSUPP;
+	}
+
 	meta->umin_src = min(meta->umin_src, reg_umin(sreg));
 	meta->umax_src = max(meta->umax_src, reg_umax(sreg));
 	meta->umin_dst = min(meta->umin_dst, reg_umin(dreg));
diff --git a/include/linux/filter.h b/include/linux/filter.h
index b17222db2efc3..b6dc4b968a9cd 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>
 
@@ -147,6 +148,44 @@ 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_is_hmul_variant(s16 off)
+{
+	return off == BPF_MUL_VARIANT_UHMUL ||
+	       off == BPF_MUL_VARIANT_SHMUL;
+}
+
+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 &&
+	       bpf_is_hmul_variant(insn->off);
+}
+
 /* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */
 
 #define BPF_ENDIAN(TYPE, DST, LEN)				\
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 732b35cc08d1c..845eee5361986 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -34,6 +34,16 @@
 #define BPF_FROM_LE	BPF_TO_LE
 #define BPF_FROM_BE	BPF_TO_BE
 
+/*
+ * BPF_MUL variants selected by the off field.
+ * UHMUL and SHMUL are only valid for BPF_ALU64.
+ */
+enum bpf_mul_variant {
+	BPF_MUL_VARIANT_LO    = 0,
+	BPF_MUL_VARIANT_UHMUL = 1,
+	BPF_MUL_VARIANT_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 4e208cc94752f..4f746973481b9 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1931,7 +1931,50 @@ 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 BPF_MUL_VARIANT_LO:
+			DST = DST * SRC;
+			break;
+		case BPF_MUL_VARIANT_UHMUL:
+			DST = bpf_uhmul64(DST, SRC);
+			break;
+		case BPF_MUL_VARIANT_SHMUL:
+			DST = bpf_shmul64((s64)DST, (s64)SRC);
+			break;
+		default:
+			goto default_label;
+		}
+		CONT;
+	ALU_MUL_X:
+		if (OFF != BPF_MUL_VARIANT_LO)
+			goto default_label;
+		DST = (u32) DST * (u32) SRC;
+		CONT;
+	ALU64_MUL_K:
+		switch (OFF) {
+		case BPF_MUL_VARIANT_LO:
+			DST = DST * IMM;
+			break;
+		case BPF_MUL_VARIANT_UHMUL:
+			DST = bpf_uhmul64(DST, (u64)IMM);
+			break;
+		case BPF_MUL_VARIANT_SHMUL:
+			DST = bpf_shmul64((s64)DST, (s32)IMM);
+			break;
+		default:
+			goto default_label;
+		}
+		CONT;
+	ALU_MUL_K:
+		if (OFF != BPF_MUL_VARIANT_LO)
+			goto default_label;
+		DST = (u32) DST * (u32) IMM;
+		CONT;
 	SHT(LSH, <<)
 	SHT(RSH, >>)
 #undef SHT
diff --git a/kernel/bpf/disasm.c b/kernel/bpf/disasm.c
index 3ce8d74b0e400..03f22845e1692 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_MUL_VARIANT_UHMUL:
+		return "uh*=";
+	case BPF_MUL_VARIANT_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 6c6b8d8520cdf..92603a6a030ba 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -15238,6 +15238,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)
 {
@@ -15934,6 +15952,25 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,
 		dst_reg->var_off = tnum_neg(env->fake_reg[0].var_off);
 		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_MUL_VARIANT_UHMUL) {
+			scalar_min_max_uhmul(dst_reg, &src_reg);
+			break;
+		}
+		if (!alu32 && insn->off == BPF_MUL_VARIANT_SHMUL) {
+			scalar_min_max_shmul(dst_reg, &src_reg);
+			break;
+		}
 		dst_reg->var_off = tnum_mul(dst_reg->var_off, src_reg.var_off);
 		scalar32_min_max_mul(dst_reg, &src_reg);
 		scalar_min_max_mul(dst_reg, &src_reg);
@@ -16059,6 +16096,11 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
 	if (dst_reg->type == PTR_TO_ARENA || (src_reg && src_reg->type == PTR_TO_ARENA)) {
 		struct bpf_insn_aux_data *aux = cur_aux(env);
 
+		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;
 
@@ -19338,6 +19380,21 @@ 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 == BPF_MUL_VARIANT_LO ||
+		       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;
+	}
+}
+
 static int check_alu_fields(struct bpf_verifier_env *env, struct bpf_insn *insn)
 {
 	u8 class = BPF_CLASS(insn->code);
@@ -19393,15 +19450,9 @@ 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;
 		}
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 732b35cc08d1c..845eee5361986 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -34,6 +34,16 @@
 #define BPF_FROM_LE	BPF_TO_LE
 #define BPF_FROM_BE	BPF_TO_BE
 
+/*
+ * BPF_MUL variants selected by the off field.
+ * UHMUL and SHMUL are only valid for BPF_ALU64.
+ */
+enum bpf_mul_variant {
+	BPF_MUL_VARIANT_LO    = 0,
+	BPF_MUL_VARIANT_UHMUL = 1,
+	BPF_MUL_VARIANT_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 7732df9bc8701..bf5d9b140c45a 100644
--- a/tools/testing/selftests/bpf/prog_tests/verifier.c
+++ b/tools/testing/selftests/bpf/prog_tests/verifier.c
@@ -51,6 +51,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_int_ptr.skel.h"
 #include "verifier_iterating_callbacks.skel.h"
 #include "verifier_jeq_infer_not_null.skel.h"
@@ -217,6 +218,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_int_ptr(void)              { RUN(verifier_int_ptr); }
 void test_verifier_iterating_callbacks(void)  { RUN(verifier_iterating_callbacks); }
 void test_verifier_jeq_infer_not_null(void)   { RUN(verifier_jeq_infer_not_null); }
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..197ceac3b7980
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/verifier_hmul.c
@@ -0,0 +1,284 @@
+// 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_MUL_VARIANT_UHMUL, 0)
+
+#define BPF_UHMUL64_IMM(DST, IMM) \
+	BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, \
+		     BPF_MUL_VARIANT_UHMUL, IMM)
+
+#define BPF_SHMUL64_REG(DST, SRC) \
+	BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_X, DST, SRC, \
+		     BPF_MUL_VARIANT_SHMUL, 0)
+
+#define BPF_SHMUL64_IMM(DST, IMM) \
+	BPF_RAW_INSN(BPF_ALU64 | BPF_MUL | BPF_K, DST, 0, \
+		     BPF_MUL_VARIANT_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(__BPF_FEATURE_ADDR_SPACE_CAST)
+
+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")
+__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")
+__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);
+}
+
+#endif
+
+#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_value_illegal_alu.c b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
index 4d8273c258d51..d7fb6b71b2061 100644
--- a/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
+++ b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
@@ -202,7 +202,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.
  */
@@ -212,5 +213,11 @@ 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_MUL_VARIANT_UHMUL, 0)
+DEFINE_BAD_OFFSET_TEST(bad_shmul32_k, BPF_ALU | BPF_MUL | BPF_K,
+		       BPF_MUL_VARIANT_SHMUL, 0)
 
 char _license[] SEC("license") = "GPL";

33/3 2026/09/18 20:54 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 19685
							output: 33
							thoughts: 1272
						

Thoughts:
**KMSAN Evaluation for BPF High-Half Multiplication Patch**

Okay, let's break this down. My goal is to determine if this BPF high-half multiplication patch series warrants a dedicated KMSAN fuzzing session. I need to see if it introduces risks related to uninitialized memory, info leaks, or other issues KMSAN is designed to catch, that KASAN or other tools might miss.

First, I see the patch adds documentation for UHMUL and SHMUL, high-half multiplications, and introduces the corresponding instructions, `bpf_uhmul64` and `bpf_shmul64`. This is ALU64 only, which is fine, but I need to make sure this doesn't introduce vulnerabilities.

The patch includes JIT implementations for several architectures (arm64, riscv, x86), along with fallback mechanisms to the interpreter for others, with some architectures explicitly rejecting the instructions. This is a red flag, as this creates multiple code paths to test. I see some of these jit implementations are for very common architectures, and I need to be sure this is correct.

I see helper functions, and a new enum, so the kernel is getting the information it needs. Disassembler support is there. But the verifier is where it gets interesting.

The verifier does bounds tracking, which is critical. The logic I see there checks whether the registers involved in the high-half multiplication instructions are initialized. The code there looks like 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;
		}
```

This is important. The verifier seems to be marking the destination register as unknown if it's not a constant. This is good because `__mark_reg_unknown()` *does not* necessarily make it uninitialized memory; the verifier tracks the register as a known scalar (`SCALAR_VALUE`) with an unknown value (min/max spanning all 64 bits). So, it's *initialized* in the BPF register file, just with an unknown value. That's a key distinction I need to remember!

Now, the important part: what does the verifier check for the source and destination registers? I need to look at where `adjust_scalar_min_max_vals()` and `check_alu_op()` are called in `kernel/bpf/verifier.c`. *That* is where the initialization checks happen, and where any potential uninitialized memory issues might arise.  I need to go deeper in my analysis there, specifically.



34/3 2026/09/18 20:54 tool grepper
0m Args:
{
  "Expression": "check_alu_op",
  "PathPrefix": "kernel/bpf/verifier.c"
}

Results:
{
  "Output": "kernel/bpf/verifier.c=16078=static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-16249-/* check validity of 32-bit and 64-bit arithmetic operations */\nkernel/bpf/verifier.c:16250:static int check_alu_op(struct bpf_verifier_env *env, struct bpf_insn *insn)\nkernel/bpf/verifier.c-16251-{\n--\nkernel/bpf/verifier.c=18628=static int do_check_insn(struct bpf_verifier_env *env, bool *do_print_state)\n--\nkernel/bpf/verifier.c-18636-\tcase BPF_ALU64:\nkernel/bpf/verifier.c:18637:\t\treturn check_alu_op(env, insn);\nkernel/bpf/verifier.c-18638-\n"
}

35/3 2026/09/18 20:54 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21849
							output: 38
							thoughts: 22
						

Thoughts:
Here's my summary, as though I'm reading and thinking about the code:

**Diving into `check_alu_op`**

Alright, let's get down to it. Time to dissect `check_alu_op` in `kernel/bpf/verifier.c`. I know this function is the gatekeeper for arithmetic and logical operations in BPF programs. It's critical for ensuring safety and preventing malicious code from messing with kernel memory or causing crashes. I'm especially interested in the nuances of how it handles different instructions and data types.

I'll be looking for how it validates the source and destination registers, confirming they contain appropriate data types and values before allowing the operation. I'll pay close attention to the checks on potential overflow or underflow conditions – that's a classic area for vulnerabilities. How does it handle division by zero? Are there any clever tricks it uses to optimize these checks while maintaining security? I want to see exactly how it tracks register state and ensures that operations don't violate type constraints.

Given my experience, I'll be particularly scrutinizing any potential blind spots for symbolic execution or other analysis techniques. It's easy to build complex checks, but can they be bypassed? I'll be comparing it to similar functions in other verifiers and considering any novel approaches or trade-offs made in the implementation. I'll expect to see careful attention to detail here; even a minor oversight can have serious consequences when dealing with untrusted code running in kernel space. Let's see how well it holds up.



36/3 2026/09/18 20:54 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 16250,
  "LineCount": 80
}

Results:
{
  "Contents": "16250:\tstatic int check_alu_op(struct bpf_verifier_env *env, struct bpf_insn *insn)\n16251:\t{\n16252:\t\tstruct bpf_reg_state *regs = cur_regs(env);\n16253:\t\tu8 opcode = BPF_OP(insn-\u003ecode);\n16254:\t\tint err;\n16255:\t\n16256:\t\tbpf_diag_mod_begin(env, \u0026regs[insn-\u003edst_reg], NULL, BPF_DIAG_MOD_WRITE);\n16257:\t\n16258:\t\tif (opcode == BPF_END || opcode == BPF_NEG) {\n16259:\t\t\t/* check src operand */\n16260:\t\t\terr = check_reg_arg(env, insn-\u003edst_reg, SRC_OP);\n16261:\t\t\tif (err)\n16262:\t\t\t\treturn err;\n16263:\t\n16264:\t\t\tif (is_pointer_value(env, insn-\u003edst_reg)) {\n16265:\t\t\t\tverbose(env, \"R%d pointer arithmetic prohibited\\n\",\n16266:\t\t\t\t\tinsn-\u003edst_reg);\n16267:\t\t\t\treturn -EACCES;\n16268:\t\t\t}\n16269:\t\n16270:\t\t\t/* check dest operand */\n16271:\t\t\tif (regs[insn-\u003edst_reg].type == SCALAR_VALUE) {\n16272:\t\t\t\terr = check_reg_arg(env, insn-\u003edst_reg, DST_OP_NO_MARK);\n16273:\t\t\t\terr = err ?: adjust_scalar_min_max_vals(env, insn,\n16274:\t\t\t\t\t\t\t\t \u0026regs[insn-\u003edst_reg],\n16275:\t\t\t\t\t\t\t\t regs[insn-\u003edst_reg]);\n16276:\t\t\t} else {\n16277:\t\t\t\terr = check_reg_arg(env, insn-\u003edst_reg, DST_OP);\n16278:\t\t\t}\n16279:\t\t\tif (err)\n16280:\t\t\t\treturn err;\n16281:\t\n16282:\t\t} else if (opcode == BPF_MOV) {\n16283:\t\n16284:\t\t\tif (BPF_SRC(insn-\u003ecode) == BPF_X) {\n16285:\t\t\t\tif (insn-\u003eoff == BPF_ADDR_SPACE_CAST) {\n16286:\t\t\t\t\tif (!env-\u003eprog-\u003eaux-\u003earena) {\n16287:\t\t\t\t\t\tverbose(env, \"addr_space_cast insn can only be used in a program that has an associated arena\\n\");\n16288:\t\t\t\t\t\treturn -EINVAL;\n16289:\t\t\t\t\t}\n16290:\t\t\t\t}\n16291:\t\n16292:\t\t\t\t/* check src operand */\n16293:\t\t\t\terr = check_reg_arg(env, insn-\u003esrc_reg, SRC_OP);\n16294:\t\t\t\tif (err)\n16295:\t\t\t\t\treturn err;\n16296:\t\t\t}\n16297:\t\n16298:\t\t\t/* check dest operand, mark as required later */\n16299:\t\t\terr = check_reg_arg(env, insn-\u003edst_reg, DST_OP_NO_MARK);\n16300:\t\t\tif (err)\n16301:\t\t\t\treturn err;\n16302:\t\n16303:\t\t\tif (BPF_SRC(insn-\u003ecode) == BPF_X) {\n16304:\t\t\t\tstruct bpf_reg_state *src_reg = regs + insn-\u003esrc_reg;\n16305:\t\t\t\tstruct bpf_reg_state *dst_reg = regs + insn-\u003edst_reg;\n16306:\t\n16307:\t\t\t\tif (BPF_CLASS(insn-\u003ecode) == BPF_ALU64) {\n16308:\t\t\t\t\tif (insn-\u003eimm) {\n16309:\t\t\t\t\t\t/* off == BPF_ADDR_SPACE_CAST */\n16310:\t\t\t\t\t\tmark_reg_unknown(env, regs, insn-\u003edst_reg);\n16311:\t\t\t\t\t\tif (insn-\u003eimm == 1) /* cast from as(1) to as(0) */\n16312:\t\t\t\t\t\t\tdst_reg-\u003etype = PTR_TO_ARENA;\n16313:\t\t\t\t\t} else if (insn-\u003eoff == 0) {\n16314:\t\t\t\t\t\t/* case: R1 = R2\n16315:\t\t\t\t\t\t * copy register state to dest reg\n16316:\t\t\t\t\t\t */\n16317:\t\t\t\t\t\tassign_scalar_id_before_mov(env, src_reg);\n16318:\t\t\t\t\t\t*dst_reg = *src_reg;\n16319:\t\t\t\t\t} else {\n16320:\t\t\t\t\t\t/* case: R1 = (s8, s16 s32)R2 */\n16321:\t\t\t\t\t\tif (is_pointer_value(env, insn-\u003esrc_reg)) {\n16322:\t\t\t\t\t\t\tverbose(env,\n16323:\t\t\t\t\t\t\t\t\"R%d sign-extension part of pointer\\n\",\n16324:\t\t\t\t\t\t\t\tinsn-\u003esrc_reg);\n16325:\t\t\t\t\t\t\treturn -EACCES;\n16326:\t\t\t\t\t\t} else if (src_reg-\u003etype == SCALAR_VALUE) {\n16327:\t\t\t\t\t\t\tbool no_sext;\n16328:\t\n16329:\t\t\t\t\t\t\tno_sext = reg_umax(src_reg) \u003c (1ULL \u003c\u003c (insn-\u003eoff - 1));\n"
}

37/3 2026/09/18 20:54 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23697
							output: 38
							thoughts: 14
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, as requested, in the first person and targeted towards an expert:

**Diving Back into the ALU Operation Check**

Alright, I'm at a point where I need to take another look at the `check_alu_op` function. I've got a good handle on the overall flow, but I need to make sure I haven't missed anything crucial in that specific piece of the logic. It's a critical function, no doubt, and it warrants a thorough going-over. I need to make sure I haven't overlooked any edge cases or potential vulnerabilities within this ALU operation check. Let's see what more it has to offer.



38/3 2026/09/18 20:54 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 16350,
  "LineCount": 80
}

Results:
{
  "Contents": "16350:\t\n16351:\t\t\t\t\t\t\tif (is_src_reg_u32)\n16352:\t\t\t\t\t\t\t\tassign_scalar_id_before_mov(env, src_reg);\n16353:\t\t\t\t\t\t\t*dst_reg = *src_reg;\n16354:\t\t\t\t\t\t\t/* Make sure ID is cleared if src_reg is not in u32\n16355:\t\t\t\t\t\t\t * range otherwise dst_reg min/max could be incorrectly\n16356:\t\t\t\t\t\t\t * propagated into src_reg by sync_linked_regs()\n16357:\t\t\t\t\t\t\t */\n16358:\t\t\t\t\t\t\tif (!is_src_reg_u32)\n16359:\t\t\t\t\t\t\t\tclear_scalar_id(dst_reg);\n16360:\t\t\t\t\t\t} else {\n16361:\t\t\t\t\t\t\t/* case: W1 = (s8, s16)W2 */\n16362:\t\t\t\t\t\t\tbool no_sext = reg_umax(src_reg) \u003c (1ULL \u003c\u003c (insn-\u003eoff - 1));\n16363:\t\n16364:\t\t\t\t\t\t\tif (no_sext)\n16365:\t\t\t\t\t\t\t\tassign_scalar_id_before_mov(env, src_reg);\n16366:\t\t\t\t\t\t\t*dst_reg = *src_reg;\n16367:\t\t\t\t\t\t\tif (!no_sext)\n16368:\t\t\t\t\t\t\t\tclear_scalar_id(dst_reg);\n16369:\t\t\t\t\t\t\tcoerce_subreg_to_size_sx(dst_reg, insn-\u003eoff \u003e\u003e 3);\n16370:\t\t\t\t\t\t}\n16371:\t\t\t\t\t} else {\n16372:\t\t\t\t\t\tmark_reg_unknown(env, regs,\n16373:\t\t\t\t\t\t\t\t insn-\u003edst_reg);\n16374:\t\t\t\t\t}\n16375:\t\t\t\t\tzext_32_to_64(dst_reg);\n16376:\t\t\t\t\treg_bounds_sync(dst_reg);\n16377:\t\t\t\t}\n16378:\t\t\t} else {\n16379:\t\t\t\t/* case: R = imm\n16380:\t\t\t\t * remember the value we stored into this reg\n16381:\t\t\t\t */\n16382:\t\t\t\t/* clear any state __mark_reg_known doesn't set */\n16383:\t\t\t\tmark_reg_unknown(env, regs, insn-\u003edst_reg);\n16384:\t\t\t\tregs[insn-\u003edst_reg].type = SCALAR_VALUE;\n16385:\t\t\t\tif (BPF_CLASS(insn-\u003ecode) == BPF_ALU64) {\n16386:\t\t\t\t\t__mark_reg_known(regs + insn-\u003edst_reg,\n16387:\t\t\t\t\t\t\t insn-\u003eimm);\n16388:\t\t\t\t} else {\n16389:\t\t\t\t\t__mark_reg_known(regs + insn-\u003edst_reg,\n16390:\t\t\t\t\t\t\t (u32)insn-\u003eimm);\n16391:\t\t\t\t}\n16392:\t\t\t}\n16393:\t\n16394:\t\t} else {\t/* all other ALU ops: and, sub, xor, add, ... */\n16395:\t\n16396:\t\t\tif (BPF_SRC(insn-\u003ecode) == BPF_X) {\n16397:\t\t\t\t/* check src1 operand */\n16398:\t\t\t\terr = check_reg_arg(env, insn-\u003esrc_reg, SRC_OP);\n16399:\t\t\t\tif (err)\n16400:\t\t\t\t\treturn err;\n16401:\t\t\t}\n16402:\t\n16403:\t\t\t/* check src2 operand */\n16404:\t\t\terr = check_reg_arg(env, insn-\u003edst_reg, SRC_OP);\n16405:\t\t\tif (err)\n16406:\t\t\t\treturn err;\n16407:\t\n16408:\t\t\tif ((opcode == BPF_MOD || opcode == BPF_DIV) \u0026\u0026\n16409:\t\t\t    BPF_SRC(insn-\u003ecode) == BPF_K \u0026\u0026 insn-\u003eimm == 0) {\n16410:\t\t\t\tverbose(env, \"div by zero\\n\");\n16411:\t\t\t\treturn -EINVAL;\n16412:\t\t\t}\n16413:\t\n16414:\t\t\tif ((opcode == BPF_LSH || opcode == BPF_RSH ||\n16415:\t\t\t     opcode == BPF_ARSH) \u0026\u0026 BPF_SRC(insn-\u003ecode) == BPF_K) {\n16416:\t\t\t\tint size = BPF_CLASS(insn-\u003ecode) == BPF_ALU64 ? 64 : 32;\n16417:\t\n16418:\t\t\t\tif (insn-\u003eimm \u003c 0 || insn-\u003eimm \u003e= size) {\n16419:\t\t\t\t\tverbose(env, \"invalid shift %d\\n\", insn-\u003eimm);\n16420:\t\t\t\t\treturn -EINVAL;\n16421:\t\t\t\t}\n16422:\t\t\t}\n16423:\t\n16424:\t\t\t/* check dest operand */\n16425:\t\t\terr = check_reg_arg(env, insn-\u003edst_reg, DST_OP_NO_MARK);\n16426:\t\t\terr = err ?: adjust_reg_min_max_vals(env, insn);\n16427:\t\t\tif (err)\n16428:\t\t\t\treturn err;\n16429:\t\t}\n"
}

39/3 2026/09/18 20:54 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 25305
							output: 309
							thoughts: 3459
						

Thoughts:
**Analysis of BPF High-Half Multiplication Instruction Implementation for Uninitialized Memory Risks**

Alright, let's break down this BPF high-half multiplication implementation from an expert's perspective, focusing on the potential for uninitialized memory usage. The core change introduces support for unsigned (`UHMUL`) and signed (`SHMUL`) high-half multiplication instructions within the BPF framework. This means updates to the interpreter, verifier, disassembler, and the JIT compilers for various architectures. The goal here is to determine if we *really* need to flag this for KMSAN.

My initial investigation of `check_alu_op` within the verifier reveals a standard pattern. Both the source and destination registers are checked for initialization with `check_reg_arg`, ensuring the operands are valid. After verification, `adjust_reg_min_max_vals` and `adjust_scalar_min_max_vals` are responsible for updating the bounds (minimum and maximum values) associated with these registers. Crucially, I see that for these new `hmul` instructions the destination register is marked as unknown using `__mark_reg_unknown` if we're *not* dealing with a constant value. Conversely, if a constant is involved, bounds are explicitly computed via calls to `___mark_reg_known`.

Now, let's consider the x86 JIT implementation in `arch/x86/net/bpf_jit_comp.c`. The code generates assembly to handle these instructions. The essence of the x86 implementation is to use the `mul`/`imul` instructions, which perform a 64x64-bit multiplication and store the result in the `RDX:RAX` register pair. I've walked through the scenarios where `dst_reg` is `BPF_REG_0` (RAX), `BPF_REG_3` (RDX), or neither. It appears that the JIT code carefully manages the high-half result in RDX. Most importantly, it's pretty clear that if `RDX` contains the result, no uninitialized memory could be read. The x86 JIT generates code to correctly handle register clobbering by pushing/popping registers. This is standard assembly generation and should not leave uninitialized registers, but instead may contain high part of the result in `RDX`.

Next, I've checked whether this patch introduced risks of uninitialized memory usage. I've exhaustively looked for specific patterns based on the rules.

1.  **Kernel structures copied to user space**: There are no new kernel structures being sent to user space. The `enum bpf_mul_variant` was added to `uapi/linux/bpf.h`, but no new structures or data is transferred out.
2.  **Conditional logic based on potentially uninitialized variables**: The code doesn't introduce any new conditional branching based on uninitialized values.
3.  **Allocation or initialization of complex data structures**: There are no new memory allocations introduced.
4.  **Bounds checks or logic that accesses uninitialized bytes**: No buffer access logic is changed by this patch.

Crucially, the BPF verifier already has an established mechanism to prevent uninitialized BPF registers from being read. The `check_reg_arg` function is used to ensure a register is valid and `NOT_INIT`. The use of `SRC_OP` ensures the source register (operand) is initialized. The `adjust_scalar_min_max_vals` and `adjust_reg_min_max_vals` functions do not introduce any risk because they operate on structures that are initialized.

Finally, the interpreter and the verifier are safe, and the JIT generates valid, if possibly suboptimal, assembly instructions. Any bugs in the math, interpreter or JIT are computational or code generation bugs that would be detected by KASAN or general kernel fault handlers, or functional correctness tests. KMSAN is not required. The patch simply adds support for integer high-half multiplication, where the verifier and JIT code maintain register tracking as necessary.

Therefore, given the lack of any uninitialized memory risks, I conclude that `NeedsKMSAN = false`.



40/3 2026/09/18 20:54 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch series implements support for BPF 64-bit high-half multiplication instructions (UHMUL and SHMUL) across the BPF interpreter, BPF verifier, disassembler, and JIT compilers (x86, arm64, riscv) while returning -EOPNOTSUPP on other architectures.\n\nThe changes involve:\n1. Pure scalar arithmetic routines (bpf_uhmul64, bpf_shmul64) operating on register values passed by value.\n2. Verifier scalar range/state tracking updates using standard register marking functions (__mark_reg_unknown, ___mark_reg_known).\n3. JIT compiler instruction emissions for the new ALU operations.\n4. Validation of instruction fields (BPF_MUL variants) in check_alu_fields().\n\nNo new heap/stack allocations, memory copying routines, kernel-to-user copy operations (e.g., copy_to_user, ioctl outputs, struct padding), or buffer length manipulations are introduced. Potential bugs in this patch would involve mathematical logic flaws, verifier state tracking inconsistencies, or JIT assembly generation errors (which could cause memory corruption detectable by KASAN/fault handlers), none of which represent uninitialized memory usage or information leaks detectable only by KMSAN. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch series implements support for BPF 64-bit high-half multiplication instructions (UHMUL and SHMUL) across the BPF interpreter, BPF verifier, disassembler, and JIT compilers (x86, arm64, riscv) while returning -EOPNOTSUPP on other architectures.\n\nThe changes involve:\n1. Pure scalar arithmetic routines (bpf_uhmul64, bpf_shmul64) operating on register values passed by value.\n2. Verifier scalar range/state tracking updates using standard register marking functions (__mark_reg_unknown, ___mark_reg_known).\n3. JIT compiler instruction emissions for the new ALU operations.\n4. Validation of instruction fields (BPF_MUL variants) in check_alu_fields().\n\nNo new heap/stack allocations, memory copying routines, kernel-to-user copy operations (e.g., copy_to_user, ioctl outputs, struct padding), or buffer length manipulations are introduced. Potential bugs in this patch would involve mathematical logic flaws, verifier state tracking inconsistencies, or JIT assembly generation errors (which could cause memory corruption detectable by KASAN/fault handlers), none of which represent uninitialized memory usage or information leaks detectable only by KMSAN. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)