From: Al Viro <viro@ZenIV.linux.org.uk>
To: netdev@vger.kernel.org
Cc: Amir Vadai <amir@vadai.me>, David Miller <davem@davemloft.net>
Subject: [RFC][bug?] "net/act_pedit: Introduce 'add' operation" is broken for anything wider than an octet
Date: Wed, 15 Aug 2018 01:22:45 +0100 [thread overview]
Message-ID: <20180815002245.GU6515@ZenIV.linux.org.uk> (raw)
The code doing addition in that commit is
+ switch (cmd) {
+ case TCA_PEDIT_KEY_EX_CMD_SET:
+ val = tkey->val;
+ break;
+ case TCA_PEDIT_KEY_EX_CMD_ADD:
+ val = (*ptr + tkey->val) & ~tkey->mask;
+ break;
+ default:
+ pr_info("tc filter pedit bad command (%d)\n",
+ cmd);
+ goto bad;
+ }
+
+ *ptr = ((*ptr & tkey->mask) ^ val);
Any net-endian field wider than an octet will have the carry between
octets handled wrong on little-endian hosts. Should we at least
verify that ~mask fits into one octet?
As it is, consider e.g. an attempt to subtract 1 from a 16bit field
at offset 2 in a word. We want {0,0,0,1} (0x10000000 from host POV)
to turn into 0, so the value to add would be 0xff000000. Except that
{0, 0, 1, 0} would turn into {0, 0, 1, 0xff} that way, not the
expected {0, 0, 0, 0xff}.
Granted, there's not a lot of wider-than-octet fields where arithmetics
would've made sense, but we probably ought to refuse allowing such
operations. Especially since on big-endian hosts they will work
just fine until you try to move that over to a little-endian box...
Alternatively, we could do something like
val = htonl(be32_to_cpup(ptr) + ntohl(tkey->val)) & ~tkey->mask;
but I'm not sure if that's worth doing. It's not as if there would be
a major overhead, but still...
Comments?
reply other threads:[~2018-08-15 3:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180815002245.GU6515@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=amir@vadai.me \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).