Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2361371lqp; Sun, 24 Mar 2024 15:45:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVBrORAMGONKMlqbs6P4xpmKFvKJB8HEmOquPrsWqTrArGvQdCSabs/4nsBrp85GPBs5gAo+qYf39224q25C/Q4HANDd5M4S3h5IsQM6g== X-Google-Smtp-Source: AGHT+IFAJGIj1exbIgWaAWKDpwJnd/iq6wCl6kYSQZ62vX1OxNLTrXL6tf7xsOY4kfSSdSXuwncJ X-Received: by 2002:a05:620a:d4a:b0:78a:3e97:4114 with SMTP id o10-20020a05620a0d4a00b0078a3e974114mr5914724qkl.5.1711320326939; Sun, 24 Mar 2024 15:45:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711320326; cv=pass; d=google.com; s=arc-20160816; b=LVjWEngyrHihqOzY8oYgWp9Tt0grMjY7zxkJKeNRmNxhz/jb99wWv/M8NcAOPyGnNY q5L2+NHoomZzkLiBPS7JJE6h5Jtt35xkPxzdQUvDn6Mnl6bh5qgjbOUze+BERpL0JsuC zEwxAtKmHMBcZ2fD2C9fcnq1vEyngqZRIFPJx4xh+bbX/TdJLgraNPHt5hn2hzs2gvOl Q9N3rOYBFgbP9H2LKykFJzDwYbOMb5EF/UImGIl4k0yqHy2OXx2hMS91qrRgjg2auCUC Kwan9bKVxAgqqEojp5u2AxWSOMS5QTUwzX9fsg9EXJrpXG1uzYgfy7GXS+n1Ez/z8Amx ACtA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=oP9sMi34Dq/KHCajeQhoS+rwoTAW1FZ617J6tw36gas=; fh=GGKFyTexTcsoqfItxaoYBYP8J7h+samPbe6bGA14Bvs=; b=jXAEKTx7dclffZP/Z4no4ojdkapqhzbyLrj8Se88yVYvq2lb/tGEjCkhv1knPyS0/s ck6XBVebuRio6UEI/0sMnvs46GJnhaRbjffF7KJg40VGEX610LzrPa0lRpLsvsiYd0y2 HBGYqbB9kf9t0vowyNiSjF9nezMmbas8ajA/eAq0TWumFm77C33BV/SEolc6lUscQwut 6ZHQ7CYuWY4MxANkMGqt1nd4mIMjUT7BKyEl+Ri3ksy5i2tTOd1iOqSak2FdFgLnafvT nhQFjCy1CD/UG9J+IMeu/krX4OoqKYnNl7lDjpc2Ek+Jv6bMhn5hTQdy9Z2NaN9mUNVe kDrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MFO9Kd0x; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112929-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112929-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id l11-20020a05620a210b00b00789e88e635bsi4207639qkl.514.2024.03.24.15.45.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 15:45:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112929-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MFO9Kd0x; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112929-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112929-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9E1311C20FF7 for ; Sun, 24 Mar 2024 22:45:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E05B73537; Sun, 24 Mar 2024 22:35:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MFO9Kd0x" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5876D73509; Sun, 24 Mar 2024 22:35:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319741; cv=none; b=tqMV6Q5tSkuHjpDhx8BqiCCqSh2e7zXLWSYCpLhykOpopUBUJhnapoN6msfi8EFqZ0SRVSw+n/fGjB8DyEUCNjBtT7FgXN3hc/5I7Or+B8ANTw+UWXrcbiDn7hLsfYXseJ42iozXFq4gNM9SG199+faokCOuHm3k8hnoE9M+r80= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319741; c=relaxed/simple; bh=sISgqsba65O84SziZyljgb9eLMnknulilo+A5OuNOLc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U+qlGtWdOemoIV58EBbvLeUjPp+dkSZcIs5jEK3aQpzHGXifRfqpmlmmDtqxd6gz/Kv/QuQ7+/k5seHOKPfP9fjrEMby1CcNKoZKRstVVP7QNDa2eBIbwCc6GIUcNAdSRuQE9Bxo7AwYaC65gUXIpLl2aujUapn2Ve6kbiCa+YU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MFO9Kd0x; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CE74C433F1; Sun, 24 Mar 2024 22:35:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319741; bh=sISgqsba65O84SziZyljgb9eLMnknulilo+A5OuNOLc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MFO9Kd0xUclEX0iXZ4cRbxxxwWhMY5NHE9WlP4b90Sp4DqMfmDWHVxt+0FFlxvFJm e81QY93aTfJtwzPz3nK9nP4GGt/uGf/RE/Qoyp0fe+7dZpoeQQhgUioQD/IrcQ163r hUErhCy7P4jdV/wlYltRobFmY+gkBYuyKUDqgvo4iq8U6gZI4+Fm122K748+aYH/37 KX0lVIwePeDi8Ui7UZq3JW7Pr8omKt5GtBuKZjDOxVo8CHOMhH9c6mIKeHU3fwFrBC iHRA56fbBJfAhwNoyI94rCGWSWulR50GjaGn+mGt4vfCaL8qhSugv7YRZYQrqZI2JA 5Y5dmM18z6xww== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Shin'ichiro Kawasaki , Christoph Hellwig , Daniel Wagner , Chaitanya Kulkarni , Keith Busch , Sasha Levin Subject: [PATCH 6.8 042/715] nvme: host: fix double-free of struct nvme_id_ns in ns_update_nuse() Date: Sun, 24 Mar 2024 18:23:41 -0400 Message-ID: <20240324223455.1342824-43-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Shin'ichiro Kawasaki [ Upstream commit 8d0d2447394b13fb22a069f0330f9c49b7fff9d3 ] When nvme_identify_ns() fails, it frees the pointer to the struct nvme_id_ns before it returns. However, ns_update_nuse() calls kfree() for the pointer even when nvme_identify_ns() fails. This results in KASAN double-free, which was observed with blktests nvme/045 with proposed patches [1] on the kernel v6.8-rc7. Fix the double-free by skipping kfree() when nvme_identify_ns() fails. Link: https://lore.kernel.org/linux-block/20240304161303.19681-1-dwagner@suse.de/ [1] Fixes: a1a825ab6a60 ("nvme: add csi, ms and nuse to sysfs") Signed-off-by: Shin'ichiro Kawasaki Reviewed-by: Christoph Hellwig Reviewed-by: Daniel Wagner Reviewed-by: Chaitanya Kulkarni Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/host/sysfs.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c index f2832f70e7e0a..09fcaa519e5bc 100644 --- a/drivers/nvme/host/sysfs.c +++ b/drivers/nvme/host/sysfs.c @@ -221,14 +221,11 @@ static int ns_update_nuse(struct nvme_ns *ns) ret = nvme_identify_ns(ns->ctrl, ns->head->ns_id, &id); if (ret) - goto out_free_id; + return ret; ns->head->nuse = le64_to_cpu(id->nuse); - -out_free_id: kfree(id); - - return ret; + return 0; } static ssize_t nuse_show(struct device *dev, struct device_attribute *attr, -- 2.43.0