Commit 14c9ca05 authored by Andreas Dilger's avatar Andreas Dilger Committed by Theodore Ts'o

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/1580076215-1048-1-git-send-email-adilger@dilger.caSigned-off-by: default avatarAndreas Dilger <adilger@dilger.ca>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
parent e5da4c93
...@@ -120,10 +120,10 @@ void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp, ...@@ -120,10 +120,10 @@ void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
{ {
__ext4_warning(sb, function, line, "%s", msg); __ext4_warning(sb, function, line, "%s", msg);
__ext4_warning(sb, function, line, __ext4_warning(sb, function, line,
"MMP failure info: last update time: %llu, last update " "MMP failure info: last update time: %llu, last update node: %.*s, last update device: %.*s",
"node: %s, last update device: %s", (unsigned long long)le64_to_cpu(mmp->mmp_time),
(long long unsigned int) le64_to_cpu(mmp->mmp_time), (int)sizeof(mmp->mmp_nodename), mmp->mmp_nodename,
mmp->mmp_nodename, mmp->mmp_bdevname); (int)sizeof(mmp->mmp_bdevname), mmp->mmp_bdevname);
} }
/* /*
...@@ -154,6 +154,7 @@ static int kmmpd(void *data) ...@@ -154,6 +154,7 @@ static int kmmpd(void *data)
mmp_check_interval = max(EXT4_MMP_CHECK_MULT * mmp_update_interval, mmp_check_interval = max(EXT4_MMP_CHECK_MULT * mmp_update_interval,
EXT4_MMP_MIN_CHECK_INTERVAL); EXT4_MMP_MIN_CHECK_INTERVAL);
mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval); mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval);
BUILD_BUG_ON(sizeof(mmp->mmp_bdevname) < BDEVNAME_SIZE);
bdevname(bh->b_bdev, mmp->mmp_bdevname); bdevname(bh->b_bdev, mmp->mmp_bdevname);
memcpy(mmp->mmp_nodename, init_utsname()->nodename, memcpy(mmp->mmp_nodename, init_utsname()->nodename,
...@@ -379,7 +380,8 @@ int ext4_multi_mount_protect(struct super_block *sb, ...@@ -379,7 +380,8 @@ int ext4_multi_mount_protect(struct super_block *sb,
/* /*
* Start a kernel thread to update the MMP block periodically. * Start a kernel thread to update the MMP block periodically.
*/ */
EXT4_SB(sb)->s_mmp_tsk = kthread_run(kmmpd, mmpd_data, "kmmpd-%s", EXT4_SB(sb)->s_mmp_tsk = kthread_run(kmmpd, mmpd_data, "kmmpd-%.*s",
(int)sizeof(mmp->mmp_bdevname),
bdevname(bh->b_bdev, bdevname(bh->b_bdev,
mmp->mmp_bdevname)); mmp->mmp_bdevname));
if (IS_ERR(EXT4_SB(sb)->s_mmp_tsk)) { if (IS_ERR(EXT4_SB(sb)->s_mmp_tsk)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment