Skip to content

Commit 28a10c4

Browse files
jhsmtdavem330
authored andcommitted
net sched: fix encoding to use real length
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: ef6980b ("net sched: introduce IFE action") Signed-off-by: Jamal Hadi Salim <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4870e70 commit 28a10c4

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

net/sched/act_ife.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int ife_tlv_meta_encode(void *skbdata, u16 attrtype, u16 dlen, const void *dval)
5353
u32 *tlv = (u32 *)(skbdata);
5454
u16 totlen = nla_total_size(dlen); /*alignment + hdr */
5555
char *dptr = (char *)tlv + NLA_HDRLEN;
56-
u32 htlv = attrtype << 16 | totlen;
56+
u32 htlv = attrtype << 16 | dlen;
5757

5858
*tlv = htonl(htlv);
5959
memset(dptr, 0, totlen - NLA_HDRLEN);
@@ -135,7 +135,7 @@ EXPORT_SYMBOL_GPL(ife_release_meta_gen);
135135

136136
int ife_validate_meta_u32(void *val, int len)
137137
{
138-
if (len == 4)
138+
if (len == sizeof(u32))
139139
return 0;
140140

141141
return -EINVAL;
@@ -144,8 +144,8 @@ EXPORT_SYMBOL_GPL(ife_validate_meta_u32);
144144

145145
int ife_validate_meta_u16(void *val, int len)
146146
{
147-
/* length will include padding */
148-
if (len == NLA_ALIGN(2))
147+
/* length will not include padding */
148+
if (len == sizeof(u16))
149149
return 0;
150150

151151
return -EINVAL;
@@ -652,12 +652,14 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,
652652
u8 *tlvdata = (u8 *)tlv;
653653
u16 mtype = tlv->type;
654654
u16 mlen = tlv->len;
655+
u16 alen;
655656

656657
mtype = ntohs(mtype);
657658
mlen = ntohs(mlen);
659+
alen = NLA_ALIGN(mlen);
658660

659-
if (find_decode_metaid(skb, ife, mtype, (mlen - 4),
660-
(void *)(tlvdata + 4))) {
661+
if (find_decode_metaid(skb, ife, mtype, (mlen - NLA_HDRLEN),
662+
(void *)(tlvdata + NLA_HDRLEN))) {
661663
/* abuse overlimits to count when we receive metadata
662664
* but dont have an ops for it
663665
*/
@@ -666,8 +668,8 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,
666668
ife->tcf_qstats.overlimits++;
667669
}
668670

669-
tlvdata += mlen;
670-
ifehdrln -= mlen;
671+
tlvdata += alen;
672+
ifehdrln -= alen;
671673
tlv = (struct meta_tlvhdr *)tlvdata;
672674
}
673675

0 commit comments

Comments
 (0)