Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3547707pxb; Mon, 24 Jan 2022 11:57:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJy39eHKxosefew8hJmUTOlsKxY9My1cBYIafSYjtrYV5u5TVQ4YQMpUyeRtoM+Tij7c9dBL X-Received: by 2002:a63:1462:: with SMTP id 34mr12843757pgu.229.1643054257036; Mon, 24 Jan 2022 11:57:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643054257; cv=none; d=google.com; s=arc-20160816; b=x6/b3CQFDfJZe5ehmqujefNJ1R9UUBBb4RwRhzvXKiK67L6o+M56rhH7ImrgeoJUi2 VVoeu7zrWRpwLuJCST1uFuxucf/bMj2HqIwTLAU76VzRPJMP624F/3iB6Cbl3ujwgJxd OKa11ytruBl/bY/wpjgUoGViHyT8UoZrIiRzCF6AqW6wxDCbPQd7xw9FZDBijCxFrRkC /2ePhfLgSpmOC27a4uhvJFEPvQq5OU/8DbypVYYZBX/Np/GBeOhI+VidkzNedtIwg8to vj+P6Dz/08apBzg2o2z4OQr3IuYxiLN0Td/j4M8pOdD0MX1bHDGK8vGyUP5eN127rXPs UCYw== 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=sdgelg9hr5LH0VTB7nFT0r2jG16KCulCC15FxX+Xi8E=; b=0ZEcF1P1YoMyiFvs6rgsO0N98oTqVugpWgYOfzGTkp6pva5c7Gz2xgn/9w5EHHAxi0 LG68/cbdhicpSJzvdkPvZ4MuF+5QHyNVQXqDDyWIB+YAJABwIEnUKF25PLeIo0GLpJDp /kIbO2tf2tbSP7SB5GUjfk0QRzMyVKdLvTqUBkbDuGWNwCOB59Q2qOOE8Gb20RBdl6h6 yVSMlrIba+irevneIKudkMIckCvNFCPcwmAnAtPG62yUfN00X4XJo1lKlao9zTjHzzbN Y549k6mWr9QgBv90xM74jI86NR4nxqVUfQ1K1UEv91fSfodvij1OIKMaYr3cY4BBXGwg w6sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bzVKa3TP; 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 q4si16205987pgj.233.2022.01.24.11.57.23; Mon, 24 Jan 2022 11:57:37 -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=bzVKa3TP; 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 S1344051AbiAXSxP (ORCPT + 99 others); Mon, 24 Jan 2022 13:53:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343718AbiAXSvh (ORCPT ); Mon, 24 Jan 2022 13:51:37 -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 8C4E6C06175A; Mon, 24 Jan 2022 10:51:30 -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 32E9CB8121C; Mon, 24 Jan 2022 18:51:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58DF6C340E5; Mon, 24 Jan 2022 18:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050288; bh=C3A7l53Vz4Z6yLJ0779NqAjKBF2eewvXM/vs65DiBvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bzVKa3TPoRM3Gs2WH0hB/5IrtSFS+rE7clGwlgw0FoUy1sAL/QQn5wvomjGPpNBHF Ig/cbxyuEPWF4CaDfJL6XfxMfVdXqTwP+NFBCYmN1Rg+Z2BxPwkQSFGmcDtAFKG2kD VZj4OAdeuhmwSgmR/NFwAT1ApxoeYIpkgec5DR+4= 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 4.4 070/114] media: saa7146: hexium_gemini: Fix a NULL pointer dereference in hexium_attach() Date: Mon, 24 Jan 2022 19:42:45 +0100 Message-Id: <20220124183929.260020963@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183927.095545464@linuxfoundation.org> References: <20220124183927.095545464@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 df1e8c975cd82..6d0a0b08853b4 100644 --- a/drivers/media/common/saa7146/saa7146_fops.c +++ b/drivers/media/common/saa7146/saa7146_fops.c @@ -524,7 +524,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 343cd75fcd8d1..f09f311a316f5 100644 --- a/drivers/media/pci/saa7146/hexium_gemini.c +++ b/drivers/media/pci/saa7146/hexium_gemini.c @@ -296,7 +296,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