lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221017192006.36398-2-saeed.mirzamohammadi@oracle.com>
Date:   Mon, 17 Oct 2022 12:20:02 -0700
From:   Saeed Mirzamohammadi <saeed.mirzamohammadi@...cle.com>
To:     unlisted-recipients:; (no To-header on input)
Cc:     linux-fsdevel@...r.kernel.org, viro@...iv.linux.org.uk,
        linux-kernel@...r.kernel.org, stable@...r.kernel.org,
        jason@...c4.com, saeed.mirzamohammadi@...cle.com,
        "Jason A. Donenfeld" <Jason@...c4.com>
Subject: [PATCH stable 1/5] fs: clear or set FMODE_LSEEK based on llseek function

From: "Jason A. Donenfeld" <Jason@...c4.com>

Pipe-like behaviour on llseek(2) (i.e. unconditionally failing with
-ESPIPE) can be expresses in 3 ways:
	1) ->llseek set to NULL in file_operations
	2) ->llseek set to no_llseek in file_operations
	3) FMODE_LSEEK *not* set in ->f_mode.

Enforce (3) in cases (1) and (2); that will allow to simplify the
checks and eventually get rid of no_llseek boilerplate.

Signed-off-by: Jason A. Donenfeld <Jason@...c4.com>
Signed-off-by: Al Viro <viro@...iv.linux.org.uk>
(cherry picked from commit e7478158e1378325907edfdd960eca98a1be405b)
Conflicts:
	fs/open.c
Cc: stable@...r.kernel.org
Signed-off-by: Saeed Mirzamohammadi <saeed.mirzamohammadi@...cle.com>
---
 fs/file_table.c | 2 ++
 fs/open.c       | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/fs/file_table.c b/fs/file_table.c
index e8c9016703ad..f675817be4ad 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -198,6 +198,8 @@ static struct file *alloc_file(const struct path *path, int flags,
 	file->f_mapping = path->dentry->d_inode->i_mapping;
 	file->f_wb_err = filemap_sample_wb_err(file->f_mapping);
 	file->f_sb_err = file_sample_sb_err(file);
+	if (fop->llseek && fop->llseek != no_llseek)
+		file->f_mode |= FMODE_LSEEK;
 	if ((file->f_mode & FMODE_READ) &&
 	     likely(fop->read || fop->read_iter))
 		file->f_mode |= FMODE_CAN_READ;
diff --git a/fs/open.c b/fs/open.c
index 1ba1d2ab2ef0..38bf38d41418 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -834,6 +834,10 @@ 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_mode & FMODE_LSEEK) && f->f_op->llseek == no_llseek)
+		f->f_mode &= ~FMODE_LSEEK;
 
 	f->f_write_hint = WRITE_LIFE_NOT_SET;
 	f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