[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250806-fscontext-log-cleanups-v1-1-880597d42a5a@cyphar.com>
Date: Wed, 06 Aug 2025 15:31:10 +1000
From: Aleksa Sarai <cyphar@...har.com>
To: Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>,
David Howells <dhowells@...hat.com>, Shuah Khan <shuah@...nel.org>
Cc: linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org, Aleksa Sarai <cyphar@...har.com>,
stable@...r.kernel.org
Subject: [PATCH 1/2] fscontext: do not consume log entries for -EMSGSIZE
case
Userspace generally expects APIs that return EMSGSIZE to allow for them
to adjust their buffer size and retry the operation. However, the
fscontext log would previously clear the message even in the EMSGSIZE
case.
Given that it is very cheap for us to check whether the buffer is too
small before we remove the message from the ring buffer, let's just do
that instead.
Fixes: 007ec26cdc9f ("vfs: Implement logging through fs_context")
Cc: David Howells <dhowells@...hat.com>
Cc: <stable@...r.kernel.org> # v5.2+
Signed-off-by: Aleksa Sarai <cyphar@...har.com>
---
fs/fsopen.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/fs/fsopen.c b/fs/fsopen.c
index 1aaf4cb2afb2..f5fdaa97965b 100644
--- a/fs/fsopen.c
+++ b/fs/fsopen.c
@@ -36,23 +36,25 @@ static ssize_t fscontext_read(struct file *file,
if (ret < 0)
return ret;
- if (log->head == log->tail) {
- mutex_unlock(&fc->uapi_mutex);
- return -ENODATA;
- }
+ ret = -ENODATA;
+ if (log->head == log->tail)
+ goto err_unlock_nomsg;
index = log->tail & (logsize - 1);
p = log->buffer[index];
+ n = strlen(p);
+
+ ret = -EMSGSIZE;
+ if (n > len)
+ goto err_unlock_nomsg;
+
+ /* Consume the message from the queue. */
need_free = log->need_free & (1 << index);
log->buffer[index] = NULL;
log->need_free &= ~(1 << index);
log->tail++;
mutex_unlock(&fc->uapi_mutex);
- ret = -EMSGSIZE;
- n = strlen(p);
- if (n > len)
- goto err_free;
ret = -EFAULT;
if (copy_to_user(_buf, p, n) != 0)
goto err_free;
@@ -62,6 +64,10 @@ static ssize_t fscontext_read(struct file *file,
if (need_free)
kfree(p);
return ret;
+
+err_unlock_nomsg:
+ mutex_unlock(&fc->uapi_mutex);
+ return ret;
}
static int fscontext_release(struct inode *inode, struct file *file)
--
2.50.1
Powered by blists - more mailing lists