drm/vc4: tests: Fix UAF in the mock helpers
authorMaxime Ripard <mripard@kernel.org>
Tue, 24 Oct 2023 10:56:40 +0000 (12:56 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 20 Nov 2023 10:59:37 +0000 (11:59 +0100)
commite733f3e9dc7c5b4210a0cc5bfb3347f6ca9fa747
treea48c8457326f70bbac6f970912ae1c6eab726f3e
parent4bc46c047ecf1818e6a053fbb399aab9c476c16d
drm/vc4: tests: Fix UAF in the mock helpers

[ Upstream commit cdcd6aef9db5797995d4153ea19fdf56d189f0e4 ]

The VC4 mock helpers allocate the CRTC, encoders and connectors using a
call to kunit_kzalloc(), but the DRM device they are attache to survives
for longer than the test itself which leads to use-after-frees reported
by KASAN.

Switch to drmm_kzalloc to tie the lifetime of these objects to the main
DRM device.

Fixes: f759f5b53f1c ("drm/vc4: tests: Introduce a mocking infrastructure")
Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Closes: https://lore.kernel.org/all/CA+G9fYvJA2HGqzR9LGgq63v0SKaUejHAE6f7+z9cwWN-ourJ_g@mail.gmail.com/
Tested-by: Anders Roxell <anders.roxell@linaro.org>
Reviewed-by: MaĆ­ra Canal <mcanal@igalia.com>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20231024105640.352752-1-mripard@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/vc4/tests/vc4_mock_crtc.c
drivers/gpu/drm/vc4/tests/vc4_mock_output.c