From patchwork Mon May 18 09:16:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 6427051 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 698479F1C1 for ; Mon, 18 May 2015 09:16:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8A8142060B for ; Mon, 18 May 2015 09:16:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 98FD620611 for ; Mon, 18 May 2015 09:16:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752962AbbERJQt (ORCPT ); Mon, 18 May 2015 05:16:49 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:32903 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752846AbbERJQr (ORCPT ); Mon, 18 May 2015 05:16:47 -0400 Received: by padbw4 with SMTP id bw4so144024264pad.0 for ; Mon, 18 May 2015 02:16:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=jNI4WQNu1yPm+/dp534bOXZNSwg4DEG1UBUMlWke7iQ=; b=PHXwfdH4ORx4UNoBS8784jYKzsM71FVP4GOr0yTW/BQrutW31yDIW45LkHxK2a0etR ERte3oKWjj6sFJOgQHqnDfMF3p/e+jTQo2lmuV2Gl9RXETSyFAtdvKEtteeHbcZEdemR B3iqYp56YMt185uwkP457PrGBFt2W3aPjgCroi7vL54YtrphlYHpksLhKgB3xcMJkmMt S+jtPhKamaR88jHqANmzRo+CPq3Qhcrel19haqOQOP1I2aVgtHgR2mWzxfcF48f+UpjV cbVyMtNmuOSjK2zcTK3tuQhKiXf4tx+czG8CRiU9RQLyVkcr32ENodHs6OWtiL0FyYJ0 neAg== X-Gm-Message-State: ALoCoQlXjz4vZ0hiKpxZGh4+sQA7fKAPbj6urDgWhbdmeg//DPZKqpUUTcwzLEZQG0vK1FHEl6SS X-Received: by 10.70.127.138 with SMTP id ng10mr42451364pdb.111.1431940606534; Mon, 18 May 2015 02:16:46 -0700 (PDT) Received: from mew.localdomain (c-76-104-211-44.hsd1.wa.comcast.net. [76.104.211.44]) by mx.google.com with ESMTPSA id v2sm9377370pdn.90.2015.05.18.02.16.45 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 May 2015 02:16:45 -0700 (PDT) From: Omar Sandoval To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Cc: Qu Wenruo , Omar Sandoval Subject: [PATCH v3 4/6] Btrfs: fail on mismatched subvol and subvolid mount options Date: Mon, 18 May 2015 02:16:29 -0700 Message-Id: <700c0dd2e687adf196a986aa8a21d70f116c2cb0.1431939732.git.osandov@osandov.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There's nothing to stop a user from passing both subvol= and subvolid= to mount, but if they don't refer to the same subvolume, someone is going to be surprised at some point. Error out on this case, but allow users to pass in both if they do match (which they could, for example, get out of /proc/mounts). Reviewed-by: David Sterba Signed-off-by: Omar Sandoval --- fs/btrfs/super.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 460e0ea..d3e312b 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1172,8 +1172,9 @@ static char *setup_root_args(char *args) return buf; } -static struct dentry *mount_subvol(const char *subvol_name, int flags, - const char *device_name, char *data) +static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid, + int flags, const char *device_name, + char *data) { struct dentry *root; struct vfsmount *mnt = NULL; @@ -1219,12 +1220,27 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags, /* mount_subtree() drops our reference on the vfsmount. */ mnt = NULL; - if (!IS_ERR(root) && !is_subvolume_inode(d_inode(root))) { + if (!IS_ERR(root)) { struct super_block *s = root->d_sb; - dput(root); - root = ERR_PTR(-EINVAL); - deactivate_locked_super(s); - pr_err("BTRFS: '%s' is not a valid subvolume\n", subvol_name); + struct inode *root_inode = d_inode(root); + u64 root_objectid = BTRFS_I(root_inode)->root->root_key.objectid; + + ret = 0; + if (!is_subvolume_inode(root_inode)) { + pr_err("BTRFS: '%s' is not a valid subvolume\n", + subvol_name); + ret = -EINVAL; + } + if (subvol_objectid && root_objectid != subvol_objectid) { + pr_err("BTRFS: subvol '%s' does not match subvolid %llu\n", + subvol_name, subvol_objectid); + ret = -EINVAL; + } + if (ret) { + dput(root); + root = ERR_PTR(ret); + deactivate_locked_super(s); + } } out: @@ -1317,7 +1333,8 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, if (subvol_name) { /* mount_subvol() will free subvol_name. */ - return mount_subvol(subvol_name, flags, device_name, data); + return mount_subvol(subvol_name, subvol_objectid, flags, + device_name, data); } security_init_mnt_opts(&new_sec_opts);