public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4.19 1/6] ovl: check permission to open real file
@ 2024-08-29 15:17 hsimeliere.opensource
  2024-08-29 15:17 ` [PATCH 4.19 2/6] ovl: verify permissions in ovl_path_open() hsimeliere.opensource
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: hsimeliere.opensource @ 2024-08-29 15:17 UTC (permalink / raw)
  To: stable; +Cc: Miklos Szeredi, Hugo SIMELIERE

From: Miklos Szeredi <mszeredi@redhat.com>

commit 05acefb4872dae89e772729efb194af754c877e8 upstream.

Call inode_permission() on real inode before opening regular file on one of
the underlying layers.

In some cases ovl_permission() already checks access to an underlying file,
but it misses the metacopy case, and possibly other ones as well.

Removing the redundant permission check from ovl_permission() should be
considered later.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Hugo SIMELIERE <hsimeliere.opensource@witekio.com>
---
 fs/overlayfs/file.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 73c3e2c21edb..24a83ed9829a 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -34,10 +34,22 @@ static struct file *ovl_open_realfile(const struct file *file,
 	struct file *realfile;
 	const struct cred *old_cred;
 	int flags = file->f_flags | OVL_OPEN_FLAGS;
+	int acc_mode = ACC_MODE(flags);
+	int err;
+
+	if (flags & O_APPEND)
+		acc_mode |= MAY_APPEND;
 
 	old_cred = ovl_override_creds(inode->i_sb);
-	realfile = open_with_fake_path(&file->f_path, flags, realinode,
-				       current_cred());
+	err = inode_permission(realinode, MAY_OPEN | acc_mode);
+	if (err) {
+		realfile = ERR_PTR(err);
+	} else if (!inode_owner_or_capable(realinode)) {
+		realfile = ERR_PTR(-EPERM);
+	} else {
+		realfile = open_with_fake_path(&file->f_path, flags, realinode,
+					       current_cred());
+	}
 	revert_creds(old_cred);
 
 	pr_debug("open(%p[%pD2/%c], 0%o) -> (%p, 0%o)\n",
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-08-29 16:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-29 15:17 [PATCH 4.19 1/6] ovl: check permission to open real file hsimeliere.opensource
2024-08-29 15:17 ` [PATCH 4.19 2/6] ovl: verify permissions in ovl_path_open() hsimeliere.opensource
2024-08-29 15:17 ` [PATCH 4.19 3/6] ovl: switch to mounter creds in readdir hsimeliere.opensource
2024-08-29 15:17 ` [PATCH 4.19 4/6] ovl: do not fail because of O_NOATIME hsimeliere.opensource
2024-08-29 15:17 ` [PATCH 4.19 5/6] ovl: pass correct flags for opening real directory hsimeliere.opensource
2024-08-29 15:17 ` [PATCH 4.19 6/6] ovl: call secutiry hook in ovl_real_ioctl() hsimeliere.opensource
2024-08-29 15:43   ` This series of patches fixes this CVE: CVE-2020-16120 https://nvd.nist.gov/vuln/detail/CVE-2020-16120 hsimeliere.opensource
2024-08-29 16:17 ` [PATCH 4.19 1/6] ovl: check permission to open real file Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox