All of lore.kernel.org
 help / color / mirror / Atom feed
From: lauri <lauri.vosandi@gmail.com>
To: linux-btrfs@vger.kernel.org
Subject: Btrfs receive hardening patches
Date: Mon, 13 Apr 2015 14:13:06 +0300	[thread overview]
Message-ID: <CAJ1pDqSeVL8kVXsAfKvw=LCk5Q9Kbej7bcJ+BVC7jSrD8Etk7w@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 490 bytes --]

Hello,

due to security reasons in certain usecases it would be nice to force
btrfs receive to confine itself to the directory of subvolume. I've
attached a patch that issues chroot before parsing btrfs stream. Let
me know if this breaks anything, preliminary tests showed it performed
as expected. If necessary I can make this functionality optional via
command-line flag.

-- 
Lauri Võsandi
tel: +372 53329412
e-mail: lauri.vosandi@gmail.com
blog: http://lauri.vosandi.com/

[-- Attachment #2: preliminary-btrfs-receive-hardening-patches.diff --]
[-- Type: text/plain, Size: 909 bytes --]

diff --git a/cmds-receive.c b/cmds-receive.c
index 44ef27e..e03acdd 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -867,15 +867,20 @@ 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.
+
+	/**
+	 * Nasty hack to enforce chroot before parsing btrfs stream
 	 */
-	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)) {
+		fprintf(stderr,
+			"ERROR: failed to chroot to %s\n",
+			dest_dir_full_path);
+		ret = -EINVAL;
+		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;

                 reply	other threads:[~2015-04-13 11:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='CAJ1pDqSeVL8kVXsAfKvw=LCk5Q9Kbej7bcJ+BVC7jSrD8Etk7w@mail.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.