@@ -2936,22 +2936,28 @@ let rec type_check_and_annotate_ast ?symbol_table:(provided_symbol_table=None) ?
29362936 Hashtbl. add ctx.test_functions attr_func.attr_function.func_name () ;
29372937
29382938 (* Extract program type from attribute for context *)
2939- let prog_type = match attr_func.attr_list with
2939+ let ( prog_type, kprobe_target) = match attr_func.attr_list with
29402940 | SimpleAttribute prog_type_str :: _ ->
29412941 (match prog_type_str with
2942- | "xdp" -> Some Xdp
2943- | "tc" -> Some Tc
2944- | "kprobe" -> Some Kprobe
2945- | "uprobe" -> Some Uprobe
2946- | "tracepoint" -> Some Tracepoint
2947- | "lsm" -> Some Lsm
2948- | "cgroup_skb" -> Some CgroupSkb
2949- | "kfunc" -> None (* kfuncs don't have program types *)
2950- | "private" -> None (* private functions don't have program types *)
2951- | "helper" -> None (* helper functions don't have program types *)
2952- | "test" -> None (* test functions don't have program types *)
2953- | _ -> None )
2954- | _ -> None
2942+ | "xdp" -> (Some Xdp , None )
2943+ | "tc" -> (Some Tc , None )
2944+ | "kprobe" ->
2945+ (* Reject old format: @kprobe without target function *)
2946+ type_error (" @kprobe requires target function specification. Use @kprobe(\" function_name\" ) instead." ) attr_func.attr_pos
2947+ | "uprobe" -> (Some Uprobe , None )
2948+ | "tracepoint" -> (Some Tracepoint , None )
2949+ | "lsm" -> (Some Lsm , None )
2950+ | "cgroup_skb" -> (Some CgroupSkb , None )
2951+ | "kfunc" -> (None , None ) (* kfuncs don't have program types *)
2952+ | "private" -> (None , None ) (* private functions don't have program types *)
2953+ | "helper" -> (None , None ) (* helper functions don't have program types *)
2954+ | "test" -> (None , None ) (* test functions don't have program types *)
2955+ | _ -> (None , None ))
2956+ | AttributeWithArg (attr_name , target_func ) :: _ ->
2957+ (match attr_name with
2958+ | "kprobe" -> (Some Kprobe , Some target_func)
2959+ | _ -> (None , None ))
2960+ | _ -> (None , None )
29552961 in
29562962
29572963 (* Validate attributed function signatures based on program type *)
@@ -3003,11 +3009,24 @@ let rec type_check_and_annotate_ast ?symbol_table:(provided_symbol_table=None) ?
30033009 | Some ret_type -> Some (resolve_user_type ctx ret_type)
30043010 | None -> None in
30053011
3006- (* For kprobe functions, accept only the new function signature format with actual kernel function parameters *)
3007- let valid_signature =
3008- (* Accept any number of parameters for new format (kernel function signature) *)
3009- List. length params > = 0 && List. length params < = 6 (* x86_64 supports max 6 function parameters *)
3010- in
3012+ (* Validate kprobe function - only modern format supported *)
3013+ (match kprobe_target with
3014+ | Some _target_func ->
3015+ (* Modern format with target function specified *)
3016+ (* Check for invalid pt_regs parameter usage *)
3017+ List. iter (fun (_ , param_type ) ->
3018+ match param_type with
3019+ | Pointer (UserType "pt_regs" ) ->
3020+ type_error (" @kprobe functions should not use pt_regs parameter. Use kernel function parameters directly." ) attr_func.attr_pos
3021+ | _ -> ()
3022+ ) params;
3023+ (* Validate signature against BTF if available *)
3024+ if List. length params > 6 then
3025+ type_error (" Kprobe functions support maximum 6 parameters" ) attr_func.attr_pos
3026+ | None ->
3027+ (* This case should never be reached due to earlier validation *)
3028+ failwith " Internal error: kprobe without target function should have been rejected earlier"
3029+ );
30113030
30123031 (* Allow both i32 (standard eBPF kprobe return) and void (matching kernel function signature) *)
30133032 let valid_return_type = match resolved_return_type with
@@ -3017,8 +3036,8 @@ let rec type_check_and_annotate_ast ?symbol_table:(provided_symbol_table=None) ?
30173036 | _ -> false
30183037 in
30193038
3020- if not valid_signature || not valid_return_type then
3021- type_error (" @kprobe attributed function must have valid signature (max 6 params) with return type -> i32, u32, or void" ) attr_func.attr_pos
3039+ if not valid_return_type then
3040+ type_error (" @kprobe attributed function must return i32, u32, or void" ) attr_func.attr_pos
30223041 | Some _ -> () (* Other program types - validation can be added later *)
30233042 | None -> type_error (" Invalid or unsupported attribute" ) attr_func.attr_pos);
30243043
0 commit comments