From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31EDF3AE5C for ; Wed, 7 Jun 2023 20:29:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A70DDC433EF; Wed, 7 Jun 2023 20:29:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1686169792; bh=JTuV9J12uZeQ1p9e5CwGKlzb45AIfzLcveympf9JIh4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uGzWK3Jo2Vl01Gj7RdI19QiCzyPmCnsoiR68GNfQnXC4LE3DcfHun3rz5zatKDYqf JSR7KKZXoV19LXao+aaMQHjlWc5ZEZmH9tmMJeqB9X7ujuuiEYp2yaBPMxiLzZVHRf 5kXjgi11r3MJ43i6B/tMgHDQHHF2K2shjH+XWG7w= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Richard Acayan , Srinivas Kandagatla Subject: [PATCH 6.3 215/286] misc: fastrpc: reject new invocations during device removal Date: Wed, 7 Jun 2023 22:15:14 +0200 Message-ID: <20230607200930.283419814@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230607200922.978677727@linuxfoundation.org> References: <20230607200922.978677727@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Richard Acayan commit 46248400d81e2aa0b65cd659d6f40188192a58b6 upstream. The channel's rpmsg object allows new invocations to be made. After old invocations are already interrupted, the driver shouldn't try to invoke anymore. Invalidating the rpmsg at the end of the driver removal function makes it easy to cause a race condition in userspace. Even closing a file descriptor before the driver finishes its cleanup can cause an invocation via fastrpc_release_current_dsp_process() and subsequent timeout. Invalidate the channel before the invocations are interrupted to make sure that no invocations can be created to hang after the device closes. Fixes: c68cfb718c8f ("misc: fastrpc: Add support for context Invoke method") Cc: stable Signed-off-by: Richard Acayan Signed-off-by: Srinivas Kandagatla Link: https://lore.kernel.org/r/20230523152550.438363-5-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman --- drivers/misc/fastrpc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -2351,7 +2351,9 @@ static void fastrpc_rpmsg_remove(struct struct fastrpc_user *user; unsigned long flags; + /* No invocations past this point */ spin_lock_irqsave(&cctx->lock, flags); + cctx->rpdev = NULL; list_for_each_entry(user, &cctx->users, user) fastrpc_notify_users(user); spin_unlock_irqrestore(&cctx->lock, flags); @@ -2370,7 +2372,6 @@ static void fastrpc_rpmsg_remove(struct of_platform_depopulate(&rpdev->dev); - cctx->rpdev = NULL; fastrpc_channel_ctx_put(cctx); }