]> git.itanic.dy.fi Git - linux-stable/commitdiff
ext4: fix fortify warning in fs/ext4/fast_commit.c:1551
authorTheodore Ts'o <tytso@mit.edu>
Sun, 6 Nov 2022 03:42:36 +0000 (23:42 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 6 Nov 2022 05:07:59 +0000 (01:07 -0400)
With the new fortify string system, rework the memcpy to avoid this
warning:

memcpy: detected field-spanning write (size 60) of single field "&raw_inode->i_generation" at fs/ext4/fast_commit.c:1551 (size 4)

Cc: stable@kernel.org
Fixes: 54d9469bc515 ("fortify: Add run-time WARN for cross-field memcpy()")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/fast_commit.c

index ef05bfa87798c12f2ebba8ff56ee58a5ab5343bf..0f6d0a80467d7eb0f5cefff63d04b250a59bf3f8 100644 (file)
@@ -1521,6 +1521,7 @@ static int ext4_fc_replay_inode(struct super_block *sb, struct ext4_fc_tl *tl,
        struct ext4_iloc iloc;
        int inode_len, ino, ret, tag = tl->fc_tag;
        struct ext4_extent_header *eh;
+       size_t off_gen = offsetof(struct ext4_inode, i_generation);
 
        memcpy(&fc_inode, val, sizeof(fc_inode));
 
@@ -1548,8 +1549,8 @@ static int ext4_fc_replay_inode(struct super_block *sb, struct ext4_fc_tl *tl,
        raw_inode = ext4_raw_inode(&iloc);
 
        memcpy(raw_inode, raw_fc_inode, offsetof(struct ext4_inode, i_block));
-       memcpy(&raw_inode->i_generation, &raw_fc_inode->i_generation,
-               inode_len - offsetof(struct ext4_inode, i_generation));
+       memcpy((u8 *)raw_inode + off_gen, (u8 *)raw_fc_inode + off_gen,
+              inode_len - off_gen);
        if (le32_to_cpu(raw_inode->i_flags) & EXT4_EXTENTS_FL) {
                eh = (struct ext4_extent_header *)(&raw_inode->i_block[0]);
                if (eh->eh_magic != EXT4_EXT_MAGIC) {