Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3529749imu; Mon, 7 Jan 2019 05:09:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN42KXWynnKKvzb/PCqZdd4r6XQAZv4h8o36DTUKZZDJyL3MXMGsxjFkkCc4Ngvn6ErfBnyN X-Received: by 2002:a17:902:2aa8:: with SMTP id j37mr5474207plb.226.1546866578999; Mon, 07 Jan 2019 05:09:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546866578; cv=none; d=google.com; s=arc-20160816; b=LdZRJrZhKD8NH5DSaS7mJWi3rmWGArOOoyauJKfmMXjog73WV8/myzI4/FEDQhXMlV ipbf52pLhrMF0BFQ6WyCqf4Pq85Y1blRXYlGOzMpFj5NePjaISKyduRS4TLleokNoRXr erU+cXDtIjSlyx4+KUyaGjwYDiZ7si7jAlgTgz8pjY6CL5XIRf/0MmmvgZZBc0Cph0Vw IkV1VzEDyeL2N//W01ALytc3adwpZwK/IwJwDod/PmHUl20EqpXt3eDVMgGR7dZVUPhC uTY07kRgAsC45u57RVQ3/9ZkaLWTD+hPC+59B0HlF05vQJV+8jTKJXNJ0WIrFKnbhM2W 0yew== 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=hxmCyLv6NQRnYaFrxdim9GL3ard3yJdqMVEPovpJKik=; b=0JWFy5tqFa4RaXgcKzQ9Mi138AV2HYdzHn6UjzSlLyDQ3lYUMa/QOUfz0532JlwrJv P3FW6zgOOGFLDhuIt/pq54yd5cU44ut9HUCOIxLurS4uNhipVSxkve8x0bZMw+TN2baO NX9a/ePHiwUPhXPcHD3l47OWcbn3Bbd0XDcpvZyzIUsTsOVr/nltdieYmKZCo6Znvm/Y idIo0Aiafzz3u4hOPrYizHEMjzYn8rRRJHsoO2xja3do1K0I0ihNB3Cc/ItrbumeZxfw Md1Sz5JnTmc4ysWuUHNoKGlqAPKL/f6FT2b60uiDVdTdnNtxixfCE8XZH7AuCpMCUgMY 5MYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gn+dSs7v; 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 p14si7963745plq.25.2019.01.07.05.09.24; Mon, 07 Jan 2019 05:09:38 -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=gn+dSs7v; 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 S1730669AbfAGNHd (ORCPT + 99 others); Mon, 7 Jan 2019 08:07:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:54610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728767AbfAGNHb (ORCPT ); Mon, 7 Jan 2019 08:07: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 82ED82089F; Mon, 7 Jan 2019 13:07:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546866451; bh=xBr8sgGJYQfmCpA4aq3hsKRv7z4GjOYGa3wSWgdJeiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gn+dSs7vaalabljO2K8bAgg3rf5JITRPs6uiG3zZmZR7GPg3AxMZUTVwj4mGvdMrG hmIYYxDi+kF5TACWHyYJQyGeilUVJaQNaxBDkjXjqNs5YU/4u87l4zbCEYKBF3/HZq XxRCMffiq5HFHlk5T0DHdF+CItvkogJ/hbhxZnLY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jia-Ju Bai Subject: [PATCH 4.9 39/71] usb: r8a66597: Fix a possible concurrency use-after-free bug in r8a66597_endpoint_disable() Date: Mon, 7 Jan 2019 13:33:08 +0100 Message-Id: <20190107105335.000970670@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107105330.280153213@linuxfoundation.org> References: <20190107105330.280153213@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.9-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 @@ -1990,6 +1990,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; @@ -2002,13 +2004,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);