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: 8943921 Return-Path: X-Original-To: patchwork-linux-fsdevel@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 3A3549F1C1 for ; Tue, 26 Apr 2016 19:46:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 55E2D20125 for ; Tue, 26 Apr 2016 19:46:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6A5F7200FE for ; Tue, 26 Apr 2016 19:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752471AbcDZTg6 (ORCPT ); Tue, 26 Apr 2016 15:36:58 -0400 Received: from mail-io0-f175.google.com ([209.85.223.175]:36092 "EHLO mail-io0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752489AbcDZTgy (ORCPT ); Tue, 26 Apr 2016 15:36:54 -0400 Received: by mail-io0-f175.google.com with SMTP id u185so30176118iod.3 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=GpTlVdLLODUzEQ1/64NbjaVhOQ8YTZvgH2kMBF4M+wZQf1xtFGb2TxIeGhYmPo+VZG 6PI6KK4J9KzMjs6yvfmGh/B5/4dXE/IBCVlbhYVOW6IDT43XTxk610GaD8Mh7fzD0vTT JZp32tcgH1NIxjcaR43bU0wCXfpT297ciE8baxVzlRsyXFlBkHaO4LG9AwALcKSp7bYk me3dSUSKICTcmAAE7gvzd6zDugKtCh8GDcm9hyt28of1/OW7FzhiVKjpiMwJjhfx90FF /A4DUpyIzNe6B5Fj3DMkyfs+hOOrP9H4eIr/VlDB3KVZqiVVZmc3Ym8S2ilDU/nodYxz uVaQ== X-Gm-Message-State: AOPr4FXOoJ/cPmZLSNPCgVTJIb2zaxXWMdjac1T4YHm3lp9r6gVJOnRA8XjbE3BMU7BESeSO 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 Cc: Serge Hallyn , Richard Weinberger , Austin S Hemmelgarn , Miklos Szeredi , Pavel Tikhomirov , linux-kernel@vger.kernel.org, linux-bcache@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org, fuse-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, cgroups@vger.kernel.org, Seth Forshee 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> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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;