public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Olaf Hering <olaf@aepfle.de>
To: Deepa Dinamani <deepa.kernel@gmail.com>,
	Jeff Layton <jlayton@kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>
Subject: [PATCH v1] mount: handle OOM on mnt_warn_timestamp_expiry
Date: Tue, 30 Jul 2024 10:58:13 +0200	[thread overview]
Message-ID: <20240730085856.32385-1-olaf@aepfle.de> (raw)

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. The API of that function is not
documented. It currently returns only ERR_PTR values, but may return
also NULL in the future. Use PTR_ERR_OR_ZERO to cover both cases.

Fixes: f8b92ba67c5d ("mount: Add mount warning for impending timestamp expiry")

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 fs/namespace.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 328087a4df8a..539d4f203a20 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2922,7 +2922,14 @@ static void mnt_warn_timestamp_expiry(struct path *mountpoint, struct vfsmount *
 	   (!(sb->s_iflags & SB_I_TS_EXPIRY_WARNED)) &&
 	   (ktime_get_real_seconds() + TIME_UPTIME_SEC_MAX > sb->s_time_max)) {
 		char *buf = (char *)__get_free_page(GFP_KERNEL);
-		char *mntpath = buf ? d_path(mountpoint, buf, PAGE_SIZE) : ERR_PTR(-ENOMEM);
+		char *mntpath;
+		
+		if (!buf)
+			return;
+
+		mntpath = d_path(mountpoint, buf, PAGE_SIZE);
+		if (PTR_ERR_OR_ZERO(mntpath))
+			goto err;
 
 		pr_warn("%s filesystem being %s at %s supports timestamps until %ptTd (0x%llx)\n",
 			sb->s_type->name,
@@ -2930,8 +2937,9 @@ static void mnt_warn_timestamp_expiry(struct path *mountpoint, struct vfsmount *
 			mntpath, &sb->s_time_max,
 			(unsigned long long)sb->s_time_max);
 
-		free_page((unsigned long)buf);
 		sb->s_iflags |= SB_I_TS_EXPIRY_WARNED;
+err:
+		free_page((unsigned long)buf);
 	}
 }
 

             reply	other threads:[~2024-07-30  8:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-30  8:58 Olaf Hering [this message]
2024-07-30  9:49 ` [PATCH v1] mount: handle OOM on mnt_warn_timestamp_expiry Christian Brauner
2024-07-30 13:11   ` Jan Kara
2024-07-30 15:49 ` Al Viro
2024-07-30 19:58   ` Olaf Hering
2024-07-30 20:45     ` Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240730085856.32385-1-olaf@aepfle.de \
    --to=olaf@aepfle.de \
    --cc=brauner@kernel.org \
    --cc=deepa.kernel@gmail.com \
    --cc=jack@suse.cz \
    --cc=jlayton@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox