From patchwork Tue Apr 26 19:36:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 8944501 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 81D43BF29F for ; Tue, 26 Apr 2016 20:12:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B60B42014A for ; Tue, 26 Apr 2016 20:12:38 +0000 (UTC) Received: from emsm-gh1-uea11.nsa.gov (emsm-gh1-uea11.nsa.gov [8.44.101.9]) by mail.kernel.org (Postfix) with ESMTP id D6CE720138 for ; Tue, 26 Apr 2016 20:12:37 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.24,538,1454976000"; d="scan'208";a="15644022" IronPort-PHdr: =?us-ascii?q?9a23=3A9ZnDcBxq0eaN54vXCy+O+j09IxM/srCxBDY+r6Qd?= =?us-ascii?q?0OkSIJqq85mqBkHD//Il1AaPBtWLra0VwLON7ejJYi8p39WoiDg6aptCVhsI24?= =?us-ascii?q?09vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6kO74TNaIBjjLw09?= =?us-ascii?q?fr2zQd6CyZvmnLnppdX6WEZhunmUWftKNhK4rAHc5IE9oLBJDeIP8CbPuWZCYO?= =?us-ascii?q?9MxGlldhq5lhf44dqsrtY4q3wD89pozcNLUL37cqIkVvQYSW1+ayFmrPHs4FPu?= =?us-ascii?q?VwqErkRaGk8XnxZFGQ3M6luyCpr7syb2u/B48DmfPNbtTLcyHz+l6vEvADbshT?= =?us-ascii?q?cOMTI06inpi9Z3xPZFoQimjw5yxY/KJoWUMuduOKTHcpUHRjwScNxWUnl6D5+8?= =?us-ascii?q?J6UIFfEBMOsQ+5Lwu1tIoxykHgmhCcvkwzlPgH791Kl82OMkR1KVlDc8Fs4D5S?= =?us-ascii?q?yH5O7+M70fBKXslPHF?= X-IPAS-Result: =?us-ascii?q?A2EJBQBzyh9X/wHyM5BeHAGCcCuBULt0IoF2hUVMAQEBAQE?= =?us-ascii?q?BAgJiJ4ItfVs9AQEBAwECDygGAQEMIAsBAgMJAQEXKQgIAwEtAwEFAQsRBgEHC?= =?us-ascii?q?wUYBAGICAGlVYExPjGKT4UoAQSMRgEBAQcBAQEBFgYKhA2CCohYAhEBhXQBjky?= =?us-ascii?q?JSIFVjESBZYdFJYVARYVfh04wgQ5iggUbFoFTTgGHbwIHFweBFwEBAQ?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2016 20:12:36 +0000 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 u3QKCZBU021656; Tue, 26 Apr 2016 16:12:35 -0400 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 u3QJat1O172294 for ; Tue, 26 Apr 2016 15:36:55 -0400 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 u3QJakxo011587 for ; Tue, 26 Apr 2016 15:36:54 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BBBQD9wR9X/yUp0Apegw0rgVC3cIQGCxeFeAKBQEwBAQEBAQFmJ4RCAQEBAxIuAQE3AQ9RNAEFARwGARIiiAgBpVeBMT4xik+FKAEEjEoBAQEBAQEBAwIBFwYKhA2CCohYgnoLQIJDjk2JSIFVjESBZYdFhWVFhV+HTjCBDmKBeA0bFoFTTgGHbwIeB4EXAQEB X-IPAS-Result: A0BBBQD9wR9X/yUp0Apegw0rgVC3cIQGCxeFeAKBQEwBAQEBAQFmJ4RCAQEBAxIuAQE3AQ9RNAEFARwGARIiiAgBpVeBMT4xik+FKAEEjEoBAQEBAQEBAwIBFwYKhA2CCohYgnoLQIJDjk2JSIFVjESBZYdFhWVFhV+HTjCBDmKBeA0bFoFTTgGHbwIeB4EXAQEB X-IronPort-AV: E=Sophos;i="5.24,537,1454994000"; d="scan'208";a="5410375" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 26 Apr 2016 15:36:55 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AL7bYHRI6EqWpWaftP9mcpTZWNBhigK39O0sv0rFi?= =?us-ascii?q?tYgVKfjxwZ3uMQTl6Ol3ixeRBMOAu6IC1Lud6vu4EUU7or+/81k6OKRWUBEEjc?= =?us-ascii?q?hE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i760zceF13FOBZv?= =?us-ascii?q?IaytQ8iJ35TxiLH5osaLKyxzxxODIppKZC2sqgvQssREyaBDEY0WjiXzn31TZu?= =?us-ascii?q?5NznlpL1/A1zz158O34YIxu38I46Fp34d6XK77Z6U1S6BDRHRjajhtpZ6jiR6W?= =?us-ascii?q?ByaV53BUbSNeuBtFDwXf6Rj8FN+lvyH7u+ZwwiyyLcj3Vqs1XjLk5KBuHlugoS?= =?us-ascii?q?MKJzc//GzNwvJxlqUT9AygvRtX0YPSYZ/TMPt4Y7ObeskVA3dCCJV/TStEV7ix?= =?us-ascii?q?c4tHIe0bJuZVosGpvFYSrV2wAhO3BO7i4jRBgHjw3KYz16IqFgSQj19oJM4HrH?= =?us-ascii?q?mB9Ia9D6wVS+3gifCQlTg=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0HzAAD9wR9Xj67fVdFegw2Be7dwhAYLF?= =?us-ascii?q?4F2hAICgUBMAQEBAQEBAgIPAQEBAQcLCwkhL4ItfVs9AQEBAxIuAQE3AQ9RNAE?= =?us-ascii?q?FARwGARIiiAgBpVeBMT4xik+FKAEEjEoBAQEBAQEBAwIBFwYKhA2CCohYgnoLQ?= =?us-ascii?q?IJDjk2JSIFVjESBZYdFhWVFhV+HTjCBDoJaDREKFoFTTgGHbwIeB4EXAQEB?= X-IPAS-Result: =?us-ascii?q?A0HzAAD9wR9Xj67fVdFegw2Be7dwhAYLF4F2hAICgUBMAQE?= =?us-ascii?q?BAQEBAgIPAQEBAQcLCwkhL4ItfVs9AQEBAxIuAQE3AQ9RNAEFARwGARIiiAgBp?= =?us-ascii?q?VeBMT4xik+FKAEEjEoBAQEBAQEBAwIBFwYKhA2CCohYgnoLQIJDjk2JSIFVjES?= =?us-ascii?q?BZYdFhWVFhV+HTjCBDoJaDREKFoFTTgGHbwIeB4EXAQEB?= X-IronPort-AV: E=Sophos;i="5.24,537,1454976000"; d="scan'208";a="15642548" Received: from mail-io0-f174.google.com ([209.85.223.174]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/AES128-GCM-SHA256; 26 Apr 2016 19:36:53 +0000 Received: by mail-io0-f174.google.com with SMTP id d62so26312240iof.2 for ; Tue, 26 Apr 2016 12:36:53 -0700 (PDT) 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=UHwmomD63z/RGnd7NeaL27R4JrM01/jEm5xMtjenPws=; b=B8HIVwhrPuXoz7l43B03uyqFwMN2nLBg8/1QDFqGG3QIg4eUlQTV9ZRQvGDsDe3TnL VOk9VYybs16BdJM9Uq0kC5NI7GPm71crin8wuRXAAVv1F2Nfy5OyRlTRM4f85wCYTbz/ 9+B86FvjoyJxb2iruRM02GdFQvkLvh9kv9mNf9IV3CqUpKDF84M2su8fbSOhqpecEXWI sA1spUWDYlfsRPObT/M9qGq2h/43/63pegJCbO41GCzfbBpAKZyssdilNi4r9gccxHSE VGOv9vu4xRJHAwHR0B5Ux9TKdkRZAY6yQkCp0sinZnIg5zrxEl8tMCYaXcp8FzZE9MvA Mr1w== 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=UHwmomD63z/RGnd7NeaL27R4JrM01/jEm5xMtjenPws=; b=dmDTWKXaNr1mhje3XKCpF8wpHYP/IhceS2cYvoI5+F2daHKdSW4g49FCJ7BI2dstf1 Z0Mw50MYZRvNAy6kJATa4yDRJYuuRvUnkG6IFqbgGJsTM1riGB3MVv/Y/tbGMIA2Q/2W 9x/L3ms80F9/QOSVyiTZOTc726P1okBm9Xe6ZYsrbYGxzUymQooRYvH+o0UwQdD5AK8E OElK1PJno3taE0OHxs5W6dfYMxDEXfCoqNgqoOmFzjxjNzvOObva2LQMad/dIbxZ2Syg 6gTcsSVuq6jIqUqUzmeTd6x2KHa2n7VTpE0VGBVDKlBaoQa4yWFi5uZSjpoXW6hdQcBc II6Q== X-Gm-Message-State: AOPr4FXFLjvLBEeFxAsqD8Ly2p2jbZrrbDWlTx0aeZM9ElviQ2sEEezhNDct+VpF4P2iT2mF X-Received: by 10.107.43.88 with SMTP id r85mr6312680ior.140.1461699413063; Tue, 26 Apr 2016 12:36:53 -0700 (PDT) Received: from localhost ([2605:a601:aab:f920:39a1:5bcf:aa:5b00]) by smtp.gmail.com with ESMTPSA id 78sm2370431iof.22.2016.04.26.12.36.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Apr 2016 12:36:52 -0700 (PDT) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro Subject: [PATCH v4 05/21] block_dev: Check permissions towards block device inode when mounting Date: Tue, 26 Apr 2016 14:36:18 -0500 Message-Id: <1461699396-33000-6-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1461699396-33000-1-git-send-email-seth.forshee@canonical.com> References: <1461699396-33000-1-git-send-email-seth.forshee@canonical.com> X-Mailman-Approved-At: Tue, 26 Apr 2016 16:11:01 -0400 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: linux-bcache@vger.kernel.org, Serge Hallyn , Seth Forshee , dm-devel@redhat.com, Miklos Szeredi , Richard Weinberger , linux-security-module@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, cgroups@vger.kernel.org, Pavel Tikhomirov MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 e9b937845bdb..2007040afb7b 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1429,9 +1429,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;