Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3728205imu; Tue, 18 Dec 2018 03:15:05 -0800 (PST) X-Google-Smtp-Source: AFSGD/WKxyxfjigECuyn4livYNPEyF2/RhJzIXTTEy8mDOUTU7EHsLqa9to1YJZpe/0m9XluRst5 X-Received: by 2002:a62:546:: with SMTP id 67mr15835264pff.99.1545131705802; Tue, 18 Dec 2018 03:15:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545131705; cv=none; d=google.com; s=arc-20160816; b=JYyhjD4lVTRTBcctjULWpVjl0hMOW6YNrBrpbd9YPnDhIaJThW+a42HQwtLFsk61go G24KfK7FCdRlJnLMU8CGsbRoM2UycqJTqIywOnYcObjgbIf2wyMrqIcXDuTGzLudfuWB WKamrhRVD8AlmqO3LR/OU6JHuLnkWiEnibxGWMjeOIYdz0Q2Ct5B1VvuNwCBCIRlUaD5 biCL1dnpNYbG4w86xiCyWPSKSiRTfQFLuOQK8E9desM8bNl3o+0NtMVBZeDqpNTItsh3 Rz5PRtey3p0CL6LLFHyUDpzbcSJaD567wRfgsBnx1usae3mCd466MVZpQ4XEM4utYw8o 3VYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hko32p5OOnZmKxTA6Yx7nrZvfVUjzW29onw16DkzqgU=; b=aj9R4h4FOhLKKLzNSJlojW5kzRF/lDJK5lK2mLh4nEXfM4AmX/7m/kEvNWHR3pD78Q z2/TlDdfTYjUkQvOcK4Cgjccw9Os9TH55uQfJGIVGeZO31kqWjpF0w912pIW0e1rMvgr +SeaYF9AWEjO9ztZUMG8xrlbK5nTq5SeOYoAUFwO0HeNVtBVaf26TCvxQy/TtNeD2TAo cGcIbPS2eOI4K2gPJ80mdvHgIaTak12n/lMzPlfAPi+EN0XQ6dNBwwNiPgyvRITYQcpm AR+ALPrJQqjFRfBLQuoNNV1KyRDGmDd+DBERhk/p2WmAKgnj93+fEESnLAwkR2MPI5Dh 14JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="nwLW9/TR"; 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 c5si12890101pgq.434.2018.12.18.03.14.50; Tue, 18 Dec 2018 03:15:05 -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="nwLW9/TR"; 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 S1726536AbeLRLLx (ORCPT + 99 others); Tue, 18 Dec 2018 06:11:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:52350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726341AbeLRLLw (ORCPT ); Tue, 18 Dec 2018 06:11:52 -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 894652184C; Tue, 18 Dec 2018 11:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545131512; bh=xU+tvzQlXqSCsQ2lxQTIc4gTZWJ+tfh7mNnYBB0EEPY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nwLW9/TR+UsczpbCs2Lfubp5yymukaxGjlRByNvSvMQvt18+e9tmoeBhpejRQObuJ wC+vFoCl+Tofs0HkilJc1cEaMUcY79aBhZlXytis4nLt9oQGJAp/Ko7aNYxsER3IAQ Vc1tGda53CvWhfLb1SNq9ZV7RSa5QAMLZLC+E00U= Date: Tue, 18 Dec 2018 12:11:49 +0100 From: Greg KH To: Jia-Ju Bai Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] r8a66597: Fix a possible concurrency use-after-free bug in r8a66597_endpoint_disable() Message-ID: <20181218111149.GA979@kroah.com> References: <20181218100020.26250-1-baijiaju1990@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181218100020.26250-1-baijiaju1990@gmail.com> User-Agent: Mutt/1.11.1 (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 18, 2018 at 06:00:20PM +0800, Jia-Ju Bai wrote: > 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 > --- > drivers/usb/host/r8a66597-hcd.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c > index 984892dd72f5..1495ce14ad22 100644 > --- a/drivers/usb/host/r8a66597-hcd.c > +++ b/drivers/usb/host/r8a66597-hcd.c > @@ -1991,13 +1991,14 @@ static void r8a66597_endpoint_disable(struct usb_hcd *hcd, > return; > pipenum = pipe->info.pipenum; > > + spin_lock_irqsave(&r8a66597->lock, flags); Don't you also need the __aquires/__releases markings on this function in order to properly annotate it, like the rest of the driver has? Otherwise this seems to look good to me. thanks, greg k-h