From patchwork Thu Mar 29 22:05:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matias Bjorling X-Patchwork-Id: 10316521 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 A3C4E60383 for ; Thu, 29 Mar 2018 22:10:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EF302A545 for ; Thu, 29 Mar 2018 22:10:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8392F2A54B; Thu, 29 Mar 2018 22:10:46 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=unavailable 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 ED6112A545 for ; Thu, 29 Mar 2018 22:10:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752633AbeC2WHc (ORCPT ); Thu, 29 Mar 2018 18:07:32 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:37885 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752638AbeC2WHZ (ORCPT ); Thu, 29 Mar 2018 18:07:25 -0400 Received: by mail-lf0-f65.google.com with SMTP id m200-v6so4581171lfm.4 for ; Thu, 29 Mar 2018 15:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=srYLl5zGLaCJFC3qda+SKxwGjs9OLllnaXRD91kAxEE=; b=eVAYMozyc/3Zc8OpacPrgFHrjBV0mgQPZ2GhIr6cQlCBE04jneEy9qZaaRgbeb4MaK HgTmtVKoo3Qre8UmWYycpwkc+aNwLIHd+foYtX2fhO6D0hzcRw/y5G0i2D3vvia1MSlJ LU29uCvGTH07kQdiMPYUH6Xc323ZlCycacpO8B3avw2O9sVokGoKROB3cBfp9bqpX3d5 FHtJU4pBed54rqdx4b/SZwQ8hIPMVxTEua9oEikK1TDz7saW7FhKitxEFXbw/rsewmDt 0+nRFmBMvR53f2+i+3uShyQpWQxGDIGbYJK5JcRLBKStSxCj1Du6OY6/jI1gSxICeoL9 gLQQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=srYLl5zGLaCJFC3qda+SKxwGjs9OLllnaXRD91kAxEE=; b=PdONQ2MTb+FDSbpNDF51La1GyTgjNFoo7rOID84uweKtINDNLBbN9UDFA1XLqp9+DA ZIkqfZtwno1NMobAJ8XXoPcFwpPLg8xKCQepYfHaWyd7ktMNjuyo1JvNsPGVd5g/AWho yGX34ZiL8Khwh2M1+DjNyqzKckySGdhHDnN59UCT2dbCTX/Lc5vBHJujDtf1qBNXtMbK QCAk/t+1J83EhKqE+eOG3GMOPjtmLjemR9ZW/JnqqTBqmcenigyHZ6hYxSTfnP7JBI32 i7n7eR4tS9cV6MH3lO/1VHQ9dFBL+3o7K0hm1PVmhjJWV/HAbIQ4H+HyUxOXcOisIijI w4Sw== X-Gm-Message-State: ALQs6tDPtZaHhEuBYLnPUrk8B0yeTyK4ptab9ye3a1v7s2V9FWLthRgS s/pWTDQ/EjUQEB13tqMhhI1ouw== X-Google-Smtp-Source: AIpwx4/QZrGKfsuAO7WpQ60jXR7Gl+lOvau3DiNJpOReMqZarzW2hFdeUvhwOqPHQlLGnluUtZh6nw== X-Received: by 2002:a19:6b09:: with SMTP id d9-v6mr574975lfa.83.1522361238960; Thu, 29 Mar 2018 15:07:18 -0700 (PDT) Received: from Macroninja.cnexlabs.com (x1-6-a4-08-f5-18-3c-3a.cpe.webspeed.dk. [188.176.29.198]) by smtp.gmail.com with ESMTPSA id i89-v6sm1365508lfk.12.2018.03.29.15.07.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Mar 2018 15:07:18 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, keith.busch@intel.com, javier@cnexlabs.com, Johannes Thumshirn , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [GIT PULL 20/37] lightnvm: centralize permission check for lightnvm ioctl Date: Fri, 30 Mar 2018 00:05:07 +0200 Message-Id: <20180329220524.30363-21-mb@lightnvm.io> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180329220524.30363-1-mb@lightnvm.io> References: <20180329220524.30363-1-mb@lightnvm.io> MIME-Version: 1.0 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 From: Johannes Thumshirn Currently all functions for handling the lightnvm core ioctl commands do a check for CAP_SYS_ADMIN. Change this to fail early in nvm_ctl_ioctl(), so we don't have to duplicate the permission checks all over. Signed-off-by: Johannes Thumshirn Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 3eec948d1b7e..5b197d6bb6d9 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -1019,9 +1019,6 @@ static long nvm_ioctl_info(struct file *file, void __user *arg) struct nvm_tgt_type *tt; int tgt_iter = 0; - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - info = memdup_user(arg, sizeof(struct nvm_ioctl_info)); if (IS_ERR(info)) return -EFAULT; @@ -1060,9 +1057,6 @@ static long nvm_ioctl_get_devices(struct file *file, void __user *arg) struct nvm_dev *dev; int i = 0; - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - devices = kzalloc(sizeof(struct nvm_ioctl_get_devices), GFP_KERNEL); if (!devices) return -ENOMEM; @@ -1103,9 +1097,6 @@ static long nvm_ioctl_dev_create(struct file *file, void __user *arg) { struct nvm_ioctl_create create; - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - if (copy_from_user(&create, arg, sizeof(struct nvm_ioctl_create))) return -EFAULT; @@ -1141,9 +1132,6 @@ static long nvm_ioctl_dev_remove(struct file *file, void __user *arg) struct nvm_dev *dev; int ret = 0; - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - if (copy_from_user(&remove, arg, sizeof(struct nvm_ioctl_remove))) return -EFAULT; @@ -1168,9 +1156,6 @@ static long nvm_ioctl_dev_init(struct file *file, void __user *arg) { struct nvm_ioctl_dev_init init; - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - if (copy_from_user(&init, arg, sizeof(struct nvm_ioctl_dev_init))) return -EFAULT; @@ -1187,9 +1172,6 @@ static long nvm_ioctl_dev_factory(struct file *file, void __user *arg) { struct nvm_ioctl_dev_factory fact; - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - if (copy_from_user(&fact, arg, sizeof(struct nvm_ioctl_dev_factory))) return -EFAULT; @@ -1205,6 +1187,9 @@ static long nvm_ctl_ioctl(struct file *file, uint cmd, unsigned long arg) { void __user *argp = (void __user *)arg; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + switch (cmd) { case NVM_INFO: return nvm_ioctl_info(file, argp);