From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f52.google.com (mail-dl1-f52.google.com [74.125.82.52]) (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 224262E0901 for ; Sun, 31 May 2026 19:14:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780254895; cv=none; b=A7RMmAIv+HC/CQrHGyxXZBGyrLWrBiF70NXAgpP3nv3idafoR5v263gQUyf8oCqb32JJhRi/sRcOiMrjv6Le8uZZ+SdwYwONT5c5OtkUTaYlhnDaA1rD4WSEvd7VJ1b9fDa/wJwPwR0jDu+gDyJHv8KxzkDNLK9+uIo8CHCFFCc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780254895; c=relaxed/simple; bh=DAHy8J54jxDA6vvUkqeHi0uN69mIZwRZPtr4XANXSCo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ayEiEpaH63BJEIraz8THPq1gdFXL/E9wXhLYL/caIcrtgO8a02QJQOiYggm6E7T11NRn+9g1oompEtVzPvtoghRq4iE6nzAymahQQihbMAp5pnbQv9B4VdeM278UfcwyQA0LErhnSuFxVhCVzn+1n2ncz0ashuTZK7rKoKytsPo= 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=NdfRqoUM; arc=none smtp.client-ip=74.125.82.52 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="NdfRqoUM" Received: by mail-dl1-f52.google.com with SMTP id a92af1059eb24-1363fe80fe8so11084022c88.0 for ; Sun, 31 May 2026 12:14:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openai.com; s=google; t=1780254892; x=1780859692; 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=3VLIr2839yosGYrgg+bhtZudSWU2zqH+9k+4w7AMccw=; b=NdfRqoUMWIl+2yP1hR2+A58fAmT7EJjKoORI3q0Jrxac+UK2aesKARW+/gozLeB8qc QSwMls1rhd2hCPo5M5pWikfl3gV2eDZNPw4QFxwGnadE4cOF7kGXPNH00Sdj7VEKyKUS pa4e/Ij28iE6z8np95Qtq//aXnH3u+t7kRkP8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780254892; x=1780859692; 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=3VLIr2839yosGYrgg+bhtZudSWU2zqH+9k+4w7AMccw=; b=DOOgimIyRcpLcmUvCqtNGIdn4aJa+YxShjZFQse8Q81Ug/T2ygStNTngWEw7lbPuqJ AmO0Ldk1xSTOJsoDO87zabKq2CUs5QPdZS78BZdk/xPjthv26cXV/6xiZcZc8NpnGE08 wAFrjhEoaZmE43HstXBaM5nTT7+i2ZoYfZTaqv4KSFVj+P88OoqcrjDV7y2EXUxjm08W LrG62k9CDkxIgF7bBc3jbm99G8kUfOzS8TJNdFshrgArwLNaMote3RLaJ75uyG/KANrg s8abC/zQuXuzfwIPifwIGHAhG0VvV/gNKclC57QsXHUvy9c/dR12ZbCCyXZ3OE1BVzF7 d+IQ== X-Forwarded-Encrypted: i=1; AFNElJ/PO+1IkB86i/zye0LPWSUWJgY0JyCD3zIKiI2JJ2zMcQCshxTfefjBGIaaeQWyPWk/dZ6LWCNXlI/5PZ0=@vger.kernel.org X-Gm-Message-State: AOJu0YyYpxWIrLaq82QaspC7WC07H9B6AkA8VOFKOOBfNnFpBFuvm8ZV /lFDJCgZHC4zwxB8cy19VrwAN1z8WpZR+ZdAGgUBVZwCXX7Xsx+2lQeUWlZukXS5f7k= X-Gm-Gg: Acq92OFEQUN9z9dQ5A3p8AinV2nhn5rSLSkZSdmvNvRefPUsUND8P6yrVUO4HuUO2mm XNf4N5Lewsk/cZW/3ETnJVRcfC25v+PUsWaAuf7KoHF1+9TELjmj0POzDSTfngCo5znKWV3LXjl UwIe/5sswsg3sdKKXDLPfTT2su5ShPLiDgPseVDCkRazUbG6SPeGKdoZsvKQuwjy4Zg5vACnKcB Tqt1P1Oujw9DLChGmMJc7SO0tTqaG780nvktV55LOpqExswEVVZhd2XQHN8J+gV7S7ko7wxMFE4 1PZgXOm3TL4scVJGAr+Z7dlFv8aelOIq8fi+102EsR2JInxg6XxbBLqcGiKV324ql9/LIZHUbHL xeIbEEQisdCztr2oImjN4yCjKhgS/BYKgxPMmVDtiUOVmZkGjhYWo8Z8bW0Kbme5YGKa3Jlq1+i LHlZnCHNe7PSjHleYBH8L3wxNsdEnjwd3jYryUMsBwfaOSBmp598HC4Yhi4/1tA5x27NsyMBdXO vBSuL3HitZpNX7cGg== X-Received: by 2002:a05:7022:527:b0:136:b45a:4f66 with SMTP id a92af1059eb24-137d3f0f124mr3347405c88.16.1780254892110; Sun, 31 May 2026 12:14:52 -0700 (PDT) Received: from com-75606 ([104.241.0.233]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-137b2d04287sm6959990c88.0.2026.05.31.12.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 May 2026 12:14:51 -0700 (PDT) Date: Sun, 31 May 2026 12:14:49 -0700 From: Kyle Zeng To: Jamal Hadi Salim Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, victor@mojatatu.com, jiri@resnulli.us, vladbu@nvidia.com, linux-kernel@vger.kernel.org, security@kernel.org, stable@kernel.org, syzbot@syzkaller.appspotmail.com Subject: Re: [PATCH net v2 1/1] net/sched: act_api: use RCU with deferred freeing for action lifecycle Message-ID: References: <20260531160812.68020-1-jhs@mojatatu.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: <20260531160812.68020-1-jhs@mojatatu.com> On Sun, May 31, 2026 at 12:08:12PM -0400, Jamal Hadi Salim wrote: > When NEWTFILTER and DELFILTER are run concurrently it is possible to create a > race with an associated action. > > Let's illustrate with CPU0 running NEWTFILTER and CPU1 running DELFILTER: > > 0: mutex_lock() <-- holds the idr lock > 0: rcu_read_lock() > 0: p = idr_find(idr, index) <-- action p is valid (RCU protects IDR) > 0: mutex_unlock() <-- releases the idr lock > 1: refcount_dec_and_mutex_lock() <-- refcnt 1->0, mutex held > 1: idr_remove(idr, index) <-- Action removed from IDR > 1: mutex_unlock() <-- mutex released allowing us to delete the action > 1: tcf_action_cleanup(p); kfree(p) <-- Kfrees p immediately, no deferral > 0: refcount_inc_not_zero(&p->tcfa_refcnt) <-- ouch, UAF p points to freed memory > > This patch fixes the race condition between NEWTFILTER and DELFILTER by > adding struct rcu_head to tc_action used in the deferral and introducing a > call_rcu() in the delete path to defer the final kfree(). > > Note: this is a revert of commit d7fb60b9cafb ("net_sched: get rid of tcfa_rcu") > but also modernization/simplification to directly use kfree_rcu(). > > Let's illustrate the new restored code path: > > 0: rcu_read_lock() > 1: refcount_dec_and_mutex_lock() <-- refcnt 1->0, mutex held > 1: idr_remove(idr, index) > 1: mutex_unlock() > 1: call_rcu(&p->tcfa_rcu, tcf_action_rcu_free) <-- defer kfree after grace period > 0: p = idr_find(idr, index) > 0: refcount_inc_not_zero(&p->tcfa_refcnt) <-- fails, refcnt already 0 > 1: rcu_read_unlock() <-- release so freeing can run after grace period > > After CPU1 calls idr_remove(), the object is no longer reachable through the IDR. > CPU0's subsequent idr_find() will return NULL, and even if it still held a > stale pointer, the immediate kfree() is now deferred until after the RCU grace > period, so no UAF can occur. > > Fixes: d7fb60b9cafb ("net_sched: get rid of tcfa_rcu") > Suggested-by: Jakub Kicinski > Reported-by: Kyle Zeng > Tested-by: Victor Nogueira > Tested-by: syzbot@syzkaller.appspotmail.com > Signed-off-by: Jamal Hadi Salim Tested-by: Kyle Zeng Best, Kyle