hfsplus: use struct_group_attr() for memcpy() region
authorKees Cook <keescook@chromium.org>
Thu, 20 Jan 2022 02:09:47 +0000 (18:09 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 20 Jan 2022 06:52:54 +0000 (08:52 +0200)
In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memset(), avoid intentionally writing across
neighboring fields.

Add struct_group() to mark the "info" region (containing struct DInfo
and struct DXInfo structs) in struct hfsplus_cat_folder and struct
hfsplus_cat_file that are written into directly, so the compiler can
correctly reason about the expected size of the writes.

"pahole" shows no size nor member offset changes to struct
hfsplus_cat_folder nor struct hfsplus_cat_file.  "objdump -d" shows no
object code changes.

Link: https://lkml.kernel.org/r/20211119192851.1046717-1-keescook@chromium.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/hfsplus/hfsplus_raw.h
fs/hfsplus/xattr.c

index 456e87aec7fd7eb016cc231822f93ce13129de42..68b4240c61916d08f2e5cad7c9239fbf8c974494 100644 (file)
@@ -260,8 +260,10 @@ struct hfsplus_cat_folder {
        __be32 access_date;
        __be32 backup_date;
        struct hfsplus_perm permissions;
-       struct DInfo user_info;
-       struct DXInfo finder_info;
+       struct_group_attr(info, __packed,
+               struct DInfo user_info;
+               struct DXInfo finder_info;
+       );
        __be32 text_encoding;
        __be32 subfolders;      /* Subfolder count in HFSX. Reserved in HFS+. */
 } __packed;
@@ -294,8 +296,10 @@ struct hfsplus_cat_file {
        __be32 access_date;
        __be32 backup_date;
        struct hfsplus_perm permissions;
-       struct FInfo user_info;
-       struct FXInfo finder_info;
+       struct_group_attr(info, __packed,
+               struct FInfo user_info;
+               struct FXInfo finder_info;
+       );
        __be32 text_encoding;
        u32 reserved2;
 
index e2855ceefd3943460d10b32408872e11953ad24c..49891b12c41566516f78ee678acd99d5f6a8b71e 100644 (file)
@@ -296,7 +296,7 @@ int __hfsplus_setxattr(struct inode *inode, const char *name,
                                        sizeof(hfsplus_cat_entry));
                if (be16_to_cpu(entry.type) == HFSPLUS_FOLDER) {
                        if (size == folder_finderinfo_len) {
-                               memcpy(&entry.folder.user_info, value,
+                               memcpy(&entry.folder.info, value,
                                                folder_finderinfo_len);
                                hfs_bnode_write(cat_fd.bnode, &entry,
                                        cat_fd.entryoffset,
@@ -309,7 +309,7 @@ int __hfsplus_setxattr(struct inode *inode, const char *name,
                        }
                } else if (be16_to_cpu(entry.type) == HFSPLUS_FILE) {
                        if (size == file_finderinfo_len) {
-                               memcpy(&entry.file.user_info, value,
+                               memcpy(&entry.file.info, value,
                                                file_finderinfo_len);
                                hfs_bnode_write(cat_fd.bnode, &entry,
                                        cat_fd.entryoffset,