From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379364; b=gzsM0f2c2wt2d8wR2Hl9dL2pmnxGh/TTyUDtTFPanjgjZyLy7H3v/7S3fU/LINo/OMoW MNn7Z8+n4gYdRp6Dur95BI3LI0BmKt6KK+kX32u3W9Vz5WtoPnT4wJC7sqzc2OfG/fIkx 6AGOb3KqC9z3vkp8dutEfuPBkWAf6fC0/FjmiQUanWj9lx5CYiv4wopBOL50uyLFbo0JE Dfm2VUJOny6naffsudvcMmYW6adKiULAhxJow1pssB5KXAtlYJUqN4VGAIwGjYtX2Xi4Q fa1hqMxxYi2a2OfnIu4rUowD8amPQBHD3JqlTVc+67BMRUTvRbrtzLoR2ReLsnC2+/Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379364; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=BqrrJKPAUlpyiYTp1K3+QovvG/UCzPcJZ83gwaYE5VY=; b=rHjajwuj93N/hEhdBiqXzXMu3cvOXRfEsdlm6XwguAx3rT2qaf94+RTyKYjg+NEyyltf 9TgjXhsTWOKDdJ5EDc5W74EjhUfdyMrAHGfaBQ7QmtOYe8VpAJhvqI0yyuctLFksF/bOY lGuIEHlqQnRiy96crdDyL1NYBdk+tZu9i8tpSWokOKLN7rLQ6GXd98FvdFCOGbqGmjJ+b KZeSVWYgM1o+AxF5rAGAXoR7hLj67U4cmjb06tTlwwgKNDx+WcKpaP1V5VmdqUG5yBXoV zx9LYjErKQRir7vRpafNNEUSL47u4htAwCgM8kwBsCrD/TI1ZEykLrLYGQ6plSTb1CQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=yV+ngmwZ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8056F606A322; Fri, 4 Dec 2026 10:16:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=yV+ngmwZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id F01F61F000C2; Fri, 4 Dec 2026 10:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379364; bh=BqrrJKPAUlpyiYTp1K3+QovvG/UCzPcJZ83gwaYE5VY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=yV+ngmwZ0FHxfqtgbqWepRpA5AoQ/4Gd0uf16ctzPNjll9VUefPvZw49PHGTYWn45 15/u6IDk/s5XOq5TmzQ/SNRzU35JsDYHfxHGtEtTO2geWKPIC97JsT2Ei+g/MLY+sE NB/RD6KIS+1XK97Cql8w45kubxrc7QC67riKe52I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alice Ryhl , Sasha Levin Subject: [PATCH 6.18 029/703] rust_binder: push BR_TRANSACTION_COMPLETE before BR_FAILED_REPLY Date: Fri, 4 Dec 2026 18:58:48 +0900 Message-ID: <20261204100628.358502201@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alice Ryhl commit ff9de8571f05e8f62f9cbe29f38e0aedda9389cf upstream. When building a reply fails in Thread::reply_inner(), BR_FAILED_REPLY is delivered to the caller before BR_TRANSACTION_COMPLETE is pushed to the replying thread's work list. In a nested transaction, the caller can wake up upon receiving BR_FAILED_REPLY and send an outer reply to the replying thread before BR_TRANSACTION_COMPLETE is queued. This causes the outer BR_REPLY to arrive ahead of BR_TRANSACTION_COMPLETE, which is not legal. This leads to userspace tripping on an assertion. Thus, push BR_TRANSACTION_COMPLETE in Thread::reply_inner() before delivering BR_FAILED_REPLY to the caller. As a nice side effect, this lets us remove the now-unused BR_TRANSACTION_COMPLETE error path in Thread::transaction(). Cc: stable@vger.kernel.org Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver") Link: https://patch.msgid.link/20261028-binder-reply-fail-v1-1-8b71d4daaf1d@google.com Signed-off-by: Greg Kroah-Hartman [aliceryhl: resolve conflicts in Thread::transaction() and reply_inner()] Signed-off-by: Alice Ryhl Signed-off-by: Sasha Levin --- drivers/android/binder/error.rs | 1 - drivers/android/binder/thread.rs | 46 +++++++++++++++----------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/drivers/android/binder/error.rs b/drivers/android/binder/error.rs index fd9e9d9e5658b..4b5689cdb2b8e 100644 --- a/drivers/android/binder/error.rs +++ b/drivers/android/binder/error.rs @@ -78,7 +78,6 @@ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { BR_DEAD_REPLY => f.pad("BR_DEAD_REPLY"), BR_FROZEN_REPLY => f.pad("BR_FROZEN_REPLY"), BR_TRANSACTION_PENDING_FROZEN => f.pad("BR_TRANSACTION_PENDING_FROZEN"), - BR_TRANSACTION_COMPLETE => f.pad("BR_TRANSACTION_COMPLETE"), _ => match self.source.as_ref() { Some(source) => source.fmt(f), None => self.reply.fmt(f), diff --git a/drivers/android/binder/thread.rs b/drivers/android/binder/thread.rs index e2320704c722e..5ae26faaf13bc 100644 --- a/drivers/android/binder/thread.rs +++ b/drivers/android/binder/thread.rs @@ -1262,26 +1262,25 @@ fn transaction(self: &Arc, cmd: u32, reader: &mut UserSliceReader) -> Resu self.transaction_inner(&mut info) }; + // This runs when a transaction fails with an error returned to the caller. if let Err(err) = ret { self.push_return_work(err.reply); - if err.reply != BR_TRANSACTION_COMPLETE { - info.reply = err.reply; - if let Some(source) = &err.source { - info.errno = source.to_errno(); - - { - let mut inner = self.inner.lock(); - inner.extended_error = - ExtendedError::new(info.debug_id as u32, err.reply, source.to_errno()); - } - - pr_warn!( - "{}:{} transaction to {} failed: {err:?}", - info.from_pid, - info.from_tid, - info.to_pid - ); + info.reply = err.reply; + if let Some(source) = &err.source { + info.errno = source.to_errno(); + + { + let mut inner = self.inner.lock(); + inner.extended_error = + ExtendedError::new(info.debug_id as u32, err.reply, source.to_errno()); } + + pr_warn!( + "{}:{} transaction to {} failed: {err:?}", + info.from_pid, + info.from_tid, + info.to_pid + ); } } @@ -1336,7 +1335,7 @@ fn reply_inner(self: &Arc, info: &mut TransactionInfo) -> BinderResult { info.to_pid = orig.from.process.task.pid(); // We need to complete the transaction even if we cannot complete building the reply. - let out = (|| -> BinderResult<_> { + if let Err(err) = (|| -> BinderResult<_> { let completion = DTRWrap::arc_try_new(DeliverCode::new(BR_TRANSACTION_COMPLETE))?; let process = orig.from.process.clone(); let allow_fds = orig.flags & TF_ACCEPT_FDS != 0; @@ -1344,11 +1343,10 @@ fn reply_inner(self: &Arc, info: &mut TransactionInfo) -> BinderResult { self.inner.lock().push_work(completion); orig.from.deliver_reply(Ok(reply), &orig, None); Ok(()) - })() - .map_err(|mut err| { + })() { // At this point we only return `BR_TRANSACTION_COMPLETE` to the caller, and we must let // the sender know that the transaction has completed (with an error in this case). - + self.push_return_work(BR_TRANSACTION_COMPLETE); pr_warn!( "{}:{} reply to {} failed: {err:?}", info.from_pid, @@ -1360,11 +1358,9 @@ fn reply_inner(self: &Arc, info: &mut TransactionInfo) -> BinderResult { let ee = ExtendedError::new(info.debug_id as u32, err.reply, param); orig.from .deliver_reply(Err(BR_FAILED_REPLY), &orig, Some(ee)); - err.reply = BR_TRANSACTION_COMPLETE; - err - }); + } - out + Ok(()) } fn oneway_transaction_inner(self: &Arc, info: &mut TransactionInfo) -> BinderResult { -- 2.53.0