Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3499869imu; Mon, 7 Jan 2019 04:38:07 -0800 (PST) X-Google-Smtp-Source: ALg8bN6uJCkOX4vNcgtVgrqt4zo1SBlnusvFs6QSEeR5RQ4/yuPxxhT+Wa+1qTdBioyfHFM+ny6Q X-Received: by 2002:a17:902:a40f:: with SMTP id p15mr62591936plq.286.1546864687775; Mon, 07 Jan 2019 04:38:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546864687; cv=none; d=google.com; s=arc-20160816; b=bztSaVznWJs9ZMKoNMndbQ9E4LZY5Y4jK4pTUAE+N5OooBdYgPoYQBUN9TZRFiBp5y cfJN3hxZsn7jckQL02nS65NaN7fWqIFdnU88yDV9VjLjUKSDgxCRH3F6jZE8yA/SXn0D Fv0iFISn+P7pIo6kopE6FNewGHEyfD4SU+0O9+g+lHwnd6wEy9NVSuj5S2osgASmdTmA 5HM6ooUdo7eYKhMrpozHMKxzXrt03LdjdOdmfLdEYDKCJmHDTK2KDRNmjL4mVyQQQ7Jm RdWuPYMR5pzLnGM2SNSd+nXLcUBc+EYR3clqCroweS340+LTQ/qPWrtIuFlBx7Bw3Pqj MY3Q== 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=r8H3tulyPamdVaAHsfNlPrHfFDXp/yIwFn7ijy4icL8=; b=r5ZoFSSmZ/NL7VtZgRqFOJw0HAx57SaYoYbS9cM93kYo9zl2wTiNWrtEmxvGPCNAnY upqk3C/WrgpVuzhc/uPa8ABVELdzxOoPgoLW2tYM5iiHfqyJpfFtbNFQ8RY7r7RDhk5v Qm2OyfRLA5SGxIaI44Y2YP6MY+skzmcCvg6RfHB01ws/BBh57sgSe0fXz8Gc5qs+F+Yg Mqj4Lw5NzOfM3ciJHpjgaATrSxG/kOPbLptYYDe8o8qViJ9oJWmvVhH5oKPY+MDER4y4 xx1MSUq6Uvdx5Icu+TonJGwYEu+NruXmW2uQvjYl0sVc0sfLfzIKYL0haoIMuhnQ3TR0 gHKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iRRGiO0Z; 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 189si13526281pfd.142.2019.01.07.04.37.52; Mon, 07 Jan 2019 04:38:07 -0800 (PST) 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=iRRGiO0Z; 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 S1727567AbfAGMfd (ORCPT + 99 others); Mon, 7 Jan 2019 07:35:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:49390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727523AbfAGMfb (ORCPT ); Mon, 7 Jan 2019 07:35:31 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 27E012173C; Mon, 7 Jan 2019 12:35:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546864530; bh=SLTjktUVA2GojJfTEVdPb0k/D5V8qLPXenVIL++++Go=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iRRGiO0Z7YvgYXGScwcawpuVMaNz6JVHdlvO03bNKQVJckNIRIa0Qo0bMtK1+E/Md sehFvd2QcKvtW1T/+rBmWVAG4yLG3UJQGbKpbSj78KUDoVLz1oK/CRmPutrqcT3lV1 4RAqT971QbWeu4oLWdRNqrinXQsN+4cv90MEX8Ls= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jia-Ju Bai Subject: [PATCH 4.20 041/145] usb: r8a66597: Fix a possible concurrency use-after-free bug in r8a66597_endpoint_disable() Date: Mon, 7 Jan 2019 13:31:18 +0100 Message-Id: <20190107104442.682511840@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107104437.308206189@linuxfoundation.org> References: <20190107104437.308206189@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jia-Ju Bai commit c85400f886e3d41e69966470879f635a2b50084c upstream. The function r8a66597_endpoint_disable() and r8a66597_urb_enqueue() may be concurrently executed. The two functions both access a possible shared variable "hep->hcpriv". This shared variable is freed by r8a66597_endpoint_disable() via the call path: r8a66597_endpoint_disable kfree(hep->hcpriv) (line 1995 in Linux-4.19) This variable is read by r8a66597_urb_enqueue() via the call path: r8a66597_urb_enqueue spin_lock_irqsave(&r8a66597->lock) init_pipe_info enable_r8a66597_pipe pipe = hep->hcpriv (line 802 in Linux-4.19) The read operation is protected by a spinlock, but the free operation is not protected by this spinlock, thus a concurrency use-after-free bug may occur. To fix this bug, the spin-lock and spin-unlock function calls in r8a66597_endpoint_disable() are moved to protect the free operation. Signed-off-by: Jia-Ju Bai Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/r8a66597-hcd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/drivers/usb/host/r8a66597-hcd.c +++ b/drivers/usb/host/r8a66597-hcd.c @@ -1979,6 +1979,8 @@ static int r8a66597_urb_dequeue(struct u static void r8a66597_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep) +__acquires(r8a66597->lock) +__releases(r8a66597->lock) { struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); struct r8a66597_pipe *pipe = (struct r8a66597_pipe *)hep->hcpriv; @@ -1991,13 +1993,14 @@ static void r8a66597_endpoint_disable(st return; pipenum = pipe->info.pipenum; + spin_lock_irqsave(&r8a66597->lock, flags); if (pipenum == 0) { kfree(hep->hcpriv); hep->hcpriv = NULL; + spin_unlock_irqrestore(&r8a66597->lock, flags); return; } - spin_lock_irqsave(&r8a66597->lock, flags); pipe_stop(r8a66597, pipe); pipe_irq_disable(r8a66597, pipenum); disable_irq_empty(r8a66597, pipenum);