Skip to contentSkip to conversation

ceph: validate fscrypt auth blob length

PATCH In review sung byeongchan 2 participants 2 messages Oct 8 – Oct 12 Ceph client

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: validate fscrypt auth blob length

ceph_crypt_get_context() trusts cfa_blob_len after checking only that the inode-owned fscrypt_auth allocation contains the fixed header and one byte. An MDS can therefore place a larger inner length in a shorter outer object, causing memcpy() to read beyond the allocation when a caller requests the encryption nonce.

Require the complete blob to fit in the inode-owned allocation before using the inner length.

On the tested baseline, the malformed reply produced the same KASAN slab-out-of-bounds read twice. An ordinary UID obtained sixteen wire-absent SLUB redzone bytes in two non-KASAN production-path runs. The input was rejected twice after this change, while a complete context still worked.

Fixes 2d332d5bc424 ("ceph: fscrypt_auth handling for ceph")
Assisted-by LLM
---
 fs/ceph/crypto.c | 3 +++
 1 file changed, 3 insertions(+)
fs/ceph/crypto.c +3 -0
index bc0a097a4cea9..720f34ee8ed42 100644
@@ -30,6 +30,9 @@ static int ceph_crypt_get_context(struct inode *inode, void *ctx, size_t len)
 		return -ENOBUFS;
 
 	ctxlen = le32_to_cpu(cfa->cfa_blob_len);
+	if (ctxlen > ci->fscrypt_auth_len -
+		     offsetof(struct ceph_fscrypt_auth, cfa_blob))
+		return -ENOBUFS;
 	if (len < ctxlen)
 		return -ERANGE;
 
Signature · 1 line
2.43.0