From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.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 6C82C437454 for ; Fri, 31 Jul 2026 15:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785510880; cv=none; b=SDtbpz6ODBS/xE1NmmBdrWAe3b5oS8m0aP3CL0W+2JelNjJIp9vNgOpUMRef3bAIjkpdqLMhtzSAPuvpO0UFJ9NgkT9EQigM+oLlgIGQ0PygAycSo+DmwbQ0vJKqipr3B4TJlzbjgPS5mmU8DCQMIjjXlG1xRatHBDkca37rd2Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785510880; c=relaxed/simple; bh=PxfbufHKEdiZJDcysFDCB9tgJLN7rUY8Stt5mTjWs3w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=BEcrFVDJSM5nBEz4q7DbNgOqRs5y+ggMI8gfkOWbBpDgd/VD/+myJopPrRPkkt6b2a4RqktGmv1M1oU9Tr2enJwod6wTAzadLxAgBM0+0MQ2E0lrvBOMVDQ63Hb2hSv66TVwQhsuQZ4EsQdFFfjIw4QCFk/vO5azmHm8eIsynw8= 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=oEHxt6oM; arc=none smtp.client-ip=209.85.215.177 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="oEHxt6oM" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-ca53979f8e8so93943a12.2 for ; Fri, 31 Jul 2026 08:14:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785510874; x=1786115674; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=zhZaO4ozJik4n9gTRf7CxEJqzo3QkPue6+aio//Q6Qg=; b=oEHxt6oM9fGDbISgZj9YrQRVrTb+39qgGf1PMCfEr274jZHc4rhpaBmNSkPo2zgUtU UMWsHZO7P4xsK19GO4Q0P+Na/HXP0kEwDhX/FMabY8kalbdHSN/YjoP6H6QEVID1impt U10gO3LXaOsfluPFu+5I7/kJcZsbDamLRsAbVhTYXcWR1NJdB5czCJ8yX8I1/2FFZLPs rrud30OhtJHVYDmHtSVElvDx2u2JppV0ud01ZdprUJ1uzUf6AZhwOG10TkHLcDXn8Qlz AoQ9Map+tHtx6X8aJhqBsTCZftWWLT/rM7MlqkJT3TtjyhlJpsfAWAAF+kXBjkMkdlXn r6Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785510874; x=1786115674; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zhZaO4ozJik4n9gTRf7CxEJqzo3QkPue6+aio//Q6Qg=; b=RCOEdbKyqOb5RE1byw6IsTBPtyiQYpXum04It7/Jfn5au/vfpci80FegMX8Lf3hZnJ DM3v1kDHFdNIsdWHMkLKxm3iOfua4WedB3WQdq4RQxdrNvIPwfVLJoJNOJSx5YWz8+OG kHuta+7olzLfe9oTDoJc1/nHW0FiwUqLIxGasNdwk1g0Y4eI+46o5sXWnju4/4hVzOwJ hdgkgjVs0XkPKm8UOoZRPVR//amHQO9e8C7KX67lECugOEc95r1qwCiMt9pXjaPfMRNs x1iIstYSIG9XAgnCOXoeYUyVhhjid1y39jMNOnuPNZEOIwcrygMwU3BIENONIYoSo66W MKBA== X-Forwarded-Encrypted: i=1; AHgh+RpeoU5tJi9Sq+afmwOLISX0uNCZFgHKPG/jlNpyDM0CyZIFLTVmO2sHIIZNrQsskLemVFnEOO7sx+5M2d8=@vger.kernel.org X-Gm-Message-State: AOJu0YzteK3tz3MbR8giObChKf+n2sugTA2Zd1oAAKkptsKKbkfNNCjR Rn1ovToRBzAwN0NmPUPw9+I/JiLszbCAg+jHa0FdJg5q/l2k5600NW3g X-Gm-Gg: AR+sD13RJ5QEUgCvqImVl8wcLIMNg/UDjQgY6UUHWPOV84aDavgqUDA7FrMOldWsreT wZJecJnCg/jXwMhP7nCVCx3ZHrtv4goqWR8TOuVoC7xb9SEDFLfGZIktARv1LCD8ZyOAbgQMV8U hHaIObDenzqWTon4RBSaz/oErwyWpT4MlQa+EjjvFVA7GgUrFP206RJxsoQkt8bclT86jpeuuu2 I4tUooStPUy82qdM8CRFA0lTJJtR3VBRFt7rb4evRnxnNE5d014OsjB6PXpQTo/qz9oR7EPmHUi 5wY//AcgtjE07QUJnv/B6Wkja7JXKN/BC8VGCH2GwAA+d76aw7VNzWPa6FuWP7WMr4k/7SZty0e bsdVFzM1VqFkCUpeJXAu8iOB0PMCIHAUK61+h0nF7804+/EUTyRKl9stzTSZunbAl8I9u6W+mAG DIWesPWxI0IPsoNOdxOjkJ303DPzifPbfwaVeYT/gsLsee37krUTJrd2oMvCYh2PIxCci2IC9Yh rXzWQ0m0vFHZCPNq8gZVmgCozI9oVFraLV9UsBX/d94ugRjgSPzBFs= X-Received: by 2002:a17:90b:562e:b0:36d:b30b:14ed with SMTP id 98e67ed59e1d1-38fbc4ad251mr377334a91.2.1785510873947; Fri, 31 Jul 2026 08:14:33 -0700 (PDT) Received: from localhost.localdomain (45.78.65.84.16clouds.com. [45.78.65.84]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153e18e107sm7985431eec.27.2026.07.31.08.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 08:14:33 -0700 (PDT) From: Chengfeng Ye To: David Howells , Marc Dionne , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Chengfeng Ye , stable@vger.kernel.org Subject: [PATCH net] rxrpc: Prevent poking connections after final put Date: Fri, 31 Jul 2026 23:14:26 +0800 Message-ID: <20260731151426.3194039-1-nicoyip.dev@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit rxrpc_poke_conn() unconditionally gets a reference before adding a connection to conn_attend_q. This is unsafe for the connection timer because timer deletion cannot stop a callback that has already started. The following interleaving can occur: I/O thread Timer softirq rxrpc_put_connection() refcount reaches zero rxrpc_connection_timer() rxrpc_poke_conn() rxrpc_get_connection() increment from zero list_add_tail() timer_delete() rxrpc_clean_up_connection() timer_delete_sync() call_rcu() The refcount increment saturates instead of resurrecting the connection, so cleanup continues after the timer callback exits. The RCU callback can then free the connection while attend_link remains queued, and the I/O thread later accesses the stale queue entry. The kernel reported: refcount_t: addition on 0; use-after-free. WARNING: lib/refcount.c:25 at refcount_warn_saturate+0xc0/0xe0 Call Trace: rxrpc_get_connection+0x185/0x1d0 rxrpc_poke_conn+0x12e/0x2b0 call_timer_fn+0x2b/0x220 __run_timers+0x561/0x8d0 run_timer_softirq+0x144/0x250 handle_softirqs+0x18d/0x5b0 rxrpc_put_connection+0x2fe/0x3f0 rxrpc_discard_expired_client_conns+0x396/0x670 rxrpc_io_thread+0xbfc/0x1640 Use rxrpc_get_connection_maybe() while holding the attend queue lock and only enqueue the connection if a live reference was acquired. The normal path for a live connection is unchanged. Fixes: 4241a702e0d0 ("rxrpc: Fix the rxrpc_connection attend queue handling") Cc: stable@vger.kernel.org Signed-off-by: Chengfeng Ye --- net/rxrpc/conn_object.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/rxrpc/conn_object.c b/net/rxrpc/conn_object.c index 0ece717db0f8..3f4516115d37 100644 --- a/net/rxrpc/conn_object.c +++ b/net/rxrpc/conn_object.c @@ -33,10 +33,8 @@ void rxrpc_poke_conn(struct rxrpc_connection *conn, enum rxrpc_conn_trace why) spin_lock_irq(&local->lock); busy = !list_empty(&conn->attend_link); - if (!busy) { - rxrpc_get_connection(conn, why); + if (!busy && rxrpc_get_connection_maybe(conn, why)) list_add_tail(&conn->attend_link, &local->conn_attend_q); - } spin_unlock_irq(&local->lock); rxrpc_wake_up_io_thread(local); } -- 2.43.0