Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3558530pxb; Mon, 24 Jan 2022 12:11:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYfQJQVf3M55ZmTCXpxbVz7CRqNTRSNtYwn8fKZKtK5Eu966ftMmwndJbKZg69hwC4GVRb X-Received: by 2002:a17:903:22d1:b0:14b:3bbd:82df with SMTP id y17-20020a17090322d100b0014b3bbd82dfmr9202229plg.101.1643055093211; Mon, 24 Jan 2022 12:11:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055093; cv=none; d=google.com; s=arc-20160816; b=H0fLyhrHqYxHd1NslAbTIhd42hZSF6hk08ODO/7UiXI1vncTxn2kxnuR4kZXrCfotk L5KVU5EraG21apa69cKoEgdayDf0dRFMUee0MGrGukTNtROTY66caWoZTgXTuJujY5+h HUSnl5lx+kwMDLewdCdXeQ4v23bKZi8ZWhuSn6GLSlS6Mmg5mkwL0+NABi63bHSyEBJC yVShDBE21z2/ym/39KkAR6Vwm2paovcpYUsuzX9XJEqPgD4wd8WkEq8MsjKwTgWFZH2R 6Le7xyvgO+NpOyd/ut+lFP1cTuK49YvmT2KkxhijXgLoOZjZKUnXwhxKhJ31gRgs1PSx 2Vwg== 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=GI1vf0lT6NqUlydGmsOuohRjQ+8LbwhxpYurgIgVECU=; b=uN+9Cr2OK8NptvhLLy+ZiNVAjTkcoQga0A8zjbRlDeCEcu+YGpEFmQQ23d7BmDDAKm vMO2sh5hu2DpE9OUj+4zXiYNhJkyYriEnXzHKQLrAmbCaoKt2hI3UrZWnBlJB1zN1EAL xOl0/Lw3Cp3nRF3fqGgzcdvOTXCyIkMAw+oMz3djQRJln1+/5rnXQq9clXxWW3crwjct v/a3t7mTe/KP2k03banDSy8BYhrY9a2B8PMhU2aoB1sDHRZJ8Jns0toyBiYOTwE3yS7Y lhSa/JlH5GfKOVn3tijE1+l40scTxays/4Vc6EYXt/sdjFSXppUFISzXthQlNHG5Vk6g fULg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h7cS6OJ7; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y15si13731961plr.199.2022.01.24.12.11.20; Mon, 24 Jan 2022 12:11:33 -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=@linuxfoundation.org header.s=korg header.b=h7cS6OJ7; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245474AbiAXTNo (ORCPT + 99 others); Mon, 24 Jan 2022 14:13:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346214AbiAXTFN (ORCPT ); Mon, 24 Jan 2022 14:05:13 -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 2FBA4C06173B; Mon, 24 Jan 2022 11:00:05 -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 C1B1560918; Mon, 24 Jan 2022 19:00:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81F59C340E5; Mon, 24 Jan 2022 19:00:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050804; bh=nwxvpnCJGN3d5gfMZI1cygkOOdHF9MuMEb7fCRve4OY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h7cS6OJ7W7Vgo4GsjdywLfWj7qcXhyDJT8gXCqzHGG87bshikP/fur47OBFe0VCPx akY1e3oX42GJJdqfF+sDtAp6X5ld8YXoQK0QVTwHdorQEl8o5oJ/Fttbmp8FsqaWKL Qb6yqt4egG3cCznNtKFp/91Ym1nglEtxYqjabs6A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhou Qingyang , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.9 084/157] media: saa7146: hexium_orion: Fix a NULL pointer dereference in hexium_attach() Date: Mon, 24 Jan 2022 19:42:54 +0100 Message-Id: <20220124183935.454758172@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183932.787526760@linuxfoundation.org> References: <20220124183932.787526760@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 dc07ca37ebd06..e8e96c7a57844 100644 --- a/drivers/media/pci/saa7146/hexium_orion.c +++ b/drivers/media/pci/saa7146/hexium_orion.c @@ -366,10 +366,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