Skip to content

Commit 14c9ca0

Browse files
adilgertytso
authored andcommitted
ext4: don't assume that mmp_nodename/bdevname have NUL
Don't assume that the mmp_nodename and mmp_bdevname strings are NUL terminated, since they are filled in by snprintf(), which is not guaranteed to do so. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Andreas Dilger <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected]
1 parent e5da4c9 commit 14c9ca0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

fs/ext4/mmp.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
120120
{
121121
__ext4_warning(sb, function, line, "%s", msg);
122122
__ext4_warning(sb, function, line,
123-
"MMP failure info: last update time: %llu, last update "
124-
"node: %s, last update device: %s",
125-
(long long unsigned int) le64_to_cpu(mmp->mmp_time),
126-
mmp->mmp_nodename, mmp->mmp_bdevname);
123+
"MMP failure info: last update time: %llu, last update node: %.*s, last update device: %.*s",
124+
(unsigned long long)le64_to_cpu(mmp->mmp_time),
125+
(int)sizeof(mmp->mmp_nodename), mmp->mmp_nodename,
126+
(int)sizeof(mmp->mmp_bdevname), mmp->mmp_bdevname);
127127
}
128128

129129
/*
@@ -154,6 +154,7 @@ static int kmmpd(void *data)
154154
mmp_check_interval = max(EXT4_MMP_CHECK_MULT * mmp_update_interval,
155155
EXT4_MMP_MIN_CHECK_INTERVAL);
156156
mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval);
157+
BUILD_BUG_ON(sizeof(mmp->mmp_bdevname) < BDEVNAME_SIZE);
157158
bdevname(bh->b_bdev, mmp->mmp_bdevname);
158159

159160
memcpy(mmp->mmp_nodename, init_utsname()->nodename,
@@ -379,7 +380,8 @@ int ext4_multi_mount_protect(struct super_block *sb,
379380
/*
380381
* Start a kernel thread to update the MMP block periodically.
381382
*/
382-
EXT4_SB(sb)->s_mmp_tsk = kthread_run(kmmpd, mmpd_data, "kmmpd-%s",
383+
EXT4_SB(sb)->s_mmp_tsk = kthread_run(kmmpd, mmpd_data, "kmmpd-%.*s",
384+
(int)sizeof(mmp->mmp_bdevname),
383385
bdevname(bh->b_bdev,
384386
mmp->mmp_bdevname));
385387
if (IS_ERR(EXT4_SB(sb)->s_mmp_tsk)) {

0 commit comments

Comments
 (0)