Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3715688pxb; Mon, 24 Jan 2022 16:09:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJxERZ1fUsUmKJ22T/uO7uMD9j3OIL6UhyCozTx7UukK2sw6V5R7TKelVuSYNEM3GZrLi++/ X-Received: by 2002:a17:90a:17c4:: with SMTP id q62mr679406pja.145.1643069368678; Mon, 24 Jan 2022 16:09:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069368; cv=none; d=google.com; s=arc-20160816; b=06M35Bg0W5+HdHRLjWyfpam6JaPkAmh4AJJ9m27R9JerDhSe+BgYrQvGTFBGd8SOGr IeHDKMmZPgpjZO/WqIONnFBLjNOZttPpqxRXeeTS9opcPaTaDTTzXOjAb9JSbpsWmVIs pwG11szT/TfCHI5M1ItxSwgUxVaRjVbWwU4lPsZz0nDeerL3sTaV/WDJJvI08GFpfejZ cjnfhNsSPsegNpgjgOjgL0V63W9aWAx04lDLYM9ktMz7Q4BilgI62CHZMs0u28wGgyPS 97FnkUTZrlG129AaazNLRr3Pz6nzyqKtsqWIBA0tjjUY660lKtq30GJSEFe01cqBMLgg 3W4g== 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=l7AstSU6a3KbIen4Ol9Gz28as8H9eJwHJPzlPI6k5D0=; b=FCldW/GlcfXn/BKa/1pKs+xKbYHf3x07+PaoDWtb/q9XBd6DAfBQ1tAsMAC1EYsAqC NXzMQarPoLvh33C8V8KzjvWZhVHem+oSOtcUrhnTxbByut3K7ZUVCZ9fCRW4lVAH0rRX K+DU6+Y9fOZOPv1qmmoHXxmh8VOxPihlVAfS7U+S3kw1C87JKfQgz9H7h7jEFRFAOR/5 MGFNuYIFrIIwYRPPrs+zuqI7Jn5xiQ21UUBGWEo1SiqrGgz9LzOqU7JkXuZZDFSwZ6Fi wPMT9OXnq1uGuPCH02FwgCoy6m5F8CIzHWMOicyT6m832SdlZ8ZFl8AXi8qaeynjp5w5 3mNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UVpETQ7T; 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 o4si14858657pgb.557.2022.01.24.16.09.16; Mon, 24 Jan 2022 16:09:28 -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=UVpETQ7T; 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 S2371062AbiAYAGx (ORCPT + 99 others); Mon, 24 Jan 2022 19:06:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1847036AbiAXXSV (ORCPT ); Mon, 24 Jan 2022 18:18:21 -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 71479C06F8D8; Mon, 24 Jan 2022 13:26:45 -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 0F89161028; Mon, 24 Jan 2022 21:26:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E102FC340E4; Mon, 24 Jan 2022 21:26:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059604; bh=zzwXETvO8DRgU0B6/KjTgVdtgOFdMCxyOYkTNdKrc3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UVpETQ7TOlpTy252P0a3olzbOPfHP5z9r1eAhd2U9qf3TxGTUQVpG6DNjzpBBifW9 vh+8NI+2+wk2eovqUHOcUCRseHSeQg0hH4lU/U+LXEpcX8O7WCoPeDe7CEuEFyAdhb GWo5ChxIWnYQwtCTJ2i9Y8s8CLDxHdRLOlwXEcmQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhou Qingyang , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.16 0654/1039] media: saa7146: hexium_gemini: Fix a NULL pointer dereference in hexium_attach() Date: Mon, 24 Jan 2022 19:40:43 +0100 Message-Id: <20220124184147.347255773@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 3af86b046933ba513d08399dba0d4d8b50d607d0 ] In hexium_attach(dev, info), saa7146_vv_init() is called to allocate a new memory for dev->vv_data. saa7146_vv_release() will be called on failure of saa7146_register_device(). 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(). 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_GEMINI=m show no new warnings, and our static analyzer no longer warns about this code. Link: https://lore.kernel.org/linux-media/20211203154030.111210-1-zhou1615@umn.edu Signed-off-by: Zhou Qingyang Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/common/saa7146/saa7146_fops.c | 2 +- drivers/media/pci/saa7146/hexium_gemini.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/media/common/saa7146/saa7146_fops.c b/drivers/media/common/saa7146/saa7146_fops.c index baf5772c52a96..be32159777142 100644 --- a/drivers/media/common/saa7146/saa7146_fops.c +++ b/drivers/media/common/saa7146/saa7146_fops.c @@ -521,7 +521,7 @@ int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv) ERR("out of memory. aborting.\n"); kfree(vv); v4l2_ctrl_handler_free(hdl); - return -1; + return -ENOMEM; } saa7146_video_uops.init(dev,vv); diff --git a/drivers/media/pci/saa7146/hexium_gemini.c b/drivers/media/pci/saa7146/hexium_gemini.c index 2214c74bbbf15..3947701cd6c7e 100644 --- a/drivers/media/pci/saa7146/hexium_gemini.c +++ b/drivers/media/pci/saa7146/hexium_gemini.c @@ -284,7 +284,12 @@ static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_d hexium_set_input(hexium, 0); hexium->cur_input = 0; - saa7146_vv_init(dev, &vv_data); + ret = saa7146_vv_init(dev, &vv_data); + if (ret) { + i2c_del_adapter(&hexium->i2c_adapter); + kfree(hexium); + return ret; + } vv_data.vid_ops.vidioc_enum_input = vidioc_enum_input; vv_data.vid_ops.vidioc_g_input = vidioc_g_input; -- 2.34.1