Skip to content

Commit 906cce0

Browse files
committed
Merge branch 'net-sched-ife-malformed-ife-packet-fixes'
Alexander Aring says: ==================== net: sched: ife: malformed ife packet fixes As promised at netdev 2.2 tc workshop I am working on adding scapy support for tdc testing. It is still work in progress. I will submit the patches to tdc later (they are not in good shape yet). The good news is I have been able to find bugs which normal packet testing would not be able to find. With fuzzy testing I was able to craft certain malformed packets that IFE action was not able to deal with. This patch set fixes those bugs. changes since v4: - use pskb_may_pull before pointer assign changes since v3: - use pskb_may_pull changes since v2: - remove inline from __ife_tlv_meta_valid - add const to cast to meta_tlvhdr - add acked and reviewed tags ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 7c5aba2 + d57493d commit 906cce0

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

include/net/ife.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
void *ife_encode(struct sk_buff *skb, u16 metalen);
1313
void *ife_decode(struct sk_buff *skb, u16 *metalen);
1414

15-
void *ife_tlv_meta_decode(void *skbdata, u16 *attrtype, u16 *dlen, u16 *totlen);
15+
void *ife_tlv_meta_decode(void *skbdata, const void *ifehdr_end, u16 *attrtype,
16+
u16 *dlen, u16 *totlen);
1617
int ife_tlv_meta_encode(void *skbdata, u16 attrtype, u16 dlen,
1718
const void *dval);
1819

net/ife/ife.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ void *ife_decode(struct sk_buff *skb, u16 *metalen)
6969
int total_pull;
7070
u16 ifehdrln;
7171

72+
if (!pskb_may_pull(skb, skb->dev->hard_header_len + IFE_METAHDRLEN))
73+
return NULL;
74+
7275
ifehdr = (struct ifeheadr *) (skb->data + skb->dev->hard_header_len);
7376
ifehdrln = ntohs(ifehdr->metalen);
7477
total_pull = skb->dev->hard_header_len + ifehdrln;
@@ -92,12 +95,43 @@ struct meta_tlvhdr {
9295
__be16 len;
9396
};
9497

98+
static bool __ife_tlv_meta_valid(const unsigned char *skbdata,
99+
const unsigned char *ifehdr_end)
100+
{
101+
const struct meta_tlvhdr *tlv;
102+
u16 tlvlen;
103+
104+
if (unlikely(skbdata + sizeof(*tlv) > ifehdr_end))
105+
return false;
106+
107+
tlv = (const struct meta_tlvhdr *)skbdata;
108+
tlvlen = ntohs(tlv->len);
109+
110+
/* tlv length field is inc header, check on minimum */
111+
if (tlvlen < NLA_HDRLEN)
112+
return false;
113+
114+
/* overflow by NLA_ALIGN check */
115+
if (NLA_ALIGN(tlvlen) < tlvlen)
116+
return false;
117+
118+
if (unlikely(skbdata + NLA_ALIGN(tlvlen) > ifehdr_end))
119+
return false;
120+
121+
return true;
122+
}
123+
95124
/* Caller takes care of presenting data in network order
96125
*/
97-
void *ife_tlv_meta_decode(void *skbdata, u16 *attrtype, u16 *dlen, u16 *totlen)
126+
void *ife_tlv_meta_decode(void *skbdata, const void *ifehdr_end, u16 *attrtype,
127+
u16 *dlen, u16 *totlen)
98128
{
99-
struct meta_tlvhdr *tlv = (struct meta_tlvhdr *) skbdata;
129+
struct meta_tlvhdr *tlv;
130+
131+
if (!__ife_tlv_meta_valid(skbdata, ifehdr_end))
132+
return NULL;
100133

134+
tlv = (struct meta_tlvhdr *)skbdata;
101135
*dlen = ntohs(tlv->len) - NLA_HDRLEN;
102136
*attrtype = ntohs(tlv->type);
103137

net/sched/act_ife.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ static int find_decode_metaid(struct sk_buff *skb, struct tcf_ife_info *ife,
652652
}
653653
}
654654

655-
return 0;
655+
return -ENOENT;
656656
}
657657

658658
static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,
@@ -682,7 +682,12 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,
682682
u16 mtype;
683683
u16 dlen;
684684

685-
curr_data = ife_tlv_meta_decode(tlv_data, &mtype, &dlen, NULL);
685+
curr_data = ife_tlv_meta_decode(tlv_data, ifehdr_end, &mtype,
686+
&dlen, NULL);
687+
if (!curr_data) {
688+
qstats_drop_inc(this_cpu_ptr(ife->common.cpu_qstats));
689+
return TC_ACT_SHOT;
690+
}
686691

687692
if (find_decode_metaid(skb, ife, mtype, dlen, curr_data)) {
688693
/* abuse overlimits to count when we receive metadata

0 commit comments

Comments
 (0)