public inbox for ceph-devel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/ceph: Fix kernel oops due invalid pointer for kfree() in parse_longname()
@ 2025-12-20 14:01 Daniel Vogelbacher
  2025-12-22 20:08 ` Viacheslav Dubeyko
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Daniel Vogelbacher @ 2025-12-20 14:01 UTC (permalink / raw)
  To: ceph-devel; +Cc: xiubli, idryomov

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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2026-02-03 20:22 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-20 14:01 [PATCH] fs/ceph: Fix kernel oops due invalid pointer for kfree() in parse_longname() Daniel Vogelbacher
2025-12-22 20:08 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox