* [PATCH 1/2 v2] xfrm: fix a potential use after free in xfrm4_policy.c
@ 2014-10-22 9:09 roy.qing.li
2014-10-22 9:09 ` [PATCH 2/2 v2] xfrm6: fix a potential use after free in xfrm6_policy.c roy.qing.li
2014-10-22 19:35 ` [PATCH 1/2 v2] xfrm: fix a potential use after free in xfrm4_policy.c David Miller
0 siblings, 2 replies; 6+ messages in thread
From: roy.qing.li @ 2014-10-22 9:09 UTC (permalink / raw)
To: netdev
From: Li RongQing <roy.qing.li@gmail.com>
pskb_may_pull() maybe change skb->data and make xprth pointer oboslete,
so recompute the xprth
Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
---
Diff with v1: NEXT_HEAD add a length parameter, which hide on v1
net/ipv4/xfrm4_policy.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
index 6156f68..d7b33c5 100644
--- a/net/ipv4/xfrm4_policy.c
+++ b/net/ipv4/xfrm4_policy.c
@@ -98,11 +98,14 @@ static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
return 0;
}
+#define NEXT_HEAD(skb, length) (skb_network_header(skb) + length)
+
static void
_decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
{
const struct iphdr *iph = ip_hdr(skb);
- u8 *xprth = skb_network_header(skb) + iph->ihl * 4;
+ int ihl = iph->ihl * 4;
+ u8 *xprth = NEXT_HEAD(skb, ihl);
struct flowi4 *fl4 = &fl->u.ip4;
int oif = 0;
@@ -122,7 +125,7 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
case IPPROTO_DCCP:
if (xprth + 4 < skb->data ||
pskb_may_pull(skb, xprth + 4 - skb->data)) {
- __be16 *ports = (__be16 *)xprth;
+ __be16 *ports = (__be16 *)NEXT_HEAD(skb, ihl);
fl4->fl4_sport = ports[!!reverse];
fl4->fl4_dport = ports[!reverse];
@@ -131,7 +134,7 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
case IPPROTO_ICMP:
if (pskb_may_pull(skb, xprth + 2 - skb->data)) {
- u8 *icmp = xprth;
+ u8 *icmp = NEXT_HEAD(skb, ihl);
fl4->fl4_icmp_type = icmp[0];
fl4->fl4_icmp_code = icmp[1];
@@ -140,7 +143,7 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
case IPPROTO_ESP:
if (pskb_may_pull(skb, xprth + 4 - skb->data)) {
- __be32 *ehdr = (__be32 *)xprth;
+ __be32 *ehdr = (__be32 *)NEXT_HEAD(skb, ihl);
fl4->fl4_ipsec_spi = ehdr[0];
}
@@ -148,7 +151,7 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
case IPPROTO_AH:
if (pskb_may_pull(skb, xprth + 8 - skb->data)) {
- __be32 *ah_hdr = (__be32 *)xprth;
+ __be32 *ah_hdr = (__be32 *)NEXT_HEAD(skb, ihl);
fl4->fl4_ipsec_spi = ah_hdr[1];
}
@@ -156,17 +159,19 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
case IPPROTO_COMP:
if (pskb_may_pull(skb, xprth + 4 - skb->data)) {
- __be16 *ipcomp_hdr = (__be16 *)xprth;
+ __be16 *ipcomp_hdr;
+ ipcomp_hdr = (__be16 *)NEXT_HEAD(skb, ihl);
fl4->fl4_ipsec_spi = htonl(ntohs(ipcomp_hdr[1]));
}
break;
case IPPROTO_GRE:
if (pskb_may_pull(skb, xprth + 12 - skb->data)) {
- __be16 *greflags = (__be16 *)xprth;
- __be32 *gre_hdr = (__be32 *)xprth;
+ __be16 *greflags;
+ __be32 *gre_hdr = (__be32 *)NEXT_HEAD(skb, ihl);
+ greflags = (__be16 *)NEXT_HEAD(skb, ihl);
if (greflags[0] & GRE_KEY) {
if (greflags[0] & GRE_CSUM)
gre_hdr++;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2 v2] xfrm6: fix a potential use after free in xfrm6_policy.c
2014-10-22 9:09 [PATCH 1/2 v2] xfrm: fix a potential use after free in xfrm4_policy.c roy.qing.li
@ 2014-10-22 9:09 ` roy.qing.li
2014-10-22 19:39 ` David Miller
2014-10-22 19:35 ` [PATCH 1/2 v2] xfrm: fix a potential use after free in xfrm4_policy.c David Miller
1 sibling, 1 reply; 6+ messages in thread
From: roy.qing.li @ 2014-10-22 9:09 UTC (permalink / raw)
To: netdev
From: Li RongQing <roy.qing.li@gmail.com>
pskb_may_pull() maybe change skb->data and make nh and exthdr pointer
oboslete, so recompute the nd and exthdr
Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
---
Diff v1: add space between the date type and *, like (__be16 *)
net/ipv6/xfrm6_policy.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
index ac49f84..5f98364 100644
--- a/net/ipv6/xfrm6_policy.c
+++ b/net/ipv6/xfrm6_policy.c
@@ -170,8 +170,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
case IPPROTO_DCCP:
if (!onlyproto && (nh + offset + 4 < skb->data ||
pskb_may_pull(skb, nh + offset + 4 - skb->data))) {
- __be16 *ports = (__be16 *)exthdr;
+ __be16 *ports;
+ nh = skb_network_header(skb);
+ ports = (__be16 *)(nh + offset);
fl6->fl6_sport = ports[!!reverse];
fl6->fl6_dport = ports[!reverse];
}
@@ -180,8 +182,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
case IPPROTO_ICMPV6:
if (!onlyproto && pskb_may_pull(skb, nh + offset + 2 - skb->data)) {
- u8 *icmp = (u8 *)exthdr;
+ u8 *icmp;
+ nh = skb_network_header(skb);
+ icmp = (u8 *)(nh + offset);
fl6->fl6_icmp_type = icmp[0];
fl6->fl6_icmp_code = icmp[1];
}
@@ -192,8 +196,9 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
case IPPROTO_MH:
if (!onlyproto && pskb_may_pull(skb, nh + offset + 3 - skb->data)) {
struct ip6_mh *mh;
- mh = (struct ip6_mh *)exthdr;
+ nh = skb_network_header(skb);
+ mh = (struct ip6_mh *)(nh + offset);
fl6->fl6_mh_type = mh->ip6mh_type;
}
fl6->flowi6_proto = nexthdr;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2 v2] xfrm: fix a potential use after free in xfrm4_policy.c
2014-10-22 9:09 [PATCH 1/2 v2] xfrm: fix a potential use after free in xfrm4_policy.c roy.qing.li
2014-10-22 9:09 ` [PATCH 2/2 v2] xfrm6: fix a potential use after free in xfrm6_policy.c roy.qing.li
@ 2014-10-22 19:35 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2014-10-22 19:35 UTC (permalink / raw)
To: roy.qing.li; +Cc: netdev
From: roy.qing.li@gmail.com
Date: Wed, 22 Oct 2014 17:09:52 +0800
> From: Li RongQing <roy.qing.li@gmail.com>
>
> pskb_may_pull() maybe change skb->data and make xprth pointer oboslete,
> so recompute the xprth
>
> Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
> ---
> Diff with v1: NEXT_HEAD add a length parameter, which hide on v1
>
> net/ipv4/xfrm4_policy.c | 21 +++++++++++++--------
> 1 file changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
> index 6156f68..d7b33c5 100644
> --- a/net/ipv4/xfrm4_policy.c
> +++ b/net/ipv4/xfrm4_policy.c
> @@ -98,11 +98,14 @@ static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
> return 0;
> }
>
> +#define NEXT_HEAD(skb, length) (skb_network_header(skb) + length)
> +
If you're going to properly have arguments, use an inline function
rather a macro so you get type checking.
THanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2][V2] xfrm6: fix a potential use after free in xfrm6_policy.c
@ 2014-10-21 0:34 roy.qing.li
2014-10-21 11:57 ` Sergei Shtylyov
0 siblings, 1 reply; 6+ messages in thread
From: roy.qing.li @ 2014-10-21 0:34 UTC (permalink / raw)
To: netdev
From: Li RongQing <roy.qing.li@gmail.com>
pskb_may_pull() maybe change skb->data and make nh and exthdr pointer
oboslete, so recompute the nd and exthdr
V2: insert a space between date type(like __be16) and * as suggested by
Sergei Shtylyov
Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
---
net/ipv6/xfrm6_policy.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
index ac49f84..115fd3b 100644
--- a/net/ipv6/xfrm6_policy.c
+++ b/net/ipv6/xfrm6_policy.c
@@ -170,8 +170,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
case IPPROTO_DCCP:
if (!onlyproto && (nh + offset + 4 < skb->data ||
pskb_may_pull(skb, nh + offset + 4 - skb->data))) {
- __be16 *ports = (__be16 *)exthdr;
+ __be16 *ports;
+ nh = skb_network_header(skb);
+ ports = (__be16 *)(nh + offset);
fl6->fl6_sport = ports[!!reverse];
fl6->fl6_dport = ports[!reverse];
}
@@ -180,8 +182,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
case IPPROTO_ICMPV6:
if (!onlyproto && pskb_may_pull(skb, nh + offset + 2 - skb->data)) {
- u8 *icmp = (u8 *)exthdr;
+ u8 *icmp;
+ nh = skb_network_header(skb);
+ icmp = (u8 *)(nh + offset);
fl6->fl6_icmp_type = icmp[0];
fl6->fl6_icmp_code = icmp[1];
}
@@ -192,8 +196,9 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
case IPPROTO_MH:
if (!onlyproto && pskb_may_pull(skb, nh + offset + 3 - skb->data)) {
struct ip6_mh *mh;
- mh = (struct ip6_mh *)exthdr;
+ nh = skb_network_header(skb);
+ mh = (struct ip6_mh *)(nh + offset);
fl6->fl6_mh_type = mh->ip6mh_type;
}
fl6->flowi6_proto = nexthdr;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-10-22 19:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-22 9:09 [PATCH 1/2 v2] xfrm: fix a potential use after free in xfrm4_policy.c roy.qing.li
2014-10-22 9:09 ` [PATCH 2/2 v2] xfrm6: fix a potential use after free in xfrm6_policy.c roy.qing.li
2014-10-22 19:39 ` David Miller
2014-10-22 19:35 ` [PATCH 1/2 v2] xfrm: fix a potential use after free in xfrm4_policy.c David Miller
-- strict thread matches above, loose matches on Subject: below --
2014-10-21 0:34 [PATCH 2/2][V2] xfrm6: fix a potential use after free in xfrm6_policy.c roy.qing.li
2014-10-21 11:57 ` Sergei Shtylyov
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).