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 6/8] xfrm: Fix stack-out-of-bounds with misconfigured transport mode policies.
Date: Fri, 22 Dec 2017 10:44:59 +0100	[thread overview]
Message-ID: <20171222094501.23345-7-steffen.klassert@secunet.com> (raw)
In-Reply-To: <20171222094501.23345-1-steffen.klassert@secunet.com>

On policies with a transport mode template, we pass the addresses
from the flowi to xfrm_state_find(), assuming that the IP addresses
(and address family) don't change during transformation.

Unfortunately our policy template validation is not strict enough.
It is possible to configure policies with transport mode template
where the address family of the template does not match the selectors
address family. This lead to stack-out-of-bound reads because
we compare arddesses of the wrong family. Fix this by refusing
such a configuration, address family can not change on transport
mode.

We use the assumption that, on transport mode, the first templates
address family must match the address family of the policy selector.
Subsequent transport mode templates must mach the address family of
the previous template.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/xfrm/xfrm_user.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index ff58c37469d6..bdb48e5dba04 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -1419,11 +1419,14 @@ static void copy_templates(struct xfrm_policy *xp, struct xfrm_user_tmpl *ut,
 
 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;
+
 	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;
+
+		prev_family = ut[i].family;
+
 		switch (ut[i].family) {
 		case AF_INET:
 			break;
-- 
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 ` [PATCH 4/8] xfrm: Fix stack-out-of-bounds read on socket policy lookup Steffen Klassert
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 ` Steffen Klassert [this message]
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-7-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).