Skip to content

Commit c82ea72

Browse files
olafheringgregkh
authored andcommitted
mount: handle OOM on mnt_warn_timestamp_expiry
[ Upstream commit 4bcda1e ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 032ca56 commit c82ea72

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
@@ -2796,17 +2796,25 @@ static void mnt_warn_timestamp_expiry(struct path *mountpoint, struct vfsmount *
27962796
if (!__mnt_is_readonly(mnt) &&
27972797
(!(sb->s_iflags & SB_I_TS_EXPIRY_WARNED)) &&
27982798
(ktime_get_real_seconds() + TIME_UPTIME_SEC_MAX > sb->s_time_max)) {
2799-
char *buf = (char *)__get_free_page(GFP_KERNEL);
2800-
char *mntpath = buf ? d_path(mountpoint, buf, PAGE_SIZE) : ERR_PTR(-ENOMEM);
2799+
char *buf, *mntpath;
2800+
2801+
buf = (char *)__get_free_page(GFP_KERNEL);
2802+
if (buf)
2803+
mntpath = d_path(mountpoint, buf, PAGE_SIZE);
2804+
else
2805+
mntpath = ERR_PTR(-ENOMEM);
2806+
if (IS_ERR(mntpath))
2807+
mntpath = "(unknown)";
28012808

28022809
pr_warn("%s filesystem being %s at %s supports timestamps until %ptTd (0x%llx)\n",
28032810
sb->s_type->name,
28042811
is_mounted(mnt) ? "remounted" : "mounted",
28052812
mntpath, &sb->s_time_max,
28062813
(unsigned long long)sb->s_time_max);
28072814

2808-
free_page((unsigned long)buf);
28092815
sb->s_iflags |= SB_I_TS_EXPIRY_WARNED;
2816+
if (buf)
2817+
free_page((unsigned long)buf);
28102818
}
28112819
}
28122820

0 commit comments

Comments
 (0)