stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Daniel Borkmann <dborkman@redhat.com>,
	Vlad Yasevich <vyasevich@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Luis Henriques <luis.henriques@canonical.com>,
	Andy Whitcroft <andy.whitcroft@canonical.com>,
	Brad Figg <brad.figg@canonical.com>, Willy Tarreau <w@1wt.eu>
Subject: [ 21/25] net: sctp: fix remote memory pressure from excessive queueing
Date: Sat, 06 Dec 2014 18:42:09 +0100	[thread overview]
Message-ID: <20141206174149.327885974@1wt.eu> (raw)
In-Reply-To: <2a26e912d2438674771c36169c190830@local>

2.6.32-longterm review patch.  If anyone has any objections, please let me know.

------------------

From: Daniel Borkmann <dborkman@redhat.com>

commit b2d33ef40de7161c23032106284959ae75bdf3cd upstream

This scenario is not limited to ASCONF, just taken as one
example triggering the issue. When receiving ASCONF probes
in the form of ...

  -------------- INIT[ASCONF; ASCONF_ACK] ------------->
  <----------- INIT-ACK[ASCONF; ASCONF_ACK] ------------
  -------------------- COOKIE-ECHO -------------------->
  <-------------------- COOKIE-ACK ---------------------
  ---- ASCONF_a; [ASCONF_b; ...; ASCONF_n;] JUNK ------>
  [...]
  ---- ASCONF_m; [ASCONF_o; ...; ASCONF_z;] JUNK ------>

... where ASCONF_a, ASCONF_b, ..., ASCONF_z are good-formed
ASCONFs and have increasing serial numbers, we process such
ASCONF chunk(s) marked with !end_of_packet and !singleton,
since we have not yet reached the SCTP packet end. SCTP does
only do verification on a chunk by chunk basis, as an SCTP
packet is nothing more than just a container of a stream of
chunks which it eats up one by one.

We could run into the case that we receive a packet with a
malformed tail, above marked as trailing JUNK. All previous
chunks are here goodformed, so the stack will eat up all
previous chunks up to this point. In case JUNK does not fit
into a chunk header and there are no more other chunks in
the input queue, or in case JUNK contains a garbage chunk
header, but the encoded chunk length would exceed the skb
tail, or we came here from an entirely different scenario
and the chunk has pdiscard=1 mark (without having had a flush
point), it will happen, that we will excessively queue up
the association's output queue (a correct final chunk may
then turn it into a response flood when flushing the
queue ;)): I ran a simple script with incremental ASCONF
serial numbers and could see the server side consuming
excessive amount of RAM [before/after: up to 2GB and more].

The issue at heart is that the chunk train basically ends
with !end_of_packet and !singleton markers and since commit
2e3216cd54b1 ("sctp: Follow security requirement of responding
with 1 packet") therefore preventing an output queue flush
point in sctp_do_sm() -> sctp_cmd_interpreter() on the input
chunk (chunk = event_arg) even though local_cork is set,
but its precedence has changed since then. In the normal
case, the last chunk with end_of_packet=1 would trigger the
queue flush to accommodate possible outgoing bundling.

In the input queue, sctp_inq_pop() seems to do the right thing
in terms of discarding invalid chunks. So, above JUNK will
not enter the state machine and instead be released and exit
the sctp_assoc_bh_rcv() chunk processing loop. It's simply
the flush point being missing at loop exit. Adding a try-flush
approach on the output queue might not work as the underlying
infrastructure might be long gone at this point due to the
side-effect interpreter run.

One possibility, albeit a bit of a kludge, would be to defer
invalid chunk freeing into the state machine in order to
possibly trigger packet discards and thus indirectly a queue
flush on error. It would surely be better to discard chunks
as in the current, perhaps better controlled environment, but
going back and forth, it's simply architecturally not possible.
I tried various trailing JUNK attack cases and it seems to
look good now.

Joint work with Vlad Yasevich.

Fixes: 2e3216cd54b1 ("sctp: Follow security requirement of responding with 1 packet")
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Vlad Yasevich <vyasevich@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 26b87c7881006311828bb0ab271a551a62dcceb4)
CVE-2014-3688
BugLink: http://bugs.launchpad.net/bugs/1386393
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
Acked-by: Andy Whitcroft <andy.whitcroft@canonical.com>
Signed-off-by: Brad Figg <brad.figg@canonical.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 net/sctp/inqueue.c      | 33 +++++++--------------------------
 net/sctp/sm_statefuns.c |  3 +++
 2 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/net/sctp/inqueue.c b/net/sctp/inqueue.c
index bbf5dd2..7f33bfa 100644
--- a/net/sctp/inqueue.c
+++ b/net/sctp/inqueue.c
@@ -149,18 +149,9 @@ struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue)
 		} else {
 			/* Nothing to do. Next chunk in the packet, please. */
 			ch = (sctp_chunkhdr_t *) chunk->chunk_end;
-
 			/* Force chunk->skb->data to chunk->chunk_end.  */
-			skb_pull(chunk->skb,
-				 chunk->chunk_end - chunk->skb->data);
-
-			/* Verify that we have at least chunk headers
-			 * worth of buffer left.
-			 */
-			if (skb_headlen(chunk->skb) < sizeof(sctp_chunkhdr_t)) {
-				sctp_chunk_free(chunk);
-				chunk = queue->in_progress = NULL;
-			}
+			skb_pull(chunk->skb, chunk->chunk_end - chunk->skb->data);
+			/* We are guaranteed to pull a SCTP header. */
 		}
 	}
 
@@ -196,24 +187,14 @@ struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue)
 	skb_pull(chunk->skb, sizeof(sctp_chunkhdr_t));
 	chunk->subh.v = NULL; /* Subheader is no longer valid.  */
 
