Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3999737ioo; Mon, 30 May 2022 15:15:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWDOt9sUzCkq5Yc2a6JUqfD7dAHy+oEwRSn8tFTSIQehr56MlLds1Aqn8bO0VQTRIEZjzT X-Received: by 2002:a17:902:a585:b0:14d:58ef:65 with SMTP id az5-20020a170902a58500b0014d58ef0065mr57418812plb.139.1653948931115; Mon, 30 May 2022 15:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653948931; cv=none; d=google.com; s=arc-20160816; b=LRrwDkBeo3188UFJyxA7Fw2rT+3uEGmEGS0Ut77eBAm6qmPVN7svTs1mLB6fcijkr2 0m1RVL5y0wo5RJh+qDTXWje/yqnXA46h2k8C5KZrllgvw/JfjuZDqSDJjgWH/r20unsu LWiKLFBVc2A1YGVxUi2Fc9xlC1TkU8159Rk0xlO7P22oNLZWN++1p06Sci6t2OaWdWKG RnSJ4vCX+m2ZiuPRcm6L1NR+zPnKAs5Bex2BCtUQ9yTF56aw4v82H6o9gdJhFUlQBMPe 3cMocbS65xNK8Kvw/GNXTCXAewFTlovcIGDx5iACfUIgHc3OYMaHa5FHjr+1OIC8W3U6 1nTA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GIICvVyfwlUrdtpR7cgtthhGpK5krKWXKbwvKqtmBTQ=; b=PKE8eerQ/n7SUJ/leVZ75nMyZhsdouERMk09gccMvm2yOkQLHkaJqX6B+UADQ76YCV uw73GbrvsOh7uAECbZLhx+G7OiETqoZ9m4qv/6b08Aegd3R4uXyCcH5DN/+ga5WupwzW braLJ0B+uLPXn/sA7hWdzIlBymRV4AvTNF/jJqGn+EgCLQSSlvD3zmjiDOGHc3KgJ+qA VTyAKfdsA7lOsXTxlvhMtEHVEMTkUNjkCdjWitsEuk9UcWmnasGXSK3Tdl73/9lNwSVi AnpqxrdQTzENgCOnVZYJ5wloftPr7OFmEiya+ufEix0Ccl+A+zSjfGswnm5GaNIfkMuh fUVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cS1+PB10; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c9-20020a170902724900b00161d3902fcfsi15393456pll.453.2022.05.30.15.15.19; Mon, 30 May 2022 15:15:31 -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=@kernel.org header.s=k20201202 header.b=cS1+PB10; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241912AbiE3OgW (ORCPT + 99 others); Mon, 30 May 2022 10:36:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241591AbiE3ORs (ORCPT ); Mon, 30 May 2022 10:17:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BFA8562DD; Mon, 30 May 2022 06:47:46 -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 ams.source.kernel.org (Postfix) with ESMTPS id C457EB80DE5; Mon, 30 May 2022 13:47:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3A72C3411A; Mon, 30 May 2022 13:47:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653918463; bh=gn/eCdmqB5fJjArNNAufz7ZEKjtYcJ3DdUYMiiTIDg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cS1+PB10GrexYBxF4CnFcRuwKmCE8Mtq9h9O8RRWT9uy1qB8yorkPXYbNtM9IVOaf dhSYi1u4vPt9ERRr4B+NPL39MYIly0x8/nC0ZTyp3oMhetgSdnpVw8VGGXn5fKC+ha jtMTAD/5iHvmmqvmXMGCVCCcJ5I35ETgB2JjzSvJFohYmDgC2e24Fw6JojuLymWqz0 3vV6C9cYV8YuceT2c49tvG/ICrRejU496Es2qnZZmigggTWwO+lDAFl+48S6uj/ISo U+KzAE+6MBI5AmwCWI/x9CPn7D3tNRumkMsBwb1/sDML4bV1Jdyq27KFuSPdeJ873/ yZpMQAZAHI+/g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zheyu Ma , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 16/55] media: pci: cx23885: Fix the error handling in cx23885_initdev() Date: Mon, 30 May 2022 09:46:22 -0400 Message-Id: <20220530134701.1935933-16-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220530134701.1935933-1-sashal@kernel.org> References: <20220530134701.1935933-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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 ead0acb7807c..6747ecb4911b 100644 --- a/drivers/media/pci/cx23885/cx23885-core.c +++ b/drivers/media/pci/cx23885/cx23885-core.c @@ -2154,7 +2154,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, @@ -2162,7 +2162,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) { @@ -2184,7 +2184,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