Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1013564pxb; Thu, 9 Sep 2021 18:01:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnqy1r/prHVxlCKg0rYchMcecnjoP/vBVKaRad8JTvTyeDTqoJaSAoY3DElsbPRuJ5inqI X-Received: by 2002:a05:6402:4311:: with SMTP id m17mr6056220edc.188.1631235663103; Thu, 09 Sep 2021 18:01:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631235663; cv=none; d=google.com; s=arc-20160816; b=nWtFnGEO7NzgMgqzzoaMVT2jxyZSCGnO17TCItF8k1eqNR3wVeU72arHJzvqJhZwjx hYbV5aar9w2VOZTrHvszW6yAxAKB9injRp6CAtGlg4ILh9JjZaF9Eb7nZMSkD6QV9wHy 0BMdhskWvTvq8PE8AxlQZdnpk9cVvD2nHzX2gJs4AB/b2qSyDX//DjSg9kdpQ0bEQMZW 28n9UVaFAWquFFSLAUvjcY9Xef8x0zb1aCkskfVSdN6M1Vexk00GKPaT7ZA11uJjn0yp 2tcdjDumhxFqvampweEAVXUYLmeIOkSPY/DkbLidd0PT1lwKhQ0d1CVE7KwRQ9/5LElZ S7EQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uxr94PPS4VPGmyR8vrQsQe+nfgCPbFrr9FmBZPyjXKs=; b=ZJ+mbu2Zwx49iMHRj0/reuvVm+bi6aWUPt1LItkGMpiau3JByCu0w0In6m49aYBqHF HJMlTLU5o+9zUTdk4VqAaMjqREkV83RRXCLoTYOdoMXjNKcDiQbPoU42Dbs+2313jhNR 7OpPoY6dJ99Gr7WOkC1I/APjqq7CvsuizuJ7cDdimeDVgJUBU1HS9umNBqI/JXsB//4p q2gjNNrniscJk6oXs2y3AugNke6kqVKP+Y2mC+sqV4eh0aQg6/EpnpPYItcfBCAUC6pf 50cUNVT4+m3Uhp9GIL6QcOUCP7sXrUVScoFutfo7joXD/80bjFIiXVDb7nBKHZCkgELu r2pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jD595yWX; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g9si3666985edp.88.2021.09.09.18.00.38; Thu, 09 Sep 2021 18:01:03 -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=@kernel.org header.s=k20201202 header.b=jD595yWX; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244407AbhIJA7b (ORCPT + 99 others); Thu, 9 Sep 2021 20:59:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:48616 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234266AbhIJAXE (ORCPT ); Thu, 9 Sep 2021 20:23:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D16026058D; Fri, 10 Sep 2021 00:21:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631233314; bh=qm+zJIDqg6LmllmM+B/hpGId9tdsJP52WsSqQ+S+tKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jD595yWX8Hiqr5Fx+RKBZ7JKvEKAg104AYGPEiyVCj0E3+Whp0DpstjeFxywU32Vw 8nbLCuGla+EAnUVP6NS5GOdr+5xw2zJCbDnheEaYNbbA3zmOvQ5Z/cxjr0Xj3ZDW4y bR8XAe3JqMMsW/rvIgRDAviKL9to2MY/HQScNioW/HL8T89b1sFPvIRmXO7Kaezlmm Epk9kCa9G9I2xX/1QgcCKzDWsXcXXYWhgl/xVgZ6q7L4TL4XSVPupweGTr1IG+T/Hb 8KSHQ7VQrGBtdWPavWUNFtMYFZhQv4MRaubDCkcPJepK4BfWmoi8+QZrVcW/kEG+a7 ulb+mx9JWcOnA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Anirudh Rayabharam , syzbot+47b26cd837ececfc666d@syzkaller.appspotmail.com, Jiri Kosina , Sasha Levin , linux-usb@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 08/37] HID: usbhid: free raw_report buffers in usbhid_stop Date: Thu, 9 Sep 2021 20:21:13 -0400 Message-Id: <20210910002143.175731-8-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210910002143.175731-1-sashal@kernel.org> References: <20210910002143.175731-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anirudh Rayabharam [ Upstream commit f7744fa16b96da57187dc8e5634152d3b63d72de ] 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: Sasha Levin --- drivers/hid/usbhid/hid-core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 1cfbbaf6901d..8537fcdb456d 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -503,7 +503,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 && @@ -1221,9 +1221,20 @@ static void usbhid_stop(struct hid_device *hid) 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); -- 2.30.2