summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Tammela <pctammela@mojatatu.com>2026-06-18 11:55:04 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-07-04 13:39:36 +0200
commit2cd0cde87e17cb31694ca935bd00cd3b60db9335 (patch)
tree2be73bccdd30d199c42cf4142d7b5277ebc0f39a
parent651801d75ad0897dbd331b3cc6a4da3e78f60d42 (diff)
downloadlinux-stable-2cd0cde87e17cb31694ca935bd00cd3b60db9335.tar.gz
linux-stable-2cd0cde87e17cb31694ca935bd00cd3b60db9335.zip
net/sched: act_pedit: check static offsets a priori
[ Upstream commit e1201bc781c28766720e78a5e099ffa568be4d74 ] Static key offsets should always be on 32 bit boundaries. Validate them on create/update time for static offsets and move the datapath validation for runtime offsets only. iproute2 already errors out if a given offset and data size cannot be packed to a 32 bit boundary. This change will make sure users which create/update pedit instances directly via netlink also error out, instead of finding out when packets are traversing. Reviewed-by: Jamal Hadi Salim <jhs@mojatatu.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: Pedro Tammela <pctammela@mojatatu.com> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit e1201bc781c28766720e78a5e099ffa568be4d74) Signed-off-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--net/sched/act_pedit.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index d800e0285d5c..999ac09e33d5 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -250,8 +250,16 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
memcpy(nparms->tcfp_keys, parm->keys, ksize);
for (i = 0; i < nparms->tcfp_nkeys; ++i) {
+ u32 offmask = nparms->tcfp_keys[i].offmask;
u32 cur = nparms->tcfp_keys[i].off;
+ /* The AT option can be added to static offsets in the datapath */
+ if (!offmask && cur % 4) {
+ NL_SET_ERR_MSG_MOD(extack, "Offsets must be on 32bit boundaries");
+ ret = -EINVAL;
+ goto put_chain;
+ }
+
/* sanitize the shift value for any later use */
nparms->tcfp_keys[i].shift = min_t(size_t,
BITS_PER_TYPE(int) - 1,
@@ -260,7 +268,7 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
/* The AT option can read a single byte, we can bound the actual
* value with uchar max.
*/
- cur += (0xff & nparms->tcfp_keys[i].offmask) >> nparms->tcfp_keys[i].shift;
+ cur += (0xff & offmask) >> nparms->tcfp_keys[i].shift;
/* Each key touches 4 bytes starting from the computed offset */
nparms->tcfp_off_max_hint =
@@ -429,12 +437,12 @@ static int tcf_pedit_act(struct sk_buff *skb, const struct tc_action *a,
sizeof(_d), &_d);
if (!d)
goto bad;
- offset += (*d & tkey->offmask) >> tkey->shift;
- }
- if (offset % 4) {
- pr_info("tc action pedit offset must be on 32 bit boundaries\n");
- goto bad;
+ offset += (*d & tkey->offmask) >> tkey->shift;
+ if (offset % 4) {
+ pr_info("tc action pedit offset must be on 32 bit boundaries\n");
+ goto bad;
+ }
}
if (!offset_valid(skb, hoffset + offset)) {