Skip to content

Commit 4bcda1e

Browse files
olafheringbrauner
authored andcommitted
mount: handle OOM on mnt_warn_timestamp_expiry
If no page could be allocated, an error pointer was used as format string in pr_warn. Rearrange the code to return early in case of OOM. Also add a check for the return value of d_path. Fixes: f8b92ba ("mount: Add mount warning for impending timestamp expiry") Signed-off-by: Olaf Hering <[email protected]> Link: https://lore.kernel.org/r/[email protected] [brauner: rewrite commit and commit message] Signed-off-by: Christian Brauner <[email protected]>
1 parent de7007f commit 4bcda1e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

fs/namespace.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,17 +2921,25 @@ static void mnt_warn_timestamp_expiry(struct path *mountpoint, struct vfsmount *
29212921
if (!__mnt_is_readonly(mnt) &&
29222922
(!(sb->s_iflags & SB_I_TS_EXPIRY_WARNED)) &&
29232923
(ktime_get_real_seconds() + TIME_UPTIME_SEC_MAX > sb->s_time_max)) {
2924-
char *buf = (char *)__get_free_page(GFP_KERNEL);
2925-
char *mntpath = buf ? d_path(mountpoint, buf, PAGE_SIZE) : ERR_PTR(-ENOMEM);
2924+
char *buf, *mntpath;
2925+
2926+
buf = (char *)__get_free_page(GFP_KERNEL);
2927+
if (buf)
2928+
mntpath = d_path(mountpoint, buf, PAGE_SIZE);
2929+
else
2930+
mntpath = ERR_PTR(-ENOMEM);
2931+
if (IS_ERR(mntpath))
2932+
mntpath = "(unknown)";
29262933

29272934
pr_warn("%s filesystem being %s at %s supports timestamps until %ptTd (0x%llx)\n",
29282935
sb->s_type->name,
29292936
is_mounted(mnt) ? "remounted" : "mounted",
29302937
mntpath, &sb->s_time_max,
29312938
(unsigned long long)sb->s_time_max);
29322939

2933-
free_page((unsigned long)buf);
29342940
sb->s_iflags |= SB_I_TS_EXPIRY_WARNED;
2941+
if (buf)
2942+
free_page((unsigned long)buf);
29352943
}
29362944
}
29372945

0 commit comments

Comments
 (0)