Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3860986pxb; Tue, 17 Nov 2020 05:37:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJwoShGkJCOIbKNSQryKLYirKnS5Xfrmq+8RXW6abw2GMc4a6TAPBvyuCbr4LOGRKhoj9AoE X-Received: by 2002:a17:906:b0d8:: with SMTP id bk24mr7916850ejb.113.1605620250059; Tue, 17 Nov 2020 05:37:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605620250; cv=none; d=google.com; s=arc-20160816; b=ZTEgc6t9N0UBF4cbvqqFsOTHaIpXupqUtGq5Z9M7LsekV58MIoxpCQGpTQE3e8TpyP m+Mgxxv7cDZaInwBBKI0XYr4ivh9nNfXRTr+jPDpUhcQ+SJSXnCHXSAl0JXJtmLMm+el YfM7t+fgenP+wDC65PhKfXKe4M8utFepT/anVMGfvqbkVN7uoHjogP/KMMlWMJ1C6dem iwn2O9KhzP376Zj0E4A4Oa8y0Iq7JcSU0+476pl9t2d9XFqeQ2Hn5TyVVQgxXP8z0blC fvL+0EVgXYxe7FM3k7pUyR79/gdFJmeqUrGpmtaRwTnBx99iUZJPJ1mWm3xha2VHD0gj hexw== 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=Bfwt8Ekcf+wXsyG4PwP8+llv6UcpVyTrfPIJIBQn+N8=; b=mWlW2qIbpmAr4CalPmutFvEslb+ykQVyu6CzNJtUA5+0ix5ItMoYxrgtJdih4X7Ctg pJWFXJwPjUiLH5bC2n44PVZnAF9c1DRvnIdsZ30V5ZtVP5SpcV3FdhNAH5n/vumfvoK5 HZ2BZcnJJY1D60GY91Fq0wGOfCsmOosWzmvivC105lndwJy1ne1tVuzXW7iLg8Kt4eYi ZAhF68+NL2mzjOYDtW0xbb+xOhQ/juUQmShfweyOXKaBREAAFUxogFmwX61WeBkoiDdV 1PZdOP0pm9FN84dzxGDNb1sgGWxwolc+68W4vfi6LCSDi8vy6toBh4Qx1bKEkFbTBAKf K/Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="NRN349/v"; 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=fail (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 z20si13245142eji.649.2020.11.17.05.37.07; Tue, 17 Nov 2020 05:37:30 -0800 (PST) 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=@kernel.org header.s=default header.b="NRN349/v"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732103AbgKQNdw (ORCPT + 99 others); Tue, 17 Nov 2020 08:33:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:44018 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731608AbgKQNds (ORCPT ); Tue, 17 Nov 2020 08:33:48 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C34E2463D; Tue, 17 Nov 2020 13:33:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605620027; bh=wxReGi6HVGFdUbh0Mok77vUSY+a2MBXG85WHU4GVGms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NRN349/vnm+GZ4yfdfbdlIFkTodMAsQEeNx6c9Z2N/XcNvluhmOSLO5WjKoPrM2p5 9Rfza4uVLwxLvqw8qpx1dVKjl2zmKwR0VH+ZuIhaX06Drq2ZYOuBl5X72xj93d7yuw frFSw/uTWSNKET4JYJtN0BBWvturEtKqmUh4DVjk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+bd38200f53df6259e6bf@syzkaller.appspotmail.com, Zqiang , Felipe Balbi , Sasha Levin Subject: [PATCH 5.9 083/255] usb: raw-gadget: fix memory leak in gadget_setup Date: Tue, 17 Nov 2020 14:03:43 +0100 Message-Id: <20201117122142.995783351@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@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: Zqiang [ Upstream commit 129aa9734559a17990ee933351c7b6956f1dba62 ] When fetch 'event' from event queue, after copy its address space content to user space, the 'event' the memory space pointed to by the 'event' pointer need be freed. BUG: memory leak unreferenced object 0xffff888110622660 (size 32): comm "softirq", pid 0, jiffies 4294941981 (age 12.480s) hex dump (first 32 bytes): 02 00 00 00 08 00 00 00 80 06 00 01 00 00 40 00 ..............@. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [<00000000efd29abd>] kmalloc include/linux/slab.h:554 [inline] [<00000000efd29abd>] raw_event_queue_add drivers/usb/gadget/legacy/raw_gadget.c:66 [inline] [<00000000efd29abd>] raw_queue_event drivers/usb/gadget/legacy/raw_gadget.c:225 [inline] [<00000000efd29abd>] gadget_setup+0xf6/0x220 drivers/usb/gadget/legacy/raw_gadget.c:343 [<00000000952c4a46>] dummy_timer+0xb9f/0x14c0 drivers/usb/gadget/udc/dummy_hcd.c:1899 [<0000000074ac2c54>] call_timer_fn+0x38/0x200 kernel/time/timer.c:1415 [<00000000560a3a79>] expire_timers kernel/time/timer.c:1460 [inline] [<00000000560a3a79>] __run_timers.part.0+0x319/0x400 kernel/time/timer.c:1757 [<000000009d9503d0>] __run_timers kernel/time/timer.c:1738 [inline] [<000000009d9503d0>] run_timer_softirq+0x3d/0x80 kernel/time/timer.c:1770 [<000000009df27c89>] __do_softirq+0xcc/0x2c2 kernel/softirq.c:298 [<000000007a3f1a47>] asm_call_irq_on_stack+0xf/0x20 [<000000004a62cc2e>] __run_on_irqstack arch/x86/include/asm/irq_stack.h:26 [inline] [<000000004a62cc2e>] run_on_irqstack_cond arch/x86/include/asm/irq_stack.h:77 [inline] [<000000004a62cc2e>] do_softirq_own_stack+0x32/0x40 arch/x86/kernel/irq_64.c:77 [<00000000b0086800>] invoke_softirq kernel/softirq.c:393 [inline] [<00000000b0086800>] __irq_exit_rcu kernel/softirq.c:423 [inline] [<00000000b0086800>] irq_exit_rcu+0x91/0xc0 kernel/softirq.c:435 [<00000000175f9523>] sysvec_apic_timer_interrupt+0x36/0x80 arch/x86/kernel/apic/apic.c:1091 [<00000000a348e847>] asm_sysvec_apic_timer_interrupt+0x12/0x20 arch/x86/include/asm/idtentry.h:631 [<0000000060661100>] native_safe_halt arch/x86/include/asm/irqflags.h:60 [inline] [<0000000060661100>] arch_safe_halt arch/x86/include/asm/irqflags.h:103 [inline] [<0000000060661100>] acpi_safe_halt drivers/acpi/processor_idle.c:111 [inline] [<0000000060661100>] acpi_idle_do_entry+0xc3/0xd0 drivers/acpi/processor_idle.c:517 [<000000003f413b99>] acpi_idle_enter+0x128/0x1f0 drivers/acpi/processor_idle.c:648 [<00000000f5e5afb8>] cpuidle_enter_state+0xc9/0x650 drivers/cpuidle/cpuidle.c:237 [<00000000d50d51fc>] cpuidle_enter+0x29/0x40 drivers/cpuidle/cpuidle.c:351 [<00000000d674baed>] call_cpuidle kernel/sched/idle.c:132 [inline] [<00000000d674baed>] cpuidle_idle_call kernel/sched/idle.c:213 [inline] [<00000000d674baed>] do_idle+0x1c8/0x250 kernel/sched/idle.c:273 Reported-by: syzbot+bd38200f53df6259e6bf@syzkaller.appspotmail.com Signed-off-by: Zqiang Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin --- drivers/usb/gadget/legacy/raw_gadget.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c index e01e366d89cd5..062dfac303996 100644 --- a/drivers/usb/gadget/legacy/raw_gadget.c +++ b/drivers/usb/gadget/legacy/raw_gadget.c @@ -564,9 +564,12 @@ static int raw_ioctl_event_fetch(struct raw_dev *dev, unsigned long value) return -ENODEV; } length = min(arg.length, event->length); - if (copy_to_user((void __user *)value, event, sizeof(*event) + length)) + if (copy_to_user((void __user *)value, event, sizeof(*event) + length)) { + kfree(event); return -EFAULT; + } + kfree(event); return 0; } -- 2.27.0