From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796552474; b=O4shHmnoXc7WROH/AJUJC+9frd0hi4cYul28gJ3mgpU3Tlfi0lD34Z+wdV/qLcrEWqVI WdcY6VM5Q80BJStZ0WS591o69a4IbHHBFAAS7ZrcuIbZiXzK5LTrwQXFUUs3f1+LAw7wV Xq3GfN5Aph9qxMTY6gAL1FtxWcqskG55Vbfwl45Kf114TSvquUkR8lin4L+YsnwHb2iQS MGnFEgsjQ9JyYkVUsc8qL6Tnw0ymP9F/knVBUZP2nQvEH7hxfu7el19kZRpul4I2zcBMx w7bD03R9WxRj1ganXO+RmMvvOZT6Eq2PCiQwTXXCwRn99HCixY0kDJAraYFfInq6vOw== 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=TU+r5PNwv4PZvNyVawYjthzJPzpdserXPziZPoAnOcmtCxFIwOwP8iG9nYK2wB+3JPcu EAdh1tQOtxRuUtjgbw9Bx5xMp4arVqpJnaVhNI+qWKdHcLmnUY0H9BfW2HwQ3G0NNAG8x MIktgouMKwv9PALiQeycyKKLD9+EtvT2MhWbTlnxSOsKoaPKqzRyLeWFsT+PWwIZ5zRNe kAVDiQv+xVAMdK3l3EPqwu87F1OZCg+dD5+Amc13QW0VqA4LemnLAt8nueNlHY6snHK60 IbhMxGe6Wp+P0D2/WpbtUEGT/iCRP6TFf9GlOogY2YLdyLL3MnPGqlcI06fNAwLiUqA== 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.177 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (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 BD972606A321 for ; Sun, 6 Dec 2026 10:21:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BD972606A321 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-f177.google.com with SMTP id 5a478bee46e88-3866a784546so3292287eec.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=gy1b1jkN7gfD2V5QAs84zeKrhn9gc/f5zKAkDaXwEtWTxvV9pe1EIipOpttYSmkDiu RYS3KA0bYSpG6nvveP8DPEk+ZzoTbQFWt0+WxdsXmIvB7zGQLOOsEDropIeFrS52oP3R c2B8e7AaY5qpN5AJRHNSFMxn9QDHljN1PvXfxUlQmmqyJfu6bMLuneYZxPSzBBR0xxgE 8ig5fkadGhIoCIMFJGl0tHuV5FMjsE2PcpeWaFVtyBYNPiYygTQSIUOxeOUejGaoeuop d3oinieVCUY6uOwXtMzdSi4Y8wv4qURnsbql6IyV6Cof+xc5OZTJjMYVHt+K2BXeTN77 QHWw== X-Forwarded-Encrypted: i=1; AL+hErGGRLGiQz1HS6etayih6f7nUZ4UC0FNwU98Jp5LnAB3MQTakaUK+kwaoRyDohvzgIbhaw68Mlt3W0zKXYPj11g=@vger.kernel.org X-Gm-Message-State: AB4q+uHvE3WQV9vP5OfEnEqDwYWAnBL26ux45gwkzf/KWuoib17pavL6 3u/JsQnSDQ45KspjE4c2+xopnPizIyIZ8B+TOpUMdTbwrE9KA5oKZwc= X-Gm-Gg: AZFdTZdHHjiqmt8HlWtZ5gkwk3qe6H0jkTz8a/qTD0LMwt7IQAxcIMUgPKg9NItxtf3 YO2BqQCh3o2I7LrjMIAwSf+7kqYk5mGJat6zisOYjTrmsMHJypaABdaG2yHFRaoztUKZM0xihSQ Znt6yUXFnJ3Mlv7+JfoIMgD4bVwI5iWIJrSDcldnaIsh8uGHrwEhiqZMpqubjKX2CtKWbcKMheZ 11I93ryszRbcmz9IyeenwOTrJi6V7Mp9obdWOI1DDBZb3TZJu7GX3BNmv4uxA4Ew5vWGgzHdfcn v5uaB9uakF08wjrNNVGT1lLXllDbwNmnmKYkQA0LdrQPOo68yX3WUtkiPtI4iVxIJWQMf0ksPK1 ivVmn2tnqlm8cDvEYPNUQ7wpCTG1dOOY8rwOmhTGEn+5bN8GUigLFyvLibQBuqIjEMr38mjBR4X cQUCZY8IDXIEXYrb42XGrxsGECVIkXhtqrIsiyHDCvm2xpR19cQ4H4nfbsqCzR6Xcym0oWMvHnd ReAVE9Gzmz75nMFY6CRGNdks0i0a8bn9SrW1eK0SM8EIRjAADc6xlR2ePO+rwEBpnmcRWgKjAVJ VJr9eumBhxwG6lurNoao 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: linux-kselftest@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