seq_file calls ->stop() after ->start() failed. A program which skips ->start() with an error leaves ->stop() to undo what was not done. kernfs_seq_start() returns -ENODEV with of->mutex held. After a skip kernfs_seq_stop() unlocks a mutex which nobody took. ipmr_vif_seq_start() does the same with RCU and warns. Skip the functions which take a struct seq_file * and return void *. Signed-off-by: Anton Protopopov --- tools/bpf/resolve_btfids/fmodret.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c index daf08a4b0204..8fa63cbfd303 100644 --- a/tools/bpf/resolve_btfids/fmodret.c +++ b/tools/bpf/resolve_btfids/fmodret.c @@ -89,6 +89,30 @@ static bool has_bpf_types(const struct btf *btf, const struct btf_type *func) return false; } +/* + * seq_file calls ->stop() after ->start() failed. Its ->start() and ->next() take + * a seq_file and return void *. A skip of ->start() leaves ->stop() to unlock + * what was not locked. + */ +static bool is_seq_op(const struct btf *btf, const struct btf_type *func) +{ + const struct btf_type *proto = btf__type_by_id(btf, func->type); + const struct btf_type *t = btf__type_by_id(btf, proto->type); + unsigned int i; + + if (!btf_is_ptr(t) || t->type) + return false; + for (i = 0; i < btf_vlen(proto); i++) { + t = btf__type_by_id(btf, btf_params(proto)[i].type); + if (!btf_is_ptr(t)) + continue; + t = btf__type_by_id(btf, t->type); + if (btf_is_struct(t) && !strcmp(btf__name_by_offset(btf, t->name_off), "seq_file")) + return true; + } + return false; +} + static bool excluded_by_name(const char *name) { static const char *const names[] = { @@ -347,6 +371,8 @@ int fmodret_tag(Elf *elf, struct btf *btf, const char *deny_path, int verbose) /* Skip functions which take or return BPF objects */ if (has_bpf_types(btf, t)) continue; + if (is_seq_op(btf, t)) + continue; /* Skip kfuncs and helpers which escaped the previous check */ if (bpf_funcs[id]) continue; -- 2.43.0