Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3663277imu; Tue, 18 Dec 2018 02:01:43 -0800 (PST) X-Google-Smtp-Source: AFSGD/XoyskvIldbLI7pGGxY2888DEFu2uIAkJh6olCUEW7T+Fy0JR/WfYQkWOqIwn5HoKYm2mhb X-Received: by 2002:a63:9712:: with SMTP id n18mr15019392pge.295.1545127303047; Tue, 18 Dec 2018 02:01:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545127303; cv=none; d=google.com; s=arc-20160816; b=g5R22oNAU1gA7l3R98e5qzyJeR6I1tBK+jSEXw+GV65bdPJeVbfoM2uRfjGiqBniSV F97COKOH8Dlz9Z8L9SzEXxUkk4Uaas2/X+a5w9UbN7Dq4K3YcVBAzABC5DgTrMiK0ItY ysiKdeflz5iLy6OP+FytaNQjpIQHpchbk799qxc+ff5UNN7InyhIcW/NycERoc6bbE55 RkCNNSCn6X8an9yuqs4dsYnold0rpgz2vTiJx/+WalX1Yv+v/AEM55aXGM2GQGCt9EhE JpiyYb8BmItfOtf1FPYQ6Bukc3k/vK7AZVTjzAMp55EdLik3KC079n+mQTecPuRZLP+A O3vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=Bygy8q+B+26MqgPUBkfyodN9+lfiaRKsw0ThW9v2JQM=; b=VdASUVy3KfSri3c/JYCXza0fQ2kKXF7wo5vSxinw04ZFJ6mHYpzCyvMZ1amPBTI7Me cGSn/jMHifFLm0Lk0zoIN3Ii+MjRnFKuTUQytKkzOggkwcBuC0I1+yeNPEePjF3QuI0m CsfmjKN3hOD2v1pZHSyoqkWsj/ul4ddmIQMPHlqagc81EEbPX5hiqHFXmu+sspP6LnAE ZNKInDsud3T4uwiE8y+/yMK8MheSAhP18dLkAorxnPvWQq1wodCHLwTKEO/ygenyJbbS R0Yhybzjf6RaSCu5zNCendXDz5WUOnMCXsd1Peq0lnRPSEB6h+FEVHv07A5BWzcyjXau BiZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vPD66ggb; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q70si13185308pgq.526.2018.12.18.02.01.27; Tue, 18 Dec 2018 02:01:43 -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=@gmail.com header.s=20161025 header.b=vPD66ggb; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726438AbeLRKAa (ORCPT + 99 others); Tue, 18 Dec 2018 05:00:30 -0500 Received: from mail-io1-f68.google.com ([209.85.166.68]:40721 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726341AbeLRKAa (ORCPT ); Tue, 18 Dec 2018 05:00:30 -0500 Received: by mail-io1-f68.google.com with SMTP id v12so8690517iop.7; Tue, 18 Dec 2018 02:00:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Bygy8q+B+26MqgPUBkfyodN9+lfiaRKsw0ThW9v2JQM=; b=vPD66ggb0O+2Ymqvhuv9Z096lrbab0CMHY9LJDyQ5f/KO1g2ppMa2CUOcp+TF6RWrT DtwwzeJAplyabkbHTWkZou6FE45zqKMbYq3PBVZCMV1+sAHTfHDOo+/0dxnDK0Bajlnc SOhV9aYreBJik+89y5HQaTudgHdH4HIsm5cGYGac1tIBet2YfWe7FvxAQNYlqapC/NmT DNLL/Oq7VOY2LgtjGEG11Z4etfJ/ppfkPOQoyDApQcy04Xkkq6S4ESJwNl0kyU7NOto/ rAvEd787tVZYVbehdOYgQRptTOWzrpPotUsqcN8lU9pUzAE1EdB/LtfvVSB5OAxB/BGx V8hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Bygy8q+B+26MqgPUBkfyodN9+lfiaRKsw0ThW9v2JQM=; b=KukHuv0/D7V36d4HjlCLJudKX+0zda2FNkW2NbALRV4cYy34LrVHfeLkFjws+TaxsR rsUBOVqWo7dnVTNhVdqYU0Z2gW9bS6D4HTTT2gdNq/VTR53gy/NKkjm/7EdMafe2A51W 0u5GCVtKbXdAeWkIUtWsSN0b2/CS2dlkQidmSvMx7KlFfWDv7MoNNMURyUYoEh5x/pvQ djOe56INEJR/Igt0JAKsdDiejn7l6eae0TK2ZVFSP3tEZLLcfqO3j0xipilXBJhLICDx 1QPYLaZslbhMqNLRmdB6BJgMaD0qkUZB8rhHZ5I8s0oCzcqLeGBqhydK0O6UvoWVvLLs DKmA== X-Gm-Message-State: AA+aEWYugoPXlzYGCmrh3cMhg249zMaeYrGptMhlssqmLxsH4ViJNh1f 1SEmHQJYrvF+RDna/Tl3fgQ= X-Received: by 2002:a6b:1807:: with SMTP id 7mr13251090ioy.167.1545127229343; Tue, 18 Dec 2018 02:00:29 -0800 (PST) Received: from localhost.localdomain ([2402:f000:1:4414:3dd3:3693:8487:3f39]) by smtp.gmail.com with ESMTPSA id p21sm6557538ioh.25.2018.12.18.02.00.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 02:00:28 -0800 (PST) From: Jia-Ju Bai To: gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] r8a66597: Fix a possible concurrency use-after-free bug in r8a66597_endpoint_disable() Date: Tue, 18 Dec 2018 18:00:20 +0800 Message-Id: <20181218100020.26250-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); 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); -- 2.17.0