Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3806014pxb; Mon, 4 Oct 2021 10:00:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyh/uNxjsqZE+wwveOW0K96nIXcmu+XFF1IC4DEu4TBN/F3Y9AGsdAiMHUKTSWjVaMOfsOO X-Received: by 2002:a17:90a:910:: with SMTP id n16mr37217231pjn.246.1633366825988; Mon, 04 Oct 2021 10:00:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633366825; cv=none; d=google.com; s=arc-20160816; b=xzomFnf/YIp9ygHxvLrSWIqjvNuVRY+lRaC5eJjZIE0noPJ5+Bc+30W2okJ0fpwnlV iiggRFzFCnUEpTseG3ca8qqRnbekZjeSkEc/QjTH7VLus4DLAlK2HCq/t6ZPqWRPJ+hd Np/j8qPaO0oLYYFJDYtUrRDx3mnKGTCj4nw4kF6powdt/1Geaq0SpQ3sojTWF9BBKJKx 2YKrLKKHYGSHTKACRJRCqMw9vTpJgK08BtMk4OPCNc0WlIm12kWa2eeTcIKLrQpB+opw H3GfLhghW9QjOrJDIF8UUGNVUiLOXbSFKpBr599QCu/McDc03aEZMYvtmIL6DItVSdXN D9fw== 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=qCnIUs1DKB2kMEhoJhn+qvVqSupI6mIYLSM/EoLTw7o=; b=afXBITO74AU80yR0kHNI7e65+7P2zWgLlcUhcG6nhVU6lPsmCpEhXJCDZFKHdQ7Jbe eEcC+3uJtCLgxjqknlTe7SikFWhDmCEMRXBB1ACfp8AQsyNXGoWaeDqQk6acu1I4i8Ua FOLVRVPyScRt54Q9yCUEz3fD+OfXO+4Vh26sgVQqQAomzmmiC/TWyHFywoUZ8wwtErvG PtT1a0MMz+MBBCpe5d/ezSyHtcRDJ9HsFGfuc2J8pnACNvkk/KlJ3RMSHdy9ZcEp6qRs /z1WzRtAX8f7povGUtJUopwJOOPezMMBHP1cDeuHdK62byDRqXzIzmOCEbySrBKLWsuM ufQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gg5LThUD; 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 u1si20436986pls.99.2021.10.04.10.00.12; Mon, 04 Oct 2021 10:00:25 -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=gg5LThUD; 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 S238388AbhJDNoP (ORCPT + 99 others); Mon, 4 Oct 2021 09:44:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:51836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238291AbhJDNl7 (ORCPT ); Mon, 4 Oct 2021 09:41:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 737F46324D; Mon, 4 Oct 2021 13:19:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353551; bh=95rQBYIkC6VMsc+agne40V5El6cVX16ikHvzhScdP4E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gg5LThUD3w/qBI62MuzT0zcS6gqdgbG+xnTzEk4IXrtNrn+xBaQ4IRayozdwJ+5nL vxCMuX7EJ7bjnbP64q2lotgdFBJwNMmeizi5UhXJrpaSifVvHY/sKK6iXEAWtg+YN4 Qazr9qfON6GqK+uiRucZzm5BBm+9yBFIJkYDc9G0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+47b26cd837ececfc666d@syzkaller.appspotmail.com, Anirudh Rayabharam , Jiri Kosina Subject: [PATCH 5.14 166/172] HID: usbhid: free raw_report buffers in usbhid_stop Date: Mon, 4 Oct 2021 14:53:36 +0200 Message-Id: <20211004125050.332477338@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@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: Anirudh Rayabharam commit f7744fa16b96da57187dc8e5634152d3b63d72de upstream. Free the unsent raw_report buffers when the device is removed. Fixes a memory leak reported by syzbot at: https://syzkaller.appspot.com/bug?id=7b4fa7cb1a7c2d3342a2a8a6c53371c8c418ab47 Reported-by: syzbot+47b26cd837ececfc666d@syzkaller.appspotmail.com Tested-by: syzbot+47b26cd837ececfc666d@syzkaller.appspotmail.com Signed-off-by: Anirudh Rayabharam Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/usbhid/hid-core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -505,7 +505,7 @@ static void hid_ctrl(struct urb *urb) if (unplug) { usbhid->ctrltail = usbhid->ctrlhead; - } else { + } else if (usbhid->ctrlhead != usbhid->ctrltail) { usbhid->ctrltail = (usbhid->ctrltail + 1) & (HID_CONTROL_FIFO_SIZE - 1); if (usbhid->ctrlhead != usbhid->ctrltail && @@ -1223,9 +1223,20 @@ static void usbhid_stop(struct hid_devic mutex_lock(&usbhid->mutex); clear_bit(HID_STARTED, &usbhid->iofl); + spin_lock_irq(&usbhid->lock); /* Sync with error and led handlers */ set_bit(HID_DISCONNECTED, &usbhid->iofl); + while (usbhid->ctrltail != usbhid->ctrlhead) { + if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_OUT) { + kfree(usbhid->ctrl[usbhid->ctrltail].raw_report); + usbhid->ctrl[usbhid->ctrltail].raw_report = NULL; + } + + usbhid->ctrltail = (usbhid->ctrltail + 1) & + (HID_CONTROL_FIFO_SIZE - 1); + } spin_unlock_irq(&usbhid->lock); + usb_kill_urb(usbhid->urbin); usb_kill_urb(usbhid->urbout); usb_kill_urb(usbhid->urbctrl);