drm/crtc: Fix uninit-value bug in drm_mode_setcrtc
authorZiqi Zhao <astrajoan@yahoo.com>
Fri, 21 Jul 2023 16:14:46 +0000 (09:14 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 20 Jan 2024 10:51:43 +0000 (11:51 +0100)
commitff89e507b231a3afbddc2972a850947b73247a3b
tree6ff304a279379271a6218eada02a618acb8ba3b0
parent5c480a6966c5a2f8a96c8440b10a4acc0fc57624
drm/crtc: Fix uninit-value bug in drm_mode_setcrtc

[ Upstream commit 3823119b9c2b5f9e9b760336f75bc989b805cde6 ]

The connector_set contains uninitialized values when allocated with
kmalloc_array. However, in the "out" branch, the logic assumes that any
element in connector_set would be equal to NULL if failed to
initialize, which causes the bug reported by Syzbot. The fix is to use
an extra variable to keep track of how many connectors are initialized
indeed, and use that variable to decrease any refcounts in the "out"
branch.

Reported-by: syzbot+4fad2e57beb6397ab2fc@syzkaller.appspotmail.com
Signed-off-by: Ziqi Zhao <astrajoan@yahoo.com>
Reported-and-tested-by: syzbot+4fad2e57beb6397ab2fc@syzkaller.appspotmail.com
Tested-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Link: https://lore.kernel.org/r/20230721161446.8602-1-astrajoan@yahoo.com
Signed-off-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/drm_crtc.c