Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1336417pxb; Tue, 26 Oct 2021 07:14:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMwymoxA63v7noTx943fzGikuWgnz2znLw97YvuHzNnrUPi7+6HG9SSBjCtAxSB9Z6nuQA X-Received: by 2002:a17:90b:4d0f:: with SMTP id mw15mr43975340pjb.207.1635257692235; Tue, 26 Oct 2021 07:14:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635257692; cv=none; d=google.com; s=arc-20160816; b=mtt3OIN+AUAe5suN9zyXLbwMh1rA7/MEcy8X8vV+7RAAysw9sDxph8A0puA7XCqTQ2 EKkgO/2nLPMwOq/OS3bvSOMVg9HXfnek1h2tM+BZ/TPA7PnxFGDml+5peog/ac9ucpOI TuPL58wxzEO4aZ9KDDDhx4Feh1BJ36XkTjIYFkl1ao3oe4HItxWEzeODPA2wlaEFjLQi q89jgQ39EgmtlRCK41qDwMgQpbllaibmSR3rc1PRaFZyRw/cu1LrOIReagZ2+XyeRI7Q 6yL0dA4KhDApMPsAd9u2fSDcvnSbc4u+YpAVi9dr7q+lAYbhT3tqFmxhjsBXfF9tCzgK MGEA== 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 :message-id:date:subject:cc:to:from; bh=XfeFBH+14rgKtG5CCeuKrcoIrcNvLDZlr49eiVxM1rc=; b=BncXUOSddoB3AADjo/nrRNJuiV5N4A87Li3a5g6kNNK3HuOtyNgpkCdWp2jgc9R53d ImiwgJgYdkUb7AatG4BMLyVUQ5CDD64dSp6Q1EZZhjZ9jzxKZgSMk+afFF7m1+TITlEE G5ATOKtmom6z+AbPc2n7kNCUhMYTvONvCxZTPlVPX9dHZLXcP9ZMqrnZfdZZ26JPKFMz 12UKrQf0R7rEaljVKZHVhnIeDESzWG1O0AWdlzQc1KaOSiO65RNGz6HXUXNrL84KHfqi HukqOD4Zf3Znhw0QuMiJsWudHCifwHxGY5mFB78gKR6gWUReNNkqcZrN80KIlGvhLb3W pWlQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d23si27058018pgv.55.2021.10.26.07.14.36; Tue, 26 Oct 2021 07:14:52 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235354AbhJZLIQ (ORCPT + 99 others); Tue, 26 Oct 2021 07:08:16 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:26122 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235369AbhJZLIP (ORCPT ); Tue, 26 Oct 2021 07:08:15 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Hdppz16rbz1DHfs; Tue, 26 Oct 2021 19:03:55 +0800 (CST) Received: from kwepemm600001.china.huawei.com (7.193.23.3) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Tue, 26 Oct 2021 19:05:49 +0800 Received: from huawei.com (10.175.104.82) by kwepemm600001.china.huawei.com (7.193.23.3) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Tue, 26 Oct 2021 19:05:48 +0800 From: Wang Hai To: , , CC: , Subject: [PATCH] msi001: fix possible null-ptr-deref in msi001_probe() Date: Tue, 26 Oct 2021 19:23:48 +0800 Message-ID: <20211026112348.2878040-1-wanghai38@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600001.china.huawei.com (7.193.23.3) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I got a null-ptr-deref report: BUG: kernel NULL pointer dereference, address: 0000000000000060 ... RIP: 0010:v4l2_ctrl_auto_cluster+0x57/0x270 ... Call Trace: msi001_probe+0x13b/0x24b [msi001] spi_probe+0xeb/0x130 ... do_syscall_64+0x35/0xb0 In msi001_probe(), if the creation of control for bandwidth_auto fails, there will be a null-ptr-deref issue when it is used in v4l2_ctrl_auto_cluster(). Check dev->hdl.error before v4l2_ctrl_auto_cluster() to fix this bug. Fixes: 93203dd6c7c4 ("[media] msi001: Mirics MSi001 silicon tuner driver") Reported-by: Hulk Robot Signed-off-by: Wang Hai --- drivers/media/tuners/msi001.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/media/tuners/msi001.c b/drivers/media/tuners/msi001.c index 78e6fd600d8e..44247049a319 100644 --- a/drivers/media/tuners/msi001.c +++ b/drivers/media/tuners/msi001.c @@ -442,6 +442,13 @@ static int msi001_probe(struct spi_device *spi) V4L2_CID_RF_TUNER_BANDWIDTH_AUTO, 0, 1, 1, 1); dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, &msi001_ctrl_ops, V4L2_CID_RF_TUNER_BANDWIDTH, 200000, 8000000, 1, 200000); + if (dev->hdl.error) { + ret = dev->hdl.error; + dev_err(&spi->dev, "Could not initialize controls\n"); + /* control init failed, free handler */ + goto err_ctrl_handler_free; + } + v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false); dev->lna_gain = v4l2_ctrl_new_std(&dev->hdl, &msi001_ctrl_ops, V4L2_CID_RF_TUNER_LNA_GAIN, 0, 1, 1, 1); -- 2.25.1