From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Alan Maguire <almagui@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
bpf@vger.kernel.org
Cc: Anton Protopopov <a.s.protopopov@gmail.com>
Subject: [PATCH v2 bpf-next 3/5] resolve_btfids: Do not tag seq_file operations
Date: Mon, 30 Nov 2026 18:04:20 +0000 [thread overview]
Message-ID: <20261130180425.150703-4-a.s.protopopov@gmail.com> (raw)
In-Reply-To: <20261130180425.150703-1-a.s.protopopov@gmail.com>
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 <a.s.protopopov@gmail.com>
---
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
next prev parent reply other threads:[~2026-11-30 17:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 18:04 [PATCH v2 bpf-next 0/5] Tag fmod_ret functions that return ERR_PTR() Anton Protopopov
2026-11-30 18:04 ` [PATCH v2 bpf-next 1/5] resolve_btfids: Do not count errors translated to NULL Anton Protopopov
2026-11-30 18:06 ` sashiko-bot
2026-11-30 20:02 ` Anton Protopopov
2026-11-30 18:04 ` [PATCH v2 bpf-next 2/5] resolve_btfids: Tag the functions that return ERR_PTR() Anton Protopopov
2026-11-30 18:04 ` Anton Protopopov [this message]
2026-11-30 18:04 ` [PATCH v2 bpf-next 4/5] resolve_btfids: Do not tag functions whose callers break on a skip Anton Protopopov
2026-11-30 18:02 ` sashiko-bot
2026-11-30 20:10 ` Anton Protopopov
2026-11-30 18:04 ` [PATCH v2 bpf-next 5/5] selftests/bpf: Test fmod_ret on functions that return a pointer Anton Protopopov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130180425.150703-4-a.s.protopopov@gmail.com \
--to=a.s.protopopov@gmail.com \
--cc=almagui@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=memxor@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox