Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp645905ybh; Tue, 10 Mar 2020 05:47:35 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsFecKzDPDvI1OC8etqOOEFn9afWIRvuRhBWcLf5MEZ7KpMyzHQ/CAva6To+X8nd+9+6HMt X-Received: by 2002:a05:6830:23b6:: with SMTP id m22mr11255417ots.225.1583844454862; Tue, 10 Mar 2020 05:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583844454; cv=none; d=google.com; s=arc-20160816; b=FsHjMhRyp8Cu1YC03SGXc7sluLdU7ZDa6Gw2CxDbkRG5YyNe7dgbwFUea0YVheVrfK mgjGDm7/1lcBX3+Cgc4FSQqD44dGRXsWXLChT6sqYCDiJmbn4hclFIWmYZznLOy5HPQx 7HJle5q0Fz8VpfBgoTco7BImLJnnD+PCH5gv+8yU+TLV5yzNehJdWJgXbTLOhoG+222K BiEWvugb/63VuvpxCMCqunoy8AJs17nU6IazKzoIUmB7dDCpH7HlNftJEfdw/ij3GCec FzhETn4+gBavt26LzXLZP+AOpBTDqX3kidDIaYYBbNQHSqhptPmUsERcY4OFlTuiZRwh VLUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=U+DGIqxRlvmL2c7xK1CCcH0qszSMqioA1Fs8jqoaekc=; b=ehXfcR76I4wKlts9Z57VxzcuyQnkLya0+jaRBsFXFv3G9utzDzN+x+nF56h8S/a73y JOLsZ27SRsjv+1Q6RPTdIXiYEqgWYAj5za+me8gJyN4BfD9qkcElLr9yyF5lYpwgcrkg I8cSFpHnbah+XILF3ZAGGP4kw0VdA9myU9grzsgnWoQlGbtHU2t+0bnMJRSzjj6rF+Cc pqtx50eKDXrdVfXO74bMFBgWPMmHspCdnXdg/8BSoZ9yfPs60erIWHfZw2GIxvnysUCE 5H94nlQj7AeSy4++Wl280HCgrSSUGT4KHLWjoEigkGsmjHGQszok52bDA0gQ+vBtwmzC mGhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JBpNMpWH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v1si1205653otj.204.2020.03.10.05.47.22; Tue, 10 Mar 2020 05:47:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JBpNMpWH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728039AbgCJMqg (ORCPT + 99 others); Tue, 10 Mar 2020 08:46:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:49624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727821AbgCJMqY (ORCPT ); Tue, 10 Mar 2020 08:46:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 598A02467D; Tue, 10 Mar 2020 12:46:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583844383; bh=k+hGJZYSyfR7ivL/m9ThcSWN/LBHQZfZdVkxeHyYmkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JBpNMpWHYySXFMFjv3vCJzRlBS8+nxFiwzlLsj3DpZnpZSeXJlgkWyp+oiP9a2Lzk /sEwvJGKGU3CZ8xn7H3Ms252MuvmmJGRHG9bAynQQ5xUKo+8M2WDl55A7tf35CNZJb Cah04Tm0rncmQkki7i1OYiZnjjmUziFFb3XADWto= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+784ccb935f9900cc7c9e@syzkaller.appspotmail.com, Alan Stern , Dan Carpenter , Jiri Kosina Subject: [PATCH 4.9 34/88] HID: hiddev: Fix race in in hiddev_disconnect() Date: Tue, 10 Mar 2020 13:38:42 +0100 Message-Id: <20200310123614.195198369@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310123606.543939933@linuxfoundation.org> References: <20200310123606.543939933@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: dan.carpenter@oracle.com commit 5c02c447eaeda29d3da121a2e17b97ccaf579b51 upstream. Syzbot reports that "hiddev" is used after it's free in hiddev_disconnect(). The hiddev_disconnect() function sets "hiddev->exist = 0;" so hiddev_release() can free it as soon as we drop the "existancelock" lock. This patch moves the mutex_unlock(&hiddev->existancelock) until after we have finished using it. Reported-by: syzbot+784ccb935f9900cc7c9e@syzkaller.appspotmail.com Fixes: 7f77897ef2b6 ("HID: hiddev: fix potential use-after-free") Suggested-by: Alan Stern Signed-off-by: Dan Carpenter Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/usbhid/hiddev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/hid/usbhid/hiddev.c +++ b/drivers/hid/usbhid/hiddev.c @@ -962,9 +962,9 @@ void hiddev_disconnect(struct hid_device hiddev->exist = 0; if (hiddev->open) { - mutex_unlock(&hiddev->existancelock); usbhid_close(hiddev->hid); wake_up_interruptible(&hiddev->wait); + mutex_unlock(&hiddev->existancelock); } else { mutex_unlock(&hiddev->existancelock); kfree(hiddev);