Commit f7b25cb6 authored by Jamal Hadi Salim's avatar Jamal Hadi Salim Committed by Greg Kroah-Hartman

net sched: fix encoding to use real length

[ Upstream commit 28a10c42 ]

Encoding of the metadata was using the padded length as opposed to
the real length of the data which is a bug per specification.
This has not been an issue todate because all metadatum specified
so far has been 32 bit where aligned and data length are the same width.
This also includes a bug fix for validating the length of a u16 field.
But since there is no metadata of size u16 yes we are fine to include it
here.

While at it get rid of magic numbers.

Fixes: ef6980b6 ("net sched: introduce IFE action")
Signed-off-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 24d2087c
...@@ -52,7 +52,7 @@ int ife_tlv_meta_encode(void *skbdata, u16 attrtype, u16 dlen, const void *dval) ...@@ -52,7 +52,7 @@ int ife_tlv_meta_encode(void *skbdata, u16 attrtype, u16 dlen, const void *dval)
u32 *tlv = (u32 *)(skbdata); u32 *tlv = (u32 *)(skbdata);
u16 totlen = nla_total_size(dlen); /*alignment + hdr */ u16 totlen = nla_total_size(dlen); /*alignment + hdr */
char *dptr = (char *)tlv + NLA_HDRLEN; char *dptr = (char *)tlv + NLA_HDRLEN;
u32 htlv = attrtype << 16 | totlen; u32 htlv = attrtype << 16 | dlen;
*tlv = htonl(htlv); *tlv = htonl(htlv);
memset(dptr, 0, totlen - NLA_HDRLEN); memset(dptr, 0, totlen - NLA_HDRLEN);
...@@ -134,7 +134,7 @@ EXPORT_SYMBOL_GPL(ife_release_meta_gen); ...@@ -134,7 +134,7 @@ EXPORT_SYMBOL_GPL(ife_release_meta_gen);
int ife_validate_meta_u32(void *val, int len) int ife_validate_meta_u32(void *val, int len)
{ {
if (len == 4) if (len == sizeof(u32))
return 0; return 0;
return -EINVAL; return -EINVAL;
...@@ -143,8 +143,8 @@ EXPORT_SYMBOL_GPL(ife_validate_meta_u32); ...@@ -143,8 +143,8 @@ EXPORT_SYMBOL_GPL(ife_validate_meta_u32);
int ife_validate_meta_u16(void *val, int len) int ife_validate_meta_u16(void *val, int len)
{ {
/* length will include padding */ /* length will not include padding */
if (len == NLA_ALIGN(2)) if (len == sizeof(u16))
return 0; return 0;
return -EINVAL; return -EINVAL;
...@@ -652,12 +652,14 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a, ...@@ -652,12 +652,14 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,
u8 *tlvdata = (u8 *)tlv; u8 *tlvdata = (u8 *)tlv;
u16 mtype = tlv->type; u16 mtype = tlv->type;
u16 mlen = tlv->len; u16 mlen = tlv->len;
u16 alen;
mtype = ntohs(mtype); mtype = ntohs(mtype);
mlen = ntohs(mlen); mlen = ntohs(mlen);
alen = NLA_ALIGN(mlen);
if (find_decode_metaid(skb, ife, mtype, (mlen - 4), if (find_decode_metaid(skb, ife, mtype, (mlen - NLA_HDRLEN),
(void *)(tlvdata + 4))) { (void *)(tlvdata + NLA_HDRLEN))) {
/* abuse overlimits to count when we receive metadata /* abuse overlimits to count when we receive metadata
* but dont have an ops for it * but dont have an ops for it
*/ */
...@@ -666,8 +668,8 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a, ...@@ -666,8 +668,8 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,
ife->tcf_qstats.overlimits++; ife->tcf_qstats.overlimits++;
} }
tlvdata += mlen; tlvdata += alen;
ifehdrln -= mlen; ifehdrln -= alen;
tlv = (struct meta_tlvhdr *)tlvdata; tlv = (struct meta_tlvhdr *)tlvdata;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment