All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Steffen Klassert <steffen.klassert@secunet.com>
Cc: David Miller <davem@davemloft.net>,
	fw@strlen.de, tc@excello.cz, stable@vger.kernel.org
Subject: Re: flow cache removed = xfrm doesnt work
Date: Mon, 27 Nov 2017 11:39:40 +0100	[thread overview]
Message-ID: <20171127103940.GA23412@breakpoint.cc> (raw)
In-Reply-To: <20171127090215.ovy2ysmv6z4fdlkh@gauss3.secunet.de>

Steffen Klassert <steffen.klassert@secunet.com> wrote:
> On Sat, Nov 25, 2017 at 04:50:31AM +0900, David Miller wrote:
> > From: Florian Westphal <fw@strlen.de>
> > Date: Fri, 24 Nov 2017 20:32:12 +0100
> > 
> > > Tomas Charvat <tc@excello.cz> wrote:
> > > 
> > > [ CC stable, Steffen ]
> > > 
> > >> Hi Florian and David, I'm running several servers that use XFRM ipsec.
> > >> It do work well on all kernels bellow 4.14.0.
> > >>
> > >> It doesnt work on 4.14.0-2. There is no any error in dmesg or in
> > >> userspace when I do configure policies.
> > >> 
> > >> Since there is not much info about XFRM in dmesg I have no clue, where
> > >> to start when I want to debug this issue.
> > > 
> > > David, please consider picking up
> > > 94802151894d482e82c324edf2c658f8e6b96508
> > > ("Revert "xfrm: Fix stack-out-of-bounds read in xfrm_state_find.")
> > > 
> > > for the 4.14.y stable queue.
> > > 
> > > I think its a pretty safe bet that this fixes the problem, it broke
> > > transport mode wildcard policy lookup.
> > 
> > Ok, once we have confirmation that this fixes it I also need to pair
> > it up with Steffen's alternative fix for the bug that commit was
> > trying to fix.
> 
> We need this revert in the 4.14.y stable tree anyway as it broke
> transport mode IPsec.
> 
> I thought quite a lot about the original problem that I tried
> to fix. It is a rather subtile thing, like almost all bugs
> reported from syzcaller I have seen.
> 
> In between I think our template validation is not strict enough.
> It is possible to configure policies with transport mode template
> where the selector address family does not match the templates
> address family. The address family can not change on a transport
> mode transformation, so this configuration does not make much
> sense but lead to problems because we use the assumption that
> the address family can not change on thransport mode later on.
> 
> Unfortunately the reproducer provided by syzcaller does not
> trigger anything on my test setup, so I don't even know if
> this fixes this exact problem.
> 
> Florian, could you please give the patch blelow a try?

Doesn't help.

>  static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)
>  {
> +	u16 prev_family;
>  	int i;
>  
>  	if (nr > XFRM_MAX_DEPTH)
>  		return -EINVAL;
>  
> +	prev_family = family;

family is AF_INET6 (10), nr is 1.

>  	for (i = 0; i < nr; i++) {
>  		/* We never validated the ut->family value, so many
>  		 * applications simply leave it at zero.  The check was
> @@ -1435,6 +1438,12 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)
>  		if (!ut[i].family)
>  			ut[i].family = family;
>  
> +		if ((ut[i].mode == XFRM_MODE_TRANSPORT) &&
> +		    (ut[i].family != prev_family))
> +			return -EINVAL;

mode is XFRM_MODE_TRANSPORT, family == prev_family (10), so no
-EINVAL here.

Socket is AF_INET6.
setsockopt(3, SOL_IPV6, 0x23 /* IPV6_??? */, ...
sendto(3, "", 0, MSG_EOR|MSG_NOSIGNAL|0x10, {sa_family=AF_INET,
	sin_port=htons(20002), sin_addr=inet_addr("0.0.0.0")}, 16) = -1
	EAGAIN (Resource temporarily unavailable)

and then used with AF_INET address, which causes the KASAN warning
as we feed xfrm_state_find with on-stack ipv4 addresses.

  parent reply	other threads:[~2017-11-27 10:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1871ed24-b210-44ad-2a9f-8ff6c9c8fcb5@excello.cz>
2017-11-24 19:32 ` flow cache removed = xfrm doesnt work Florian Westphal
2017-11-24 19:50   ` David Miller
2017-11-27  9:02     ` Steffen Klassert
2017-11-27  9:39       ` Tomas Charvat
2017-11-27 11:41         ` Steffen Klassert
2017-11-27 12:36           ` Tomas Charvat
2017-11-27 12:49             ` Steffen Klassert
2017-11-27 16:46               ` Tomas Charvat
2017-11-30 10:20                 ` Steffen Klassert
2018-01-19 22:48                   ` Tomas Charvat
2017-11-27 10:39       ` Florian Westphal [this message]
2017-11-27 11:32         ` Steffen Klassert
2017-11-30  6:06         ` Steffen Klassert
2017-11-25 13:13   ` Tomas Charvat

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171127103940.GA23412@breakpoint.cc \
    --to=fw@strlen.de \
    --cc=davem@davemloft.net \
    --cc=stable@vger.kernel.org \
    --cc=steffen.klassert@secunet.com \
    --cc=tc@excello.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.