Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp915797pxb; Wed, 1 Sep 2021 12:35:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyME3zXS5QrTp8gFlIikd+xDztJUTMZvOWJlU0rhHOtL53WMulL2S/uhi2ZLgbqHh5FrYMH X-Received: by 2002:a02:1dc9:: with SMTP id 192mr1070997jaj.92.1630524949440; Wed, 01 Sep 2021 12:35:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630524949; cv=none; d=google.com; s=arc-20160816; b=GLy+HFN1p0WiTGvYzgTAQGUK7zp4Y1t2PDT4w8C7TEWxt9aZYHcxxyRxj2/KwFnGaq 21YtKiK2CJy+G4+7bWG0gL6e6epedn13SxJ73TpL8UVfj4/UJJQd7i6aKd/jZ1CBvVxz ObpPuBOeOZLfNKH/COFgfHrlVwAkRh96XQTDOcCLdX3Q/ym/PMguxo2TjRu31fSRpuzH g5rNXEAvI659uXCY2OVMlhqxKy6wI6W31pcJCHAIF7ek0Wr8P9XDitbZKXBOGAxdz+Qk nkt2t2IF0IY2GMWVzaEm93G3UEFwn731YRg1evqO5i5144FU/VhVOpjJo6+UzGq7LpI7 umUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aYxuaaTErQMSGtdY2D9LDRphOGOu6EmOqwajXXVAGqc=; b=TaQXsOUOji6aTMJhU3vs6jH5/N/AUtaq1VS7BrcfOFmH8nzfRD4XQIeppdCOLsqN5N 0f5LhNn5pGeqcvdsWlfY4IgDyOjmwHwlGIbz0q2cSEAhsWoUYtSs3TaEghs7I0GRjBL6 Kn+nPlWKaqAZ0kl3uP6bkk5WipIs+lWNasR/9GmGsVV/scbe4/aNu0MoRKCWW8BubFBq bX4isFAQQLyFWK1ATg1BYxcAIHOnB/MkBOwME0bHuw11Z7gCj8XhaYZd25BesPQDUY6t SQyvqkxibIeAHCY5p/b96/Wb1fk2VcNo4TIkRtXgIbyQtLie+hTkZO5KlUbkWgTNmNUO JzqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rp2xnDC5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p4si341526jam.67.2021.09.01.12.35.38; Wed, 01 Sep 2021 12:35:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rp2xnDC5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344531AbhIAMmU (ORCPT + 99 others); Wed, 1 Sep 2021 08:42:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:44058 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245544AbhIAMiz (ORCPT ); Wed, 1 Sep 2021 08:38:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3543C6115C; Wed, 1 Sep 2021 12:34:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1630499697; bh=garZmkr3x6ZGvRxB0Wobo7VLCt6GC7nXcCcwN5F+RYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rp2xnDC5j1PTIiQxVajd+CRamoruThgdlcG03TIP2W13kQmuwSPqSpUL2v2tpa+bH YQ2gNULIFRUPo0dM4WjRDcLu28bG6yThlBdRHjm2fM/vzNkuXIl/MxGpnE2sttj7BZ 4vYp4alD3D26YF5FPcCIg+QBEJxqt2osVsmOh7A8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thinh Nguyen , Jerome Brunet , Sasha Levin Subject: [PATCH 5.10 050/103] usb: gadget: u_audio: fix race condition on endpoint stop Date: Wed, 1 Sep 2021 14:28:00 +0200 Message-Id: <20210901122302.256387763@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210901122300.503008474@linuxfoundation.org> References: <20210901122300.503008474@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jerome Brunet [ Upstream commit 068fdad20454f815e61e6f6eb9f051a8b3120e88 ] If the endpoint completion callback is call right after the ep_enabled flag is cleared and before usb_ep_dequeue() is call, we could do a double free on the request and the associated buffer. Fix this by clearing ep_enabled after all the endpoint requests have been dequeued. Fixes: 7de8681be2cd ("usb: gadget: u_audio: Free requests only after callback") Cc: stable Reported-by: Thinh Nguyen Signed-off-by: Jerome Brunet Link: https://lore.kernel.org/r/20210827092927.366482-1-jbrunet@baylibre.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/gadget/function/u_audio.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 908e49dafd62..95605b1ef4eb 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -334,8 +334,6 @@ static inline void free_ep(struct uac_rtd_params *prm, struct usb_ep *ep) if (!prm->ep_enabled) return; - prm->ep_enabled = false; - audio_dev = uac->audio_dev; params = &audio_dev->params; @@ -353,11 +351,12 @@ static inline void free_ep(struct uac_rtd_params *prm, struct usb_ep *ep) } } + prm->ep_enabled = false; + if (usb_ep_disable(ep)) dev_err(uac->card->dev, "%s:%d Error!\n", __func__, __LINE__); } - int u_audio_start_capture(struct g_audio *audio_dev) { struct snd_uac_chip *uac = audio_dev->uac; -- 2.30.2