Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3512655imu; Mon, 7 Jan 2019 04:53:13 -0800 (PST) X-Google-Smtp-Source: ALg8bN5ADWNxFahkJ46sMfg7kxEi78otW/WBbB1pMVunnBiu/ApsZQti25NJjFhu+uFWhEfEFuiv X-Received: by 2002:a63:bd1a:: with SMTP id a26mr10679960pgf.121.1546865593590; Mon, 07 Jan 2019 04:53:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546865593; cv=none; d=google.com; s=arc-20160816; b=ng6X4SlcACSqZZKqfnMpkYolzylBeokbLkuRt5yQt5dDSMxKrgCC+DPNHkeguRnQ1M qh+UtRsxm+b/81T2lUvxD2ozDCF7vnTXlFcS58T2KbUo1zrZhru9+TLPe7DN5wgxp4o2 mRGNDBJu/59WMhVIC0+iS4vQ0jcOliMe/tYxBx6XuMY8+Zyw0xeBPnWDFXbiyaez2u7U PVtHtYaui6sHR+vH8aETZteYmQ/0hN7gyYcB9q28i0Cj6QTRdzgcOFFTJJS+dvRDZ8uH edu93bbxnr7NvhIbQel+jw5SYIkCT1xBBLJaoP9L6biTABdXA/AySB9NDNg4PobTULek rrEg== 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=HtUiNX5XIu/KSwJLVm9XHVRoJ20qQFID1a2F6/6p94I=; b=jb7Q+EJN4P5B7o9w+Z/fAGiMrLFpd64Oxxq0GcBCo+SVoRpLpZB8i3WpQ63NsHKUaP hSjzsVxY2C1bQDt9ipjyFZS/slsritGi28mFumUUV8wW98a6qjnW4KfJ/hdl2FqDb2qV xVvN+4Cfv9NNDUtZpAHhbIwYYKynxnfSs6rXWqRnw3x3lj/wIvRnPTGrQrfJD6JKKefm xwt5q7KHDJJMk0VqXjB2SW6San8vtVUraT5ruydl7Z5ywzGvaFfmJEl42734086j2urE 4b/UpDofu2KgvEGhGVV3fIyctICk6JW2N4OuYQ2NpOfBzdDAIKhIHQRizuJMSjqN+HrK bTUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yddmBd8s; 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 x8si59133482pll.187.2019.01.07.04.52.58; Mon, 07 Jan 2019 04:53:13 -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=yddmBd8s; 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 S1729325AbfAGMuY (ORCPT + 99 others); Mon, 7 Jan 2019 07:50:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:40926 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728495AbfAGMuY (ORCPT ); Mon, 7 Jan 2019 07:50:24 -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 ACFEF218A3; Mon, 7 Jan 2019 12:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546865423; bh=ntrVVlzpWh2l/M123MeiJXw6BOHo2xcZQtQ4NuZFgh4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yddmBd8sKXA0IpjYzhFovMFbxkrGX1wwsnIPUiP5Hj76OnimsQ6L0Um2h689EjIzR qrdot6quLrnHQyx/sNI1Yb9XJmJRA3K9NBiZMcQ6ssF6AEsHWbPDEA1WdaV7traHaw mKvAZqx7Knj022PyEvIJKnOO0fJW0fDpvxZxhpAc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jia-Ju Bai Subject: [PATCH 4.19 079/170] usb: r8a66597: Fix a possible concurrency use-after-free bug in r8a66597_endpoint_disable() Date: Mon, 7 Jan 2019 13:31:46 +0100 Message-Id: <20190107104502.395920429@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107104452.953560660@linuxfoundation.org> References: <20190107104452.953560660@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.19-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);