Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3546963pxj; Mon, 24 May 2021 09:06:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5G6HxjdPebnb9WzE3f8knrjvjK52HUqAn7LIWx6SFJR/kpA6+WEnFgL0E9QnO7Qtsx0Z5 X-Received: by 2002:a92:7b12:: with SMTP id w18mr19235699ilc.28.1621872387090; Mon, 24 May 2021 09:06:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621872387; cv=none; d=google.com; s=arc-20160816; b=AgAVXN85lAGC5YG+wXhdixJ4ZBPsPrLDg6IUwyWpWDJgnlpNzZgTBFOwceS3S3ZrRG pP1nvJ2u6VyhmpBsDtPUT62DRmbql+8zeo7rG9YrEtK6kFKXQibeiB+h9bBUe0FXkhuJ g1QGpbULPpbxUYxo6qd8/JU0ipRGI1tWDcy/xLfvHOMoR+ohEKEUERNBzPrCkp6X9SDY wQNJXnlrVACXroxaxKC5uXlH1A8LNh4dfDPQF8+X1xCg9GUNhEE4rr95P+HO22LR5v4f AbJm+p3ZJAcksF0L+ZyIW6TBtv/CVVPowGl/y1J07VM3NTIGLc7GUlTx45xpw0Hzd0KA jDYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Gbp3w+Ixkk77GSRTbl87ivh6zg4ZG+aF7FgFlQXU3DQ=; b=IozM5nhOAMBTeswfUZplyNQNt2mVt4IRrk5WYCZDf1xbSuHVXnMnjUOofuPs8rRfBD GD/mSi/mdv0G0Nu3l1NaLG/B0vhpDN0nPE3/LMsOycUXfsGRwtO4l+UTsGndCiapSRYQ Ge802OyafLCyO6fBFkqGCk+RVd6weTDNQL+7UIw9PqPUCZruXn2NMi8bvtxcc9KhLMO6 XjVJlG/CYRg3Tnan3mczwSLqEriiYhHezpo7G+CF+8RaE70pmCa+SDwFfJwRFtDfdXpz QMWcvxE/HyGSey3x3MjO0u9gb/UZ0F2JTWgxfJtvPkezAhTyN838OkrsPqjl9qXs3n6O 230w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o0Gf67kU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y196si16146228iof.24.2021.05.24.09.06.07; Mon, 24 May 2021 09:06:27 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o0Gf67kU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235220AbhEXQEB (ORCPT + 99 others); Mon, 24 May 2021 12:04:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:40506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235000AbhEXP5L (ORCPT ); Mon, 24 May 2021 11:57:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 14D1D6194E; Mon, 24 May 2021 15:43:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621871007; bh=Bc053HPaJe0xqf2Y0GabxuPN8VVuRr4PB/4xGxebFr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o0Gf67kUeTF/qMTbyWjLqEXr25CLuKAFG8/BXveLWOZaTwx7U0eP1//hnqgMAgAsK sqTTqhLCui5KKnczZNHQohEmp9/+lJW/f5P2lyz9AlZbtt02igdQ7gkJbbr/mUvTQA Pz7mDzwdxCY3s8IAPwWBL2tGd99tmpcmq65ZLBdA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Enzo Matsumiya , Daniel Wagner , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.12 030/127] nvmet: seset ns->file when open fails Date: Mon, 24 May 2021 17:25:47 +0200 Message-Id: <20210524152335.863598658@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152334.857620285@linuxfoundation.org> References: <20210524152334.857620285@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Wagner [ Upstream commit 85428beac80dbcace5b146b218697c73e367dcf5 ] Reset the ns->file value to NULL also in the error case in nvmet_file_ns_enable(). The ns->file variable points either to file object or contains the error code after the filp_open() call. This can lead to following problem: When the user first setups an invalid file backend and tries to enable the ns, it will fail. Then the user switches over to a bdev backend and enables successfully the ns. The first received I/O will crash the system because the IO backend is chosen based on the ns->file value: static u16 nvmet_parse_io_cmd(struct nvmet_req *req) { [...] if (req->ns->file) return nvmet_file_parse_io_cmd(req); return nvmet_bdev_parse_io_cmd(req); } Reported-by: Enzo Matsumiya Signed-off-by: Daniel Wagner Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/target/io-cmd-file.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c index 715d4376c997..7fdbdc496597 100644 --- a/drivers/nvme/target/io-cmd-file.c +++ b/drivers/nvme/target/io-cmd-file.c @@ -49,9 +49,11 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns) ns->file = filp_open(ns->device_path, flags, 0); if (IS_ERR(ns->file)) { - pr_err("failed to open file %s: (%ld)\n", - ns->device_path, PTR_ERR(ns->file)); - return PTR_ERR(ns->file); + ret = PTR_ERR(ns->file); + pr_err("failed to open file %s: (%d)\n", + ns->device_path, ret); + ns->file = NULL; + return ret; } ret = nvmet_file_ns_revalidate(ns); -- 2.30.2