From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1B97C433ED for ; Fri, 2 Apr 2021 16:43:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74151610A0 for ; Fri, 2 Apr 2021 16:43:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235015AbhDBQnX (ORCPT ); Fri, 2 Apr 2021 12:43:23 -0400 Received: from verein.lst.de ([213.95.11.211]:44266 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbhDBQnW (ORCPT ); Fri, 2 Apr 2021 12:43:22 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id B1B3C68BEB; Fri, 2 Apr 2021 18:43:18 +0200 (CEST) Date: Fri, 2 Apr 2021 18:43:18 +0200 From: Christoph Hellwig To: Niklas Cassel Cc: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , "minwoo.im.dev@gmail.com" , "javier@javigon.com" , "linux-nvme@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2] nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev Message-ID: <20210402164318.GA21840@lst.de> References: <20210326194749.396599-1-Niklas.Cassel@wdc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210326194749.396599-1-Niklas.Cassel@wdc.com> User-Agent: Mutt/1.5.17 (2007-11-01) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 26, 2021 at 07:48:00PM +0000, Niklas Cassel wrote: > From: Niklas Cassel > > When a passthru command targets a specific namespace, the ns parameter to > nvme_user_cmd()/nvme_user_cmd64() is set. However, there is currently no > validation that the nsid specified in the passthru command targets the > namespace/nsid represented by the block device that the ioctl was > performed on. > > Add a check that validates that the nsid in the passthru command matches > that of the supplied namespace. git-am doesn't seem to like this patch: pplying: nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev error: invalid mode on line 2: 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1599,6 +1599,12 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
                return -EFAULT;
        if (cmd.flags)
                return -EINVAL;
+       if (ns && cmd.nsid != ns->head->ns_id) {
+               dev_err(ctrl->device,
+                       "%s: nsid (%u) in cmd does not match nsid (%u) of namespace\n",
+                       current->comm, cmd.nsid, ns->head->ns_id);
+               return -EINVAL;
+       }

        memset(&c, 0, sizeof(c));
        c.common.opcode = cmd.opcode;
@@ -1643,6 +1649,12 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
                return -EFAULT;
        if (cmd.flags)
                return -EINVAL;
+       if (ns && cmd.nsid != ns->head->ns_id) {
+               dev_err(ctrl->device,
+                       "%s: nsid (%u) in cmd does not match nsid (%u) of namespace\n",
+                       current->comm, cmd.nsid, ns->head->ns_id);
+               return -EINVAL;
+       }

        memset(&c, 0, sizeof(c));
        c.common.opcode = cmd.opcode;

Looks good.
Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>