Skip to content

Commit 0ecee66

Browse files
ebiggersAl Viro
authored andcommitted
fs/namespace.c: fix use-after-free of mount in mnt_warn_timestamp_expiry()
After do_add_mount() returns success, the caller doesn't hold a reference to the 'struct mount' anymore. So it's invalid to access it in mnt_warn_timestamp_expiry(). Fix it by calling mnt_warn_timestamp_expiry() before do_add_mount() rather than after, and adjusting the warning message accordingly. Reported-by: [email protected] Fixes: f8b92ba ("mount: Add mount warning for impending timestamp expiry") Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 4f5cafb commit 0ecee66

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

fs/namespace.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,8 +2478,10 @@ static void mnt_warn_timestamp_expiry(struct path *mountpoint, struct vfsmount *
24782478

24792479
time64_to_tm(sb->s_time_max, 0, &tm);
24802480

2481-
pr_warn("Mounted %s file system at %s supports timestamps until %04ld (0x%llx)\n",
2482-
sb->s_type->name, mntpath,
2481+
pr_warn("%s filesystem being %s at %s supports timestamps until %04ld (0x%llx)\n",
2482+
sb->s_type->name,
2483+
is_mounted(mnt) ? "remounted" : "mounted",
2484+
mntpath,
24832485
tm.tm_year+1900, (unsigned long long)sb->s_time_max);
24842486

24852487
free_page((unsigned long)buf);
@@ -2764,14 +2766,11 @@ static int do_new_mount_fc(struct fs_context *fc, struct path *mountpoint,
27642766
if (IS_ERR(mnt))
27652767
return PTR_ERR(mnt);
27662768

2767-
error = do_add_mount(real_mount(mnt), mountpoint, mnt_flags);
2768-
if (error < 0) {
2769-
mntput(mnt);
2770-
return error;
2771-
}
2772-
27732769
mnt_warn_timestamp_expiry(mountpoint, mnt);
27742770

2771+
error = do_add_mount(real_mount(mnt), mountpoint, mnt_flags);
2772+
if (error < 0)
2773+
mntput(mnt);
27752774
return error;
27762775
}
27772776

0 commit comments

Comments
 (0)