From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 ED8A646C4BD; Tue, 21 Jul 2026 19:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784663373; cv=none; b=Yk4CEPCJEUZmiCfT8vskMFGzz23InHZ8dVW6xWuLVVNTiwUChfu5/FLNl/t5o8PW6li9Gn1FIUd4WI9EvO37BEnjkseN1PKJlqeT8pXMhr0KpZxQiTg0WbIhJuuhLFX5iVrKwI9Wli1msi9tZwYYIgexNJ6HVVNK3gAo0aK8mTk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784663373; c=relaxed/simple; bh=Rj5JmPCELv8uBZgWmMH4SeROd25ZMUDwOOb3UhA+LZk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IwmqHF4tKZEXx4MiOd2w4plmYpii8/uoQ3BYnUtDUeLRcqgak8T1dWsjmIDQjQ1xPDkVoMYjU148vs5m03VRDJXYoRvhbDonQ43h1tq0j89s+0ut2Wk38kq7ywT6Z40RuMEHCc+HHuhFCMA/1f3lsiM12Cn1Xb3f0dbm3YGArqM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=VfY/PI2V; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="VfY/PI2V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59A341F00A3D; Tue, 21 Jul 2026 19:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784663371; bh=PMF1gDevKuqsQJjOkhn9YCc+TMHZgDFIlSubnJEYKbs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VfY/PI2VSRR203AGfctkUhY7rfXdCfn6LuvjZrzy5gpj17WgrCiX9nH+JTjbMhRJw 6HCmkbzjrxM6QlR85YaT/AEIfPbfVkyeedpwj3qZ6hKwEieNuh1aV+Bq53xy0ZygWU mDliUm9p3K6hsGU+5rW+1hW/6RVaDjjfck8kUy8Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Cao Guanghui , Su Yue , Ming-Hung Tsai , Mikulas Patocka , Sasha Levin Subject: [PATCH 6.12 0799/1276] dm era: fix NULL pointer dereference in metadata_open() Date: Tue, 21 Jul 2026 17:20:42 +0200 Message-ID: <20260721152503.953979197@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152446.065700225@linuxfoundation.org> References: <20260721152446.065700225@linuxfoundation.org> User-Agent: quilt/0.69 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 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cao Guanghui [ Upstream commit 9ae672606c17891d90b282e3490b817620549599 ] metadata_open() returns NULL when kzalloc_obj() fails, but the caller era_ctr() only checks IS_ERR(md). Since IS_ERR(NULL) returns false, the NULL pointer is treated as a valid result and later assigned to era->md, leading to a NULL pointer dereference when the metadata is accessed. Fix this by returning ERR_PTR(-ENOMEM) on allocation failure, consistent with dm-cache-metadata.c, dm-thin-metadata.c, and dm-clone-metadata.c which all use ERR_PTR(-ENOMEM) for the same pattern. Fixes: eec40579d848 ("dm: add era target") Signed-off-by: Cao Guanghui Reviewed-by: Su Yue Reviewed-by: Ming-Hung Tsai Signed-off-by: Mikulas Patocka Signed-off-by: Sasha Levin --- drivers/md/dm-era-target.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm-era-target.c b/drivers/md/dm-era-target.c index 9c84e9d13eca6d..5cc71dbc7e039c 100644 --- a/drivers/md/dm-era-target.c +++ b/drivers/md/dm-era-target.c @@ -810,8 +810,10 @@ static struct era_metadata *metadata_open(struct block_device *bdev, int r; struct era_metadata *md = kzalloc(sizeof(*md), GFP_KERNEL); - if (!md) - return NULL; + if (!md) { + DMERR("could not allocate metadata struct"); + return ERR_PTR(-ENOMEM); + } md->bdev = bdev; md->block_size = block_size; -- 2.53.0