Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Nov 2016 13:14:19 +0000 (UTC)
From:      "George V. Neville-Neil" <gnn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r309057 - stable/11/sys/netinet6
Message-ID:  <201611231314.uANDEJsT047882@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gnn
Date: Wed Nov 23 13:14:19 2016
New Revision: 309057
URL: https://svnweb.freebsd.org/changeset/base/309057

Log:
  MFC: 307541
  
  Limit the number of mbufs that can be allocated for IPV6_2292PKTOPTIONS
  (and IPV6_PKTOPTIONS).
  
  PR:		100219
  Submitted by:	Joseph Kong

Modified:
  stable/11/sys/netinet6/ip6_output.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/netinet6/ip6_output.c
==============================================================================
--- stable/11/sys/netinet6/ip6_output.c	Wed Nov 23 12:20:38 2016	(r309056)
+++ stable/11/sys/netinet6/ip6_output.c	Wed Nov 23 13:14:19 2016	(r309057)
@@ -1398,6 +1398,15 @@ ip6_ctloutput(struct socket *so, struct 
 	int retval;
 #endif
 
+/*
+ * Don't use more than a quarter of mbuf clusters.  N.B.:
+ * nmbclusters is an int, but nmbclusters * MCLBYTES may overflow
+ * on LP64 architectures, so cast to u_long to avoid undefined
+ * behavior.  ILP32 architectures cannot have nmbclusters
+ * large enough to overflow for other reasons.
+ */
+#define IPV6_PKTOPTIONS_MBUF_LIMIT	((u_long)nmbclusters * MCLBYTES / 4)
+
 	level = sopt->sopt_level;
 	op = sopt->sopt_dir;
 	optname = sopt->sopt_name;
@@ -1453,6 +1462,12 @@ ip6_ctloutput(struct socket *so, struct 
 			{
 				struct mbuf *m;
 
+				if (optlen > IPV6_PKTOPTIONS_MBUF_LIMIT) {
+					printf("ip6_ctloutput: mbuf limit hit\n");
+					error = ENOBUFS;
+					break;
+				}
+
 				error = soopt_getm(sopt, &m); /* XXX */
 				if (error != 0)
 					break;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201611231314.uANDEJsT047882>