From: Daniel Vogelbacher <daniel@chaospixel.com>
To: ceph-devel@vger.kernel.org
Cc: xiubli@redhat.com, idryomov@gmail.com
Subject: [PATCH] fs/ceph: Fix kernel oops due invalid pointer for kfree() in parse_longname()
Date: Sat, 20 Dec 2025 15:01:53 +0100 [thread overview]
Message-ID: <20251220140153.1523907-1-daniel@chaospixel.com> (raw)
This fixes a kernel oops when reading ceph snapshot directories (.snap),
for example by simply run `ls /mnt/my_ceph/.snap`.
The bug was introduced in commit:
bb80f7618832 - parse_longname(): strrchr() expects NUL-terminated string
str is guarded by __free(kfree), but advanced later for skipping
the initial '_' in snapshot names.
This patch removes the need for advancing the pointer so kfree()
could do proper memory cleanup.
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220807
Fixes: bb80f7618832 - parse_longname(): strrchr() expects NUL-terminated string
Cc: stable@vger.kernel.org
Suggested-by: Helge Deller <deller@gmx.de>
Signed-off-by: Daniel Vogelbacher <daniel@chaospixel.com>
---
fs/ceph/crypto.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/ceph/crypto.c b/fs/ceph/crypto.c
index 0ea4db650f85..3e051972e49d 100644
--- a/fs/ceph/crypto.c
+++ b/fs/ceph/crypto.c
@@ -166,12 +166,12 @@ static struct inode *parse_longname(const struct inode *parent,
struct ceph_vino vino = { .snap = CEPH_NOSNAP };
char *name_end, *inode_number;
int ret = -EIO;
- /* NUL-terminate */
- char *str __free(kfree) = kmemdup_nul(name, *name_len, GFP_KERNEL);
+ if (*name_len <= 1)
+ return ERR_PTR(-EIO);
+ /* Skip initial '_' and NUL-terminate */
+ char *str __free(kfree) = kmemdup_nul(name + 1, *name_len - 1, GFP_KERNEL);
if (!str)
return ERR_PTR(-ENOMEM);
- /* Skip initial '_' */
- str++;
name_end = strrchr(str, '_');
if (!name_end) {
doutc(cl, "failed to parse long snapshot name: %s\n", str);
--
2.47.3
next reply other threads:[~2025-12-20 14:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-20 14:01 Daniel Vogelbacher [this message]
2025-12-22 20:08 ` [PATCH] fs/ceph: Fix kernel oops due invalid pointer for kfree() in parse_longname() Viacheslav Dubeyko
2025-12-22 21:26 ` Daniel Vogelbacher
2025-12-23 22:49 ` Viacheslav Dubeyko
2026-01-20 13:42 ` Daniel Vogelbacher
2026-01-21 20:44 ` Viacheslav Dubeyko
2026-01-21 21:38 ` Daniel Vogelbacher
2026-02-01 8:34 ` [PATCH v2] " Daniel Vogelbacher
2026-02-02 19:13 ` Viacheslav Dubeyko
2026-02-03 19:23 ` Viacheslav Dubeyko
2026-02-03 19:41 ` Daniel Vogelbacher
2026-02-03 19:40 ` [PATCH v3] " Daniel Vogelbacher
2026-02-03 20:16 ` Viacheslav Dubeyko
2026-02-03 20:22 ` Ilya Dryomov
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=20251220140153.1523907-1-daniel@chaospixel.com \
--to=daniel@chaospixel.com \
--cc=ceph-devel@vger.kernel.org \
--cc=idryomov@gmail.com \
--cc=xiubli@redhat.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