Skip to content

Commit 49bddd2

Browse files
harshimogalapallijannau
authored andcommitted
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: c559645 ("soc: apple: rtkit: Pass the crashlog to the crashed() callback") Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> Reviewed-by: Eric Curtin <ecurtin@redhat.com> Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 08bcb5c commit 49bddd2

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

drivers/soc/apple/rtkit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ static void apple_rtkit_crashlog_rx(struct apple_rtkit *rtk, u64 msg)
388388
apple_rtkit_memcpy(rtk, bfr, &rtk->crashlog_buffer, 0,
389389
rtk->crashlog_buffer.size);
390390
apple_rtkit_crashlog_dump(rtk, bfr, rtk->crashlog_buffer.size);
391-
kfree(bfr);
392391
} else {
393392
dev_err(rtk->dev,
394393
"RTKit: Couldn't allocate crashlog shadow buffer\n");
@@ -397,6 +396,8 @@ static void apple_rtkit_crashlog_rx(struct apple_rtkit *rtk, u64 msg)
397396
rtk->crashed = true;
398397
if (rtk->ops->crashed)
399398
rtk->ops->crashed(rtk->cookie, bfr, rtk->crashlog_buffer.size);
399+
400+
kfree(bfr);
400401
}
401402

402403
static void apple_rtkit_ioreport_rx(struct apple_rtkit *rtk, u64 msg)

0 commit comments

Comments
 (0)