Skip to contentSkip to conversation

ceph: validate snapdirname option length when mounting

PATCH In review Ilya Dryomov 2 participants 2 messages Dec 7, 2024 – Dec 9, 2024 Ceph client

lore
Share & tools
lore

Ilya Dryomov

author maintainer
#0 lore raw

PATCH 1/1 ceph: validate snapdirname option length when mounting

It becomes a path component, so it shouldn't exceed NAME_MAX characters. This was hardened in commit c152737be22b ("ceph: Use strscpy() instead of strcpy() in __get_snap_name()"), but no actual check was put in place.

---
 fs/ceph/super.c | 2 ++
 1 file changed, 2 insertions(+)
fs/ceph/super.c +2 -0
index cfe21f320f4a..f86fc5fb858a 100644
@@ -431,6 +431,8 @@ static int ceph_parse_mount_param(struct fs_context *fc,
 
 	switch (token) {
 	case Opt_snapdirname:
+		if (strlen(param->string) > NAME_MAX)
+			return invalfc(fc, "snapdirname too long");
 		kfree(fsopt->snapdir_name);
 		fsopt->snapdir_name = param->string;
 		param->string = NULL;
Signature · 1 line
2.46.1
#1 lore raw
Quoted 20 lines · Ilya Dryomov

It becomes a path component, so it shouldn't exceed NAME_MAX characters.  This was hardened in commit c152737be22b ("ceph: Use strscpy() instead of strcpy() in __get_snap_name()"), but no actual check was put in place.

---
 fs/ceph/super.c | 2 ++

 1 file changed, 2 insertions(+)
fs/ceph/super.c +0 -0
index cfe21f320f4a..f86fc5fb858a 100644
@@ -431,6 +431,8 @@ static int ceph_parse_mount_param(struct
 fs_context *fc,


  switch (token) {
  case Opt_snapdirname:

fs/ceph/super.c static int ceph_parse_mount_param(struct fs_context *fc, · line 435

Quoted 2 lines
fs/ceph/super.c +2 -0
+		if (strlen(param->string) > NAME_MAX)
+			return invalfc(fc, "snapdirname too long");

This check makes sense to me. :) Looks really good!

Thanks,
Slava.

Quoted 3 lines

  kfree(fsopt->snapdir_name); fsopt->snapdir_name = param->string; param->string = NULL;