Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2649036pxj; Mon, 14 Jun 2021 04:01:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCQdvZcMyCSGMols3E3wIVrbhM8gxai7U1jqvOoLJlD00K02sAVKokixNJdLPpgx2/Jv8D X-Received: by 2002:aa7:c84a:: with SMTP id g10mr16190866edt.326.1623668510404; Mon, 14 Jun 2021 04:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623668510; cv=none; d=google.com; s=arc-20160816; b=HEG0nF+kGxgXnKaw+dKVLtBgP5zeA9+KsO9nNJ1zWIJJwL3W8VgEw9LbKZeL5DhKHu I/0EOnefimv1/34o5EMp4s2B6+ZIZlnirtn2n8ho5mOKszAqGL6RKm6IIt/I368/AJKZ v/tk6IxAZ60ojZg1bWIla9KDtvgPyX1P2a8Y/iU/L2AVipZ4gBg5BRQKJJJi22aHMEtS qNrIIYTfZx0gHMzVJhkmDHAxA4K8Jl4RU9UME0EHa6RvHliO0i15+O+5kZUpj0Cs6IcA J4qM8bLx6M8UPmIU9q85LUY8+cLn3iYcs73WFdVhw8xxTqEgJpCLOQWOwDxihOUl+gUQ zLKw== 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=jV72I47ghvC4vtY0csPdNBInzqJsBgJccm1AA3lNnbI=; b=L8bfTmDPemT1a8M+VBO5yMUveGnWy9u8Sod6egdPw7wj6z4Gt7MldRVYq0PsQIDaJl H8dMci5x8dIsD2C1hwfrvDOR7Pkb5fn90D+yQWt4sCcoREtGKVveuUUwTvCt2QR1BK3Z ZfTP29u7bHUPsyaNKuqr3xk0Kdw1P+3RDkXE0m1s8xtiRE6nnUk6mA+kdgzCwzYcVVmd 2kBkipi7Icsjgl0GeJscQCcp1A90zEv7VOKMknrsMOutTJSxN/QXNs12XURDJo0G0vWh I4PwYz69TpHZLT19rZcVfPP4AWGExhDVKleDM29POPSO/vKroXsktrGfa9Ch5QGEl3B+ OI0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KttWnJvm; 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 p22si11648036edq.409.2021.06.14.04.01.28; Mon, 14 Jun 2021 04:01:50 -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=KttWnJvm; 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 S234402AbhFNLBs (ORCPT + 99 others); Mon, 14 Jun 2021 07:01:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:60644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234018AbhFNKwl (ORCPT ); Mon, 14 Jun 2021 06:52:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F22BA6147D; Mon, 14 Jun 2021 10:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623667175; bh=TxUPBybTXrdBKhJ2d5K76pBOCVAEfFMYwRZhWsQqSI8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KttWnJvmP/VqOO1bX18Lzb/yHnTzQUrS33XfjfybwLTUakYRBtW4vXYAN481b/REm 7m8ufafIO6+XEzVlRUB5baZqtR8fzpin5S1Tg6ji/u6uQup0pi8uIYrJOoRagrB1qC 8ZBQdC0l9QBV+lPEM2un5ZamurZvILs2OIt0uR4U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wesley Cheng Subject: [PATCH 5.4 54/84] usb: gadget: f_fs: Ensure io_completion_wq is idle during unbind Date: Mon, 14 Jun 2021 12:27:32 +0200 Message-Id: <20210614102648.202962924@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102646.341387537@linuxfoundation.org> References: <20210614102646.341387537@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 @@ -3585,6 +3585,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);