]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ntfs: limit memory allocation in ntfs_attr_readall
authorHyunchul Lee <hyc.lee@gmail.com>
Fri, 3 Apr 2026 01:10:39 +0000 (10:10 +0900)
committerNamjae Jeon <linkinjeon@kernel.org>
Sat, 18 Apr 2026 02:33:02 +0000 (11:33 +0900)
check an attribute size before memory allocation, and reject if the size
is over the maximum size.

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/ntfs/attrib.c

index 78915c1d5128025e2a989bd0962722e14fd4d48f..e8cc74c9c9a735cfeb40b5e6623b092d6da047ab 100644 (file)
 
 __le16 AT_UNNAMED[] = { cpu_to_le16('\0') };
 
+/*
+ * Maximum size allowed for reading attributes by ntfs_attr_readall().
+ * Extended attribute, reparse point are not expected to be larger than this size.
+ */
+
+#define NTFS_ATTR_READALL_MAX_SIZE     (64 * 1024)
+
 /*
  * ntfs_map_runlist_nolock - map (a part of) a runlist of an ntfs inode
  * @ni:                ntfs inode for which to map (part of) a runlist
@@ -5117,6 +5124,13 @@ void *ntfs_attr_readall(struct ntfs_inode *ni, const __le32 type,
        }
        bmp_ni = NTFS_I(bmp_vi);
 
+       if (bmp_ni->data_size > NTFS_ATTR_READALL_MAX_SIZE &&
+               (bmp_ni->type != AT_BITMAP ||
+               bmp_ni->data_size > ((ni->vol->nr_clusters + 7) >> 3))) {
+               ntfs_error(sb, "Invalid attribute data size");
+               goto out;
+       }
+
        data = kvmalloc(bmp_ni->data_size, GFP_NOFS);
        if (!data)
                goto out;