Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3624792pxb; Mon, 24 Jan 2022 13:48:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFk+gKwYw2yP7RwCjzZIPEf8dK7l9N0n1Repzqak/9YJd3b6z2FaMJuD8DvRtSvmZJYqS1 X-Received: by 2002:a17:90a:f413:: with SMTP id ch19mr252254pjb.19.1643060781639; Mon, 24 Jan 2022 13:46:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643060781; cv=none; d=google.com; s=arc-20160816; b=YuoorPPp6dSTgHaZJM0T7BBp1AImVdQ1rdXQrOzttXSZgpWeXQ5jFEvb+gaJrlEzdz OVl3UTNf4jXh8hn4AAJZu3Jc9esuUFddCSSFK3Op6bJitsSGLze6bUDrk9d33xJEDeDl IC817i5M7pLh/vznGZCGjmqM1YALSwhfkkh8QD6RAlh+gUai6lNCPfyQs8sisanCYFh7 M8g2kMwDmCFv0z1f3qD4vzrv+Xp/S6xnVcpRyWAe2+//U6aeOMnvSbItipfMseKnHRo/ mpTYpOSSBgM7UCHlG9npUp13gZyKeN78gvVUib3/OQNorsdmQ+FSHVfEs/mOcyVYtLbV nptg== 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=QHBAHIg0xk6fgm6NcpOGyax15C5Sh0pUZqvjC1AJs3+k2ULuJNtfcOZT5F4YGZm8Zv ZVVyipg3Pdmb3XREkXBKmliTwtHA3gb2RnhpmxoLrY/eBhZ6gZCNwO6OZNqLiCmpE99i T78YD10E4iNdbQ5kdZJql3Pl8rNVihx09OHXK/7iRu5QUN0eFhh2f8bJc5munaAiTBK1 7IUlgAW/rvJABxzgSoSK75LVH8r5dQLI4YOpbEKUnQvMqlUqp6I9XeTCKITnkBy4Zebu TxQiBuQ74wm+IcKc2uJ8ub5J2gdDDLrzDtMV1Wf/B2CGih0u2c406DKh1Q3Ax+ixuUp9 /N1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uEvl33PG; 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 e36si13785589pge.147.2022.01.24.13.46.09; Mon, 24 Jan 2022 13:46:21 -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=uEvl33PG; 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 S1450318AbiAXVUP (ORCPT + 99 others); Mon, 24 Jan 2022 16:20:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1392365AbiAXUvE (ORCPT ); Mon, 24 Jan 2022 15:51:04 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98AFBC054325; Mon, 24 Jan 2022 11:58:24 -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 ams.source.kernel.org (Postfix) with ESMTPS id 577B5B8119D; Mon, 24 Jan 2022 19:58:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AD0BC340E5; Mon, 24 Jan 2022 19:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643054302; bh=JjoTPxcrsm13yYDz2X0aCGOrakWj/cvM4DjQzFBa75A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uEvl33PG4PPhjxI0aEAMSxO9ikEBrIAAZuf3SNDRDbIh9df/u5cbxO3NYbiN24y6s zjic6cIYomUy+OTLpXJPA4R/5jk4YUEHeSyGGJIpqt2UkMF/y9iWss0cqEPDLuQ1rE bUyCoKwojDCLiifVYZ+Zm6rotJzy7fPsJAWEWceQ= 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.10 344/563] media: saa7146: hexium_orion: Fix a NULL pointer dereference in hexium_attach() Date: Mon, 24 Jan 2022 19:41:49 +0100 Message-Id: <20220124184036.320287570@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184024.407936072@linuxfoundation.org> References: <20220124184024.407936072@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