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=1796379312; b=kh8b8OjiTjgbZccvEO5EOJV+UPrONB52OuE77AhLoFUKfB7a3bqf4TVRaimApb4U3fCM 8f+7LIBH/LEcnjTedpwo/jjCEHkK6+Xclk4+ChZFg0PMaz6bxG8lu0JN10FemadRKiu1/ DNVF9NhzG16ti9j24L9EvR//MwxExp6Jr2KtvqkuwyE46H7BH5+WaIzsf8mjDOAultrA1 IYicHNG9y8cTG1MABiFuQdTHsXaYJ5ZsPKRghAG8M83NEwvMtsOdhdmVu9bWuhtzqqlV6 39UkNEUTeR4fvBn54foBuEICOx64vMMZCFBwaKSST1M/1KkuVMVgF/96RYKKiX7a5Lg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379312; 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=i+Qp18/Me7g3rmrp/9P4FXDx7yyq+LdhRwWYKtCACvI=; b=gIjvWPyyZ2/K1109MMRlQlazrD+cSyv14ovJdLNDZ5QV6Db7S392U0Q7UMAYG+nhlq0Z i/4K5LhVSXyIy2r0dTkzld0M0VWVFpHcpLZWwX04TguMqA+i0oz4UiTAmfeaqXwXuNyli 9q7uKJNPu3QT18LAme8bjTkPNv+n/nCYpilpDSgPizU2lp+MDaONXM9WvrK1uM9XFXYhc NBOrfy6P9FUj5rpNNtgAgv3L8YM6QsJaCe8mYfB89V1fzuuu2MooeDIJUfTDl2lDRRhwz BCawVtLGOX4g9/8/H3Wr/yojZsLywzWr+t7OQVbZ42iBUbQBOKypfM0Exg4ycdKrstQ== 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=CircpxUg; 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 E0095606A32F; Fri, 4 Dec 2026 10:15:11 +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=CircpxUg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CBF01F00897; Fri, 4 Dec 2026 10:15:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379311; bh=i+Qp18/Me7g3rmrp/9P4FXDx7yyq+LdhRwWYKtCACvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CircpxUgCBoIt6UoicPLMvIMzDNGN0vU/cdrjw68ROzproY/giGJ2LybZz6NML9Y/ aivg1BSDKJE0vPUfMKN3WmI36EYttdJE4WBNElnQABvKLM1WNAECMccJECL4HyF7Fu vYmuBshwAoCBuXevqEGyGyke4qH0UCZOWToBC/Wc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alice Ryhl , Sasha Levin Subject: [PATCH 7.3 012/742] rust_binder: push BR_TRANSACTION_COMPLETE before BR_FAILED_REPLY Date: Fri, 4 Dec 2026 18:57:56 +0900 Message-ID: <20261204100635.367125242@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-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 | 68 +++++++++++++++----------------- 2 files changed, 32 insertions(+), 37 deletions(-) diff --git a/drivers/android/binder/error.rs b/drivers/android/binder/error.rs index 1296072c35d96..b9faf09566108 100644 --- a/drivers/android/binder/error.rs +++ b/drivers/android/binder/error.rs @@ -79,7 +79,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> 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 a1bef151c2c59..e1929f5739dfb 100644 --- a/drivers/android/binder/thread.rs +++ b/drivers/android/binder/thread.rs @@ -1309,37 +1309,36 @@ 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()); - } - - binder_debug!( - FailedTransaction, - "transaction {} to {}:{} failed {:?}, code {} size {}-{}", - if info.is_reply { - "reply" - } else if info.is_oneway() { - "async" - } else { - "call" - }, - info.to_pid, - info.to_tid, - err, - info.code, - info.data_size, - info.offsets_size - ); + 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()); } + + binder_debug!( + FailedTransaction, + "transaction {} to {}:{} failed {:?}, code {} size {}-{}", + if info.is_reply { + "reply" + } else if info.is_oneway() { + "async" + } else { + "call" + }, + info.to_pid, + info.to_tid, + err, + info.code, + info.data_size, + info.offsets_size + ); } } @@ -1416,7 +1415,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, self.process.task.pid(), @@ -1431,11 +1430,10 @@ fn reply_inner(self: &Arc, info: &mut TransactionInfo) -> BinderResult { } 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, @@ -1447,11 +1445,9 @@ fn reply_inner(self: &Arc, info: &mut TransactionInfo) -> BinderResult { orig.from .deliver_reply(Err(BR_FAILED_REPLY), &orig, Some(ee)); info.reply = BR_FAILED_REPLY; - err.reply = BR_TRANSACTION_COMPLETE; - err - }); + } - out + Ok(()) } fn oneway_transaction_inner(self: &Arc, info: &mut TransactionInfo) -> BinderResult { -- 2.53.0