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 500622222B0; Mon, 2 Jun 2025 14:54:13 +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=1748876053; cv=none; b=tIjRNfoyDt9UhkjIYGm90jQo89xhR1Ei6n8oJZadWjrMoMQL1IVOXLEG7CdhiWYKhiuxgmSBs5OslhJ5bcaC1BlUH61DGEnm4PRzg9DA6Cy6Y988yA+wmUYs9ij6QxrwdBRr4stedUAF3SShBc+0c6of+khaSfxie+VYXIeG+go= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748876053; c=relaxed/simple; bh=1fXhPbpv/aTsxA1t5fxUaKAgER7rdBMgCq7Hrl45eCw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pu8I+sAjySG9M5IlO4QS/OXyYO9dba5W9Tv8Mb9qB8IufLuCaFqKLKcpbJDbixgEW3OXXkKeCRSfmwAQUmaqeCFHydKvMj+FadGc9UD8En9Y5IJGqofe/VH5H+TlMPnKdeBWf590lckSJ+sqTJmWRZoTtdVdefAHqxx4bU59rds= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=nFWT9cct; 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="nFWT9cct" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6456C4CEEB; Mon, 2 Jun 2025 14:54:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1748876053; bh=1fXhPbpv/aTsxA1t5fxUaKAgER7rdBMgCq7Hrl45eCw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nFWT9cctJCFzDsRTtaZnOqXBjPKZ6U3RMnI7wyPj+sTAKB7uTdLPo8QuQ8ukVCarP Tappp1Q8hExzoBpRLUSRpDhUDIVDceZty1c5gfd4egGPSHEsr/9kvlxy/UqWDATOxj zCKtrpJT4Gioke3uj0vjm/hrvvomo7dmLR0LRv/Q= 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.15 025/207] libnvdimm/labels: Fix divide error in nd_label_data_init() Date: Mon, 2 Jun 2025 15:46:37 +0200 Message-ID: <20250602134259.756948963@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250602134258.769974467@linuxfoundation.org> References: <20250602134258.769974467@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.15-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 7f473f9db300d..e1b511d09295f 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -437,7 +437,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