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 BD4061A9B46; Mon, 13 Oct 2025 15:19:12 +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=1760368752; cv=none; b=VPsYy7UZBVW9BzO/KtBP/BanouL/+ROXBGpxwzOt9IujkpcV0HxD1RqKdYMhr0l/fx3aVtE8OuUvqroEv/mwMGynO0tgMsrouejXYKmqtONs+R6bnTqX8roc7Cf/ATVqT6CPd/rTtHbmauEhrNfu+nyY006SnXFELqajGGg+1oM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760368752; c=relaxed/simple; bh=6RAqLPfosLsFnfTUtjtlL9nUIxjVcHyV/A8Tz4byi2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tWnzDcSvHY6d16zCfzECmooPunBvW7m/7v1VVnkhYHc38ndNkSd7CumN5OD9/pn/DRpGJAoIKhDUA784gHalll7NMXMJhxMe6AAxQxGmE5IkC5qr6ZXvpNGma7TtbhjXoHITSlGyYArP+kA+FZdd2OPU9DzUPLf8wvGHsH2S0dQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JZcBbIMT; 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="JZcBbIMT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40551C4CEE7; Mon, 13 Oct 2025 15:19:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1760368752; bh=6RAqLPfosLsFnfTUtjtlL9nUIxjVcHyV/A8Tz4byi2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JZcBbIMTT4f9fcaoR8lGgKf1Nk5NL/lmss0sIVE/nsyISliiuXbWEV8NWV1Rzagbc c58wYp0cGzV78cpObjr9zlDXOFWHDSVgwGasKVoRwzm0xJh186bIvb+ZOcULcwAu89 mxgJ28Q9c8hvsLB3DXS4ptFX5pjW7HoJYP5EIqj4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guangshuo Li , Alison Schofield , Ira Weiny , Dave Jiang Subject: [PATCH 6.12 246/262] nvdimm: ndtest: Return -ENOMEM if devm_kcalloc() fails in ndtest_probe() Date: Mon, 13 Oct 2025 16:46:28 +0200 Message-ID: <20251013144335.097194450@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251013144326.116493600@linuxfoundation.org> References: <20251013144326.116493600@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guangshuo Li commit a9e6aa994917ee602798bbb03180a194b37865bb upstream. devm_kcalloc() may fail. ndtest_probe() allocates three DMA address arrays (dcr_dma, label_dma, dimm_dma) and later unconditionally uses them in ndtest_nvdimm_init(), which can lead to a NULL pointer dereference under low-memory conditions. Check all three allocations and return -ENOMEM if any allocation fails, jumping to the common error path. Do not emit an extra error message since the allocator already warns on allocation failure. Fixes: 9399ab61ad82 ("ndtest: Add dimms to the two buses") Cc: stable@vger.kernel.org Signed-off-by: Guangshuo Li Reviewed-by: Alison Schofield Reviewed-by: Ira Weiny Reviewed-by: Dave Jiang Signed-off-by: Ira Weiny Signed-off-by: Greg Kroah-Hartman --- tools/testing/nvdimm/test/ndtest.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) --- a/tools/testing/nvdimm/test/ndtest.c +++ b/tools/testing/nvdimm/test/ndtest.c @@ -850,11 +850,22 @@ static int ndtest_probe(struct platform_ p->dcr_dma = devm_kcalloc(&p->pdev.dev, NUM_DCR, sizeof(dma_addr_t), GFP_KERNEL); + if (!p->dcr_dma) { + rc = -ENOMEM; + goto err; + } p->label_dma = devm_kcalloc(&p->pdev.dev, NUM_DCR, sizeof(dma_addr_t), GFP_KERNEL); + if (!p->label_dma) { + rc = -ENOMEM; + goto err; + } p->dimm_dma = devm_kcalloc(&p->pdev.dev, NUM_DCR, sizeof(dma_addr_t), GFP_KERNEL); - + if (!p->dimm_dma) { + rc = -ENOMEM; + goto err; + } rc = ndtest_nvdimm_init(p); if (rc) goto err;