From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796552474; b=mBGzpwYEK1JtZcXQI+/YYajbE+6Q8wzwv+hnioAFXAZztDD+5dnk14NeRPRgqNfsAY4y /etJjtAOtNWSKj7ToxDJ7JlZu+AUXVd+de75oSvI82i05PD0eYHq6P+n4gnX24dc71zjH geday1h50Fi2NdXSPOZx1UuIpeQEgjyZknvJhB0nE3pIN+8oPlgixHwpiSZ1j23S9Il0e oaBrJmJqCUrACxRkewJtqGRP7D/pxkBzNzfG5N8hlcvIjy2t9NBL8E5kPmdjzdNGr7hYf CYdL6J+1qoxrGnDV2frWecWTYli/7cTyFP9QrWcDi8HwTzZCEd+0SpLY5tdddUTy2Gw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796552474; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=FDYvHLw7rL5OmMBYH9GN8mtabFv+hx69jLv+CAEL63s=; b=nXUoxB+Xbze6X/s/7lSfSrEH/ytgPDF/xu8rRf93OOre1WNj6J7RJoN8OV2EaxS/7eg+ hoG/gw+Ombn3aP4oWBqSzj4vry9NxRM48ydHU89zF+IcCha4Hbdjhma7RE8VVpEJThZ4j TQf7pbfvQq1UqehoDiHcJqsEu7L6ewdrbNKe9R8GPdtNZqEDdVT6OUf1aNWnZxuNkbNVW vFY6QK+VX59NTldmb3KEfXhRPhf591oy9BFbhY6o7mYNy5xDiSSBxPQjc+FrSqo7uTM0+ 9RzwlHrw9f8ygEj2SAkaXe3aSPgMQk7aa9hCO5bqJAXX4m8mUqif6g0M3N1gf8HHdMA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=VwxJnNi9; arc=none smtp.remote-ip=74.125.82.176 Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC8E1606A31F for ; Sun, 6 Dec 2026 10:21:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AC8E1606A31F 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.a=rsa-sha256 header.s=20260707 header.b=VwxJnNi9 Received: by mail-dy1-f176.google.com with SMTP id 5a478bee46e88-3866a784546so3292284eec.0 for ; Sun, 06 Dec 2026 02:21:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796552473; x=1797157273; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FDYvHLw7rL5OmMBYH9GN8mtabFv+hx69jLv+CAEL63s=; b=VwxJnNi9cjIJAKuXCSY4rf7UEKVPqktFaqUhiuQiWCp8haRI0SenjcJC+m15BE99iq XYwOvX3zUb8EFfxYR8Os5t+HpAfGAjuxvpMmuOtLf0k8p2Ic+Tz940k9peMCagfcPPH7 sc/e5PRGzX4GEjWN6Zf+mVACsaBdy7aBiNUc1eN3YqTVnbSaBDBhaN0MLTKtb8Wz3awg C4k0Uctwf3fst/kN8hefbF74Lu4dkKRZnfRVybQKB02op6fNSzMPeIC7rfcoNHmSwmJ2 UcV3M2KZJDSL5ejRAi/SOcIkKGhALfQ5s8gNyMcF9C22peCqLUtbTOHZfOUGY61CgcN5 QTTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796552473; x=1797157273; h=content-transfer-encoding:mime-version:references:in-reply-to :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=FDYvHLw7rL5OmMBYH9GN8mtabFv+hx69jLv+CAEL63s=; b=qL5JpQo2K648oxLdWdr0sbJdR6CZ97dBLxUveLUnpXq7DHEVrnsmKvCJ7eRUe9plW6 cgWKG8Bq/0KbOGuOYNjtzV4cYmPbX2u/2e0L8KGHgvCRJGRzxsG5MH0Ew6uOAEZPTcgP KJaAX+WueAkt2GNswGlQveyFAi78osY6fhv6wwq2oFR7pf50R3wx5APsYQygDFRHlFeg IsqKnGgpJIqni8Rzx87MNqEcsyA8TAy3QdSLAROnzTisVCaT0puXxzCu0TcOckPg/spR N4xSq1nGoN7o0YrCou/zig+tf94PQQdpRVO/zuqmq5TW5/xHrfK1FA4tkZBAAaNBPhH9 3IHA== X-Forwarded-Encrypted: i=1; AL+hErHI5IgKVB4m6rYRAjwec713LmOPZKIGoSr8oaPkB6KI5mt+p2kcvP7A3ngOdE9wOkxb6yV33pE=@vger.kernel.org X-Gm-Message-State: AB4q+uE+ZPrtD4f5NZNcnm8gxulZNa0pU0RPazM+yl6uwpP7/yD1RDkc 6LSovqMgf7Y/+w9j4zE5TW1Ps1NHpCAVzBQD+VCHSQZvaTiRXgPnQwQ= X-Gm-Gg: AZFdTZcsLDny07FIzutAv74iW0JTlmvNOKd8AqbVw/Ut3sJOW3m76mxZ2CopH3Kmrmb /lBF7ktusc0M2JqjxfROysnmV+N5moJp/573tdLYyvVVlg4VyOSg7TySlGpNpGIuq2TKMW060ym p6houaJvRyPBTgbTEJphtX82JYhi/v2jwASZSjOkoZfcrRMH82bjolXkOyjoGzA74HUvYyibWvx dn4I70/a0h/xPHN9wNujH4KkKHmyXT8qSxFlCTM7DFbywI5TUTqJ6Ynrsz7FLxZZTxkrEvQP3f9 xHkeVIc2iw4AYLoyNrRmmSqyDtzqu/X0a+xw0qBWYnUM5+BFSKjbU5jbzFM9TyDUqTDuUcm+fn7 9fPabv6G/SwS+lBekSxsMpi/axMje11nwupOlisT5rTc7F+ctrGx04gWJR8KPDn/r7FTMYw7vzf 7Tk3PpnpaGQR7pdJagV4A416JzS3tkx7sw7wb31ot2YRe8HbtRSoAzYOCdVEuKLOSTfEt9w5gUJ q3/bJ/zrqwUX34pAhKk+UZv/nzjIRe3hGPG8jUxgQ75/N5tOPTtdCVyb8KzoI2rP4wSGdOBxw6u H8Svt/EPvVzpo59LQ2JN X-Received: by 2002:a05:7301:9f06:b0:387:3dd4:e79 with SMTP id 5a478bee46e88-3875212fef3mr10283281eec.26.1796552472694; Sun, 06 Dec 2026 02:21:12 -0800 (PST) Received: from kali ([39.52.248.243]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38752204591sm33937507eec.21.2026.12.06.02.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 02:21:12 -0800 (PST) From: Muhammad Umer To: jhs@mojatatu.com, jiri@resnulli.us Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, willemb@google.com, shuah@kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH net 1/2] net/sched: act_api: reject binding actions that jump to another block Date: Sun, 6 Dec 2026 05:20:11 -0500 Message-ID: <20261206102012.2264-2-mumer.mobi@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261206102012.2264-1-mumer.mobi@gmail.com> References: <20261206102012.2264-1-mumer.mobi@gmail.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A filter can bind an existing action by index. If that action was created by a filter of another block with a "goto chain" control action, it still holds a chain of that other block: the bind path returns before any control action handling and leaves goto_chain as is. tcf_action_exec() then sends classification of the binding filter into a chain of the other block. Filters of that chain may carry a tcf_result class bound to the qdisc owning the other block. The qdisc classifying the packet uses that class pointer as one of its own classes, which crashes when the two qdiscs differ, e.g. an htb qdisc reading a drr class. Before commit 85d0966fa57e ("net/sched: prepare TC actions to properly validate the control action"), the generic code instead re-pointed goto_chain to the binding block on every bind, which made the original filter jump across blocks. Reject the bind in tcf_action_init_1() when the action's goto chain belongs to a block other than the one of the binding filter. Doing it there covers the legacy police path of tcf_exts_validate_ex() too. Binding an action whose goto chain is in the same block is unchanged. The issue was discovered by an AI code review agent and confirmed by triggering it on an unmodified kernel built with KASAN, as an unprivileged user in a new user and network namespace: KASAN reports a slab-out-of-bounds read in htb_enqueue() on a drr class, followed by a general protection fault. Reproducing it did not need any kernel modification or error injection. A reproducer is available and will be sent to the maintainers privately. The fix was tested with that reproducer, which no longer triggers, and with the tc-testing selftests for gact, matchall, police, hfsc, qfq, drr and ets, including the cases added in the next patch. The fix was written with the help of the same AI agent. Fixes: db50514f9a9c ("net: sched: add termination action to allow goto chain") Cc: stable@vger.kernel.org Signed-off-by: Muhammad Umer --- net/sched/act_api.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index e142d33dc5e..78d72568f8f 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1421,6 +1421,20 @@ struct tc_action_ops *tc_action_load_ops(struct nlattr *nla, u32 flags, return a_o; } +static bool tcf_action_goto_chain_foreign(const struct tc_action *a, + const struct tcf_proto *tp) +{ + const struct tcf_chain *chain; + bool foreign; + + rcu_read_lock(); + chain = rcu_dereference(a->goto_chain); + foreign = chain && chain->block != tp->chain->block; + rcu_read_unlock(); + + return foreign; +} + struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, struct nlattr *nla, struct nlattr *est, struct tc_action_ops *a_o, int *init_res, @@ -1467,6 +1481,20 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, goto err_out; *init_res = err; + /* A filter may bind an existing action by index. If that action + * jumps to a chain of another block, the filter would continue + * classification there, and the qdisc owning this filter would + * receive tcf_result class pointers of another qdisc. + */ + if ((flags & TCA_ACT_FLAGS_BIND) && tp && err == ACT_P_BOUND && + tcf_action_goto_chain_foreign(a, tp)) { + NL_SET_ERR_MSG(extack, + "Action jumps to a chain of a different block"); + tcf_idr_release(a, true); + err = -EINVAL; + goto err_out; + } + if (!police && tb[TCA_ACT_COOKIE]) tcf_set_action_cookie(&a->user_cookie, user_cookie); -- 2.53.0