From patchwork Wed Dec 2 15:40:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7756921 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: X-Original-To: patchwork-dm-devel@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 125BB9F30B for ; Thu, 3 Dec 2015 08:15:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 42D242050B for ; Thu, 3 Dec 2015 08:15:09 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EC33B20481 for ; Thu, 3 Dec 2015 08:15:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id tB38CJUl014381; Thu, 3 Dec 2015 03:12:20 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id tB2Fg7xD010655 for ; Wed, 2 Dec 2015 10:42:07 -0500 Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tB2Fg7kP020078 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 2 Dec 2015 10:42:07 -0500 Received: from mail-io0-f177.google.com (mail-io0-f177.google.com [209.85.223.177]) by mx1.redhat.com (Postfix) with ESMTPS id 63F17C0CC629 for ; Wed, 2 Dec 2015 15:42:05 +0000 (UTC) Received: by iofh3 with SMTP id h3so49548616iof.3 for ; Wed, 02 Dec 2015 07:42:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=y+FUp222mT7SmSct54tR0p/5Or4CNldUBAVqU8U2UPM=; b=0QoQnaw+SsHOz0IBjewmfRmu98tPSEGB6Uu6w+16PPuSNfMuSSN4jDxbnTBuL0o03K DS9rkWex6aq95ZH0Nfg20NHLpCJI6mMZWYJXwgAdhHKPiZ7qNEDAmZAMlUJWdt0mpI6H oc1LdF2dLwbr5Thk2YAZGvVcieQUy8Gf/PFqCZ8T9NfQvX+bvYigPfVUVZN5aSqI3rm4 t++pvwr2aL4k2dVMAwHQNBM3XT5KUHqPl9TwNvcpOnp0gVjUCDlqZCQ0C9rI6ttVrG9D 9XktRWoXm+1P9+m8fZMcWI1f2ggOpa22fLDrV92BZMKgOH6rOYp62EWpp+Fh0DuUPpgf 9r7Q== 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; bh=y+FUp222mT7SmSct54tR0p/5Or4CNldUBAVqU8U2UPM=; b=dOg5EgjjlkcMuocGwieFQMgSLhgja3BV49WhF0RTnMFoe72rJ1WlZaz6V+V5Xcs/0C y+bCBOYYLB5om0N/1dR9VGzWyGS8Featuo/DB8ybJzUup8NtqxDa4/BuLQxW+CiX1GWt WhIJZ3R1dZKJ7mYJuY7wN+JeBchO3EiUbIxWDVtHNxazMopUa5aRycJ6UoHlRdFQunOa pHTwN1OofNJaIR/LMAu1qK7oaifUolM4yhresbcbs3e7sZOwwwpJu//L5oZWwxE2ecXh 3GwaDHJSPQcjwmswT8Mekr0SA6POqNtKUeHJDlNA293UsH3//PqaDbIJOpuqcx/mdj9c /UtQ== X-Gm-Message-State: ALoCoQmb4v0+mS2x6gRxkj8OU+PjNJb04K0c5m++yQq/MmYz79lBA34AANSbXmRyhKyF4m1PwN/j X-Received: by 10.107.33.203 with SMTP id h194mr3863086ioh.108.1449070924781; Wed, 02 Dec 2015 07:42:04 -0800 (PST) Received: from localhost (199-87-125-144.dyn.kc.surewest.net. [199.87.125.144]) by smtp.gmail.com with ESMTPSA id j10sm1332857igx.13.2015.12.02.07.42.04 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 02 Dec 2015 07:42:04 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro Date: Wed, 2 Dec 2015 09:40:02 -0600 Message-Id: <1449070821-73820-3-git-send-email-seth.forshee@canonical.com> In-Reply-To: <1449070821-73820-1-git-send-email-seth.forshee@canonical.com> References: <1449070821-73820-1-git-send-email-seth.forshee@canonical.com> X-RedHat-Spam-Score: 0.099 (BAYES_50, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2) 209.85.223.177 mail-io0-f177.google.com 209.85.223.177 mail-io0-f177.google.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Thu, 03 Dec 2015 03:12:19 -0500 Cc: Serge Hallyn , Seth Forshee , dm-devel@redhat.com, Miklos Szeredi , Richard Weinberger , linux-security-module@vger.kernel.org, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, fuse-devel@lists.sourceforge.net, Austin S Hemmelgarn , linux-mtd@lists.infradead.org, selinux@tycho.nsa.gov, linux-fsdevel@vger.kernel.org Subject: [dm-devel] [PATCH 02/19] block_dev: Check permissions towards block device inode when mounting X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable 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 Unprivileged users should not be able to mount block devices when they lack sufficient privileges towards the block device inode. Update blkdev_get_by_path() to validate that the user has the required access to the inode at the specified path. The check will be skipped for CAP_SYS_ADMIN, so privileged mounts will continue working as before. Signed-off-by: Seth Forshee Acked-by: Serge Hallyn --- fs/block_dev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index 3ebbde85d898..4fdb6ab59816 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1424,9 +1424,14 @@ struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, void *holder) { struct block_device *bdev; + int perm = 0; int err; - bdev = lookup_bdev(path, 0); + if (mode & FMODE_READ) + perm |= MAY_READ; + if (mode & FMODE_WRITE) + perm |= MAY_WRITE; + bdev = lookup_bdev(path, perm); if (IS_ERR(bdev)) return bdev;