Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2321727rdb; Fri, 8 Dec 2023 05:06:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQ4mHMaRHbgs2spJPBlNHH2OncXEWXcS+YmjJuV51+kWJdy2lpRlWRtnkFDGRflhHzhR78 X-Received: by 2002:a17:902:c64c:b0:1d0:89b7:c1a4 with SMTP id s12-20020a170902c64c00b001d089b7c1a4mr2952899pls.92.1702040782588; Fri, 08 Dec 2023 05:06:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702040782; cv=none; d=google.com; s=arc-20160816; b=bTEM2JepVIN0C1A5ZEcuQejSfp0a3lMEjnrsHLXbXcXd+sAHVLXbjrsCDEKarOOXWZ 2PmcwcZ98YxyI7Vu9yc8MTYBFWL0kGZ8P8V2PrmWTHNNTiJkGGXGEuvKwbkNp4K+mA9i qbwbxIDeCfcWyI8SN/A/dR0HpZKZWB5Q1/aP/Qm+iCzLJxHR1Ys2+3B3cV/D9wr5IAg0 VsxJEfxaHjCBWNENvXn8fVfap3L4SGjWw17tj1HzaFaIPC/kQV79P6gyXPzRKZ26X/IJ 64UtazZc7E7pxTwGZFpOULFbiu7bKYrnfR4owPcmyslGgO74RDAmQbwBtqDs0dDypMdJ a6vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :organization:in-reply-to:subject:cc:to:from:dkim-signature; bh=v6fZA3CooFkj0AaHDPe10Kw+LrjCggozFuxZC4UNFBM=; fh=YqxUmYHS4YUX7WGIBnSl1d2uOg+dHG3jQM7jiOPFsMM=; b=ZYjCxwUIFUvKDyp5bYbb4Kt02X8q2ikxAUOssmDVqHoNEtji4LsCUN1bXwvZ+v1FAh Y+np3/326HWjR8BiVycsZHrVCjTp41xSnKIX+4YLjr6b7K/sflnQedThK/vFZ2HsnM9v pyLpEgCHz4pLdqq1iqptxhSey/BCPmDS/NRFh7C9aJALfJATGI3fuukSsX0/Dytx6UEZ 7dCIliDcGGN2zuT2dVwtuB+ntdE+jvMHU56/u8piUuAoMiY0LSKek4Szv5TqVWlyflNO O/o99QukU8QlGfORebitEO56KT/RBmYqMlAB78WRFETHipxFl6S6zpFA2oM+TPk4kbVa ncUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=h0kZxPLR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l12-20020a170902d34c00b001c566ea86eesi1566145plk.177.2023.12.08.05.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 05:06:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=h0kZxPLR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 946BD8184535; Fri, 8 Dec 2023 05:06:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233578AbjLHNFq (ORCPT + 99 others); Fri, 8 Dec 2023 08:05:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573773AbjLHNFn (ORCPT ); Fri, 8 Dec 2023 08:05:43 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D67E9171F; Fri, 8 Dec 2023 05:05:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702040750; x=1733576750; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=QnOL0HstChe82dZJLaFn2ppbg9Lg6p6vs8wKcJ3EoZU=; b=h0kZxPLRvfEdQj2JMxHfOraKbH6V0kN9Nea7K2XxBuYsS5YuCADNe1FO s6Iv842c2fd48a4TRysGMmUE1gRUGFE8o5iRjiir5VBWYbB+1Xx6lKIGB FIVS7WhNms3MRIgAVJN7aV5DrQamrGyAtwQdGxgX7XnNtxNSF4O01uUNG eXsgIPec3c9bx94WCKM+uZoxKjtsYNENpy1ritc7X7XV1gmxD0jO5eOAv 34OvIZepWndgy2XUyfwMsNNqE8Vr4Sx6csseybTL0xqxZdTuijUvCJHDO 3owq8eHM7de1EhpFScMIasLZcPe9DMvCPgUqXzPichpJ3f1529fzTrhYO Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="15954734" X-IronPort-AV: E=Sophos;i="6.04,260,1695711600"; d="scan'208";a="15954734" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2023 05:05:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="721861244" X-IronPort-AV: E=Sophos;i="6.04,260,1695711600"; d="scan'208";a="721861244" Received: from mvafin-mobl2.ger.corp.intel.com (HELO localhost) ([10.252.63.236]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2023 05:05:43 -0800 From: Jani Nikula To: Ziqi Zhao , astrajoan@yahoo.com, airlied@gmail.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, ivan.orlov0322@gmail.com, maarten.lankhorst@linux.intel.com, mripard@kernel.org, skhan@linuxfoundation.org, tzimmermann@suse.de Cc: syzkaller-bugs@googlegroups.com, linux-kernel@vger.kernel.org, christian.koenig@amd.com, linaro-mm-sig@lists.linaro.org, glider@google.com, syzbot+4fad2e57beb6397ab2fc@syzkaller.appspotmail.com, sumit.semwal@linaro.org, linux-media@vger.kernel.org Subject: Re: [PATCH] drm/crtc: Fix uninit-value bug in drm_mode_setcrtc In-Reply-To: <20230721161446.8602-1-astrajoan@yahoo.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20230716043411.4950-1-astrajoan@yahoo.com> <20230721161446.8602-1-astrajoan@yahoo.com> Date: Fri, 08 Dec 2023 15:05:40 +0200 Message-ID: <87h6kszvx7.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 08 Dec 2023 05:06:13 -0800 (PST) On Fri, 21 Jul 2023, Ziqi Zhao wrote: > The connector_set contains uninitialized values when allocated with > kmalloc_array. However, in the "out" branch, the logic assumes that any > element in connector_set would be equal to NULL if failed to > initialize, which causes the bug reported by Syzbot. The fix is to use > an extra variable to keep track of how many connectors are initialized > indeed, and use that variable to decrease any refcounts in the "out" > branch. From one uninit-value bug to another? > > Reported-by: syzbot+4fad2e57beb6397ab2fc@syzkaller.appspotmail.com > Signed-off-by: Ziqi Zhao > --- > drivers/gpu/drm/drm_crtc.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c > index df9bf3c9206e..d718c17ab1e9 100644 > --- a/drivers/gpu/drm/drm_crtc.c > +++ b/drivers/gpu/drm/drm_crtc.c > @@ -715,8 +715,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, > struct drm_mode_set set; > uint32_t __user *set_connectors_ptr; > struct drm_modeset_acquire_ctx ctx; > - int ret; > - int i; > + int ret, i, num_connectors; num_connectors is uninitialized. > > if (!drm_core_check_feature(dev, DRIVER_MODESET)) > return -EOPNOTSUPP; > @@ -851,6 +850,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, > goto out; > } > > + num_connectors = 0; num_connectors is initialized only if crtc_req->count_connectors > 0. > for (i = 0; i < crtc_req->count_connectors; i++) { > connector_set[i] = NULL; > set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr; > @@ -871,6 +871,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, > connector->name); > > connector_set[i] = connector; > + num_connectors++; > } > } > > @@ -879,7 +880,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, > set.y = crtc_req->y; > set.mode = mode; > set.connectors = connector_set; > - set.num_connectors = crtc_req->count_connectors; > + set.num_connectors = num_connectors; num_connectors is used uninitialized if crtc_req->count_connectors <= 0. BR, Jani. > set.fb = fb; > > if (drm_drv_uses_atomic_modeset(dev)) > @@ -892,7 +893,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, > drm_framebuffer_put(fb); > > if (connector_set) { > - for (i = 0; i < crtc_req->count_connectors; i++) { > + for (i = 0; i < num_connectors; i++) { > if (connector_set[i]) > drm_connector_put(connector_set[i]); > } -- Jani Nikula, Intel