netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [4.9.10] ip_route_me_harder() reading off-slab
       [not found] <CAMVG2ssKxnEsu4=orZyB3UsHwT2CZhpWKFn2UmtoPOEu1KMHPw@mail.gmail.com>
@ 2017-02-17  7:39 ` Florian Westphal
  2017-02-27 14:41   ` Daniel J Blueman
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Westphal @ 2017-02-17  7:39 UTC (permalink / raw)
  To: Daniel J Blueman
  Cc: Netdev, David S. Miller, Eric W. Biederman, David Ahern,
	Jan Beulich, Eric Dumazet, netfilter-devel, pablo

Daniel J Blueman <daniel@quora.org> wrote:

[ CC nf-devel, pablo ]

> When booting a VM in libvirt/KVM attached to a local bridge and KASAN
> enabled on 4.9.10, we see a stream of KASAN warnings about off-slab
> access [1].
> 
> Let me know if you'd like more debug.

Does this patch help?

Subject: [PATCH nf] netfilter: use skb_to_full_sk in ip_route_me_harder

inet_sk(skb->sk) is illegal in case skb is attached to request socket.

Fixes: ca6fb0651883 ("tcp: attach SYNACK messages to request sockets instead of listener")
Reported by: Daniel J Blueman <daniel@quora.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/ipv4/netfilter.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/netfilter.c b/net/ipv4/netfilter.c
index b3cc1335adbc..c0cc6aa8cfaa 100644
--- a/net/ipv4/netfilter.c
+++ b/net/ipv4/netfilter.c
@@ -23,7 +23,8 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t
 	struct rtable *rt;
 	struct flowi4 fl4 = {};
 	__be32 saddr = iph->saddr;
-	__u8 flags = skb->sk ? inet_sk_flowi_flags(skb->sk) : 0;
+	const struct sock *sk = skb_to_full_sk(skb);
+	__u8 flags = sk ? inet_sk_flowi_flags(sk) : 0;
 	struct net_device *dev = skb_dst(skb)->dev;
 	unsigned int hh_len;
 
@@ -40,7 +41,7 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t
 	fl4.daddr = iph->daddr;
 	fl4.saddr = saddr;
 	fl4.flowi4_tos = RT_TOS(iph->tos);
-	fl4.flowi4_oif = skb->sk ? skb->sk->sk_bound_dev_if : 0;
+	fl4.flowi4_oif = sk ? sk->sk_bound_dev_if : 0;
 	if (!fl4.flowi4_oif)
 		fl4.flowi4_oif = l3mdev_master_ifindex(dev);
 	fl4.flowi4_mark = skb->mark;
