Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1842158pxb; Mon, 13 Sep 2021 06:44:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAj3+m6xEC8pWRUPTaIqFYov/rhexFc7C0qXuR8GCPbPFMhlJLNrOYvqb3nFoz0AfG0a+6 X-Received: by 2002:a5d:9319:: with SMTP id l25mr2571733ion.208.1631540698586; Mon, 13 Sep 2021 06:44:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631540698; cv=none; d=google.com; s=arc-20160816; b=QBNfeHQiH9ZLiMsXy3hEhWCoqhJcGD3mwPrmZvOIqaavsejbxYPBf94dZNtcHqlS4W zZj2YgQ31VhCrn3ig7/c3su4jsMnUPNThPAM2eCXqCXBxmcG4+BFfUj7hdPTIR7OZwRI HSqI9+LO4Tl7apDEgNuBOLV5aFWoZdjyZrRe7ry/vATkfikf2Vm8HZtBQ7IXaoTQ+B9l vMI6AOwr92H/0s1NwhwdWcd0IsRPrQQSiTMnDYKLBGDTYzq0L+iLLaRvVdhOT8V+xKMq FtuaQGiDf6NtOgqHRdXf1rLme7jymS5f3YZ1TmcvRFXkcJZ2zI72xtKAZogDcsDEjKG6 0mfQ== 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=JfnXz/e5sWWoH9u2T2A0ZsNoM6V9DTZA8OlUBnAFRbXmv4p72X8tJHNRKlppZmnow5 FOQZbyyqQDRG2nD7DFwYihMRZJrNNmYiOQEzq5FfpBGd6dUFYHuwILAi0JXQlLcmHPjv xP8c/icZ7xf8H2rmBxeVqq5dXITliKjkPGJgUVII+kbz3Qga04FLNF0KyC1ruhPjmDJ2 9MaWzM+QrwGW5CQ5RHt0elanxWF9icJdyFqTfb8mOixi734Y6Qm2DBHAiGcPd94vO6N2 8x9KdYU1uMnIh3TCrBrmXK6RVejFz13Y5mjKqZ1VAc5Tf0GhmKH62i6i/vX9EWIithxj O7nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pNMjg7NJ; 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 c11si6170630ild.118.2021.09.13.06.44.19; Mon, 13 Sep 2021 06:44:58 -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=pNMjg7NJ; 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 S242023AbhIMNnI (ORCPT + 99 others); Mon, 13 Sep 2021 09:43:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:40602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243108AbhIMNiS (ORCPT ); Mon, 13 Sep 2021 09:38:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B7FBA613BD; Mon, 13 Sep 2021 13:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539694; bh=Ny8wVJn4A9i6ipl3UIAXM88BcEFMhX2inpmHcX3ehGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pNMjg7NJQfaOZAVY/CY++xpf5HHG4jyAbkzmzhW4d/GRXdrd27qswzEY4CoxNnRWV fTpLrLaqovgqPAyKsC8WuiKTBhGwghQxbRuybm2Boq76mU6YF5sIFo20KVfQedT6Y0 lkvFbE9XWQzcp6cybSF5x5fkMofrL7g0uRdL7Veo= 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.10 123/236] media: em28xx-input: fix refcount bug in em28xx_usb_disconnect Date: Mon, 13 Sep 2021 15:13:48 +0200 Message-Id: <20210913131104.544526647@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@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