Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2663038pxj; Mon, 14 Jun 2021 04:20:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuDrbsoUqThnRM3QGVrgW4EwDRbOzAe0V1387VyjiVzKAXxiObPlb4oXpSjEl3M2/KT8jP X-Received: by 2002:a17:906:c212:: with SMTP id d18mr14947126ejz.291.1623669659297; Mon, 14 Jun 2021 04:20:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623669659; cv=none; d=google.com; s=arc-20160816; b=qzOT8Xs0ghJpbGYHtfjGruPog80KpWv/3PyMTYxDiG7jP8Xl9x8zQFmgyYyR6fdQBE 8QsxndUWsg8ryffRZMRUAGHjw6+PzIyT8AaToU748DQqW5TCMT/jNnpa1ncRkuMfoH6/ MgHyFvjj0ZE550NA/oIImwingip/OUYqLZaGL4jyh86Rd+FsIE9dpG9lOn6ht609vKI9 tnorBc4GQDBBPUJ1EVwaEw0KacJ4OoqI/mQgEQIQs3t0/gq/QOTMrZAuaprn2pQ+I8YG ai3XreZa5j6f/k6K6Bswkp5ODapq+xPKj036R+v6PzcqhrkC/DNtseXMn6KpT0R4svlw yj6Q== 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=ed76RcuDJaFIav3qR7Um2fEi4/tMxdl50zsV1kOeSRM=; b=W3ASd3hiRPl8AEPRAk3D7CrBJZ9bJwGQwtDgkHMCVZYHMRivwT4feMRULDRlUJdvPz DaxqyANJHLkQQB6GNiwtAEtmOFKmAA5ecO7Fq3h1sGsQ5jv5TRhIhl+ELlJeNtsr7vaq VDLE6rMnZ2jWLUau5QJyz4HA8LIGtkQYwNCvleZQlUaE5VdbPt/bWb170yCdKhoz8IOl wlN3XuUgSqyJw5M4bKO0SyVKrQlI0OQ+ORcQDDTRsp0KrkQNl2xAs8f8SnGQ0wuKyzCe T9dgIBF1w1xW76Rf/fi6CKBT1QTxCI+jM7zwonwaOjkp3eWvqv6pM5Rao+4lFGwSQRF9 cDqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=a05qneJD; 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 g15si8061225edb.340.2021.06.14.04.20.37; Mon, 14 Jun 2021 04:20:59 -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=a05qneJD; 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 S235820AbhFNLTk (ORCPT + 99 others); Mon, 14 Jun 2021 07:19:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:39218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235278AbhFNLHH (ORCPT ); Mon, 14 Jun 2021 07:07:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BB80E6192E; Mon, 14 Jun 2021 10:45:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623667548; bh=TUTo1GsdjuW143Sof0pwTsd3oqXK0ENbz1qo1DDTrGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a05qneJDtouX/c4kyORk5svc0GVLT/nnjkj9eVGnq+HvYPfddx8WkWk4ogrItq/1b 23Neje0UX8jZRWyj+HhmDb8wIw14LOok40HI3EpxXgnJkY2YjNXXp4fscu42W/Wo3H UE956tmvYxtckAiK35kbDiHezyLN26cC7WhFUOOE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wesley Cheng Subject: [PATCH 5.10 080/131] usb: gadget: f_fs: Ensure io_completion_wq is idle during unbind Date: Mon, 14 Jun 2021 12:27:21 +0200 Message-Id: <20210614102655.740009123@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102652.964395392@linuxfoundation.org> References: <20210614102652.964395392@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: Wesley Cheng commit 6fc1db5e6211e30fbb1cee8d7925d79d4ed2ae14 upstream. During unbind, ffs_func_eps_disable() will be executed, resulting in completion callbacks for any pending USB requests. When using AIO, irrespective of the completion status, io_data work is queued to io_completion_wq to evaluate and handle the completed requests. Since work runs asynchronously to the unbind() routine, there can be a scenario where the work runs after the USB gadget has been fully removed, resulting in accessing of a resource which has been already freed. (i.e. usb_ep_free_request() accessing the USB ep structure) Explicitly drain the io_completion_wq, instead of relying on the destroy_workqueue() (in ffs_data_put()) to make sure no pending completion work items are running. Signed-off-by: Wesley Cheng Cc: stable Link: https://lore.kernel.org/r/1621644261-1236-1-git-send-email-wcheng@codeaurora.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_fs.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -3566,6 +3566,9 @@ static void ffs_func_unbind(struct usb_c ffs->func = NULL; } + /* Drain any pending AIO completions */ + drain_workqueue(ffs->io_completion_wq); + if (!--opts->refcnt) functionfs_unbind(ffs);