From patchwork Mon Dec 7 21:21:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7792881 Return-Path: X-Original-To: patchwork-selinux@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 68C259F349 for ; Mon, 7 Dec 2015 23:10:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B75C420585 for ; Mon, 7 Dec 2015 23:10:40 +0000 (UTC) Received: from emvm-gh1-uea09.nsa.gov (emvm-gh1-uea09.nsa.gov [63.239.67.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DE99020576 for ; Mon, 7 Dec 2015 23:10:39 +0000 (UTC) X-TM-IMSS-Message-ID: <3ea8f08e00007f74@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([10.208.42.194]) with ESMTP (TREND IMSS SMTP Service 7.1) id 3ea8f08e00007f74 ; Mon, 7 Dec 2015 18:10:40 -0500 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id tB7N8r3O010787; Mon, 7 Dec 2015 18:08:55 -0500 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id tB7LQ9iO263186 for ; Mon, 7 Dec 2015 16:26:09 -0500 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id tB7LOYBL001477 for ; Mon, 7 Dec 2015 16:26:09 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CeBABD9WVW/6rfVdFeGQEBAQEPAQEBAYRLuxeEFoYOAoITAQEBAQEBhUABAQEDEi4BATcBD1E0AQUBHAYBEiKIDaJHgTE+MYpXhVQBBYt1AQEBAQEBAQMCARoGCoQ6ghCJJYUTjiSIQo8XhzaGIYRfhw82gRdjggQNHRaBX1MBhCQCHgeBIwEBAQ X-IPAS-Result: A1CeBABD9WVW/6rfVdFeGQEBAQEPAQEBAYRLuxeEFoYOAoITAQEBAQEBhUABAQEDEi4BATcBD1E0AQUBHAYBEiKIDaJHgTE+MYpXhVQBBYt1AQEBAQEBAQMCARoGCoQ6ghCJJYUTjiSIQo8XhzaGIYRfhw82gRdjggQNHRaBX1MBhCQCHgeBIwEBAQ X-IronPort-AV: E=Sophos;i="5.20,396,1444708800"; d="scan'208";a="5004892" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 07 Dec 2015 16:23:19 -0500 X-TM-IMSS-Message-ID: <3e4e6bd30002800c@nsa.gov> Received: from mail-io0-f170.google.com (mail-io0-f170.google.com [209.85.223.170]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 3e4e6bd30002800c ; Mon, 7 Dec 2015 16:23:15 -0500 Received: by ioir85 with SMTP id r85so4060109ioi.1 for ; Mon, 07 Dec 2015 13:23:17 -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=KwI1s3gwjCl10xkZ9B7vbZUHX5GBLc5P+FmDmpdIksM=; b=DCxNAji6PBDa+d0Nqh9Jzc1ie2lfoQoBtOw3IqMC0aVk7kfFe9uCJYE3doC8/lbdyJ z1KIKRXLkZPYpifimO4e+S/kk2QavWVAS6/9/VwGIlohkQVw1c3bX0jTchz/oqSPNnqM XofyaarRSERIVtPm+Fxl6VKMC8iK7vNDtIWZM65R9mFsDiy8UekZOLXREBtF35i/V+8Y gPPfJe4Xq3bYPEY7tm5tqNQERC7tUdNDFQbtNz5nTouFyYKu42Ui38qc1jkHnLyL4ELK 3BpXpprRCGZH31R0ey2BqSaD0QcbvBVa6IvZn9c7sGvCfrdvUDjwqcXhZ/RY8aUKPiFL /SvA== 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=KwI1s3gwjCl10xkZ9B7vbZUHX5GBLc5P+FmDmpdIksM=; b=cYuUWBfTHnIZaksU0fo9MBHW0wM6PpZPQ96lAtWbRJP9uUGgCbnSGAoddRHPHLhmfb KV75BxYiRWK77nitqHZ6p4ZvP7gj0t3LL+K6rPp/hH1kWPsgEmA40q7LO84tu/htqz5q 31hKxszp2X7lbALlfkcasywG834vbGiU/TYqfqz4ROXaGT1TKOHoBHPvnhXoctRPeLoq dwsVrKyu0L5wmw6Z4AbUqoXdvQUdkcgR5BAfe/F0I1H3L1JBvaOLZgdchCuPzZtMNG8d 8tTIILTPG7vrmL8iPyiJyCEtIITfP0pUkyJgLZWiPQwkBWJcW9z6AZNVd0ReMsqMZgkP u/uA== X-Gm-Message-State: ALoCoQmJ0ufzSMp51bpxPZW9vgyixU8dlk27x7aRkLNkJs2x24ai4vmOV7e4TBnNGHVb0x0wdw/aWSqNb4YO8NSnMSWGdc2t+Q== X-Received: by 10.107.14.147 with SMTP id 141mr561652ioo.137.1449523397667; Mon, 07 Dec 2015 13:23:17 -0800 (PST) Received: from localhost (199-87-125-144.dyn.kc.surewest.net. [199.87.125.144]) by smtp.gmail.com with ESMTPSA id c92sm229435iod.0.2015.12.07.13.23.17 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 07 Dec 2015 13:23:17 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro Subject: [PATCH v2 02/18] block_dev: Check permissions towards block device inode when mounting Date: Mon, 7 Dec 2015 15:21:11 -0600 Message-Id: <1449523289-144238-3-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449523289-144238-1-git-send-email-seth.forshee@canonical.com> References: <1449523289-144238-1-git-send-email-seth.forshee@canonical.com> X-TM-AS-MML: disable X-Mailman-Approved-At: Mon, 07 Dec 2015 16:44:28 -0500 X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: 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 MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" 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=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 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;