From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80284366566 for ; Fri, 29 May 2026 02:41:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780022521; cv=none; b=oQUkLTop2RMjrK2W7fCjyRalht4GpXwC7JVev1HABuIJ6NZThC9sYlGomVykH6/hO/O4sHlo+t0gxo/NV8NgTzxQLq3iV0elQGUXkjOIRmo77tv29xahDYwQYc9zircZfKfljT/A2f5r9WmlphWsyLZcSCuq8hmHcV42Yt0YtnY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780022521; c=relaxed/simple; bh=Ds1p122B60FV2zTmvWNc9nWzQxs8vMilrGSAwxzAFxM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EUeIWrHQfKwssMjtzf3OjR8J5TBWaro1cUQIatkp35VITni+dUOzhK5AS2yUPMnXNqZebHdjHJ7U6fq+TSvBafMInyXODAtY6r8o4f5mma2mtd7oOPfPN97AWsNxxyNwKHc/sNDR6rnhNX6+pD5KEbMAyXIeCbUZyIWJF17/OyA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=amPlXST+; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="amPlXST+" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2b4583f0a1aso98503935ad.3 for ; Thu, 28 May 2026 19:41:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780022519; x=1780627319; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=GZDub8BcFtFH80ZleNgO+woCxrWrG0i7gSDN+ih8DeY=; b=amPlXST+wEFjX8ga5F62ffh03AdDxP5AXZUkZrniJU0c9qqM1WvhRYjr/kU8WLCFu3 vjKH3ZhDJaOeeLcMksIJzDN75v7CZMAKvbUvHSw5fbq9ZGJ0LoGNME+PUMO6UiqXoC1w MG6vZWArSeeTEajwcbbXoGjksTsbyKv9BeMJsmL8cPdd709jfQeytEkBEQlD0nO+6JHu LvKC8/DEt6PO5XyfxzNI5382J3vqaearojYWPf5K6tmLTYKWXMSzUncLVej4qMPsDpeq 2li3jg0iXui2z3Bf5CsiZFpxiCQ4ct8Y95vB7u4XI4BCxosEdc6Gkk1YjAdsafctAx8e X7Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780022519; x=1780627319; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GZDub8BcFtFH80ZleNgO+woCxrWrG0i7gSDN+ih8DeY=; b=aOMI7b+dGRRFctU8d1STqqwNrMXamK/KL+ucMCYUT0DzPhnIP61rz+j7GzZera2Ojm 2m2MSkp3/TRftnHqTQXm2jFSvyjPK6b2iaYWSMXp12lHipUQSRcL1wOI0TVM7k8W5wDl Zj8TpSl7YkPP7HIusNXIrGpjkH47vml53T5QXX6DHZ+7Z8PtXriaAcQhCtL0g2c6v+6Z 9oW1Aiyt1Kt9zic2Zi7f31guvma4ufSnQtRjZ5ih5CULQL2sVwN5MN8rLBnAyJlL7AO0 /NpustC+Nwwv7V4q964Ton4Y4glMqAslV+M5FrZy6DtLHxQd9GRD2XMQT+Y/fBQq23Ue GGUQ== X-Gm-Message-State: AOJu0YwtuVUwhd8vce1CayD/VGjMfbQtDk4TZ3kVFu68GobOG5VcFu8B QPTNfSytkEykre1KwCD/A5i9sq9hCmrkD52C0dilLneDubbKwKgQLrHB X-Gm-Gg: Acq92OF61kYSWCeRHlYya9Xb99gmaTdo8kh4+M9SV4Z8iKmorIShzwT47XFsH3Gt4Ph GwHO4Mhu1gFAKW61HaJH5ixm8KvDxDwvmHcf6OaNX8ZEYIDJkGdMmbryxNA+QWn9MwPzRKY4uGC box0HZR/9j7LvrhnDROIR9F8EcPWwkdtuUlWvjP7rSnNRlLq2+V64ox74IE3jL+D3Lgv4tPyZHt CH6Wrk2qyjtqAHwXU4mG2a3MjUYd05WS/lj9F6L5fWlgOPmkrxXI3OYU/6VSvKWagZ/yiph6Fnk Ssl/sWYLDgl7twZjuXhECUQi3iC6yvl6VpAUPtGqQeVItXJl8w6hRRKJKx4i1ifAnvMFMdb2NCk 03lSoZQYIr1Ii8+5gdK8wgk5kwCLK9utZA5mSgppjcRiYl2niYyBd55kQ5+rL4f9ctDA/53SReF shsaDBdHW3it70+Ui0eXkDKzPKURt7xHMMnIyC8wRW/zwbp2BpSo6qXw== X-Received: by 2002:a17:902:f641:b0:2b9:ea53:4cfc with SMTP id d9443c01a7336-2bf20976e99mr12238495ad.19.1780022518682; Thu, 28 May 2026 19:41:58 -0700 (PDT) Received: from v4bel ([58.123.110.97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2bf23a0fd4csm1915955ad.30.2026.05.28.19.41.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 19:41:58 -0700 (PDT) Date: Fri, 29 May 2026 11:41:53 +0900 From: Hyunwoo Kim To: gregkh@linuxfoundation.org, arve@android.com, tkjos@android.com, brauner@kernel.org, cmllamas@google.com, aliceryhl@google.com, mo@sdhn.cc, wedsonaf@gmail.com, Liam.Howlett@oracle.com Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, stable@vger.kernel.org, imv4bel@gmail.com Subject: Re: [PATCH] rust_binder: use a u64 stride when cleaning up the offsets array Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, May 29, 2026 at 10:19:27AM +0900, Hyunwoo Kim wrote: > Allocation's Drop walks the offsets array (binder_size_t = u64 entries), > cleaning up the objects, but it used usize instead of u64 for both the > stride and the per-entry read. > > On 64-bit kernels (usize == u64) this is harmless, but on 32-bit kernels > it walks the 8-byte entries in 4-byte steps, iterating an N-entry array > 2N times, and reads the always-zero high word as offset 0, cleaning up > the object at offset 0 N extra times. As a result the referenced node or > handle ends up with a lower reference count than it actually has (a > refcount over-decrement), and binder's reference accounting is corrupted; > for example, the owner can be notified of a strong reference release > (BR_RELEASE) even though references still remain. > > Change the stride to u64, and read each entry as a u64, narrowing it to > usize with try_into(). > > On 32-bit ARM, when this over-decrement would drive a count below zero, > the driver's existing refcount guard refuses it and fires: > > rust_binder: Failure: refcount underflow! > > Cc: stable@vger.kernel.org > Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver") > Signed-off-by: Hyunwoo Kim > --- > drivers/android/binder/allocation.rs | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/android/binder/allocation.rs b/drivers/android/binder/allocation.rs > index 0cab959e4b7e..f4ffc57a8cb2 100644 > --- a/drivers/android/binder/allocation.rs > +++ b/drivers/android/binder/allocation.rs > @@ -251,7 +251,7 @@ fn drop(&mut self) { > > if let Some(offsets) = info.offsets.clone() { > let view = AllocationView::new(self, offsets.start); > - for i in offsets.step_by(size_of::()) { > + for i in offsets.step_by(size_of::()) { > if view.cleanup_object(i).is_err() { > pr_warn!("Error cleaning up object at offset {}\n", i) > } > @@ -412,7 +412,7 @@ pub(crate) fn transfer_binder_object( > } > > fn cleanup_object(&self, index_offset: usize) -> Result { > - let offset = self.alloc.read(index_offset)?; > + let offset: usize = self.alloc.read::(index_offset)?.try_into().map_err(|_| EINVAL)?; > let header = self.read::(offset)?; > match header.type_ { > BINDER_TYPE_WEAK_BINDER | BINDER_TYPE_BINDER => { > -- > 2.43.0 > The BC_FREE_BUFFER handling in thread.rs's write() seems to have a similar problem. Sashiko's review: https://sashiko.dev/#/patchset/ahjpn-3WQTywTdyj@v4bel?part=1 Best regards, Hyunwoo Kim