From: Harshit Mogalapalli Date: Wed, 12 Feb 2025 08:58:53 +0000 (-0800) Subject: soc: apple: rtkit: Fix use-after-free in apple_rtkit_crashlog_rx() X-Git-Tag: v6.15-rc1~158^2~17^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=00834971f0d9e38beae37e92055b1432782827d0;p=thirdparty%2Fkernel%2Flinux.git soc: apple: rtkit: Fix use-after-free in apple_rtkit_crashlog_rx() This code calls kfree(bfr); and then passes "bfr" to rtk->ops->crashed() which is a use after free. The ->crashed function pointer is implemented by apple_nvme_rtkit_crashed() and it doesn't use the "bfr" pointer so this doesn't cause a problem. But it still looks sketchy as can be. Fix this by moving kfree() after the last usage of bfr. Fixes: bf8b4e49777d ("soc: apple: rtkit: Pass the crashlog to the crashed() callback") Signed-off-by: Harshit Mogalapalli Reviewed-by: Eric Curtin Link: https://lore.kernel.org/r/20250212085853.1357906-1-harshit.m.mogalapalli@oracle.com Signed-off-by: Sven Peter --- diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index f190619674592..2f5f878bf899b 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -370,7 +370,6 @@ static void apple_rtkit_crashlog_rx(struct apple_rtkit *rtk, u64 msg) apple_rtkit_memcpy(rtk, bfr, &rtk->crashlog_buffer, 0, rtk->crashlog_buffer.size); apple_rtkit_crashlog_dump(rtk, bfr, rtk->crashlog_buffer.size); - kfree(bfr); } else { dev_err(rtk->dev, "RTKit: Couldn't allocate crashlog shadow buffer\n"); @@ -379,6 +378,8 @@ static void apple_rtkit_crashlog_rx(struct apple_rtkit *rtk, u64 msg) rtk->crashed = true; if (rtk->ops->crashed) rtk->ops->crashed(rtk->cookie, bfr, rtk->crashlog_buffer.size); + + kfree(bfr); } static void apple_rtkit_ioreport_rx(struct apple_rtkit *rtk, u64 msg)