All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lauri Võsandi" <lauri.vosandi@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: "Lauri Võsandi" <lauri.vosandi@gmail.com>
Subject: [PATCH] btrfs-progs: enforce chroot for btrfs receive
Date: Tue, 14 Apr 2015 13:44:32 +0300	[thread overview]
Message-ID: <217a387d55b5828a82fadad98dd88a959e7a13ed.1429008167.git.lauri.vosandi@gmail.com> (raw)

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


             reply	other threads:[~2015-04-14 10:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-14 10:44 Lauri Võsandi [this message]
2015-04-14 12:28 ` [PATCH] btrfs-progs: enforce chroot for btrfs receive 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=217a387d55b5828a82fadad98dd88a959e7a13ed.1429008167.git.lauri.vosandi@gmail.com \
    --to=lauri.vosandi@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.