Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp598432iog; Mon, 13 Jun 2022 08:52:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFXv3GFcAbe5vOl2JQEvAMViR8tY+i7UypCpDyk2g7Suzx+Iub4gruugEi6bpMTjJrxipv X-Received: by 2002:a17:906:77d1:b0:713:cc5e:e908 with SMTP id m17-20020a17090677d100b00713cc5ee908mr460279ejn.254.1655135560164; Mon, 13 Jun 2022 08:52:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655135560; cv=none; d=google.com; s=arc-20160816; b=uUdDWDKplrw/bTc/otrSJI3+QxHYTMPWNVy0GKGQM2916XdxtTt7JkhK7xNyROsBWV 7RzCdywTkyAZqfJ5a9wNEQ18rlikcacRpDuqhO/oyPLBFCOlsTRPUoJ8pUHQLi6F+RgP zeiBD2+U0+xELSmuCCdmVow4AQ1wLdXLvFmD0EPAYYE+O/yKpPiYriCzvSjYB5ync68q xLcBZ84ChjPU8+fHkvUmxwr8iDyfHIM/aVTU9KRNuMt6YsA0wmCemc1CElKe+jTAtgUI N1UlVrO0xz6K/T829CoT8x+8Sog96z+ZHvtXZeALsc7GFk/YLHZwR3oy4EwzSr2beINk Jqhw== 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=dsIUeBiFmsJjLi75sJywmGCewhDhAgLq4W9707yfjNI=; b=it7BToqX4QLPhaC0x06/OsOsdk8u6nE5dvoTPjdnw1NJ50VuFJ91oZAKJV0PokyHE4 rPeIuu0aTN4nEh2R0+MoN6XkA2PCZaMZ+FM4yJ6tSUuLdZg2ghwHefJCIWzCi8G5EUHI dt1MzwTFhXNAs8YMDmGhMY5jx22/UsSKUX6q5tzE3FLepl5qyssI0uULXgSfkmjVD0Jj 1MWtAx1w3J4cqbMrkHyVI9Ki+eiF8wZPW3aH5gok+UVE1UGUbF9ZUF04nA8C8JKlJs6d HvPl800SujAMk2l+vuOCJmLU58klWq6XxlpcFGUM6spbUSblHUFgyclGplguLzu/B4af gmRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lvIFRGhE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a5-20020a509e85000000b0042aaec01a46si8444239edf.462.2022.06.13.08.52.15; Mon, 13 Jun 2022 08:52:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lvIFRGhE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1346060AbiFMKgl (ORCPT + 99 others); Mon, 13 Jun 2022 06:36:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346949AbiFMKej (ORCPT ); Mon, 13 Jun 2022 06:34:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E47F82721; Mon, 13 Jun 2022 03:22:32 -0700 (PDT) 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 8E86A60B8B; Mon, 13 Jun 2022 10:22:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E3F7C34114; Mon, 13 Jun 2022 10:22:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655115751; bh=eMPpJKwA8BTKycbUU9Cu8i3R9Q5hXb8qPpxRbTtLBFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lvIFRGhEBhapPUAfYVdIWivWHpDIJ3PVM7nOqTxZS6Cteuvjz5HgNv4eKTWHtrTZ9 g6q/iJBgFaxhiiOiAEV5X3FphVb0ebhbuw0sCTul9an7vWZp9u/eX6HT1IzMBqFdpd b3yc431IJyptGmo9/PhedPaMSOnXzOHGBoVbVZPk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zheyu Ma , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.14 018/218] media: pci: cx23885: Fix the error handling in cx23885_initdev() Date: Mon, 13 Jun 2022 12:07:56 +0200 Message-Id: <20220613094912.633693709@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094908.257446132@linuxfoundation.org> References: <20220613094908.257446132@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zheyu Ma [ Upstream commit e8123311cf06d7dae71e8c5fe78e0510d20cd30b ] When the driver fails to call the dma_set_mask(), the driver will get the following splat: [ 55.853884] BUG: KASAN: use-after-free in __process_removed_driver+0x3c/0x240 [ 55.854486] Read of size 8 at addr ffff88810de60408 by task modprobe/590 [ 55.856822] Call Trace: [ 55.860327] __process_removed_driver+0x3c/0x240 [ 55.861347] bus_for_each_dev+0x102/0x160 [ 55.861681] i2c_del_driver+0x2f/0x50 This is because the driver has initialized the i2c related resources in cx23885_dev_setup() but not released them in error handling, fix this bug by modifying the error path that jumps after failing to call the dma_set_mask(). Signed-off-by: Zheyu Ma Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/pci/cx23885/cx23885-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/media/pci/cx23885/cx23885-core.c b/drivers/media/pci/cx23885/cx23885-core.c index 4612f26fcd6d..6f297caf5540 100644 --- a/drivers/media/pci/cx23885/cx23885-core.c +++ b/drivers/media/pci/cx23885/cx23885-core.c @@ -2005,7 +2005,7 @@ static int cx23885_initdev(struct pci_dev *pci_dev, err = pci_set_dma_mask(pci_dev, 0xffffffff); if (err) { pr_err("%s/0: Oops: no 32bit PCI DMA ???\n", dev->name); - goto fail_ctrl; + goto fail_dma_set_mask; } err = request_irq(pci_dev->irq, cx23885_irq, @@ -2013,7 +2013,7 @@ static int cx23885_initdev(struct pci_dev *pci_dev, if (err < 0) { pr_err("%s: can't get IRQ %d\n", dev->name, pci_dev->irq); - goto fail_irq; + goto fail_dma_set_mask; } switch (dev->board) { @@ -2035,7 +2035,7 @@ static int cx23885_initdev(struct pci_dev *pci_dev, return 0; -fail_irq: +fail_dma_set_mask: cx23885_dev_unregister(dev); fail_ctrl: v4l2_ctrl_handler_free(hdl); -- 2.35.1