Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3922939pxb; Mon, 4 Oct 2021 12:44:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiOseI7YWTklXa5HG8bA5hpG/r3YTttpMIXCrO7KiWAOI8WFDHmGTfYs2rw2U43B/rtO2r X-Received: by 2002:aa7:dcca:: with SMTP id w10mr3941755edu.113.1633376656599; Mon, 04 Oct 2021 12:44:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633376656; cv=none; d=google.com; s=arc-20160816; b=Cg2Ucf2cajXQZz/yJ+eAyF9J8itTbAZsrj08Vdcb4dcCvWokvaAmezAm/s7ep91qqn xzE3rMQj05eadiISpnB3zZZFplsMeL+fRry/+5I64izEDA55Isn4LjLdz5nvTuCr6DwF ksaX07nelfq+Q0FcOnVAVvpgyC/XMGTYPu2sxK+K65jLpED9rpmcKv8BRNKzHVce/o8o a0Vety8JmhftkzrACo0CtXuA30CmhoxeLs0QY1fSTfqfLKf6M7WpbJufb4B1PlEj0Rzs oCLlqYlv02cxKs6pV1O/IlS0NKH4u5GrJP6lo5cNth1b7KuQOOV27ga/I6AGo/VDmxG6 +uRQ== 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=BDHJ3zBBSSCyNrbTodY5EnZ9Pr5ngFsFvjVqRXoA57U=; b=I3hY565yr+I2AHD8yP3VCrV25EqqQYm+fUi4jDYUgwv6kdo20OXO2YJCr2ixOb3aLl FCuClW1CusQZcL0e7clBvxO6eYbpVmZBK2EYLlfQI/DUgX/EC5gsuT+dwA7J1M2dG6zl PMMvRT9l/ZzjeWxsxrncFsNXdSmDmYUuJVKC+rBURHtaEQXfj+6XI0/k128oHpzGalNv DejagC7yBhQJ5ZQUBz9Hk/wtyN5KC+cL42gUf5DpkfZbBE09CASRQTi/adRDou7ras9e 4NOsQRCIqZv7vPOZ8KIOlWdQuiKPrTQ7JHDT3aEvpc8jeDbiFtpVmtlzVWvL5UtUaFFh eTEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NTqDGqoe; 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 hq6si29148503ejc.558.2021.10.04.12.43.53; Mon, 04 Oct 2021 12:44:16 -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=NTqDGqoe; 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 S235300AbhJDNJJ (ORCPT + 99 others); Mon, 4 Oct 2021 09:09:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:39242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235307AbhJDNGr (ORCPT ); Mon, 4 Oct 2021 09:06:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 474CD613AC; Mon, 4 Oct 2021 13:01:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633352485; bh=PaS8DXTucc4XRnztat11GNzIWcUA1B1MLeSoIEYNxDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NTqDGqoei4mS61gEbSbvUG9fzH9hc0YP3qrY6+PzP8FUjDKu+h2R2vifXkcFbPzNT K08AXdQbLaKcFZ4AFkkhfOD+00gKJCbb9Ppv/TIChVf+EKOEkpNDi3h0omZ8XbYqUZ WrrJaSiHHmv3bD5w9iJZg3Bm/ehi9NcvIVzKtfQM= 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 4.14 74/75] HID: usbhid: free raw_report buffers in usbhid_stop Date: Mon, 4 Oct 2021 14:52:49 +0200 Message-Id: <20211004125034.017930999@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125031.530773667@linuxfoundation.org> References: <20211004125031.530773667@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 @@ -501,7 +501,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 && @@ -1214,9 +1214,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);