Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1409783pxf; Fri, 2 Apr 2021 09:44:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVxOtqkYFKSvRufON0sxGFKsNE4Z1qHsvMJ4y2NvooFBBJZmP8hSTWXPpiTcUf3SwPoOQL X-Received: by 2002:a17:906:8043:: with SMTP id x3mr14666311ejw.149.1617381852620; Fri, 02 Apr 2021 09:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617381852; cv=none; d=google.com; s=arc-20160816; b=r7tAHyiTEPaOiW9BIErQua6lTAmjoa+XiQC/N7LOXdu0jYEmUGCcyTAnxfLBaSfK+v kWYExGKy6uOMEAWE5RmZUY7iFsGh8l/JApza/9SzhMXD1WFVVSZp8iHmwWP8ovEJdblF gIczhaMDAuF6LK5hIqrDhJqLkXnDKqGXd8XASb1CvBeFqM27ipevdXf0DfYuEXptAcMf ++xKob7Zkm/kA8iHxMnRZfekYS3Ysaw4hr1VYZb/Zv2Yihom6KfoXYAzbAuuzUo8sxxo a7B25Bme+21Rj+oeXyknU5lCU53fttjJWPEjb9ZYaAFe0lb5IeN/lZyEDRscgYE+S0iz i5CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=2JrddUUJNqKjBrJbn/63eFfz+Xevp+e0feXc0rEPXLo=; b=XMoFn89vwhMciG3NB1tRm9DpipkDoW6C8MCsG3dSnPmCdhtMILdBeB4Vy3y6tSzbCV Cy5VUjGMYlBStXKuca1w9bCh7T/mxELynwSKnHnBy0wTwqnitzMPWrW38hFDwukU+gr6 mGPLFe6uxNtGOZ8ftIH+wqj2/6Lx7ZPAshfGU8OgnKTdOxCmUCx0z/IxKdDMvW2qjyrM RG3Xhj2xNmcXGi2nr5fOaesQWIiJGQlb6EiPXGJEV70UVM4EcDauIsyp/eZzOZL/FnbR wabbNOVONinX2W2tyxYO7BZbVxHRX1UCeUuckAgf+CDh1s1VYc1h39Khvz+TTu9d296f OEvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c18si6787771ejr.332.2021.04.02.09.43.48; Fri, 02 Apr 2021 09:44:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234759AbhDBQnX (ORCPT + 99 others); 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>