From mboxrd@z Thu Jan 1 00:00:00 1970 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 B542C1C5D72; Mon, 2 Jun 2025 14:31:11 +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=1748874671; cv=none; b=QAJ7fZW/asuwmHB+AQ58RM0EXamnfP7ekDKGNMsz4BZAl/uI9DmspQIpWtQ5dMHI4xbp+Xeub0/sMgHgDqMIhQB9gXX6DczxNlgvX89BDfuXvVKDjn8sKoto5O5Em2Rk/JlB0kNEK/at4DDlMl9M1cJA3pacjSWNAj0S7cL2p0A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748874671; c=relaxed/simple; bh=eR2qw3Ph+nNaX6W6CdWt7Qkgspo6/fNjx6SpLf5j9b4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MaU2hD+nHF15hAd25jaTtnD25kQaklPy6gXvrknCFQsks2T+BW21Pjs/4FLjil41hU7SFgEhxE19EzK9HfQUsawFOCIfmEBfgnFFHNxwUo0qBc/UZZ+uL0+x/bhwyurzNJaVGVxCuqzBmCx8sEn4LIat55f9X2jRslPJps6oC34= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=pvFKaZp2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="pvFKaZp2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 286F6C4CEEB; Mon, 2 Jun 2025 14:31:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1748874671; bh=eR2qw3Ph+nNaX6W6CdWt7Qkgspo6/fNjx6SpLf5j9b4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pvFKaZp2fKZGWmkPAoV9dT7l+qMZcCSBZVzVvSvAbBJ6INwf6qIXJdID4MdEqKepe pFj23RWHs9ZGsGYBlFPQXEeuoFlVSBSMPu9uS+nBmEHLZm1ErnBB3CAHwGRz8KCUXl pNmAiByvDoxcqSGx11krvb1bkuIVPHe7IzMJYje8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Robert Richter , Pankaj Gupta , Ira Weiny , Sasha Levin Subject: [PATCH 5.4 098/204] libnvdimm/labels: Fix divide error in nd_label_data_init() Date: Mon, 2 Jun 2025 15:47:11 +0200 Message-ID: <20250602134259.514176059@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250602134255.449974357@linuxfoundation.org> References: <20250602134255.449974357@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Robert Richter [ Upstream commit ef1d3455bbc1922f94a91ed58d3d7db440652959 ] If a faulty CXL memory device returns a broken zero LSA size in its memory device information (Identify Memory Device (Opcode 4000h), CXL spec. 3.1, 8.2.9.9.1.1), a divide error occurs in the libnvdimm driver: Oops: divide error: 0000 [#1] PREEMPT SMP NOPTI RIP: 0010:nd_label_data_init+0x10e/0x800 [libnvdimm] Code and flow: 1) CXL Command 4000h returns LSA size = 0 2) config_size is assigned to zero LSA size (CXL pmem driver): drivers/cxl/pmem.c: .config_size = mds->lsa_size, 3) max_xfer is set to zero (nvdimm driver): drivers/nvdimm/label.c: max_xfer = min_t(size_t, ndd->nsarea.max_xfer, config_size); 4) A subsequent DIV_ROUND_UP() causes a division by zero: drivers/nvdimm/label.c: /* Make our initial read size a multiple of max_xfer size */ drivers/nvdimm/label.c: read_size = min(DIV_ROUND_UP(read_size, max_xfer) * max_xfer, drivers/nvdimm/label.c- config_size); Fix this by checking the config size parameter by extending an existing check. Signed-off-by: Robert Richter Reviewed-by: Pankaj Gupta Reviewed-by: Ira Weiny Link: https://patch.msgid.link/20250320112223.608320-1-rrichter@amd.com Signed-off-by: Ira Weiny Signed-off-by: Sasha Levin --- drivers/nvdimm/label.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 9251441fd8a35..5251058adc4d1 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -421,7 +421,8 @@ int nd_label_data_init(struct nvdimm_drvdata *ndd) if (ndd->data) return 0; - if (ndd->nsarea.status || ndd->nsarea.max_xfer == 0) { + if (ndd->nsarea.status || ndd->nsarea.max_xfer == 0 || + ndd->nsarea.config_size == 0) { dev_dbg(ndd->dev, "failed to init config data area: (%u:%u)\n", ndd->nsarea.max_xfer, ndd->nsarea.config_size); return -ENXIO; -- 2.39.5