-	if (chunk->chunk_end < skb_tail_pointer(chunk->skb)) {
+	if (chunk->chunk_end + sizeof(sctp_chunkhdr_t) <
+	    skb_tail_pointer(chunk->skb)) {
 		/* This is not a singleton */
 		chunk->singleton = 0;
 	} else if (chunk->chunk_end > skb_tail_pointer(chunk->skb)) {
-		/* RFC 2960, Section 6.10  Bundling
-		 *
-		 * Partial chunks MUST NOT be placed in an SCTP packet.
-		 * If the receiver detects a partial chunk, it MUST drop
-		 * the chunk.
-		 *
-		 * Since the end of the chunk is past the end of our buffer
-		 * (which contains the whole packet, we can freely discard
-		 * the whole packet.
-		 */
-		sctp_chunk_free(chunk);
-		chunk = queue->in_progress = NULL;
-
-		return NULL;
+		/* Discard inside state machine. */
+		chunk->pdiscard = 1;
+		chunk->chunk_end = skb_tail_pointer(chunk->skb);
 	} else {
 		/* We are at the end of the packet, so mark the chunk
 		 * in case we need to send a SACK.
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index ac98a1e..d40ff4a 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -160,6 +160,9 @@ sctp_chunk_length_valid(struct sctp_chunk *chunk,
 {
 	__u16 chunk_length = ntohs(chunk->chunk_hdr->length);
 
+	/* Previously already marked? */
+	if (unlikely(chunk->pdiscard))
+		return 0;
 	if (unlikely(chunk_length < required_length))
 		return 0;
 
-- 
1.7.12.2.21.g234cd45.dirty




  parent reply	other threads:[~2014-12-06 17:42 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2a26e912d2438674771c36169c190830@local>
2014-12-06 17:41 ` [ 00/25] 2.6.32.65-longterm review Willy Tarreau
2014-12-08  0:58   ` Willy Tarreau
2014-12-06 17:41 ` [ 01/25] net: sendmsg: fix failed backport of "fix NULL pointer dereference" Willy Tarreau
2014-12-06 17:41 ` [ 02/25] x86, 64-bit: Move K8 B step iret fixup to fault entry asm Willy Tarreau
2014-12-06 17:41 ` [ 03/25] x86-64: Adjust frame type at paranoid_exit: Willy Tarreau
2014-12-06 17:41 ` [ 04/25] x86-64, modify_ldt: Ban 16-bit segments on 64-bit kernels Willy Tarreau
2014-12-06 17:41 ` [ 05/25] x86-32, espfix: Remove filter for espfix32 due to race Willy Tarreau
2014-12-06 17:41 ` [ 06/25] x86-64, espfix: Dont leak bits 31:16 of %esp returning to 16-bit stack Willy Tarreau
2014-12-06 17:41 ` [ 07/25] x86, espfix: Move espfix definitions into a separate header file Willy Tarreau
2014-12-06 17:41 ` [ 08/25] x86, espfix: Fix broken header guard Willy Tarreau
2014-12-06 17:41 ` [ 09/25] x86, espfix: Make espfix64 a Kconfig option, fix UML Willy Tarreau
2014-12-06 17:41 ` [ 10/25] x86, espfix: Make it possible to disable 16-bit support Willy Tarreau
2014-12-08  2:58   ` Ben Hutchings
2014-12-08  7:11     ` Willy Tarreau
2014-12-06 17:41 ` [ 11/25] x86_64/entry/xen: Do not invoke espfix64 on Xen Willy Tarreau
2014-12-06 17:42 ` [ 12/25] x86/espfix/xen: Fix allocation of pages for paravirt page tables Willy Tarreau
2014-12-06 17:42 ` [ 13/25] x86_64, traps: Stop using IST for #SS Willy Tarreau
2014-12-06 17:42 ` [ 14/25] x86_64, traps: Fix the espfix64 #DF fixup and rewrite it in C Willy Tarreau
2014-12-06 17:42 ` [ 15/25] x86_64, traps: Rework bad_iret Willy Tarreau
2014-12-06 17:42 ` [ 16/25] net/l2tp: dont fall back on UDP [get|set]sockopt Willy Tarreau
2014-12-06 17:42 ` [ 17/25] ALSA: control: Dont access controls outside of protected regions Willy Tarreau
2014-12-06 17:42 ` [ 18/25] ALSA: control: Fix replacing user controls Willy Tarreau
2014-12-06 17:42 ` [ 19/25] USB: whiteheat: Added bounds checking for bulk command response Willy Tarreau
2014-12-06 17:42 ` [ 20/25] net: sctp: fix panic on duplicate ASCONF chunks Willy Tarreau
2014-12-06 17:42 ` Willy Tarreau [this message]
2014-12-06 17:42 ` [ 22/25] udf: Avoid infinite loop when processing indirect ICBs Willy Tarreau
2014-12-06 17:42 ` [ 23/25] net: sctp: fix NULL pointer dereference in af->from_addr_param on malformed packet Willy Tarreau
2014-12-06 17:42 ` [ 24/25] mac80211: fix fragmentation code, particularly for encryption Willy Tarreau
2014-12-06 17:42 ` [ 25/25] ttusb-dec: buffer overflow in ioctl Willy Tarreau

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=20141206174149.327885974@1wt.eu \
    --to=w@1wt.eu \
    --cc=andy.whitcroft@canonical.com \
    --cc=brad.figg@canonical.com \
    --cc=davem@davemloft.net \
    --cc=dborkman@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luis.henriques@canonical.com \
    --cc=stable@vger.kernel.org \
    --cc=vyasevich@gmail.com \
    /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).