Skip to contentSkip to conversation

ceph: fix base64 encoded name's length check in ceph_fname_to_usr()

PATCH In review [email protected] 2 participants 3 messages Mar 11, 2022 – Mar 12, 2022 Ceph client

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: fix base64 encoded name's length check in ceph_fname_to_usr()

From: Xiubo Li <[email protected]>

The fname->name is based64_encoded names and the max long shouldn't exceed the NAME_MAX.

The FSCRYPT_BASE64URL_CHARS(NAME_MAX) will be 255 * 4 / 3.

---

Note:

This patch is bansed on the wip-fscrpt branch in ceph-client repo.

 fs/ceph/crypto.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/crypto.c +1 -1
index 5a87e7385d3f..560481b6c964 100644
@@ -205,7 +205,7 @@ int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname,
 	}
 
 	/* Sanity check that the resulting name will fit in the buffer */
-	if (fname->name_len > FSCRYPT_BASE64URL_CHARS(NAME_MAX))
+	if (fname->name_len > NAME_MAX || fname->ctext_len > NAME_MAX)
 		return -EIO;
 
 	ret = __fscrypt_prepare_readdir(fname->dir);
Signature · 1 line
2.27.0
#1 lore raw
Quoted 23 lines · On Fri, 2022-03-11 at 12:15 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

The fname->name is based64_encoded names and the max long shouldn't exceed the NAME_MAX.

The FSCRYPT_BASE64URL_CHARS(NAME_MAX) will be 255 * 4 / 3.

---

Note:

This patch is bansed on the wip-fscrpt branch in ceph-client repo.

 fs/ceph/crypto.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/crypto.c +0 -0
index 5a87e7385d3f..560481b6c964 100644

fs/ceph/crypto.c int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname, · line 211

Quoted 8 lines
fs/ceph/crypto.c +1 -1
@@ -205,7 +205,7 @@ int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname,
 	}
 
 	/* Sanity check that the resulting name will fit in the buffer */
-	if (fname->name_len > FSCRYPT_BASE64URL_CHARS(NAME_MAX))
+	if (fname->name_len > NAME_MAX || fname->ctext_len > NAME_MAX)
 		return -EIO;
 
 	ret = __fscrypt_prepare_readdir(fname->dir);

Thanks, Xiubo. Merged into wip-fscrypt branch. For now I've left this as a separate patch, but I may squash it into the patch that adds ceph_fname_to_usr eventually.

Signature · 1 line
Jeff Layton <[email protected]>
author
#2 lore raw
Quoted 31 lines · Jeff Layton
Quoted 30 lines · On Fri, 2022-03-11 at 12:15 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

The fname->name is based64_encoded names and the max long shouldn't exceed the NAME_MAX.

The FSCRYPT_BASE64URL_CHARS(NAME_MAX) will be 255 * 4 / 3.

---

Note:

This patch is bansed on the wip-fscrpt branch in ceph-client repo.

  fs/ceph/crypto.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/crypto.c +1 -1
index 5a87e7385d3f..560481b6c964 100644
@@ -205,7 +205,7 @@ int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname,
  	}
 
  	/* Sanity check that the resulting name will fit in the buffer */
-	if (fname->name_len > FSCRYPT_BASE64URL_CHARS(NAME_MAX))
+	if (fname->name_len > NAME_MAX || fname->ctext_len > NAME_MAX)
  		return -EIO;
 
Quoted 5 lines

fs/ceph/crypto.c int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname, · line 211

Quoted 1 line
fs/ceph/crypto.c +0 -0
  	ret = __fscrypt_prepare_readdir(fname->dir);

Thanks, Xiubo. Merged into wip-fscrypt branch. For now I've left this as a separate patch, but I may squash it into the patch that adds ceph_fname_to_usr eventually.

Yeah, sure. Maybe just as one separate patch to help other to understand the code here ?

Thanks Jeff.

- Xiubo