Commit db2c2417 authored by Changli Gao's avatar Changli Gao Committed by David S. Miller

act_pedit: access skb->data safely

access skb->data safely

we should use skb_header_pointer() and skb_store_bits() to access skb->data to
handle small or non-linear skbs.
Signed-off-by: default avatarChangli Gao <xiaosuo@gmail.com>
----
 net/sched/act_pedit.c |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3df95ce9
...@@ -125,7 +125,7 @@ static int tcf_pedit(struct sk_buff *skb, struct tc_action *a, ...@@ -125,7 +125,7 @@ static int tcf_pedit(struct sk_buff *skb, struct tc_action *a,
{ {
struct tcf_pedit *p = a->priv; struct tcf_pedit *p = a->priv;
int i, munged = 0; int i, munged = 0;
u8 *pptr; unsigned int off;
if (!(skb->tc_verd & TC_OK2MUNGE)) { if (!(skb->tc_verd & TC_OK2MUNGE)) {
/* should we set skb->cloned? */ /* should we set skb->cloned? */
...@@ -134,7 +134,7 @@ static int tcf_pedit(struct sk_buff *skb, struct tc_action *a, ...@@ -134,7 +134,7 @@ static int tcf_pedit(struct sk_buff *skb, struct tc_action *a,
} }
} }
pptr = skb_network_header(skb); off = skb_network_offset(skb);
spin_lock(&p->tcf_lock); spin_lock(&p->tcf_lock);
...@@ -144,17 +144,17 @@ static int tcf_pedit(struct sk_buff *skb, struct tc_action *a, ...@@ -144,17 +144,17 @@ static int tcf_pedit(struct sk_buff *skb, struct tc_action *a,
struct tc_pedit_key *tkey = p->tcfp_keys; struct tc_pedit_key *tkey = p->tcfp_keys;
for (i = p->tcfp_nkeys; i > 0; i--, tkey++) { for (i = p->tcfp_nkeys; i > 0; i--, tkey++) {
u32 *ptr; u32 *ptr, _data;
int offset = tkey->off; int offset = tkey->off;
if (tkey->offmask) { if (tkey->offmask) {
if (skb->len > tkey->at) { char *d, _d;
char *j = pptr + tkey->at;
offset += ((*j & tkey->offmask) >> d = skb_header_pointer(skb, off + tkey->at, 1,
tkey->shift); &_d);
} else { if (!d)
goto bad; goto bad;
} offset += (*d & tkey->offmask) >> tkey->shift;
} }
if (offset % 4) { if (offset % 4) {
...@@ -169,9 +169,13 @@ static int tcf_pedit(struct sk_buff *skb, struct tc_action *a, ...@@ -169,9 +169,13 @@ static int tcf_pedit(struct sk_buff *skb, struct tc_action *a,
goto bad; goto bad;
} }
ptr = (u32 *)(pptr+offset); ptr = skb_header_pointer(skb, off + offset, 4, &_data);
if (!ptr)
goto bad;
/* just do it, baby */ /* just do it, baby */
*ptr = ((*ptr & tkey->mask) ^ tkey->val); *ptr = ((*ptr & tkey->mask) ^ tkey->val);
if (ptr == &_data)
skb_store_bits(skb, off + offset, ptr, 4);
munged++; munged++;
} }
......
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