Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2110475iof; Tue, 7 Jun 2022 20:05:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4bwL+BSgCBz4VXpR4aCAzWakb+y49lkc7Wbos/FPgzLSza6YSWjGig1QHsygVAPvQHY3F X-Received: by 2002:aa7:88d2:0:b0:50a:cf7d:6ff1 with SMTP id k18-20020aa788d2000000b0050acf7d6ff1mr32952045pff.67.1654657501167; Tue, 07 Jun 2022 20:05:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654657501; cv=none; d=google.com; s=arc-20160816; b=aJxD3qQMh3msW+Moj1JuWywBjfhNl6IWf6cmMzV8nSw7LpsOywUGuWSFQBC33bdqF0 ejgQ9r+wYmrYmxd50fATJGdBg+0pA+dhMEbcVLV230E45K8lt4EYZbdKCEW9P6IY7Jbl Y4feziOGi/NPlGlXRUzUSeUek+cvpXwPsBuCSDnRNj7HW8PMm6wLoN1C9Ag+j+cW9CKp hTh53V49Ow+NB6XSLgMuZcGKV+yBSwVbBB65Eo+me+gj/Ntsg3Sn4pv5xFCM5lKO+K4k 9uOwZ4X2F8p4vbfwFhrpzHmwvka/XUisLrOjhZitwdMqJiAzXaDbd1s8twIRl2QqdEXF lAMA== 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=Va7GZVShpLC9odGoLPx1X+8KD6NAV2demUC7kHbR5hk=; b=Hx7I4I4gJMk6DfX3/KtslZL9cw0gzfR9c9R+uZI97jLo6UIklHSB536JmsqDr0pQAd u/2fYk5cEK5wAIhdiYrnon5yM8J5/lz4qLl4XdOxvKqw4xU6Bk0QbAn0zeLyHmlRX/Bp mgAAobyDSoB+tA2df9bG+J93hvM8J2dIjJnmPLg1z8i3mxSsy1tqxmdFQbMaBW2NOBau XABBeRiZZyr8OrNRn59jCr7NpaJYSIuWonIL7C6LLArH/0ClK5dJKPEAFLF7ZXVouQxQ IsUdJeO45kPBMAGIKv97F/THvormNfgG/yGjBo0iGoUxkzEG2QfuWiscHv1JKgAGMU2L F7mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="S/HSI+I1"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b189-20020a6334c6000000b003fe34317ce2si1122367pga.778.2022.06.07.20.05.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 20:05:01 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="S/HSI+I1"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9F7043D500E; Tue, 7 Jun 2022 19:22:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382492AbiFGWG6 (ORCPT + 99 others); Tue, 7 Jun 2022 18:06:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379841AbiFGVGa (ORCPT ); Tue, 7 Jun 2022 17:06:30 -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 DCEF4211AB3; Tue, 7 Jun 2022 11:50:27 -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 0343061777; Tue, 7 Jun 2022 18:50:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10219C385A2; Tue, 7 Jun 2022 18:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654627824; bh=dnVq8A+QaRcFBuWkdXsDnNqK0ZQ2F6cv/bJXs+evh2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S/HSI+I1TTmPGI7RFwuQj00kTe0GX8TEwKk428x3cFOf/kL+3S2uzDHO/xNoGpt0I fJ2TKxNIG5+eoHQA+PpSyuTdf09Se2+oHSXUPIQ/QpMVXOcHzNAm/hzKgcvhseV4AP CAirht/cVRug5i2C9g/I0H4sfTgnJuhq9f4Lok74= 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 5.18 104/879] media: pci: cx23885: Fix the error handling in cx23885_initdev() Date: Tue, 7 Jun 2022 18:53:42 +0200 Message-Id: <20220607165005.713750327@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 f8f2ff3b00c3..a07b18f2034e 100644 --- a/drivers/media/pci/cx23885/cx23885-core.c +++ b/drivers/media/pci/cx23885/cx23885-core.c @@ -2165,7 +2165,7 @@ static int cx23885_initdev(struct pci_dev *pci_dev, err = dma_set_mask(&pci_dev->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, @@ -2173,7 +2173,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) { @@ -2195,7 +2195,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