[PATCH] ext4: avoid huge mmp update interval value

From: Pavel Skripkin
Date: Thu Aug 05 2021 - 10:23:40 EST


/* .. */

Signed-off-by: Pavel Skripkin <paskripkin@xxxxxxxxx>
---
fs/ext4/mmp.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
index bc364c119af6..2f632344d38c 100644
--- a/fs/ext4/mmp.c
+++ b/fs/ext4/mmp.c
@@ -7,6 +7,9 @@

#include "ext4.h"

+#define EXT4_KMMP_MAX_INTERVAL 100
+#define EXT4_KMMP_MIN_INTERVAL 5
+
/* Checksumming functions */
static __le32 ext4_mmp_csum(struct super_block *sb, struct mmp_struct *mmp)
{
@@ -140,6 +143,11 @@ static int kmmpd(void *data)
unsigned long diff;
int retval;

+ /* We should avoid unreasonale huge update interval, since it can cause
+ * task hung bug on umount or on error handling path in ext4_fill_super()
+ */
+ mmp_update_interval = clamp(mmp_update_interval, EXT4_KMMP_MIN_INTERVAL, EXT4_KMMP_MAX_INTERVAL);
+
mmp_block = le64_to_cpu(es->s_mmp_block);
mmp = (struct mmp_struct *)(bh->b_data);
mmp->mmp_time = cpu_to_le64(ktime_get_real_seconds());
@@ -156,6 +164,9 @@ static int kmmpd(void *data)
memcpy(mmp->mmp_nodename, init_utsname()->nodename,
sizeof(mmp->mmp_nodename));

+ ext4_msg(sb, KERN_INFO, "Started kmmp thread with update interval = %u\n",
+ mmp_update_interval);
+
while (!kthread_should_stop() && !sb_rdonly(sb)) {
if (!ext4_has_feature_mmp(sb)) {
ext4_warning(sb, "kmmpd being stopped since MMP feature"
--
2.32.0


--------------675893B3B0BF5C1099A6646E--