Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3822288ioo; Mon, 30 May 2022 10:22:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdKIf53tweays5jccJaAFLkmzSPk4pAU7j/gYi2fWvWb2+xfQObVEPWLjKou2ZjKi9QN66 X-Received: by 2002:a17:907:7291:b0:6f9:a3b5:7ce4 with SMTP id dt17-20020a170907729100b006f9a3b57ce4mr50735593ejc.642.1653931341308; Mon, 30 May 2022 10:22:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653931341; cv=none; d=google.com; s=arc-20160816; b=pj9FjsfhTkluIxrh1GQ/FN3jVzZt4jZKZW27kUsM5INcLVAdkr4FCpQHyHLGdfobzR JDBACUOEXllgWpT54InqTRxFEwWOhUOKPakb3bu9fi0DNp3WjkCFhzKVguQqso58yYxp 1iI1NY4xyVRXSJx05el2dREMPw/HoQF7IOVuRIYaVyZETgPLFnPBg47NXNEkELBIMGzu Qt5PdgcUmBHqSvi7Ajq803PSj2D8FEvtH7Jwn0YHcp17WbIBLcqhEFzIlL2PeC/XfPVR 0xNlWxge/Oz41XLGEOIslQBVdji+CGPpskaVYHZLetBF1YV0UCndliG7gwgThSqzDwjC ZvlQ== 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=PfAi3efrs7RZ8Jx4xmgz3iQ31QTJjjLkD6Jm09CY9K0=; b=hlkRg62R4QgGQgEJLcOC2cLr3sd0SAS0vtk9dKhT2UmIajTRglSQHfhimTPIpIC5SR wp+PhYOkI71fvHGanzQJrNtEfkGK1+v8OxJuAFDIeWK6Z99jfx1oH/WbtCryMgCQkGod 5f5sUs1CL2hIZixWBR9R3gqhtrcImgtifIs/i//3MFG7gzgJuiQYlIkYmix4iBmR1WJc cMH7aGVGIAEnKeEN1XMlY4U859hcKOpsGN5Skq8mZf+M/1RNR/EucaMXEGINB6EnZCpT G+mmM6DFXZlqcDAjz1qqL5T4m8Gmro36key8boMdTZVAPdYRynYYuvtA39VddVzJiI98 /XyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ARTSGrvw; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mu31-20020a1709068a9f00b006df79ec22fdsi10190538ejc.567.2022.05.30.10.21.54; Mon, 30 May 2022 10:22:21 -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=@kernel.org header.s=k20201202 header.b=ARTSGrvw; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237255AbiE3OuE (ORCPT + 99 others); Mon, 30 May 2022 10:50:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241636AbiE3Oae (ORCPT ); Mon, 30 May 2022 10:30:34 -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 4265C5D5DA; Mon, 30 May 2022 06:52:17 -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 E539FB80ABD; Mon, 30 May 2022 13:52:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99750C385B8; Mon, 30 May 2022 13:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653918734; bh=+Zw83mbhprbhnSOioWOEg4ncO5kSDXaueMFhlxbMSE8=; h=From:To:Cc:Subject:Date:From; b=ARTSGrvwGtjiVxnP0jamSJ3cct60LgvkH+Hw644OTE62YGmG3JUVn/KjELRKx1/kn je0678pgrXWER48aEFWicZDdEyevR/hGldlO01CDkQXqJ4AKdht5d3bPX086FuuaO8 PPvXJ7NCofGLaagu0ULq4nzUu7V6Mg8vbDZ2Vw5Y/qgrE1DzLRK1I6AmidbqrGJ94m 0tbcfEPvM+hQ8MWabUx9cygxqEHYJXqC4xw6LyMh+Pm7Cx9RAJr14VFjUEbHuoxo3W RWXzkq2V4c0N9WbmTZsJIrAIHJBVi86nFBOdcYuFc80XUgt9Wh0UgRd1SlnpJzpjJr zHrJyOGjARGDg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Liu Zixian , Gerd Hoffmann , Sasha Levin , airlied@linux.ie, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Subject: [PATCH AUTOSEL 4.9 01/24] drm/virtio: fix NULL pointer dereference in virtio_gpu_conn_get_modes Date: Mon, 30 May 2022 09:51:48 -0400 Message-Id: <20220530135211.1937674-1-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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 58048709c34e..1e528f13959d 100644 --- a/drivers/gpu/drm/virtio/virtgpu_display.c +++ b/drivers/gpu/drm/virtio/virtgpu_display.c @@ -184,6 +184,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