Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp631443imu; Fri, 11 Jan 2019 06:30:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN4jR5KxwalLO9z5KOz0yUTCA4Q0EIisX0B120XovCl5gs+qa+qrFKlrxTQ9mDdN4EuSwYpo X-Received: by 2002:a17:902:43e4:: with SMTP id j91mr4297327pld.147.1547217028395; Fri, 11 Jan 2019 06:30:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547217028; cv=none; d=google.com; s=arc-20160816; b=zSghNNQRgqQk63u6u8cmkhWEW+p6hYx3M9JPkGtdqeXvD1abhmreulZou54Dha46zE ODy2LxMYQQ3HkRYpsjZs5Kz9UFIJ3sbcEXJJE5VekZIAGTsvyReNj3BsEwfmsFROqi0+ jdXU94fy73L2pFnvwoLVS3vD7El/PTIiJMaznkgkKraeJaGzIEPbSIKAoSVwnT9PX+n7 +l9vMqq2HTpoF58dR5rEx/mUbXL66j9BRTA6NU9YJJHjIgwe8NVXrbQJyFUnfsg3vkNN UAAF6KrN9IPpHtFjs2U+pbWSby1TRnNkJ4gwPVxmO9jofgyirxe9jGbitCTYET1ExyL5 MkHw== 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=IMzvuVu5R4LIfvNZHW/8oPW0d6/BuUiqCTDV0aYwkfI=; b=JhyebE4xfAnSlmqMO9cl5RpUFiy71gq39buo0IHdpdbdxZiJDKMtTxraubZzTXe45o juMRbbQqz/rq6gv3zIEcC0DdFhq2FPLyCzzM0oxtpQmj75jR6fDd9d/O9/38UMv6VkSK GoFEIlNhx08rm/DOCsyegdj6nyY4Bxc2Ddf7+ewIQgY/Ebq8bSHYK0DC2OQNtvYQQjdM DoxhlLehMe2NGIXJLxFQYWvsvw6zhxNVjKH8vsZ0jGLqwMQXumJJ2mX2AP7CIWFFFK/h DWQHfDvDhPLbuM0h/ndVbuaLnMDd/27RNUvfU5OHrMtwq+bbwZhTDAe6ko6LEyg3DkQh iG7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="nH/C4oEi"; 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 c24si74013977pgk.269.2019.01.11.06.30.13; Fri, 11 Jan 2019 06:30:28 -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="nH/C4oEi"; 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 S1731202AbfAKOR7 (ORCPT + 99 others); Fri, 11 Jan 2019 09:17:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:34328 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387926AbfAKOR4 (ORCPT ); Fri, 11 Jan 2019 09:17:56 -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 C24352177B; Fri, 11 Jan 2019 14:17:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547216275; bh=6cwYZmWQgk+SgoL6guhbO5WdJx/kxbdjXjKBbHrnlZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nH/C4oEiR6avvzLodsMApqlnLOo1LTij8070Kz2RTpBI+SuOVTit3jhkOM/CP2twG /+jpxicUA+VNq6NIydaZfHfTzhKeSTn1fxEe6Dk4KWne7DTsQ4rtkne0ZF+7FH/RLD avP8kPvATDaLB6gt7RI+owh8GtOZ/98UURZ4SmDQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jia-Ju Bai Subject: [PATCH 4.4 38/88] usb: r8a66597: Fix a possible concurrency use-after-free bug in r8a66597_endpoint_disable() Date: Fri, 11 Jan 2019 15:08:07 +0100 Message-Id: <20190111131051.526008588@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111131045.137499039@linuxfoundation.org> References: <20190111131045.137499039@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.4-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);