[PATCH] fs/ecryptfs: fix slab-out-of-bounds read in ecryptfs_verify_auth_tok_from_key

Nguyen Duy Nhat Anh posted 1 patch 1 week ago
There is a newer version of this series
fs/ecryptfs/ecryptfs_kernel.h | 3 +++
1 file changed, 3 insertions(+)
[PATCH] fs/ecryptfs: fix slab-out-of-bounds read in ecryptfs_verify_auth_tok_from_key
Posted by Nguyen Duy Nhat Anh 1 week ago
Add a bounds check in ecryptfs_get_key_payload_data() to ensure the
key payload datalen is at least sizeof(struct ecryptfs_auth_tok) before
returning the pointer. This prevents out-of-bounds reads when userspace
supplies a short payload via add_key().

Reported-by: syzbot+b9529ebe6a9394ddf825@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=b9529ebe6a9394ddf825
Signed-off-by: Nguyen Duy Nhat Anh <neganhat@gmail.com>
---
 fs/ecryptfs/ecryptfs_kernel.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index 58165928ed1e..3baccd4143e8 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -124,6 +124,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.55.0