Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3389385pxb; Mon, 17 Jan 2022 19:23:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxeKM29PMwtuT6SZb+t3bdvfVSf6z1uicMxNIeN4fRsY2e6pLuJtmaxbPvZfgASD2UqAe+N X-Received: by 2002:a17:902:8b8b:b0:149:66d6:b034 with SMTP id ay11-20020a1709028b8b00b0014966d6b034mr25256412plb.129.1642476200542; Mon, 17 Jan 2022 19:23:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642476200; cv=none; d=google.com; s=arc-20160816; b=yIbjFhMZi4cvBCwjLpJGvPWNwhFu0yrc0U9xLEA0TxVSDm/D4cn5gfXiPgIXtlh/Od yK5ihoFuP8vygUmA/In8zTT8FlVA1BpfWsyfwvHI4I/MKp74tavLlTY0h8SU8TGEeNlb NeabeyiVaH8I1uH50EgSjbHkk6EN0oJE9AmQFRR+lefHQ67Z9+ju/zqz1xIejHt1FpAL /gZe+IHOde6813VP2S2/l20zaNrnVTNu2zXcre+Xwh80xhp0fjeCr4f2JbeJstX6u3Dw SUy9eavjrsNYrhjh+wCUHMuttWfpROUkuZ8Xnt6NPUWU4Jfpl5OAV96jh5gSrjHrxXTO F9Vw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=22DxtKofNVHhWbauilQFj8CEmHl2oQ46rXxH+jYkg2k=; b=zCYKtrvde4rIDEkbgTf31EHnwTBJnzsIvYBwlEmPTMrIXxW05669dvbzq1fPe4J3mW E9RrYV+nqMOHjhp++GXYoRWh89FSqr/2eq56WC1uKzTTzU2sa5hh111zkNOESZQC6yaa 9rRn51zTbYN24mP+qQVsbb26QUDy0bHRADB7cdTA+Vm99oAAl0aU1PG3j1O202r2U7m4 jpLtWVUeALlYzUN7klsTaUqQAutjq/RKKeukTzMr+ZcU7Mdmohwirz6NeiKn+zViimuF 0QZjYcBDiEBHL4QTNEXMUOKnMHiqZuuHQE322UVVUKHjQABfCn9uyUIP6WDEbRpRPx9b 50qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qENeY61f; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si5199185pge.819.2022.01.17.19.23.09; Mon, 17 Jan 2022 19:23:20 -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=@kernel.org header.s=k20201202 header.b=qENeY61f; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345876AbiARCcI (ORCPT + 99 others); Mon, 17 Jan 2022 21:32:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245101AbiARC0P (ORCPT ); Mon, 17 Jan 2022 21:26:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AA22C06136A; Mon, 17 Jan 2022 18:24:46 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 1B201610AB; Tue, 18 Jan 2022 02:24:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89E3DC36AF5; Tue, 18 Jan 2022 02:24:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642472685; bh=JjoTPxcrsm13yYDz2X0aCGOrakWj/cvM4DjQzFBa75A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qENeY61fHWgB76s7sAo7GLnyzm0oQtXGKOPCRSAAlrVp8WbRUa44v8Z1oKWN8+OJ9 XTHhWQc6PyP/qixHuo29VbgplPyxSljEqKZ5rEARBan5FiT2nLUURFOFGcIiyIUiO3 BdXuOsqtisg+g8cu3XJxdYsqbyY8ue1YE0KitLipvhIn7Lv+a5/cWrELL95vPccAnp j/XwO7T00OuDhcGLQKwte9/FeTtD2WFKDwIsqY6Xm03rMdhM0tihI1IVWmhLxqJsEQ 1a2rxF8cFDYKuPhdobFJZyuu0AYZijUnFKADYYOKp27QnWLRhomQwHLPcH4Zk8qvH8 pdKOx4BgfnWjQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhou Qingyang , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , hverkuil@xs4all.nl, mchehab@kernel.org, linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.16 099/217] media: saa7146: hexium_orion: Fix a NULL pointer dereference in hexium_attach() Date: Mon, 17 Jan 2022 21:17:42 -0500 Message-Id: <20220118021940.1942199-99-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220118021940.1942199-1-sashal@kernel.org> References: <20220118021940.1942199-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhou Qingyang [ Upstream commit 348df8035301dd212e3cc2860efe4c86cb0d3303 ] In hexium_attach(dev, info), saa7146_vv_init() is called to allocate a new memory for dev->vv_data. In hexium_detach(), saa7146_vv_release() will be called and there is a dereference of dev->vv_data in saa7146_vv_release(), which could lead to a NULL pointer dereference on failure of saa7146_vv_init() according to the following logic. Both hexium_attach() and hexium_detach() are callback functions of the variable 'extension', so there exists a possible call chain directly from hexium_attach() to hexium_detach(): hexium_attach(dev, info) -- fail to alloc memory to dev->vv_data | in saa7146_vv_init(). | | hexium_detach() -- a dereference of dev->vv_data in saa7146_vv_release() Fix this bug by adding a check of saa7146_vv_init(). This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs. Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug. Builds with CONFIG_VIDEO_HEXIUM_ORION=m show no new warnings, and our static analyzer no longer warns about this code. Signed-off-by: Zhou Qingyang Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/pci/saa7146/hexium_orion.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/media/pci/saa7146/hexium_orion.c b/drivers/media/pci/saa7146/hexium_orion.c index 39d14c179d229..2eb4bee16b71f 100644 --- a/drivers/media/pci/saa7146/hexium_orion.c +++ b/drivers/media/pci/saa7146/hexium_orion.c @@ -355,10 +355,16 @@ static struct saa7146_ext_vv vv_data; static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info) { struct hexium *hexium = (struct hexium *) dev->ext_priv; + int ret; DEB_EE("\n"); - saa7146_vv_init(dev, &vv_data); + ret = saa7146_vv_init(dev, &vv_data); + if (ret) { + pr_err("Error in saa7146_vv_init()\n"); + return ret; + } + vv_data.vid_ops.vidioc_enum_input = vidioc_enum_input; vv_data.vid_ops.vidioc_g_input = vidioc_g_input; vv_data.vid_ops.vidioc_s_input = vidioc_s_input; -- 2.34.1