Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp6285pxb; Mon, 13 Sep 2021 11:28:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqegfO9NxWxwMzSyIfO1+m7KOjeMTeYs8V0NEooPZImj/SLVDNvKYpfZpy1Ah0K9rijF5U X-Received: by 2002:a05:6638:1606:: with SMTP id x6mr11080297jas.25.1631557688557; Mon, 13 Sep 2021 11:28:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631557688; cv=none; d=google.com; s=arc-20160816; b=TZOg+kO4/u7f1UwxkSPGpTmy0wVEXJn4/MX9GlklQwNJnHKM0UeWDNhN1ni7gLGOzQ khewVF8mx9XFsqmbrkco033qIaBmzo/b7+qJ3rBJh7HkQg0uzF755rP2hIXZ9ADvv8MG +GG8M91c9MTn+UhQOh/Valw4H4THhd3o7AIOXAk4UWP1c0mA6LxmLbywf7puNggijol5 +IIs+1KZkdnSXn14tr+ac3CWpCEZ9B4E8Vcy8uGy03Jonriy5heSTIibSduWnjrt4r1N DQg/mjFTwWAGWQabqiZZ44wXfA2XPtQqaA35uf++EMZd8Z9LjkbZqWiztmiBCDe14oLA yC7A== 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=RGvILgpaXMgNsPyTpyVIrvSosfBb0VqUsVty+KeCSiE=; b=CMPCVyIiZ3hLBx6+PaAMcfwC9jmPwEWFVkYQKcWtkvvO7H7tJ9lzKHhV/7amS07IJr mQ//ZzDCkJ4rPLuZ7OO803IkL25WLyuBNdH6eclsfvbN1BBmpb/ZA/KwE7zqEqucs8Ls oxP5OBqYv3gDUXDSiUTNjEJuBLp/iZfAipEozjd7sT45zYvHLGvnRhHSdA+4DhmyHIDe 6rRINShk79FGbtOX0/My8CkqjM0gVOCDb67bU+tuSkO51UDxm091vJSDeKxcVjSlffl1 IhbZJ70dtCpHprCJpcIAAhQOLytYZVCF7VMygdNnA8UtbqZmLB3tPRnYRE9BIYJ2PmuZ LfXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sllzLn7P; 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 i62si7189568iof.83.2021.09.13.11.27.55; Mon, 13 Sep 2021 11:28:08 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sllzLn7P; 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 S240768AbhIMNWv (ORCPT + 99 others); Mon, 13 Sep 2021 09:22:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:34832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240423AbhIMNVW (ORCPT ); Mon, 13 Sep 2021 09:21:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7B597610A5; Mon, 13 Sep 2021 13:19:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539188; bh=Ny8wVJn4A9i6ipl3UIAXM88BcEFMhX2inpmHcX3ehGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sllzLn7Pjj00J3XuzvQF9SoXfCq4wNQVXWBDh1qlVGUgG1kApIHyPgq6mb7LoSW5V M+/dpPSom99/HRXtz3Oq2ncHIei1VKHNNH8fIiJQp/Gj4aD+xXV1WzfWc1x2m+4kF2 0fj+IEkcEc7pzLb/iX75vJGlZbIjzcsZkV10KatU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dongliang Mu , Sean Young , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.4 075/144] media: em28xx-input: fix refcount bug in em28xx_usb_disconnect Date: Mon, 13 Sep 2021 15:14:16 +0200 Message-Id: <20210913131050.471233640@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131047.974309396@linuxfoundation.org> References: <20210913131047.974309396@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: Dongliang Mu [ Upstream commit 6fa54bc713c262e1cfbc5613377ef52280d7311f ] If em28xx_ir_init fails, it would decrease the refcount of dev. However, in the em28xx_ir_fini, when ir is NULL, it goes to ref_put and decrease the refcount of dev. This will lead to a refcount bug. Fix this bug by removing the kref_put in the error handling code of em28xx_ir_init. refcount_t: underflow; use-after-free. WARNING: CPU: 0 PID: 7 at lib/refcount.c:28 refcount_warn_saturate+0x18e/0x1a0 lib/refcount.c:28 Modules linked in: CPU: 0 PID: 7 Comm: kworker/0:1 Not tainted 5.13.0 #3 Workqueue: usb_hub_wq hub_event RIP: 0010:refcount_warn_saturate+0x18e/0x1a0 lib/refcount.c:28 Call Trace: kref_put.constprop.0+0x60/0x85 include/linux/kref.h:69 em28xx_usb_disconnect.cold+0xd7/0xdc drivers/media/usb/em28xx/em28xx-cards.c:4150 usb_unbind_interface+0xbf/0x3a0 drivers/usb/core/driver.c:458 __device_release_driver drivers/base/dd.c:1201 [inline] device_release_driver_internal+0x22a/0x230 drivers/base/dd.c:1232 bus_remove_device+0x108/0x160 drivers/base/bus.c:529 device_del+0x1fe/0x510 drivers/base/core.c:3540 usb_disable_device+0xd1/0x1d0 drivers/usb/core/message.c:1419 usb_disconnect+0x109/0x330 drivers/usb/core/hub.c:2221 hub_port_connect drivers/usb/core/hub.c:5151 [inline] hub_port_connect_change drivers/usb/core/hub.c:5440 [inline] port_event drivers/usb/core/hub.c:5586 [inline] hub_event+0xf81/0x1d40 drivers/usb/core/hub.c:5668 process_one_work+0x2c9/0x610 kernel/workqueue.c:2276 process_scheduled_works kernel/workqueue.c:2338 [inline] worker_thread+0x333/0x5b0 kernel/workqueue.c:2424 kthread+0x188/0x1d0 kernel/kthread.c:319 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295 Reported-by: Dongliang Mu Fixes: ac5688637144 ("media: em28xx: Fix possible memory leak of em28xx struct") Signed-off-by: Dongliang Mu Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/em28xx/em28xx-input.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/media/usb/em28xx/em28xx-input.c b/drivers/media/usb/em28xx/em28xx-input.c index 59529cbf9cd0..0b6d77c3bec8 100644 --- a/drivers/media/usb/em28xx/em28xx-input.c +++ b/drivers/media/usb/em28xx/em28xx-input.c @@ -842,7 +842,6 @@ error: kfree(ir); ref_put: em28xx_shutdown_buttons(dev); - kref_put(&dev->ref, em28xx_free_device); return err; } -- 2.30.2