netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steffen Klassert <steffen.klassert@secunet.com>
To: David Miller <davem@davemloft.net>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	<netdev@vger.kernel.org>
Subject: [PATCH 4/8] xfrm: Fix stack-out-of-bounds read on socket policy lookup.
Date: Fri, 22 Dec 2017 10:44:57 +0100	[thread overview]
Message-ID: <20171222094501.23345-5-steffen.klassert@secunet.com> (raw)
In-Reply-To: <20171222094501.23345-1-steffen.klassert@secunet.com>

When we do tunnel or beet mode, we pass saddr and daddr from the
template to xfrm_state_find(), this is ok. On transport mode,
we pass the addresses from the flowi, assuming that the IP
addresses (and address family) don't change during transformation.
This assumption is wrong in the IPv4 mapped IPv6 case, packet
is IPv4 and template is IPv6.

Fix this by catching address family missmatches of the policy
and the flow already before we do the lookup.

Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/xfrm/xfrm_policy.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 9542975eb2f9..038ec68f6901 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -1168,9 +1168,15 @@ static struct xfrm_policy *xfrm_sk_policy_lookup(const struct sock *sk, int dir,
  again:
 	pol = rcu_dereference(sk->sk_policy[dir]);
 	if (pol != NULL) {
-		bool match = xfrm_selector_match(&pol->selector, fl, family);
+		bool match;
 		int err = 0;
 
+		if (pol->family != family) {
+			pol = NULL;
+			goto out;
+		}
+
+		match = xfrm_selector_match(&pol->selector, fl, family);
 		if (match) {
 			if ((sk->sk_mark & pol->mark.m) != pol->mark.v) {
 				pol = NULL;
-- 
2.14.1

  parent reply	other threads:[~2017-12-22  9:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-22  9:44 pull request (net): ipsec 2017-12-22 Steffen Klassert
2017-12-22  9:44 ` [PATCH 1/8] xfrm: check id proto in validate_tmpl() Steffen Klassert
2017-12-22  9:44 ` [PATCH 2/8] xfrm: fix XFRMA_OUTPUT_MARK policy entry Steffen Klassert
2017-12-22  9:44 ` [PATCH 3/8] xfrm: Fix xfrm_input() to verify state is valid when (encap_type < 0) Steffen Klassert
2017-12-22  9:44 ` Steffen Klassert [this message]
2017-12-22  9:44 ` [PATCH 5/8] xfrm: fix xfrm_do_migrate() with AEAD e.g(AES-GCM) Steffen Klassert
2017-12-22  9:44 ` [PATCH 6/8] xfrm: Fix stack-out-of-bounds with misconfigured transport mode policies Steffen Klassert
2017-12-22  9:45 ` [PATCH 7/8] xfrm: put policies when reusing pcpu xdst entry Steffen Klassert
2017-12-22  9:45 ` [PATCH 8/8] xfrm: Reinject transport-mode packets through tasklet Steffen Klassert
2017-12-27 16:00 ` pull request (net): ipsec 2017-12-22 David Miller

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=20171222094501.23345-5-steffen.klassert@secunet.com \
    --to=steffen.klassert@secunet.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=netdev@vger.kernel.org \
    /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 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).