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 68CC1190462 for ; Sat, 27 Jun 2026 00:00:53 +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=1782518455; cv=none; b=qjnckxLbAzB2qSktQbgfzapnIqg2gqyjtnb21q/dre7IU/cSsfVYPhZHY6guN9V4Y2lrWM+9gFj8JAzDpe2WDwGSz9G3xyNiYQfwYsEsCzs4gyfuTj9UlLKJzv+doS9Td4t5V+8i0quq2Kr/3O0h65lOwmjne3o4frrtN/nGnho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782518455; c=relaxed/simple; bh=tGIQHoq4qK5Eb4FAZpd/KMB8JhWc6zGurunEeF1Sxg0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=g42//8jfhdUsNSYVqSBnh3/D8bwyy1NIH4pq6leag6G0Cklz241+vftoLvY77YgppE448A3OpNf8DZrcLdbURafAWjEPB6F5CAcsIQ0rgzUiAb5fs6rtLjiWQLAnWD2dJTvBhXh2SHBNtnhppvBQEXgamad8Qgm+PHfJ1z7b+2s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=l5damnCH; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="l5damnCH" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2c81db32393so21935ad.0 for ; Fri, 26 Jun 2026 17:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782518453; x=1783123253; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=QqDPPLJzwuxTB89us7bsdVJAmyNxYkv4BpfCzxYJck0=; b=l5damnCH21c52U4xUKOm6SbLFVDsXUmSrT0CBS9sAHcDHYexifr8aH7AXLtNV9mDXT u47nuU0LlCSlBLh38P2xXdOi3xwxAtm4hpwVoMq+ERCsOJxLSpcAOgIbAU74i7IDgQKC MHN5NlIUTS2t1lh5AWDvj9YtSzNCrNhHNbTqf1WtjNn5AQmHx9GOll9Dm+wvcfapkQJc E6IN4lBAUWIJfckcMo/bZ/hBk2E+vsc/FN0xbnbLNZdkYWWfDTj2nSnHzIcNMb5vExeR qF7UVXk/EiA9Et+Ac7kxHyi+V945x7IEi4kCqpwhRdXFp+R7ohDlxTldUAtpA0gUjVli NJVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782518453; x=1783123253; h=in-reply-to:content-disposition:content-type: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 :content-type; bh=QqDPPLJzwuxTB89us7bsdVJAmyNxYkv4BpfCzxYJck0=; b=bGAnY6nzVoM/9LW0L2KHl2QVInmYosL9/fALfP070AcSMq0DM3Dh+FJy3UBfwgxK7Q tUwdSmKvbetF9NUpFnXxXyE/kgCq49cLoiAsEONUY9hM/u3tTHJZJQ76jQnyA44erj8/ wwNOAfPSKd8sfexgfQJhZ9VAId42iZ90kh11XfalODEqNfcO7ORPz4wIKOA3FIQ/us9m MjvV0/zgB0+Cut0VONYTsCo4UNGGHLv36AqTa0b+UhgaIOpSDZU6icw9YO4F9bykAlRb UVd8QWXp5F4uqFcCE/w7zYSXfIsZHAfXCHUD/bzJLQexvt54MPFrYDP/9LZT5qGN92By f+uQ== X-Forwarded-Encrypted: i=1; AHgh+RrUzzpFsvP0S17QfKkvZJHJZPY3ClTogMelxfTF3N1ceWKKsw6JrpLSYjNdaEH99rTQTMmOXHxcuVFYg10=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0WIH8JhtHcwt1cDoinFUjuIpxt+J3jWRVA8rlPp6S4zRpsMnm ooInLjZrF+ZepmGoakuXde5ZiHO5W7jLJo1ojtKOJ1/MCKp/hizTTGuxIrIOy8Zp7w== X-Gm-Gg: AfdE7cm9cXt69YoT5EGxyzOKiYqp+f2Nd6bV11MCo3GRTFUlxqbZ9GcSY2uYYkwXG43 KyFmeW2xOMutDrbEpwAF4j2+SaeK95OondxC4opB+4wGvFVvNXqlqJ2oQADTyRWbUNfXaZvK8jr Rs7PKfKFUjGMWCgeQvbHMowkPUg2Du3C5nbKjA936FtnDsMykYA1XTseNKlD118bb52TJsuuo1W tJfGxykoR8IEg5KTniJb7mXI3drlkSh6kiQUF0uX3Y7uJ/qkXe69HqRtMzgeQ+L8lVxl22Jz+mz IDpZ632Ziu4uPmdmHJs8a2dV3TD5JpTHjaGnDcQ85/fO8L1RLJ1EdXjab+X2ec8KN4IuPn/IpKx CYaCvDJGF+jvArsdtZHyhSNysNQwtucrPfme8oHnmZLGQ3wq3JUZ02wqx8Bs5fHibmtnJaOCO66 vZpOKL6YRjvkrhKxPbqKbGCoFokIjf9vA+j+UI3tjhvP9zbIX+YN8t31JT2tl3tLRkkZxxEv3+P 9HFKH/Kfvl53mszCV3muU70tRats4KYTgg= X-Received: by 2002:a17:902:f612:b0:2c7:9e6a:1a8d with SMTP id d9443c01a7336-2c9a24512fcmr1139135ad.12.1782518452128; Fri, 26 Jun 2026 17:00:52 -0700 (PDT) Received: from google.com (112.174.16.34.bc.googleusercontent.com. [34.16.174.112]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c81aa46aeasm20037615ad.17.2026.06.26.17.00.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 17:00:51 -0700 (PDT) Date: Sat, 27 Jun 2026 00:00:46 +0000 From: Carlos Llamas To: Hyunwoo Kim , aliceryhl@google.com Cc: gregkh@linuxfoundation.org, arve@android.com, tkjos@android.com, brauner@kernel.org, aliceryhl@google.com, mo@sdhn.cc, wedsonaf@gmail.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] 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 Sun, May 31, 2026 at 10:29:24PM +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 > --- > Changes in v2: > - reformat to satisfy rustfmt, as pointed out by the kernel test robot > - v1: https://lore.kernel.org/all/ahjpn-3WQTywTdyj@v4bel/ > --- > drivers/android/binder/allocation.rs | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/android/binder/allocation.rs b/drivers/android/binder/allocation.rs > index b7b05e72970a..ea5846e4da16 100644 > --- a/drivers/android/binder/allocation.rs > +++ b/drivers/android/binder/allocation.rs > @@ -259,7 +259,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) > } > @@ -420,7 +420,8 @@ pub(crate) fn transfer_binder_object( > } > > fn cleanup_object(&self, index_offset: usize) -> Result { > - let offset = self.alloc.read(index_offset)?; > + let offset = self.alloc.read::(index_offset)?; > + let offset: usize = offset.try_into().map_err(|_| EINVAL)?; > let header = self.read::(offset)?; > match header.type_ { > BINDER_TYPE_WEAK_BINDER | BINDER_TYPE_BINDER => { > -- > 2.43.0 > Hey Alice, have you seen this? This looks correct to me so, Acked-by: Carlos Llamas