From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 7241621CA03 for ; Thu, 25 Jun 2026 02:45:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782355545; cv=none; b=Uvtm3yk3G1h9HOjO4nwS6BiY19Y4CoSpnbAvrDMm9PWRSXPk73JQWJqHvJS8LdgXbhRZqSTxQ3q9hQBiI8WsgskkoPjya+sQ6dd75Efc3DA7WRC/a971r1UiswqPoHYCmVi7xxsdxVnLNds8+ijnDzo0vUHXJKQRfh1Mq9Ek9iU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782355545; c=relaxed/simple; bh=AySLtgFOtp3529pAwkKmx1IWp7boPyf16WKMeJ7VPcE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BigH2m7/TNM9y5co2Pv2uhn+64IPweZAfoD4pOBSNW4757EdR0gAdJXllsIWPEHE/iTsuxZKUXaO0T79TBOLJpzGzudR4Z7P5lSvE4WheUdN4cIf6KSp9TybkoQ3BkoB64CH2B/zFz5T7FEQ8RXqLPNlvCQ84+emTyoV6sD4Kk4= 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=f1O3RzMw; arc=none smtp.client-ip=209.85.214.177 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="f1O3RzMw" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2c6b7bd4e8dso25025ad.0 for ; Wed, 24 Jun 2026 19:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782355544; x=1782960344; 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=wJTr5Nx9Y5ptjpvg/KPhM4NW7y4Vw06GKfeQFFI2HR0=; b=f1O3RzMw9Cu/2cncPlbWfkljhEUyroaiSd+5NxpGSJguPyNinmxzsBtG5ctxTKO6On 82KefBXYsrO8w+dEBs1Gt6bDiPixgtCY6K1XqZyAk1ZJYhNdTmKgKYmPLzy4JEhTzCzN 6tLsmS48/FHQTtaKOVGNSJiSdMIM5aPY2wNuPbff22wDsnPr3X+c+A50IoOSZ4mihYZA CWpkf6WWCO9hPD1pnjEmB3uWE7gRgiaZGFeKWMVfc7rx75AY2PEibZcbZHmjiZEAjGze +WsVAsAGUPgWCRPml5/zYodbj0LFQPI7pUA0xPtFZsOUugsFbErjkb8Ab5oFGb7cWIa+ 2kwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782355544; x=1782960344; 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=wJTr5Nx9Y5ptjpvg/KPhM4NW7y4Vw06GKfeQFFI2HR0=; b=hPGTenbAWH/J8ZiqVZkqIpEXRRrTMAtfz4vCWGMRoG7nhMsBEfYbTfqHo+1Tbd0MwM Q89ynzEPRUmLzmQn8mkFSCpMN62XHuN1bXSyjuICyazX8ZoCjflAgnNWY+lkuAlPmoKS 0JJ9hLLeYNvCN0Wx3g8CisX2H8T/LXP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b9c1mr870365ad.7.1782355543229; Wed, 24 Jun 2026 19:45:43 -0700 (PDT) Received: from google.com (112.174.16.34.bc.googleusercontent.com. [34.16.174.112]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c92b9cc8496sm744276a12.8.2026.06.24.19.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 19:45:41 -0700 (PDT) Date: Thu, 25 Jun 2026 02:45:37 +0000 From: Carlos Llamas To: Alice Ryhl Cc: Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Christian Brauner , kernel-team@android.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2 2/2] binder: fix UAF in binder_free_transaction() Message-ID: References: <20260619185233.2194678-1-cmllamas@google.com> <20260619185233.2194678-2-cmllamas@google.com> 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 Mon, Jun 22, 2026 at 09:55:29PM +0200, Alice Ryhl wrote: > > --- a/drivers/android/binder.c > > +++ b/drivers/android/binder.c > > @@ -1658,10 +1658,19 @@ static void binder_txn_latency_free(struct binder_transaction *t) > > > > static void binder_free_transaction(struct binder_transaction *t) > > { > > + struct binder_thread *target_thread; > > struct binder_proc *target_proc; > > > > spin_lock(&t->lock); > > target_proc = t->to_proc; > > + target_thread = t->to_thread; > > + /* > > + * Pin target_thread to keep target_proc alive. Undelivered > > + * transactions with !target_thread are safe, as target_proc > > + * can only be the current context there. > > + */ > > + if (target_thread) > > + atomic_inc(&target_thread->tmp_ref); > > This is more complicated than the comment suggests, but I think it's > correct. As far as I can tell, scenarios where to_thread is NULL but > to_proc is not are also scenarios where the caller ensures that > to_proc stays alive during this function call. Right, transactions with !to_thread and a valid to_proc are undelivered, and as such they can only reach this point from the to_proc's context. > > It's unfortunate that there's no obvious better way of doing this. I'd > like to just take a refcount on the process, but it's not atomic, and > you can't take the proc lock protecting it because of lock inversion. Bingo! I'm using the thread as a proxy because refactoring proc->tmp_ref to be atomic would be a bigger and thus riskier change. > > Reviewed-by: Alice Ryhl Thanks!