|
|
1d442b |
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
1d442b |
Date: Mon, 27 Jan 2020 19:01:24 +0000
|
|
|
1d442b |
Subject: [PATCH] virtiofsd: prevent ".." escape in lo_do_lookup()
|
|
|
1d442b |
|
|
|
1d442b |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
1d442b |
Reviewed-by: Sergio Lopez <slp@redhat.com>
|
|
|
1d442b |
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
1d442b |
(cherry picked from commit 854684bc0b3d63eb90b3abdfe471c2e4271ef176)
|
|
|
1d442b |
---
|
|
|
1d442b |
tools/virtiofsd/passthrough_ll.c | 7 ++++++-
|
|
|
1d442b |
1 file changed, 6 insertions(+), 1 deletion(-)
|
|
|
1d442b |
|
|
|
1d442b |
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
|
|
|
1d442b |
index e375406160..79d5966eea 100644
|
|
|
1d442b |
--- a/tools/virtiofsd/passthrough_ll.c
|
|
|
1d442b |
+++ b/tools/virtiofsd/passthrough_ll.c
|
|
|
1d442b |
@@ -624,12 +624,17 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
|
|
|
1d442b |
int res;
|
|
|
1d442b |
int saverr;
|
|
|
1d442b |
struct lo_data *lo = lo_data(req);
|
|
|
1d442b |
- struct lo_inode *inode;
|
|
|
1d442b |
+ struct lo_inode *inode, *dir = lo_inode(req, parent);
|
|
|
1d442b |
|
|
|
1d442b |
memset(e, 0, sizeof(*e));
|
|
|
1d442b |
e->attr_timeout = lo->timeout;
|
|
|
1d442b |
e->entry_timeout = lo->timeout;
|
|
|
1d442b |
|
|
|
1d442b |
+ /* Do not allow escaping root directory */
|
|
|
1d442b |
+ if (dir == &lo->root && strcmp(name, "..") == 0) {
|
|
|
1d442b |
+ name = ".";
|
|
|
1d442b |
+ }
|
|
|
1d442b |
+
|
|
|
1d442b |
newfd = openat(lo_fd(req, parent), name, O_PATH | O_NOFOLLOW);
|
|
|
1d442b |
if (newfd == -1) {
|
|
|
1d442b |
goto out_err;
|