Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp439118iog; Mon, 13 Jun 2022 06:03:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjR4hPWaBp/EscRMDzwW96grfNaSDnMPWk3iDlLl3Qp6VknXqY7frXEuLWwp7STlRiN1K9 X-Received: by 2002:a65:554b:0:b0:3fc:159c:823e with SMTP id t11-20020a65554b000000b003fc159c823emr51410565pgr.33.1655125392343; Mon, 13 Jun 2022 06:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125392; cv=none; d=google.com; s=arc-20160816; b=VHHiQN1uaorfMIPq8mzRJX2lg8/PzV0DBWrF5BjWALgKuA+bZfkzd08DLeZNjPdzzI Rw13PlS7NOQxQBs0O9015P04MZU/p+Aw5I7zStX4tn1YOm4SR93YvR11Ej3oWTxxGcDV voO57rEwhk33uSLt2Zsw0SL8vEWZjMOEkkp5TZv5ZcKOs4GScCRHcah7KcPcEx9Z0dPb TU/TFUJRi6vMbhLAQG1u7J+GtP1zhIIanEqc93aT5GFOcrJ6biwA99Z3bRfbEINt57+4 akITh7xJ45VCMWitKaWO59KMNKBygQd3I4I9D39t45zsWQmNCMFR2N/YP69lVuAoyr+R 3ULw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=io2eShBZ0rudq1rI8/moFhd6vpr5Zl6noiXdLfpmOFc=; b=gX0FDRu30r2SYbuK9WsJbobJH+p2VytyX6vU1kF3zKVGmZoBqPUokz7e+qgPd6Bzxh G0DTSnZGLc5JDmK/4ul/n0WAJqSATfWJag5Tgfnj2Yae61+5vjHw9fiyiScfrq6Iuz5t PPs2uWX33ycfV5aOVqjxOaP2vRNEZG/nLeNektxy5fkSgTCYnYlI9zNpPxLleGX5cBon 1RDyW7Ebeg/AogGaUCKHMbtO6wgaDIhvouEBmLee8EesB7wK2kh5ymrdDeiXn/6icDbZ SxxJEZ6JnP1VO/oT7HW7EywgSliU6XEZSowwd+/QEG79yufgBR0M1yyictM4WUL/U+wa 0IpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q6NNHDMW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r13-20020aa7988d000000b0051bc45234f6si8504321pfl.21.2022.06.13.06.02.57; Mon, 13 Jun 2022 06:03:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q6NNHDMW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347827AbiFMKza (ORCPT + 99 others); Mon, 13 Jun 2022 06:55:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347583AbiFMKwL (ORCPT ); Mon, 13 Jun 2022 06:52:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B29851FCE1; Mon, 13 Jun 2022 03:27:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8BDD0B80E92; Mon, 13 Jun 2022 10:27:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 057E9C34114; Mon, 13 Jun 2022 10:27:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116045; bh=TwVHwNN/o9XLM+Y5O2G/KwViT1tktgTbWNFKIcVo8PU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q6NNHDMWcOmbcAZiC6alSANEdNph14pN1+wEEmxULV7ZW9A2Bi//tdZ6S9BkGwPrD uLoXAnMI5oAkR1FJzIYtb8E0lQfnK/eysi2Sc9OHnpm9WEoWlwiDbLRLT9y8i/TjBC 5Qcga4AuWZRbUMhD7T59c+as/HAL5brNHYB6OP8c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liu Zixian , Gerd Hoffmann , Sasha Levin Subject: [PATCH 5.4 012/411] drm/virtio: fix NULL pointer dereference in virtio_gpu_conn_get_modes Date: Mon, 13 Jun 2022 12:04:45 +0200 Message-Id: <20220613094928.866495355@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liu Zixian [ Upstream commit 194d250cdc4a40ccbd179afd522a9e9846957402 ] drm_cvt_mode may return NULL and we should check it. This bug is found by syzkaller: FAULT_INJECTION stacktrace: [ 168.567394] FAULT_INJECTION: forcing a failure. name failslab, interval 1, probability 0, space 0, times 1 [ 168.567403] CPU: 1 PID: 6425 Comm: syz Kdump: loaded Not tainted 4.19.90-vhulk2201.1.0.h1035.kasan.eulerosv2r10.aarch64 #1 [ 168.567406] Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015 [ 168.567408] Call trace: [ 168.567414] dump_backtrace+0x0/0x310 [ 168.567418] show_stack+0x28/0x38 [ 168.567423] dump_stack+0xec/0x15c [ 168.567427] should_fail+0x3ac/0x3d0 [ 168.567437] __should_failslab+0xb8/0x120 [ 168.567441] should_failslab+0x28/0xc0 [ 168.567445] kmem_cache_alloc_trace+0x50/0x640 [ 168.567454] drm_mode_create+0x40/0x90 [ 168.567458] drm_cvt_mode+0x48/0xc78 [ 168.567477] virtio_gpu_conn_get_modes+0xa8/0x140 [virtio_gpu] [ 168.567485] drm_helper_probe_single_connector_modes+0x3a4/0xd80 [ 168.567492] drm_mode_getconnector+0x2e0/0xa70 [ 168.567496] drm_ioctl_kernel+0x11c/0x1d8 [ 168.567514] drm_ioctl+0x558/0x6d0 [ 168.567522] do_vfs_ioctl+0x160/0xf30 [ 168.567525] ksys_ioctl+0x98/0xd8 [ 168.567530] __arm64_sys_ioctl+0x50/0xc8 [ 168.567536] el0_svc_common+0xc8/0x320 [ 168.567540] el0_svc_handler+0xf8/0x160 [ 168.567544] el0_svc+0x10/0x218 KASAN stacktrace: [ 168.567561] BUG: KASAN: null-ptr-deref in virtio_gpu_conn_get_modes+0xb4/0x140 [virtio_gpu] [ 168.567565] Read of size 4 at addr 0000000000000054 by task syz/6425 [ 168.567566] [ 168.567571] CPU: 1 PID: 6425 Comm: syz Kdump: loaded Not tainted 4.19.90-vhulk2201.1.0.h1035.kasan.eulerosv2r10.aarch64 #1 [ 168.567573] Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015 [ 168.567575] Call trace: [ 168.567578] dump_backtrace+0x0/0x310 [ 168.567582] show_stack+0x28/0x38 [ 168.567586] dump_stack+0xec/0x15c [ 168.567591] kasan_report+0x244/0x2f0 [ 168.567594] __asan_load4+0x58/0xb0 [ 168.567607] virtio_gpu_conn_get_modes+0xb4/0x140 [virtio_gpu] [ 168.567612] drm_helper_probe_single_connector_modes+0x3a4/0xd80 [ 168.567617] drm_mode_getconnector+0x2e0/0xa70 [ 168.567621] drm_ioctl_kernel+0x11c/0x1d8 [ 168.567624] drm_ioctl+0x558/0x6d0 [ 168.567628] do_vfs_ioctl+0x160/0xf30 [ 168.567632] ksys_ioctl+0x98/0xd8 [ 168.567636] __arm64_sys_ioctl+0x50/0xc8 [ 168.567641] el0_svc_common+0xc8/0x320 [ 168.567645] el0_svc_handler+0xf8/0x160 [ 168.567649] el0_svc+0x10/0x218 Signed-off-by: Liu Zixian Link: http://patchwork.freedesktop.org/patch/msgid/20220322091730.1653-1-liuzixian4@huawei.com Signed-off-by: Gerd Hoffmann Signed-off-by: Sasha Levin --- drivers/gpu/drm/virtio/virtgpu_display.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/virtio/virtgpu_display.c b/drivers/gpu/drm/virtio/virtgpu_display.c index e622485ae826..7e34307eb075 100644 --- a/drivers/gpu/drm/virtio/virtgpu_display.c +++ b/drivers/gpu/drm/virtio/virtgpu_display.c @@ -174,6 +174,8 @@ static int virtio_gpu_conn_get_modes(struct drm_connector *connector) DRM_DEBUG("add mode: %dx%d\n", width, height); mode = drm_cvt_mode(connector->dev, width, height, 60, false, false, false); + if (!mode) + return count; mode->type |= DRM_MODE_TYPE_PREFERRED; drm_mode_probed_add(connector, mode); count++; -- 2.35.1