[PATCH] hfsplus: add check for cat key length

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Syzbot reported a uninit-value in hfsplus_cat_bin_cmp_key.
The result of reading from the raw data of the node in hfs_bnode_read_u16()
is 0, and the final calculated catalog key length is 2, which will eventually
lead to too little key data read from the node to initialize the parent member
of struct hfsplus_cat_key.

The solution is to increase the key length judgment, and terminate the
subsequent operations if it is too small.

#syz test

Reported-by: syzbot+968ecf5dc01b3e0148ec@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=968ecf5dc01b3e0148ec
Signed-off-by: Edward Adam Davis <eadavis@xxxxxx>
---
 fs/hfsplus/brec.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/hfsplus/brec.c b/fs/hfsplus/brec.c
index 1918544a7871..da38638ad808 100644
--- a/fs/hfsplus/brec.c
+++ b/fs/hfsplus/brec.c
@@ -51,6 +51,13 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec)
 		}
 
 		retval = hfs_bnode_read_u16(node, recoff) + 2;
+		if (node->tree->cnid == HFSPLUS_CAT_CNID &&
+		    retval < offsetof(struct hfsplus_cat_key, parent) +
+			     sizeof(hfsplus_cnid)) {
+			pr_err("keylen %d too small\n",
+				retval);
+			return 0;
+		}
 		if (retval > node->tree->max_key_len + 2) {
 			pr_err("keylen %d too large\n",
 				retval);
-- 
2.43.0





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux