Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3608220pxb; Mon, 24 Jan 2022 13:25:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJyquIyYCZh/SumpfMItYJdFN+qBQWxS9TTlEMmxTtARVNUVDAeIJmIBimGGfwvJ0rf8B+6Q X-Received: by 2002:a17:902:7287:b0:14a:b594:7fa1 with SMTP id d7-20020a170902728700b0014ab5947fa1mr15575558pll.117.1643059509936; Mon, 24 Jan 2022 13:25:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643059509; cv=none; d=google.com; s=arc-20160816; b=GhtvBJYHG0+fRqoNzFfm1lSzkXMZNQIZeO68pZnNieoq0oJ3VTyADtNvLbK3QEHhwM x9PFM03Vum2m4ykOqobwtIIY8uLduA67h2n6WKzqQZcDzRGUIQ2tP0Iftt86UYhFk7BH 7vcizX5hUOwlhbuxVYdXEqMLLPqLkZfRH2GocbNv3hSMHMRuG/4UOG9RGnb6YReTFrAv FBC2JYecHJI0pFW13hOo9SLDiOUTmva540vxRe2d46w7mBUPz8h8U6DbQHah6UXPb0Hb RXmZFm4EbJMymhovayurKSTaGCDH1JSr+3OE/wZVd57ZEe1J3d9uHOSi0rBV96L9ohPc hPiA== 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=22DxtKofNVHhWbauilQFj8CEmHl2oQ46rXxH+jYkg2k=; b=zPlmB3DhBcGgfqhoZ6e439wzUVaAvoi0IynynC28oErehxPWqcsyrZPhApp72Q5KD7 JqQf6VhF5ZtROkdIIq3h9LmhsMXGMDw4/iWwObcz/hVyJ+Nk5JZFcsBr0YNXW5tThPoz jgRn7CeFcnHO1nt3wNqvTwk8Ool5BMc5jKf8VcO+6u9DLPIrMEFDSY3H6BFcBynDEvZg XYM8q6JnGPrC0WePuykkzuzNxwCJPrY0HIu0Ejcb8+bOD2PmScxewZKYiWUtiSnQlxaL Q1WHn1NmG+8VmCW7HuZwqetrJPf0U9gHeHFdGX5O02auDRw4E14MwhJhIieu4n5APd4P w9Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ChPu5Ynj; 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 c10si14441963plg.392.2022.01.24.13.24.58; Mon, 24 Jan 2022 13:25:09 -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=ChPu5Ynj; 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 S1442447AbiAXU66 (ORCPT + 99 others); Mon, 24 Jan 2022 15:58:58 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:39724 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386882AbiAXUgF (ORCPT ); Mon, 24 Jan 2022 15:36:05 -0500 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 9A887B80FA1; Mon, 24 Jan 2022 20:36:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9907C340E5; Mon, 24 Jan 2022 20:36:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056562; bh=JjoTPxcrsm13yYDz2X0aCGOrakWj/cvM4DjQzFBa75A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ChPu5YnjUmHHvGPMNRSiQ1BRcx6DQFxbuh+gUSe1ExHOXjcq5LReOYoyWbQybeNDG 04zp9m103iRmR2iVLnom/JlwNTfB/gexscA8SXN4BPOx2VIAjdMiWd2y1ll54a9AXj 7ouzwuMSiqA7mZqVDSdTY9iGJLjmL4O+wshFY6UQ= 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 5.15 525/846] media: saa7146: hexium_orion: Fix a NULL pointer dereference in hexium_attach() Date: Mon, 24 Jan 2022 19:40:42 +0100 Message-Id: <20220124184119.119583436@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 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