linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: enforce chroot for btrfs receive
@ 2015-04-14 10:44 Lauri Võsandi
  2015-04-14 12:28 ` David Sterba
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Lauri Võsandi @ 2015-04-14 10:44 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Lauri Võsandi

This patch forces btrfs receive to issue chroot before
parsing the btrfs stream to confine the process and
minimize damage that could be done via malicious
btrfs stream.

Signed-off-by: Lauri Võsandi <lauri.vosandi@gmail.com>
---
 cmds-receive.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/cmds-receive.c b/cmds-receive.c
index 44ef27e..8be92ea 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -867,15 +867,17 @@ static int do_receive(struct btrfs_receive *r, const char *tomnt, int r_fd,
 		goto out;
 	}
 
-	/*
-	 * find_mount_root returns a root_path that is a subpath of
-	 * dest_dir_full_path. Now get the other part of root_path,
-	 * which is the destination dir relative to root_path.
-	 */
-	r->dest_dir_path = dest_dir_full_path + strlen(r->root_path);
-	while (r->dest_dir_path[0] == '/')
-		r->dest_dir_path++;
+	if (chroot(dest_dir_full_path)) {
+		ret = -errno;
+		fprintf(stderr,
+			"ERROR: failed to chroot to %s, %s\n",
+			dest_dir_full_path,
+			strerror(-ret));
+		goto out;
+	}
 
+	r->root_path = r->dest_dir_path = strdup("/");
+	
 	ret = subvol_uuid_search_init(r->mnt_fd, &r->sus);
 	if (ret < 0)
 		goto out;
-- 
1.9.1


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

end of thread, other threads:[~2015-04-22 17:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-14 10:44 [PATCH] btrfs-progs: enforce chroot for btrfs receive Lauri Võsandi
2015-04-14 12:28 ` David Sterba
2015-04-14 13:19   ` Austin S Hemmelgarn
2015-04-17 17:34     ` David Sterba
2015-04-18 13:59 ` [PATCH] btrfs-progs: optionally " Lauri Võsandi
2015-04-18 14:52   ` Lauri Võsandi
2015-04-19  7:25   ` Mike Fleetwood
2015-04-19 11:46 ` Lauri Võsandi
2015-04-19 12:05   ` Roman Mamedov
2015-04-20 12:13     ` lauri
2015-04-22 17:27   ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).