Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1261562pxb; Thu, 4 Feb 2021 08:37:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMjkaXMMwbQgK5BymYb0Mp1mgO2RUCoMHq7Q3XF/wJT5rM1B0bWOcYvYFCehwYgSA7v0In X-Received: by 2002:a17:907:76c5:: with SMTP id kf5mr8744506ejc.534.1612456666874; Thu, 04 Feb 2021 08:37:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612456666; cv=none; d=google.com; s=arc-20160816; b=VUbzh0BQoZzT2r9fVgpLuLWWvSvJixqoncbAx8c1Y/DWMl696CwDTybbU+gcLCvWn4 FyP+sniQ+YwGNkjxhB4xSikS7TJRo2ksSZ46x9HeboaCnO5/CpIPqcEeaJ1YO11XI+6a KxT+QvFTEi0w7VrIsSyb/It6iMhoy/gxi3U7bhVRlG6PO/ZVpED58jg+oQwb3o3aUWfC 1CNoQKGvDnTGiONZsP+L5MfC1ieOoXKbdNu5uywDy0pL23piBigkSmkFxmCieQ00dvBH TD5jizosdGgByqVrlrQ6qm448LIa2Ust+/GKUfzpokTK84GewEH1fp6wwGzCRrbuhXU6 B3kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=T0NRt1RoecFJjcNoijwWrOJLmNFoPaYZ4YyMc8TegcU=; b=cy54eS0bzyD/TKC+5OG20g+lJn6dZFU9n3GKp6cNHn8X3JlwkVhcaUef0mzdUNR6df CUUlW1zpk716PmQRnC6/L0HIWpaNju+widKRTHTooIHvv9sRlOJ2kqs9lFfLeyArBvp5 lyenxWLC3UOh2TOYGGmVVlH/8rSNYS3h9ApMcRx4oyzT17dhkTRU8ZiP2jvTRdi27tLD OBbq1INyXT9RDC2XcyvzRNWnxavrfpi5+fL9io+x9Xicc9JmxAgL5YZPwbHAesgBHJTd 0SODCLQmD1AX6hahHuDQsg6Y1PHBla9+/p6fTGhpTOQ03aOedIgnwTSoSu3HxSCAUyB8 7cOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lG+DgfQ9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l13si3184914ejx.754.2021.02.04.08.37.20; Thu, 04 Feb 2021 08:37:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lG+DgfQ9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238065AbhBDQcy (ORCPT + 99 others); Thu, 4 Feb 2021 11:32:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238097AbhBDQbj (ORCPT ); Thu, 4 Feb 2021 11:31:39 -0500 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7B71C0613D6 for ; Thu, 4 Feb 2021 08:30:59 -0800 (PST) Received: by mail-qk1-x733.google.com with SMTP id s77so3882765qke.4 for ; Thu, 04 Feb 2021 08:30:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=T0NRt1RoecFJjcNoijwWrOJLmNFoPaYZ4YyMc8TegcU=; b=lG+DgfQ93qIQHJWos7mTV85Ys/7hSvcDXIFoGSDhZFxEz1Helq+xUggdjnusRYGw5e Vu78Jua2vyOvjsXnbwJkbkyO3Veyto7w5Qsbm9l0AeCf01J1L+aDMa83dFHZQFsuQY8B UDO6RUSdlUYBKtlUPvdBWR3dGtYlWN7ZZzYw2JflERwekh/XrBoiKispqVTTVeYscq2E hONOYxE4a1x6Jmwtim+H8X1ho7d1qZYxaTemuDadJ5YOoeNY3Xp89ZCKKgPcY1KIIni9 XDuZcOQVR2ty4hEhnl+L2+X9+RoRPDRHuuaPqX6aQwuF17xFRbLsY6VSZBothEA7ZiwX KZkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=T0NRt1RoecFJjcNoijwWrOJLmNFoPaYZ4YyMc8TegcU=; b=fiILEIVEmNMVyXopm5XGwvgE36wZKacyn1ju/DCKae1ognl8HppLMoUEdR2NLFIzoX KoWQUP7akGuIwA6Q3im9pRV5SZnjWQ1ATJeTdmrz2WZJra/JroNTsCaNlb5mcCRh+EVH OPYjMRiZf35MYkG+/srtz5gUM+aa2yblnhJ0Pn4uB1uNWNdSALri+ICPgGM7HCfqBVmC vIydYUDBGMLQje8VUnAXWT0xNGlT3YF4gwt0HpgHp8jr7ANdRVeE3jzp0Fw2brSc6Adr DSynxu68iYQV4xDduP/b0T+Jcxf5HS2INncm5/3I1afVIq9+rGjfXnUsHTZoECqx0Qph 1q/g== X-Gm-Message-State: AOAM531VtvpIVwnSTFdGCf+XDqhHuNqdjaQ2gqsesGPXZwZKKofY6s55 H8c5KW1r0ZpEt4Ao2sGIazc= X-Received: by 2002:ae9:c111:: with SMTP id z17mr8561357qki.475.1612456258950; Thu, 04 Feb 2021 08:30:58 -0800 (PST) Received: from tong-desktop.local ([2601:5c0:c200:27c6:1d8e:4975:1aa2:eea2]) by smtp.googlemail.com with ESMTPSA id h6sm5510920qkf.96.2021.02.04.08.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 08:30:58 -0800 (PST) From: Tong Zhang To: Dave Airlie , Gerd Hoffmann , David Airlie , Daniel Vetter , virtualization@lists.linux-foundation.org, spice-devel@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: ztong0001@gmail.com Subject: [PATCH v2] drm/qxl: do not run release if qxl failed to init Date: Thu, 4 Feb 2021 11:30:50 -0500 Message-Id: <20210204163050.1232756-1-ztong0001@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org if qxl_device_init() fail, drm device will not be registered, in this case, do not run qxl_drm_release() [ 5.258534] ================================================================== [ 5.258931] BUG: KASAN: user-memory-access in qxl_destroy_monitors_object+0x42/0xa0 [qxl] [ 5.259388] Write of size 8 at addr 00000000000014dc by task modprobe/95 [ 5.259754] [ 5.259842] CPU: 0 PID: 95 Comm: modprobe Not tainted 5.11.0-rc6-00007-g88bb507a74ea #62 [ 5.260309] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-48-gd9c812dda54 [ 5.260917] Call Trace: [ 5.261056] dump_stack+0x7d/0xa3 [ 5.261245] kasan_report.cold+0x10c/0x10e [ 5.261475] ? qxl_destroy_monitors_object+0x42/0xa0 [qxl] [ 5.261789] check_memory_region+0x17c/0x1e0 [ 5.262029] qxl_destroy_monitors_object+0x42/0xa0 [qxl] [ 5.262332] qxl_modeset_fini+0x9/0x20 [qxl] [ 5.262595] qxl_drm_release+0x22/0x30 [qxl] [ 5.262841] drm_dev_release+0x32/0x50 [ 5.263047] release_nodes+0x39e/0x410 [ 5.263253] ? devres_release+0x40/0x40 [ 5.263462] really_probe+0x2ea/0x420 [ 5.263664] driver_probe_device+0x6d/0xd0 [ 5.263888] device_driver_attach+0x82/0x90 [ 5.264116] ? device_driver_attach+0x90/0x90 [ 5.264353] __driver_attach+0x60/0x100 [ 5.264563] ? device_driver_attach+0x90/0x90 [ 5.264801] bus_for_each_dev+0xe1/0x140 [ 5.265014] ? subsys_dev_iter_exit+0x10/0x10 [ 5.265251] ? klist_node_init+0x61/0x80 [ 5.265464] bus_add_driver+0x254/0x2a0 [ 5.265673] driver_register+0xd3/0x150 [ 5.265882] ? 0xffffffffc0048000 [ 5.266064] do_one_initcall+0x84/0x250 [ 5.266274] ? trace_event_raw_event_initcall_finish+0x150/0x150 [ 5.266596] ? unpoison_range+0xf/0x30 [ 5.266801] ? ____kasan_kmalloc.constprop.0+0x84/0xa0 [ 5.267082] ? unpoison_range+0xf/0x30 [ 5.267287] ? unpoison_range+0xf/0x30 [ 5.267491] do_init_module+0xf8/0x350 [ 5.267697] load_module+0x3fe6/0x4340 [ 5.267902] ? vm_unmap_ram+0x1d0/0x1d0 [ 5.268115] ? module_frob_arch_sections+0x20/0x20 [ 5.268375] ? __do_sys_finit_module+0x108/0x170 [ 5.268624] __do_sys_finit_module+0x108/0x170 [ 5.268865] ? __ia32_sys_init_module+0x40/0x40 [ 5.269111] ? file_open_root+0x200/0x200 [ 5.269330] ? do_sys_open+0x85/0xe0 [ 5.269527] ? filp_open+0x50/0x50 [ 5.269714] ? exit_to_user_mode_prepare+0xfc/0x130 [ 5.269978] do_syscall_64+0x33/0x40 [ 5.270176] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 5.270450] RIP: 0033:0x7fa3f685bcf7 [ 5.270646] Code: 48 89 57 30 48 8b 04 24 48 89 47 38 e9 1d a0 02 00 48 89 f8 48 89 f7 48 89 d1 [ 5.271634] RSP: 002b:00007ffca83048d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [ 5.272037] RAX: ffffffffffffffda RBX: 0000000001e94a70 RCX: 00007fa3f685bcf7 [ 5.272416] RDX: 0000000000000000 RSI: 0000000001e939e0 RDI: 0000000000000003 [ 5.272794] RBP: 0000000000000003 R08: 0000000000000000 R09: 0000000000000001 [ 5.273171] R10: 00007fa3f68bf300 R11: 0000000000000246 R12: 0000000001e939e0 [ 5.273550] R13: 0000000000000000 R14: 0000000001e93bd0 R15: 0000000000000001 [ 5.273928] ================================================================== Signed-off-by: Tong Zhang --- v2: use qdev->ddev.mode_config.funcs instead of dev->registered, since mode_config.funcs will only be set if qxl_modeset_init() returns 0 drivers/gpu/drm/qxl/qxl_drv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/qxl/qxl_drv.c b/drivers/gpu/drm/qxl/qxl_drv.c index 6e7f16f4cec7..839d9e7a5765 100644 --- a/drivers/gpu/drm/qxl/qxl_drv.c +++ b/drivers/gpu/drm/qxl/qxl_drv.c @@ -144,6 +144,8 @@ static void qxl_drm_release(struct drm_device *dev) * reodering qxl_modeset_fini() + qxl_device_fini() calls is * non-trivial though. */ + if (!qdev->ddev.mode_config.funcs) + return; qxl_modeset_fini(qdev); qxl_device_fini(qdev); } -- 2.25.1