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 A6F3B17BBF; Mon, 2 Jun 2025 14:45:27 +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=1748875527; cv=none; b=cQn32xD3OEaUjL8SeKHYeeRIxbnx2B7UBKlobHc4lH32tkAP6nCRFjnWUuhHvKuZL1HNJkW6Jeh6PqVVvvDLTyzRXh8KnUhRW0EC/QtF6pdrBVh3exonyXxoJkXVXK3O4p4E+ayK0b2txTiTY4sx4MduwTAE0VGyHhPEMMwJsn8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748875527; c=relaxed/simple; bh=WeDqzgQ48gSDPMPjWY39zgQvsSQ5vmwCO8F2gKAoiM0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jld24HCnSHUjmPxOEvZXqXVbPmLvdGP017oYVxi9zTqeL4+SG78B22xaV7YEw0z9rlq/tQJRLXYCGd7P3NS6fa4dsapGui/r0cIJVbuAJ/eusv8FKcllYFVB1obsGAIRu+QjD7fDOr2ZwrVVQrmp42qUfwidX4SYMxcAUltc3/g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=s+y7wlBe; 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="s+y7wlBe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6EF4C4CEEB; Mon, 2 Jun 2025 14:45:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1748875527; bh=WeDqzgQ48gSDPMPjWY39zgQvsSQ5vmwCO8F2gKAoiM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s+y7wlBerWWbCFbQsz7XaccKvpVPGZotdUl5gRWjPlbIWu43VewImPW/WD/Ha3kF8 qCEQYsyngaqkGz13FdGnU0wWorU+oH3tkmEkzrGihrNgxvAwD6QTgHOIJGX+Zk1DKh Cz4vsAJsH/8r0LlcxWXok8qg6rJj9w0UBzu7GKTM= 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.10 132/270] libnvdimm/labels: Fix divide error in nd_label_data_init() Date: Mon, 2 Jun 2025 15:46:57 +0200 Message-ID: <20250602134312.623924734@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250602134307.195171844@linuxfoundation.org> References: <20250602134307.195171844@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.10-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