From patchwork Wed Oct 18 12:38:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 10014623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A1B4D601E7 for ; Wed, 18 Oct 2017 12:40:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 905C128B37 for ; Wed, 18 Oct 2017 12:40:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 843BE28B3E; Wed, 18 Oct 2017 12:40:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38FD928B37 for ; Wed, 18 Oct 2017 12:40:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935834AbdJRMk1 (ORCPT ); Wed, 18 Oct 2017 08:40:27 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:55199 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934046AbdJRMkZ (ORCPT ); Wed, 18 Oct 2017 08:40:25 -0400 Received: by mail-wr0-f195.google.com with SMTP id o44so4857466wrf.11 for ; Wed, 18 Oct 2017 05:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ZgTZzJCJI/IWwpB1xkjhIRJ4oOq+OlFz+BGj/RINs5U=; b=qITbjuztO26Dw0StPj4/xQjmrA5p2LP0Ix9w1wlxDJNhgTry+oeFz4U0enxbkXBkV7 PsfZVdUMoiqWMbPQo4bJELq8LiZ7/KTRsTn6s0Fv6Els/dwQp4D4m1ioxRkF2/BkwH7/ Bp5FI7wqm3HnFb7je9p6hHFE/PUJZ4u1bvqykqs0zz41Mj77Ba9DgWJaeRsmcD8EMnW+ HLhhn+biSDHEo4d8qqksiJRnM4/QjXQTMSJrXnl2/tR6RES9468s/D5rqrqyiw6qEQFx LVcTshmQNpNZssWn/qOL8VRyuunOTjY2UcjNeafPvZxGN9G/GboaQpdsoOLrcffJm8BT gLLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ZgTZzJCJI/IWwpB1xkjhIRJ4oOq+OlFz+BGj/RINs5U=; b=IssJYAKkV1xcrwQPyaZkyHSiiLd1yRKF8YbkNF/AjL6om5/7VPa8fjIeQDNLBzCAkC pKgciPayov+fkTGHDy5XezXZVrU9YgtQC9ja8FGwJoGAMVQLMyU/1uRklrxb/hJipn4N HkU0b/UdFGbFIxi6zf3PRW4sruok5XDM303JFbHSuyxG5AGdzWUDNKDCaWvtZJ2E2xEv 8qFpkAfQzm/8F6HdDCAY40fBAw+OV5zGsDOkEUtz6b0P4akzZT+JDJXDvY61pGA7rTto QWeEqkr5FKkBemm+Qr/rpqE/n+fMyM/9DIVf9eQ8aiOGzoMSwb6q67uJ6i5qb4G/+j36 MyHw== X-Gm-Message-State: AMCzsaWbrhgE4FK5yl1o0Oq82ljKk/Mmf/oInZcF7i3NGcVGpkC+fSJH /R3jaNPs6qQ3MPgfldFO3ww= X-Google-Smtp-Source: ABhQp+RO53YaQ/epRnFKMHKsow5MTufSAVSds/mJwB6tl29K7wDkQur/onMoxiWWcTsO48gmKf7flw== X-Received: by 10.223.159.83 with SMTP id f19mr5343wrg.20.1508330424502; Wed, 18 Oct 2017 05:40:24 -0700 (PDT) Received: from orange.brq.redhat.com. (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id f6sm20018696wre.66.2017.10.18.05.40.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 05:40:23 -0700 (PDT) From: Ilya Dryomov To: Al Viro Cc: Jens Axboe , linux-block@vger.kernel.org Subject: [PATCH] block: move CAP_SYS_ADMIN check in blkdev_roset() Date: Wed, 18 Oct 2017 14:38:38 +0200 Message-Id: <1508330318-19456-1-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.3 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Check for CAP_SYS_ADMIN before calling into the driver, similar to blkdev_flushbuf(). This is safer and can spare a check in the driver. (Currently BLKROSET is overridden by md and rbd, rbd is missing the check. md has the check, but it covers a lot more than BLKROSET.) Signed-off-by: Ilya Dryomov --- Al, this appears to go back to your "[PATCH] block ioctl cleanup", history commit c6973580141c. 2002 was a long time ago, but still ;) Was there a reason you made BLKFLSBUF check for CAP_SYS_ADMIN before ->ioctl() and BLKROSET after? --- block/ioctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/ioctl.c b/block/ioctl.c index 0de02ee67eed..3f81bc50ac00 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -437,11 +437,12 @@ static int blkdev_roset(struct block_device *bdev, fmode_t mode, { int ret, n; + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg); if (!is_unrecognized_ioctl(ret)) return ret; - if (!capable(CAP_SYS_ADMIN)) - return -EACCES; if (get_user(n, (int __user *)arg)) return -EFAULT; set_device_ro(bdev, n);