public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dpll: Add a check before kfree() to match the existing check before kmemdup()
@ 2025-02-23 20:17 Jiasheng Jiang
  2025-02-24  9:31 ` Kubalewski, Arkadiusz
  0 siblings, 1 reply; 10+ messages in thread
From: Jiasheng Jiang @ 2025-02-23 20:17 UTC (permalink / raw)
  To: vadim.fedorenko, arkadiusz.kubalewski, jiri, davem, jan.glaza,
	przemyslaw.kitszel
  Cc: netdev, linux-kernel, Jiasheng Jiang, stable

When src->freq_supported is not NULL but src->freq_supported_num is 0,
dst->freq_supported is equal to src->freq_supported.
In this case, if the subsequent kstrdup() fails, src->freq_supported may
be freed without being set to NULL, potentially leading to a
use-after-free or double-free error.

Fixes: 830ead5fb0c5 ("dpll: fix pin dump crash for rebound module")
Cc: <stable@vger.kernel.org> # v6.8+
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
 drivers/dpll/dpll_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c
index 32019dc33cca..7d147adf8455 100644
--- a/drivers/dpll/dpll_core.c
+++ b/drivers/dpll/dpll_core.c
@@ -475,7 +475,8 @@ static int dpll_pin_prop_dup(const struct dpll_pin_properties *src,
 err_panel_label:
 	kfree(dst->board_label);
 err_board_label:
-	kfree(dst->freq_supported);
+	if (src->freq_supported_num)
+		kfree(dst->freq_supported);
 	return -ENOMEM;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-02-27  5:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-23 20:17 [PATCH] dpll: Add a check before kfree() to match the existing check before kmemdup() Jiasheng Jiang
2025-02-24  9:31 ` Kubalewski, Arkadiusz
2025-02-24 12:04   ` Jiri Pirko
2025-02-24 16:47     ` Jiasheng Jiang
2025-02-25 12:08       ` Jiri Pirko
2025-02-26  3:09         ` [PATCH v2] dpll: Add an assertion to check freq_supported_num Jiasheng Jiang
2025-02-26 14:24           ` Jiri Pirko
2025-02-26 19:37             ` [PATCH v3 net-next] " Jiasheng Jiang
2025-02-26 19:38               ` kernel test robot
2025-02-27  5:21               ` Przemek Kitszel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox