Re: [PATCH bpf 2/2] bpf: Reject kprobe_multi links on coming modules
From: Chris Mason
Date: Fri Dec 04 2026 - 10:12:03 EST
On Fri, 4 Dec 2026 11:05:47 +0100, Jiri Olsa wrote:
> On Thu, Dec 03, 2026 at 03:26:17PM -0500, Chris Mason wrote:
>> bpf_kprobe_multi_link_release() hits a use-after-free on struct module
>> if a probed module fails to load.
>>
>> get_modules_for_addrs() pins each probed module with try_module_get(),
>> which also succeeds in MODULE_STATE_COMING. But the error paths of
>> load_module() and do_init_module() free the module without checking
>> refcnt:
[ ... ]
>> The fix used here is to pin a module only once it is live, as
>> btf_try_get_module() does.
>
> I wonder this is a problem in other places as well, like in
> trace_event_try_get_ref and possibly other places
Yeah, trace_event_try_get_ref() has the same bug, and perf events, triggers,
function probes and eprobes all use it. I had scanned my pending queue
just for bpf, and this one missed the cut. Thanks for flagging:
https://lore.kernel.org/all/20261204130200.15208-1-mason@xxxxxxxxxx/
>From the code, it looks like register_kprobe(), validate_probe_symbol() and
trace_fprobe_create_internal() have similar issues. They drop their
reference before they return, and Mahanta's patch handles things:
https://lore.kernel.org/all/20261204104104.1711861-1-mjambigi@xxxxxxxxxxxxx/
-chris