@@ -61,7 +62,7 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t
 	    xfrm_decode_session(skb, flowi4_to_flowi(&fl4), AF_INET) == 0) {
 		struct dst_entry *dst = skb_dst(skb);
 		skb_dst_set(skb, NULL);
-		dst = xfrm_lookup(net, dst, flowi4_to_flowi(&fl4), skb->sk, 0);
+		dst = xfrm_lookup(net, dst, flowi4_to_flowi(&fl4), sk, 0);
 		if (IS_ERR(dst))
 			return PTR_ERR(dst);
 		skb_dst_set(skb, dst);
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [4.9.10] ip_route_me_harder() reading off-slab
  2017-02-17  7:39 ` [4.9.10] ip_route_me_harder() reading off-slab Florian Westphal
@ 2017-02-27 14:41   ` Daniel J Blueman
  2017-02-28 11:50     ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel J Blueman @ 2017-02-27 14:41 UTC (permalink / raw)
  To: Florian Westphal
  Cc: Netdev, David S. Miller, Eric W. Biederman, David Ahern,
	Jan Beulich, Eric Dumazet, netfilter-devel, pablo

On 17 February 2017 at 15:39, Florian Westphal <fw@strlen.de> wrote:
> Daniel J Blueman <daniel@quora.org> wrote:
>
> [ CC nf-devel, pablo ]
>
>> When booting a VM in libvirt/KVM attached to a local bridge and KASAN
>> enabled on 4.9.10, we see a stream of KASAN warnings about off-slab
>> access [1].
>>
>> Let me know if you'd like more debug.
>
> Does this patch help?
>
> Subject: [PATCH nf] netfilter: use skb_to_full_sk in ip_route_me_harder
>
> inet_sk(skb->sk) is illegal in case skb is attached to request socket.
>
> Fixes: ca6fb0651883 ("tcp: attach SYNACK messages to request sockets instead of listener")
> Reported by: Daniel J Blueman <daniel@quora.org>
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
>  net/ipv4/netfilter.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/net/ipv4/netfilter.c b/net/ipv4/netfilter.c
> index b3cc1335adbc..c0cc6aa8cfaa 100644
> --- a/net/ipv4/netfilter.c
> +++ b/net/ipv4/netfilter.c
> @@ -23,7 +23,8 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t
>         struct rtable *rt;
>         struct flowi4 fl4 = {};
>         __be32 saddr = iph->saddr;
> -       __u8 flags = skb->sk ? inet_sk_flowi_flags(skb->sk) : 0;
> +       const struct sock *sk = skb_to_full_sk(skb);
> +       __u8 flags = sk ? inet_sk_flowi_flags(sk) : 0;
>         struct net_device *dev = skb_dst(skb)->dev;
>         unsigned int hh_len;
>
> @@ -40,7 +41,7 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t
>         fl4.daddr = iph->daddr;
>         fl4.saddr = saddr;
>         fl4.flowi4_tos = RT_TOS(iph->tos);
> -       fl4.flowi4_oif = skb->sk ? skb->sk->sk_bound_dev_if : 0;
> +       fl4.flowi4_oif = sk ? sk->sk_bound_dev_if : 0;
>         if (!fl4.flowi4_oif)
>                 fl4.flowi4_oif = l3mdev_master_ifindex(dev);
>         fl4.flowi4_mark = skb->mark;
> @@ -61,7 +62,7 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t
>             xfrm_decode_session(skb, flowi4_to_flowi(&fl4), AF_INET) == 0) {
>                 struct dst_entry *dst = skb_dst(skb);
>                 skb_dst_set(skb, NULL);
> -               dst = xfrm_lookup(net, dst, flowi4_to_flowi(&fl4), skb->sk, 0);
> +               dst = xfrm_lookup(net, dst, flowi4_to_flowi(&fl4), sk, 0);
>                 if (IS_ERR(dst))
>                         return PTR_ERR(dst);
>                 skb_dst_set(skb, dst);

Apologies for the delays; this also addresses the issue just fine.

Tested-by: Daniel J Blueman <daniel@quora.org>

Dan
-- 
Daniel J Blueman

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [4.9.10] ip_route_me_harder() reading off-slab
  2017-02-27 14:41   ` Daniel J Blueman
@ 2017-02-28 11:50     ` Pablo Neira Ayuso
  0 siblings, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-02-28 11:50 UTC (permalink / raw)
  To: Daniel J Blueman
  Cc: Florian Westphal, Netdev, David S. Miller, Eric W. Biederman,
	David Ahern, Jan Beulich, Eric Dumazet, netfilter-devel

On Mon, Feb 27, 2017 at 10:41:48PM +0800, Daniel J Blueman wrote:
> On 17 February 2017 at 15:39, Florian Westphal <fw@strlen.de> wrote:
> > Daniel J Blueman <daniel@quora.org> wrote:
> >
> > [ CC nf-devel, pablo ]
> >
> >> When booting a VM in libvirt/KVM attached to a local bridge and KASAN
> >> enabled on 4.9.10, we see a stream of KASAN warnings about off-slab
> >> access [1].
> >>
> >> Let me know if you'd like more debug.
> >
> > Does this patch help?
> >
> > Subject: [PATCH nf] netfilter: use skb_to_full_sk in ip_route_me_harder
> >
> > inet_sk(skb->sk) is illegal in case skb is attached to request socket.
> >
> > Fixes: ca6fb0651883 ("tcp: attach SYNACK messages to request sockets instead of listener")
> > Reported by: Daniel J Blueman <daniel@quora.org>
> > Signed-off-by: Florian Westphal <fw@strlen.de>
[...]
> Apologies for the delays; this also addresses the issue just fine.
> 
> Tested-by: Daniel J Blueman <daniel@quora.org>

Applied, thanks for testing.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-28 12:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CAMVG2ssKxnEsu4=orZyB3UsHwT2CZhpWKFn2UmtoPOEu1KMHPw@mail.gmail.com>
2017-02-17  7:39 ` [4.9.10] ip_route_me_harder() reading off-slab Florian Westphal
2017-02-27 14:41   ` Daniel J Blueman
2017-02-28 11:50     ` Pablo Neira Ayuso

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).