From: Suchit Karunakaran <suchitkarunakaran@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev
Cc: song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org,
emil@etsalapatis.com, ihor.solodrai@linux.dev,
brauner@kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org,
Suchit Karunakaran <suchitkarunakaran@gmail.com>
Subject: [PATCH] bpf: Fix inode leak on token FD preparation failure
Date: Thu, 24 Sep 2026 00:22:06 +0530 [thread overview]
Message-ID: <20260923185206.91210-1-suchitkarunakaran@gmail.com> (raw)
bpf_token_create() allocates an inode before calling FD_PREPARE().
If descriptor allocation fails, alloc_file_pseudo() is never called.
If alloc_file_pseudo() fails, it leaves the inode reference with the
caller. Neither failure path releases the inode.
Call iput(inode) before returning the FD preparation error.
Fixes: 981bec8f698b ("bpf: convert bpf_token_create() to FD_PREPARE()")
Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com>
---
kernel/bpf/token.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/token.c b/kernel/bpf/token.c
index da915a4f972b..7375eaee6a23 100644
--- a/kernel/bpf/token.c
+++ b/kernel/bpf/token.c
@@ -169,8 +169,10 @@ int bpf_token_create(union bpf_attr *attr)
FD_PREPARE(fdf, O_CLOEXEC,
alloc_file_pseudo(inode, path.mnt, BPF_TOKEN_INODE_NAME,
O_RDWR, &bpf_token_fops));
- if (fdf->fd < 0)
+ if (fdf->fd < 0) {
+ iput(inode);
return fdf->fd;
+ }
token = kzalloc_obj(*token, GFP_USER);
if (!token)
--
2.55.0
reply other threads:[~2026-09-23 18:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260923185206.91210-1-suchitkarunakaran@gmail.com \
--to=suchitkarunakaran@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®