Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp668322rdg; Thu, 12 Oct 2023 18:21:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAK/WADbar7lM2Yo62HYpn+kV55ao8O92C5AO5vYYu89kK6rPIItKMwjzrgzLNHTRThKOW X-Received: by 2002:a17:90b:238d:b0:27d:6dd:fb7e with SMTP id mr13-20020a17090b238d00b0027d06ddfb7emr6001139pjb.17.1697160061750; Thu, 12 Oct 2023 18:21:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697160061; cv=none; d=google.com; s=arc-20160816; b=huuGWeX+7PKPNEDfNcjVraItI4k3voX55YsGuWtNnd3nBO/wpYEvgoH+X4/ez6AISQ mfUVvi+qdV4Dqcr7I2nYPCPtgvax+8zBM6k1ne56dOvOb/7mT9kqY/ds08ctjXys5uVu xIqf1eUKehz+Ee/+c6DxSBzxTvhvF5ikyMpTOnJAc4lRCv03BVKJ/UVqT9xBcSs+EOSQ S+6/JkSjQHzRuQq/pdeusyrm+Nh+Z7YrXxSX1+pjTuGc5Z3tX8fAY8lF4/KB6lnT3xc8 shS2poeCJoheHMbGt6CVBfnqX+fWvejQp/MNXXiKL+gJl8JYOocctSvsjXB/7BGY8eUW 5w3A== 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=aLj4BqY2YBYcmIcxL988YnyhrGGYNyKmp6Yo5wsu3R0=; fh=R3IxxdXDbndDYupQYm+0YV7s8Ntq9c4go2WHv1sg4tg=; b=CieDe5v/KamoDPFLx3QtKW34jwFnjgQdEPS0qxYhUqIJ3ZnXQfcH7acpnR/O2EW67W mfpAbTcwmj7MOx3mjCkvI3cahkmE4zj8W4qiSEu/Yf3zpXH5ClK0PNcKrojj0xrFYTvK R5xPLFXxGSuRmaAsO9EIMl3ZF0wNDyMIHGiyS/R9HSKD8ZdYJv89m0tkugX6aVkF9FUv WOBCtjdzYUGHvvkmerK1NORZz8VNb/N/6A6bntjFKfg+1/5FSnTM11aOkoJ6HgojDTYJ op303nnqiP/QJ5IJBrIec2xFnf3Jt1VYG1+HfQhfeQVXVp5HHMie6USeTYXbva6xj2dt cffQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=k02fwX3v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id oa10-20020a17090b1bca00b00268e32e99f0si3882460pjb.28.2023.10.12.18.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 18:21:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=k02fwX3v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 498D7802A3F4; Thu, 12 Oct 2023 18:20:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229453AbjJMBUt (ORCPT + 99 others); Thu, 12 Oct 2023 21:20:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjJMBUs (ORCPT ); Thu, 12 Oct 2023 21:20:48 -0400 Received: from m15.mail.163.com (m15.mail.163.com [45.254.50.220]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9EB9BA9 for ; Thu, 12 Oct 2023 18:20:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=aLj4B qY2YBYcmIcxL988YnyhrGGYNyKmp6Yo5wsu3R0=; b=k02fwX3vSjsWETELM6crX ZMmYLuGEkbZoN087Yix4cq1B3lVzOf6oKzAwgmnFEMRyMDfYZGkXf4Lkhac1HCg6 sx9Yu7j6d1TbC1MGVYpwIGXgHA0Iq3CUKQuVEt79MjG4fdj6AZkwCy7oO5rg7Wpo tpOWdUA70P26mGaC5Od4ZM= Received: from icess-ProLiant-DL380-Gen10.. (unknown [183.174.60.14]) by zwqz-smtp-mta-g2-0 (Coremail) with SMTP id _____wD3_1P7mihlaruYAQ--.37582S4; Fri, 13 Oct 2023 09:18:59 +0800 (CST) From: Ma Ke To: kherbst@redhat.com, lyude@redhat.com, dakr@redhat.com, airlied@gmail.com, daniel@ffwll.ch, tzimmermann@suse.de, noralf@tronnes.org, mripard@kernel.org, jani.nikula@intel.com, make_ruc2021@163.com Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/nouveau/dispnv04: fix a possible null pointer dereference Date: Fri, 13 Oct 2023 09:18:50 +0800 Message-Id: <20231013011850.103967-1-make_ruc2021@163.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wD3_1P7mihlaruYAQ--.37582S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7JrykAryftw43ur1ruF17Jrb_yoW8JF1fpF 4xGFyYvr1DJFykKa40y3WDWFWY9a1kKFWvkw1ak39I93Z0yr1qqryDAr98Wry7JFW5GFy3 trn3Ja4qgr18Zr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziTGQkUUUUU= X-Originating-IP: [183.174.60.14] X-CM-SenderInfo: 5pdnvshuxfjiisr6il2tof0z/xtbBFQIHC2B9oe1JLgAGsr X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 12 Oct 2023 18:20:59 -0700 (PDT) In nv17_tv_get_hd_modes(), the return value of drm_mode_duplicate() is assigned to mode, which will lead to a NULL pointer dereference on failure of drm_mode_duplicate(). The same applies to drm_cvt_mode(). Add a check to avoid null pointer dereference. Signed-off-by: Ma Ke --- drivers/gpu/drm/nouveau/dispnv04/tvnv17.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c b/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c index 670c9739e5e1..9c3dc9a5bb46 100644 --- a/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c +++ b/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c @@ -258,6 +258,8 @@ static int nv17_tv_get_hd_modes(struct drm_encoder *encoder, if (modes[i].hdisplay == output_mode->hdisplay && modes[i].vdisplay == output_mode->vdisplay) { mode = drm_mode_duplicate(encoder->dev, output_mode); + if (!mode) + continue; mode->type |= DRM_MODE_TYPE_PREFERRED; } else { @@ -265,6 +267,8 @@ static int nv17_tv_get_hd_modes(struct drm_encoder *encoder, modes[i].vdisplay, 60, false, (output_mode->flags & DRM_MODE_FLAG_INTERLACE), false); + if (!mode) + continue; } /* CVT modes are sometimes unsuitable... */ -- 2.37.2