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 9023F30FC03; Mon, 13 Oct 2025 15:05:30 +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=1760367930; cv=none; b=hHJ/fh3bTclHimirjfma8tOKOOPwn7A2tt/UN+6zIIQPEPjmE10nGdnkJl/zffB4Lkz302bEScJVwgZj4SxTys4Zjenk0ymwPIqoAMWIIVWqe3gSc6eHh82X0+RsaPtYRgU9sprSlSrQQQcAy036Hvz+jEaNPPMRQ1SPGnBBw2s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760367930; c=relaxed/simple; bh=FZP9Ysg9Jrf3N1uDpouGJvH28kYv0DFuzHFU6t9feBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cEkRWCt6oqkjgdJd0nQ9ycwf7Ew67bycvAXRLoq6bjM02+jR/PiMHJ/M3hCKTa6Cne0StRySzChzoG/ClQW5Z4iIAon3lBr8iMlf2ln4/nz5ObYn+wdwL126n1wPCbT03hWf8e/zYKDRtWh1ScWplKfbhwxqeHJXP6m0QlYtm8w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hdD0+FHI; 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="hdD0+FHI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 181C3C4CEE7; Mon, 13 Oct 2025 15:05:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1760367930; bh=FZP9Ysg9Jrf3N1uDpouGJvH28kYv0DFuzHFU6t9feBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hdD0+FHIFNo9sczgn+alQlol9uN5XU+EjXcAo+54OlPGKa5wOqEDCqZCq5cOV6Vzu IjQHKPezGe287OkXkLZalBMcpenUhrVmY8s2DYZaE2bpAEE9fGXg+Z/21omgjlC92h Zb1vSrc4fix4oEtgISjMJIWPtXXmEgFta6S1oc5c= 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.6 183/196] nvdimm: ndtest: Return -ENOMEM if devm_kcalloc() fails in ndtest_probe() Date: Mon, 13 Oct 2025 16:46:14 +0200 Message-ID: <20251013144321.927892146@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251013144315.184275491@linuxfoundation.org> References: <20251013144315.184275491@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.6-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 @@ -845,11 +845,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;