From nobody Mon Jun 8 19:35:23 2026 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) (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 365D83C584F for ; Tue, 26 May 2026 22:09:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779833346; cv=none; b=QbkplGc4w65w5t/0SJC+G8qg2isCxkjPbaMr+Yw99GQDWeThQotboWlNlnSsaZq63VAcopBa9R20I3aBspvtDiJzGQogoG00LhtqrhwELdtBF+4Q/UUmUw0sdVDGm7sT52C0dCG1oBXhWujOBH7DkPi30n74o+Mj0gAEfGHBSY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779833346; c=relaxed/simple; bh=v1fNEW1CUkenypQxcpfx96PucSNIlS2ovv28XZSpsfw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dtqI/pgdET3QfpY/0uJNGEN+wOUodjfKHs5jJKMgM+yovgqhE/eGoYc08wvV2JOnb1pTIsIIwqXzCNYePVMHmqMLNLnQFQjAaTXWrhLiqv4JDYIoWDNwMDKGCgx8Dr/XdE0SDCHvzErK7Fn9pU1L1vLjOgBUAQrmSNDzWALuIgk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=openai.com; spf=pass smtp.mailfrom=openai.com; dkim=pass (1024-bit key) header.d=openai.com header.i=@openai.com header.b=CsGe4Tt1; arc=none smtp.client-ip=209.85.219.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=openai.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=openai.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=openai.com header.i=@openai.com header.b="CsGe4Tt1" Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-8b3d6b215cfso188356956d6.3 for ; Tue, 26 May 2026 15:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openai.com; s=google; t=1779833342; x=1780438142; 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; bh=Yo4q5u1cngoVL2GKQJNtjQ/o4VaVPhWtqVFE1iLulo0=; b=CsGe4Tt19knjquAlUz9cGgLK7Jz+LZNKb6Yug/HsXvxt4VqKnA/44AHQou6/ASDbJz QEVhTKEXZ2BNgJENu248N0WC3V8Y5guRyoxWEIBOrPlAZCpkWwSRAhiYaKsrbYbgHNJH gAI4r4SKlBlQiB+RSDcyqCFc4mtd2a6h5WLrM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779833342; x=1780438142; 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; bh=Yo4q5u1cngoVL2GKQJNtjQ/o4VaVPhWtqVFE1iLulo0=; b=g6z3YYX0wsfYqk28mIyq8d0T+za/dcc8bu+/OQ/0aLLHxadoXn5uYmzG1B3a7KD0N+ yy47AOBvwYdzkg+2YAginhvRK13f/8w5MM+KBisLbuUzBKX7Yv9Hbf/6raqAr+ixWY9P tPUHz8e3vPYI3sPxcNR+H6q2Ccw3jjpNNz3BuyvfBTq9wvFbsXXvdY/LoAKCHl+hcgMi XFASuqJkEdD9OpDIrS2CANQcgbD12VU2jwDdsZYHtqdyiFRBW+DJs1g8KvZPxAc9UBNk nvFW9p+IYuTKI55Iem5nznb0/zhQ/Xlhusjeicp2EQ64bq2dJehlXALGBeNjnQ2ZPi04 tUtw== X-Forwarded-Encrypted: i=1; AFNElJ8D7DK+myLrdZrPfu0bGpjkWODhy+sO+/O4cXdXqm0XDSTQLK8np1d4Q95KzAIdyf4I+tGFDLmqtDfWzsQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwyJwtKzqgFcSZHufUv9hshu1Gd++jM1dPMUqy1ljkSd/BbwVLt rvNY1OCcZ6IVP6HvNAeZIN6ipqyLZdfYqugk80WIYG/cyhmCGTJEvaMc9U5EVYExGs8= X-Gm-Gg: Acq92OHQQ/nNgYFBfEz+kmrrT8ijCiuRrUj53dp6ChiK2WBBGgu9N2O4r8B0Yp9qYY0 D/HLjAMSDWQZ1492itVE2DSx/hkY8yCmSF+GdpEn7tpmGmfb7RcHltzfN/rdyqC7oFF9Bjde7Am P3UotXVN83LldH8+ug1ZVGXy6Nd/4MNCA1hiyxMRN5ft0vmUSXzwteAQaqdG5sy6paZ1yrLD7ME N5fBftWKW9IQn3DHOLR6GMtEw9cgjfLzeuyrJtcMwvmdflq2cdtWwruV8/ZR5DK9QxEa7SKWbG7 cmofOmWbrYU+DlQGaeWJwlK/EZs6khMeoVzR3Ds1m7X4aVzTbOvfmpOuig6nFxn0PODOAMXqNpg 3i4ao4NbksKb/ijlcFTIi7i9cDvc/iG3CWZb82wLKrkk7lc1uEJbQtfs+wU1etBoA5zIArpMWX2 JTEIQNXtX0fNbCfHUO+12NWQvUX0fpAWJl0Mm1JTWYZEA6hjDYzfFrBLYYdkpr/E1VPCdqCqcSv Bx6rwrKkjGU63x1KGE4NPcb5FBqdIh84yXQW7iYB2CJcyBcAF2+VikB X-Received: by 2002:a05:6214:3c89:b0:8cc:611f:197f with SMTP id 6a1803df08f44-8cc7b69fb91mr349610706d6.44.1779833342560; Tue, 26 May 2026 15:09:02 -0700 (PDT) Received: from com-75606.node.ndb.openai.org ([209.249.37.146]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8cc80dcd43dsm152500136d6.3.2026.05.26.15.09.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 26 May 2026 15:09:02 -0700 (PDT) From: Kyle Zeng To: Jamal Hadi Salim , Jiri Pirko Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Vlad Buslov , Pedro Tammela , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Zeng Subject: [PATCH net] net/sched: act_api: use mutex in tcf_idr_check_alloc Date: Tue, 26 May 2026 15:08:47 -0700 Message-ID: <20260526220847.28365-1-kylebot@openai.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, the NEWTFILTER path uses RCU to guard action idr accesses while the DELTFILTER path uses mutex to guard action accesses. This inconsistency leads to a race condition scenario, which can lead to erroneous operations on refcount, eventually leading to use-after-free situation. In this patch, we revert the introduction of RCU back to mutex in the NEWFILTER path, which is consistent with the DELFILTER path, avoiding the race condition. Fixes: 4b55e86736d5 ("net/sched: act_api: rely on rcu in tcf_idr_check_allo= c") Signed-off-by: Kyle Zeng Acked-by: Jamal Hadi Salim Reviewed-by: Pedro Tammela Reviewed-by: Victor Nogueira --- net/sched/act_api.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 332fd9695e54..63841c3e4310 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -874,36 +874,34 @@ int tcf_idr_check_alloc(struct tc_action_net *tn, u32= *index, u32 max; =20 if (*index) { - rcu_read_lock(); + mutex_lock(&idrinfo->lock); p =3D idr_find(&idrinfo->action_idr, *index); =20 if (IS_ERR(p)) { /* This means that another process allocated * index but did not assign the pointer yet. */ - rcu_read_unlock(); + mutex_unlock(&idrinfo->lock); return -EAGAIN; } =20 if (!p) { /* Empty slot, try to allocate it */ max =3D *index; - rcu_read_unlock(); + mutex_unlock(&idrinfo->lock); goto new; } =20 if (!refcount_inc_not_zero(&p->tcfa_refcnt)) { /* Action was deleted in parallel */ - rcu_read_unlock(); + mutex_unlock(&idrinfo->lock); return -EAGAIN; } =20 if (bind) atomic_inc(&p->tcfa_bindcnt); *a =3D p; - - rcu_read_unlock(); - + mutex_unlock(&idrinfo->lock); return 1; } else { /* Find a slot */ --=20 2.54.0