Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp847880imu; Fri, 11 Jan 2019 10:04:49 -0800 (PST) X-Google-Smtp-Source: ALg8bN6mZML+Ns1EwS0TaDQ/wXCDCsVC1Dq+Zs5haTbX6sVzBibPKqZKi9zCEKSYMoaJBb8Y22XA X-Received: by 2002:a17:902:12b:: with SMTP id 40mr15338054plb.72.1547229889102; Fri, 11 Jan 2019 10:04:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547229889; cv=none; d=google.com; s=arc-20160816; b=FV9YeVM4LkMwzGvfQJb4h6NDcP/40yNHDXy/HUYXilSJgCpqGFDXekzyBSggi+enfy k8wSU/d/ZMKqRI+76Azjvh5o9se+kEqTMZ8e9/1KA5m0a7d+2VJYc+/+6pFrekv75VAL c6vxBAGxQew0q5ym96ErY/gAooJDeRb6tFfbtC79zLokmO0Ya4i2PtwOssL/W5SMRF3m QvgfBbSMeP/xJy94iTKdTMmXyICY7iwYWhaqCafyVIuWLksUHdWXIzlLJyKR/9OyKr2B ni3sCOAIgCVo1wR6/67WTiKSiHZfVFFtdzNraedYSyriSthWba8LJ94uHqBnj3ZJ4EvP 3SvQ== 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=I1Q8VlSSiZ3HpBFLm9gg/H8a5G6kh2UMyzzHhv6UW8A=; b=QRHIgKUgVsQ8O2/EzuBg8BuK2JtDGfRe6IWZF7iqPk58KN74WSNRtRbFVigotBsvkM pAI8DqHDk7wCOePOB3CsQLzwN3HDnNhzpr8gpqRmYiKDTj2kNZszYRUt9Ahjf5t3zNYq m3luJgLcq9yQlO4zclCSnqk7xS+Hi9qN+MOosk7r/vmWJeSihMqcdpeCrili02o8c6go ZHc35X0bEU/xqvZ8pZlTbm9LXIlcWxLCjo4kDh6OU8FU/K1HJL5DDo/kHQyuu05g8kuF jLx9so96EYLd8FBGObheIfhBmvGNZT5lPXUXz/yfZpONERxlWtGfR+m0H5I9+CgdoHPL ZGMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RoWyqvT8; 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 r12si12087225pgl.350.2019.01.11.10.04.33; Fri, 11 Jan 2019 10:04:49 -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=RoWyqvT8; 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 S1733185AbfAKOPB (ORCPT + 99 others); Fri, 11 Jan 2019 09:15:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:58922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732147AbfAKOO6 (ORCPT ); Fri, 11 Jan 2019 09:14:58 -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 5F74F2183F; Fri, 11 Jan 2019 14:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547216097; bh=vGgYQhPF1YxlepAPJrgQ564x2GsAUr73OJqZPnT7iiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RoWyqvT8oqzFCWENMLIOVePqtbVcdHePa4ywx761NNUhcf9yedc2NDDFN9pGxGznL 1hbrPRB1ZSmm9I0AZERlGR++vfFFkQ8T9ndAsChKGHWNuaJT0BfuEI9H/twRrootYK 6su1koNvRrmuFYaowgMGoTEa5OF1vpQ2UNoUK1M0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jia-Ju Bai Subject: [PATCH 3.18 21/47] usb: r8a66597: Fix a possible concurrency use-after-free bug in r8a66597_endpoint_disable() Date: Fri, 11 Jan 2019 15:08:06 +0100 Message-Id: <20190111130958.840855386@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111130956.170952125@linuxfoundation.org> References: <20190111130956.170952125@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 3.18-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);