Skip to content

Commit ed15511

Browse files
JoseExpositoFomys
authored andcommitted
drm/vkms: Fix use after free and double free on init error
If the driver initialization fails, the vkms_exit() function might access an uninitialized or freed default_config pointer and it might double free it. Fix both possible errors by initializing default_config only when the driver initialization succeeded. Reported-by: Louis Chauvet <[email protected]> Closes: https://lore.kernel.org/all/Z5uDHcCmAwiTsGte@louis-chauvet-laptop/ Fixes: 2df7af9 ("drm/vkms: Add vkms_config type") Signed-off-by: José Expósito <[email protected]> Reviewed-by: Thomas Zimmermann <[email protected]> Reviewed-by: Louis Chauvet <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Louis Chauvet <[email protected]>
1 parent ff3881c commit ed15511

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/gpu/drm/vkms/vkms_drv.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,19 @@ static int __init vkms_init(void)
235235
if (!config)
236236
return -ENOMEM;
237237

238-
default_config = config;
239-
240238
config->cursor = enable_cursor;
241239
config->writeback = enable_writeback;
242240
config->overlay = enable_overlay;
243241

244242
ret = vkms_create(config);
245-
if (ret)
243+
if (ret) {
246244
kfree(config);
245+
return ret;
246+
}
247247

248-
return ret;
248+
default_config = config;
249+
250+
return 0;
249251
}
250252

251253
static void vkms_destroy(struct vkms_config *config)
@@ -269,9 +271,10 @@ static void vkms_destroy(struct vkms_config *config)
269271

270272
static void __exit vkms_exit(void)
271273
{
272-
if (default_config->dev)
273-
vkms_destroy(default_config);
274+
if (!default_config)
275+
return;
274276

277+
vkms_destroy(default_config);
275278
kfree(default_config);
276279
}
277280

0 commit comments

Comments
 (0)