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 C9BBF3803D2; Sat, 12 Sep 2026 19:34:04 +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=1789241645; cv=none; b=jebBhU+9nYbRlwIEOg/3SSDAZ9JEduVPdZPgDup5Xdu2PseTH4/u8fi9ufE8i/iGUWcF1/B5ctAGDePZ1i0y7ij/iFMmFh0H4xtr3g2cUWwXmZqyysd77vPDCFbj/x96szPYHKqQ/fTtjoCy12XQ2wVwW/Swvvgnq4Rt3VkuC60= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789241645; c=relaxed/simple; bh=6KA23sCwmSZSnCgyraV+Hh1iVJ2NtEX3wDoCF8UkMLQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WyS2Whe2hHThcuDFD+OiibEa23zRegQ+/n3lKbJNGM7A07PWdiF/Ecjzin119+8TlqMVZfSDRC4PF9E/icDtnARvNXkZ3P5kKe95vjCMe/nsIXPfkIDcXFPzewS9vN21jWL77fu9LOknG1C0EBj+2V0hH2YS8ithEA1wN96Obq8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NJ80G/KY; 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="NJ80G/KY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D05DE1F000FF; Sat, 12 Sep 2026 19:34:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789241644; bh=/523GdSeNPdJBH/mtejHtqgHmn5y4q7CXkXoOf3Yh8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NJ80G/KYwGOtTPsFKxxBZML7qm7jNrmVPlEwaRKV29mTdp0yDWRMD8iLZPZEri3k0 8qnc21NUtBSe5F0B1nwGBU/ew7Acm4EZckNdY+PYxLGIVIr2GHLsoMGcu6WIwNgVuf WW5MJL8bDS4fktI4Uv7D9EbbKME+W6hppHqT4sqM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Junzhe Yu , Mikulas Patocka Subject: [PATCH 5.10 177/798] dm-stats: fix a crash if allocation of per-cpu data fails Date: Sat, 12 Sep 2026 08:56:45 +0200 Message-ID: <20260912065521.078618374@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065516.948645775@linuxfoundation.org> References: <20260912065516.948645775@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 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mikulas Patocka commit cc87e26d9cce22061dc21e51e11afef29dbbc36a upstream. If "dm_kvzalloc(percpu_alloc_size, cpu_to_node(cpu))" fails, the code jumps to the "out" label and calls dm_stat_free. dm_stat_free does "for_each_possible_cpu(cpu) { dm_kvfree(s->stat_percpu[cpu][0].histogram, s->histogram_alloc_size);", which crashes with NULL pointer dereference if s->stat_percpu[cpu] is NULL. This commit fixes the bug by testing s->stat_percpu[cpu] for NULL before using it. Reported-by: Junzhe Yu Signed-off-by: Mikulas Patocka Fixes: fd2ed4d25270 ("dm: add statistics support") Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-stats.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/md/dm-stats.c +++ b/drivers/md/dm-stats.c @@ -175,8 +175,10 @@ static void dm_stat_free(struct rcu_head kfree(s->program_id); kfree(s->aux_data); for_each_possible_cpu(cpu) { - dm_kvfree(s->stat_percpu[cpu][0].histogram, s->histogram_alloc_size); - dm_kvfree(s->stat_percpu[cpu], s->percpu_alloc_size); + if (s->stat_percpu[cpu]) { + dm_kvfree(s->stat_percpu[cpu][0].histogram, s->histogram_alloc_size); + dm_kvfree(s->stat_percpu[cpu], s->percpu_alloc_size); + } } dm_kvfree(s->stat_shared[0].tmp.histogram, s->histogram_alloc_size); dm_kvfree(s, s->shared_alloc_size);