Skip to content

Commit e35fa56

Browse files
keestorvalds
authored andcommitted
hfsplus: use struct_group_attr() for memcpy() region
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>
1 parent e1ce8a9 commit e35fa56

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

fs/hfsplus/hfsplus_raw.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,10 @@ struct hfsplus_cat_folder {
260260
__be32 access_date;
261261
__be32 backup_date;
262262
struct hfsplus_perm permissions;
263-
struct DInfo user_info;
264-
struct DXInfo finder_info;
263+
struct_group_attr(info, __packed,
264+
struct DInfo user_info;
265+
struct DXInfo finder_info;
266+
);
265267
__be32 text_encoding;
266268
__be32 subfolders; /* Subfolder count in HFSX. Reserved in HFS+. */
267269
} __packed;
@@ -294,8 +296,10 @@ struct hfsplus_cat_file {
294296
__be32 access_date;
295297
__be32 backup_date;
296298
struct hfsplus_perm permissions;
297-
struct FInfo user_info;
298-
struct FXInfo finder_info;
299+
struct_group_attr(info, __packed,
300+
struct FInfo user_info;
301+
struct FXInfo finder_info;
302+
);
299303
__be32 text_encoding;
300304
u32 reserved2;
301305

fs/hfsplus/xattr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ int __hfsplus_setxattr(struct inode *inode, const char *name,
296296
sizeof(hfsplus_cat_entry));
297297
if (be16_to_cpu(entry.type) == HFSPLUS_FOLDER) {
298298
if (size == folder_finderinfo_len) {
299-
memcpy(&entry.folder.user_info, value,
299+
memcpy(&entry.folder.info, value,
300300
folder_finderinfo_len);
301301
hfs_bnode_write(cat_fd.bnode, &entry,
302302
cat_fd.entryoffset,
@@ -309,7 +309,7 @@ int __hfsplus_setxattr(struct inode *inode, const char *name,
309309
}
310310
} else if (be16_to_cpu(entry.type) == HFSPLUS_FILE) {
311311
if (size == file_finderinfo_len) {
312-
memcpy(&entry.file.user_info, value,
312+
memcpy(&entry.file.info, value,
313313
file_finderinfo_len);
314314
hfs_bnode_write(cat_fd.bnode, &entry,
315315
cat_fd.entryoffset,

0 commit comments

Comments
 (0)