From b6eaff88011de0f7d90801508161102d15453107 Mon Sep 17 00:00:00 2001 From: Charles Han Date: Fri, 27 Dec 2024 17:20:46 +0800 Subject: [PATCH] Bluetooth: btbcm: Fix NULL deref in btbcm_get_board_name() BugLink: https://bugs.launchpad.net/bugs/2111953 [ Upstream commit b88655bc6593c6a7fdc1248b212d17e581c4334e ] devm_kstrdup() can return a NULL pointer on failure,but this returned value in btbcm_get_board_name() is not checked. Add NULL check in btbcm_get_board_name(), to handle kernel NULL pointer dereference error. Fixes: f9183eaad915 ("Bluetooth: btbcm: Use devm_kstrdup()") Signed-off-by: Charles Han Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin Signed-off-by: Manuel Diewald Signed-off-by: Mehmet Basaran --- drivers/bluetooth/btbcm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c index 501a34975577..c580c43f893d 100644 --- a/drivers/bluetooth/btbcm.c +++ b/drivers/bluetooth/btbcm.c @@ -555,6 +555,9 @@ static const char *btbcm_get_board_name(struct device *dev) /* get rid of any '/' in the compatible string */ len = strlen(tmp) + 1; board_type = devm_kzalloc(dev, len, GFP_KERNEL); + if (!board_type) + return NULL; + strscpy(board_type, tmp, len); for (i = 0; i < len; i++) { if (board_type[i] == '/')