Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2023344rwe; Fri, 2 Sep 2022 07:29:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR5LqlQLW/VW19ici6sxQIZyI6dKqpeNAOGNP1lcn2zbYh8rXodUI3pKJKILsX173ZX9afcy X-Received: by 2002:a05:6402:4414:b0:434:f58c:ee2e with SMTP id y20-20020a056402441400b00434f58cee2emr33068054eda.362.1662128962723; Fri, 02 Sep 2022 07:29:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662128962; cv=none; d=google.com; s=arc-20160816; b=GvPPQtXhfLTkHy4P9w9/UMNcjnbSNHfp5o4lv2v1HLkQNSXSIiJCeL/CTpbOF+RenY Dg4e0fzKrce3XRHuhFU1j5i32AJ6uWhQg3nlSibwgiRVfv0o3YzTWO97U5/DchJUjzQe mN/DP2dPuxt8LPMaxpfH3e3xsTE+bQ1llLwcQ+DGgeAQ49ftPldRWU3mVoOpUX9qRBOS sioBFUAXXe4SkTn3lNmXE62y1tgMAT+VGjRdxN7ZMRmDmGkl9nUETUgulmJ25yczDD12 pfB7uoMpN7tj/mAiKvvFdx3CZmYzajH6qC6daZZu2ZbuIDcayWcr2y8Nuk1eqgtVkzyz zhYQ== 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=I+QQ4kfSvDfgDJv3KaMyGJD6GPOo2D8gduNX8mCotBM=; b=ftE2hDXzbMBvHm59KkAiPpD7USqI1ayWoQjjNCOFFtKDKqu+xGdFkRVs56VK8805lZ f4Okpl+ROgSZvpIZopx9u6aT6KUw/aKdmorZzU6vcaUwipUGoBpyLvOnlienTso3FTg/ /XI0SAxE93JOcNr+b4SmhBdX1oiH/BlAMb2NG5ySCRJua8Mhy2cFDPx1E4sg3srwDhnT 6EmznnWvsQ73DarffKV2cjAX8M9XqtZ6l0/500XWJzWfzUp3LkSxw+l/IWBMxqeY4Ufr BYvK51dS060LwGyc9waf3GMUtYsIdEwmyy/eRRdVtJSw7TggKMHb85dM4S7GrDG1Rc1S XjUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ss8vjLUQ; 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 t11-20020a1709067c0b00b0073d847631d2si1672399ejo.158.2022.09.02.07.28.55; Fri, 02 Sep 2022 07:29:22 -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=Ss8vjLUQ; 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 S235974AbiIBMXr (ORCPT + 99 others); Fri, 2 Sep 2022 08:23:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236201AbiIBMWn (ORCPT ); Fri, 2 Sep 2022 08:22:43 -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 9B33FD5E88; Fri, 2 Sep 2022 05:21:47 -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 EB04F620C5; Fri, 2 Sep 2022 12:21:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07DDEC433C1; Fri, 2 Sep 2022 12:21:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662121297; bh=ggkzR7fXpZd66zV4XncdCKBI8YV+okgrGR8z07c89yk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ss8vjLUQSGodLcIZgP1SaS4jeLIY6QMKK4e41oOO5DQ7TiLzY8fPTBbFOF8M1vuqn ItLBYhpHD2P4/hWl3Hoxej/DeITI/eRYVJpLBzgJPx2HVWDQKK/+FYUX7Y8+INtQLU 6qnmQlfT4pdqC0Y58ouHSsXAfSN9CBOtk+DC/1Ek= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+f59100a0428e6ded9443@syzkaller.appspotmail.com, Karthik Alapati , Jiri Kosina Subject: [PATCH 4.9 24/31] HID: hidraw: fix memory leak in hidraw_release() Date: Fri, 2 Sep 2022 14:18:50 +0200 Message-Id: <20220902121357.642923635@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121356.732130937@linuxfoundation.org> References: <20220902121356.732130937@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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: Karthik Alapati commit a5623a203cffe2d2b84d2f6c989d9017db1856af upstream. Free the buffered reports before deleting the list entry. BUG: memory leak unreferenced object 0xffff88810e72f180 (size 32): comm "softirq", pid 0, jiffies 4294945143 (age 16.080s) hex dump (first 32 bytes): 64 f3 c6 6a d1 88 07 04 00 00 00 00 00 00 00 00 d..j............ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [] kmemdup+0x23/0x50 mm/util.c:128 [] kmemdup include/linux/fortify-string.h:440 [inline] [] hidraw_report_event+0xa2/0x150 drivers/hid/hidraw.c:521 [] hid_report_raw_event+0x27d/0x740 drivers/hid/hid-core.c:1992 [] hid_input_report+0x1ae/0x270 drivers/hid/hid-core.c:2065 [] hid_irq_in+0x1ff/0x250 drivers/hid/usbhid/hid-core.c:284 [] __usb_hcd_giveback_urb+0xf9/0x230 drivers/usb/core/hcd.c:1670 [] usb_hcd_giveback_urb+0x1b6/0x1d0 drivers/usb/core/hcd.c:1747 [] dummy_timer+0x8e4/0x14c0 drivers/usb/gadget/udc/dummy_hcd.c:1988 [] call_timer_fn+0x38/0x200 kernel/time/timer.c:1474 [] expire_timers kernel/time/timer.c:1519 [inline] [] __run_timers.part.0+0x316/0x430 kernel/time/timer.c:1790 [] __run_timers kernel/time/timer.c:1768 [inline] [] run_timer_softirq+0x44/0x90 kernel/time/timer.c:1803 [] __do_softirq+0xe6/0x2ea kernel/softirq.c:571 [] invoke_softirq kernel/softirq.c:445 [inline] [] __irq_exit_rcu kernel/softirq.c:650 [inline] [] irq_exit_rcu+0xc0/0x110 kernel/softirq.c:662 [] sysvec_apic_timer_interrupt+0xa2/0xd0 arch/x86/kernel/apic/apic.c:1106 [] asm_sysvec_apic_timer_interrupt+0x1b/0x20 arch/x86/include/asm/idtentry.h:649 [] native_safe_halt arch/x86/include/asm/irqflags.h:51 [inline] [] arch_safe_halt arch/x86/include/asm/irqflags.h:89 [inline] [] acpi_safe_halt drivers/acpi/processor_idle.c:111 [inline] [] acpi_idle_do_entry+0xc0/0xd0 drivers/acpi/processor_idle.c:554 Link: https://syzkaller.appspot.com/bug?id=19a04b43c75ed1092021010419b5e560a8172c4f Reported-by: syzbot+f59100a0428e6ded9443@syzkaller.appspotmail.com Signed-off-by: Karthik Alapati Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hidraw.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/hid/hidraw.c +++ b/drivers/hid/hidraw.c @@ -354,10 +354,13 @@ static int hidraw_release(struct inode * unsigned int minor = iminor(inode); struct hidraw_list *list = file->private_data; unsigned long flags; + int i; mutex_lock(&minors_lock); spin_lock_irqsave(&hidraw_table[minor]->list_lock, flags); + for (i = list->tail; i < list->head; i++) + kfree(list->buffer[i].value); list_del(&list->node); spin_unlock_irqrestore(&hidraw_table[minor]->list_lock, flags); kfree(list);