[PATCH 3/6] fs: clear FMODE_LSEEK if no llseek function

From: Jason A. Donenfeld
Date: Fri Jun 24 2022 - 12:57:36 EST


This helps unify a longstanding wart where FMODE_LSEEK hasn't been
uniformly unset when it should be.

Signed-off-by: Jason A. Donenfeld <Jason@xxxxxxxxx>
---
fs/file_table.c | 2 ++
fs/open.c | 2 ++
2 files changed, 4 insertions(+)

diff --git a/fs/file_table.c b/fs/file_table.c
index 5424e3a8df5f..15700b2e1b53 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -241,6 +241,8 @@ static struct file *alloc_file(const struct path *path, int flags,
if ((file->f_mode & FMODE_WRITE) &&
likely(fop->write || fop->write_iter))
file->f_mode |= FMODE_CAN_WRITE;
+ if ((file->f_mode & FMODE_LSEEK) && !file->f_op->llseek)
+ file->f_mode &= ~FMODE_LSEEK;
file->f_mode |= FMODE_OPENED;
file->f_op = fop;
if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
diff --git a/fs/open.c b/fs/open.c
index 1d57fbde2feb..07c332753a36 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -858,6 +858,8 @@ static int do_dentry_open(struct file *f,
if ((f->f_mode & FMODE_WRITE) &&
likely(f->f_op->write || f->f_op->write_iter))
f->f_mode |= FMODE_CAN_WRITE;
+ if ((f->f_mode & FMODE_LSEEK) && !f->f_op->llseek)
+ f->f_mode &= ~FMODE_LSEEK;
if (f->f_mapping->a_ops && f->f_mapping->a_ops->direct_IO)
f->f_mode |= FMODE_CAN_ODIRECT;

--
2.35.1