[PATCH] ecryptfs: validate auth token payload length before use

From: Qing Zhang

Date: Thu Nov 05 2026 - 13:05:00 EST


From: Qing Zhang <diasyzhang@xxxxxxxxxxx>

eCryptfs treats user and encrypted key payloads as struct
ecryptfs_auth_tok without checking their length. Short payloads with
valid version and token type fields can pass verification and cause
out-of-bounds reads during file or filename encryption.

Reject undersized payloads in both payload accessors with -EINVAL
before any authentication token fields are accessed.

Fixes: 237fead61998 ("[PATCH] ecryptfs: fs/Makefile and fs/Kconfig")
Fixes: 1252cc3b232e ("eCryptfs: added support for the encrypted key type")
Reported-by: syzbot+2e8c4ecc07730b29ae27@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzbot.org/bug?extid=2e8c4ecc07730b29ae27
Signed-off-by: Qing Zhang <diasyzhang@xxxxxxxxxxx>
---

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
fs/ecryptfs/ecryptfs_kernel.h | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index 58165928ed1e..4315c18ba1cd 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -88,6 +88,9 @@ ecryptfs_get_encrypted_key_payload_data(struct key *key)
if (!payload)
return ERR_PTR(-EKEYREVOKED);

+ if (payload->payload_datalen < sizeof(struct ecryptfs_auth_tok))
+ return ERR_PTR(-EINVAL);
+
return (struct ecryptfs_auth_tok *)payload->payload_data;
}

@@ -124,6 +127,9 @@ ecryptfs_get_key_payload_data(struct key *key)
if (!ukp)
return ERR_PTR(-EKEYREVOKED);

+ if (ukp->datalen < sizeof(struct ecryptfs_auth_tok))
+ return ERR_PTR(-EINVAL);
+
return (struct ecryptfs_auth_tok *)ukp->data;
}

--
2.43.7