diff -druNp --no-dereference linux-libre-4.4.49-gnu/drivers/net/ethernet/mellanox/mlx4/en_rx.c linux-libre-4.4.50-gnu/drivers/net/ethernet/mellanox/mlx4/en_rx.c
--- linux-libre-4.4.49-gnu/drivers/net/ethernet/mellanox/mlx4/en_rx.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/drivers/net/ethernet/mellanox/mlx4/en_rx.c	2017-02-18 10:39:37.000000000 -0500
@@ -502,8 +502,11 @@ void mlx4_en_recover_from_oom(struct mlx
 		return;
 
 	for (ring = 0; ring < priv->rx_ring_num; ring++) {
-		if (mlx4_en_is_ring_empty(priv->rx_ring[ring]))
+		if (mlx4_en_is_ring_empty(priv->rx_ring[ring])) {
+			local_bh_disable();
 			napi_reschedule(&priv->rx_cq[ring]->napi);
+			local_bh_enable();
+		}
 	}
 }
 
diff -druNp --no-dereference linux-libre-4.4.49-gnu/drivers/net/loopback.c linux-libre-4.4.50-gnu/drivers/net/loopback.c
--- linux-libre-4.4.49-gnu/drivers/net/loopback.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/drivers/net/loopback.c	2017-02-18 10:39:37.000000000 -0500
@@ -164,6 +164,7 @@ static void loopback_setup(struct net_de
 {
 	dev->mtu		= 64 * 1024;
 	dev->hard_header_len	= ETH_HLEN;	/* 14	*/
+	dev->min_header_len	= ETH_HLEN;	/* 14	*/
 	dev->addr_len		= ETH_ALEN;	/* 6	*/
 	dev->type		= ARPHRD_LOOPBACK;	/* 0x0001*/
 	dev->flags		= IFF_LOOPBACK;
diff -druNp --no-dereference linux-libre-4.4.49-gnu/drivers/net/macvtap.c linux-libre-4.4.50-gnu/drivers/net/macvtap.c
--- linux-libre-4.4.49-gnu/drivers/net/macvtap.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/drivers/net/macvtap.c	2017-02-18 10:39:37.000000000 -0500
@@ -725,7 +725,7 @@ static ssize_t macvtap_get_user(struct m
 	ssize_t n;
 
 	if (q->flags & IFF_VNET_HDR) {
-		vnet_hdr_len = q->vnet_hdr_sz;
+		vnet_hdr_len = READ_ONCE(q->vnet_hdr_sz);
 
 		err = -EINVAL;
 		if (len < vnet_hdr_len)
@@ -865,7 +865,7 @@ static ssize_t macvtap_put_user(struct m
 
 	if (q->flags & IFF_VNET_HDR) {
 		struct virtio_net_hdr vnet_hdr;
-		vnet_hdr_len = q->vnet_hdr_sz;
+		vnet_hdr_len = READ_ONCE(q->vnet_hdr_sz);
 		if (iov_iter_count(iter) < vnet_hdr_len)
 			return -EINVAL;
 
diff -druNp --no-dereference linux-libre-4.4.49-gnu/drivers/net/tun.c linux-libre-4.4.50-gnu/drivers/net/tun.c
--- linux-libre-4.4.49-gnu/drivers/net/tun.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/drivers/net/tun.c	2017-02-18 10:39:37.000000000 -0500
@@ -1108,9 +1108,11 @@ static ssize_t tun_get_user(struct tun_s
 	}
 
 	if (tun->flags & IFF_VNET_HDR) {
-		if (len < tun->vnet_hdr_sz)
+		int vnet_hdr_sz = READ_ONCE(tun->vnet_hdr_sz);
+
+		if (len < vnet_hdr_sz)
 			return -EINVAL;
-		len -= tun->vnet_hdr_sz;
+		len -= vnet_hdr_sz;
 
 		n = copy_from_iter(&gso, sizeof(gso), from);
 		if (n != sizeof(gso))
@@ -1122,7 +1124,7 @@ static ssize_t tun_get_user(struct tun_s
 
 		if (tun16_to_cpu(tun, gso.hdr_len) > len)
 			return -EINVAL;
-		iov_iter_advance(from, tun->vnet_hdr_sz - sizeof(gso));
+		iov_iter_advance(from, vnet_hdr_sz - sizeof(gso));
 	}
 
 	if ((tun->flags & TUN_TYPE_MASK) == IFF_TAP) {
@@ -1301,7 +1303,7 @@ static ssize_t tun_put_user(struct tun_s
 		vlan_hlen = VLAN_HLEN;
 
 	if (tun->flags & IFF_VNET_HDR)
-		vnet_hdr_sz = tun->vnet_hdr_sz;
+		vnet_hdr_sz = READ_ONCE(tun->vnet_hdr_sz);
 
 	total = skb->len + vlan_hlen + vnet_hdr_sz;
 
diff -druNp --no-dereference linux-libre-4.4.49-gnu/include/linux/can/core.h linux-libre-4.4.50-gnu/include/linux/can/core.h
--- linux-libre-4.4.49-gnu/include/linux/can/core.h	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/include/linux/can/core.h	2017-02-18 10:39:37.000000000 -0500
@@ -45,10 +45,9 @@ struct can_proto {
 extern int  can_proto_register(const struct can_proto *cp);
 extern void can_proto_unregister(const struct can_proto *cp);
 
-extern int  can_rx_register(struct net_device *dev, canid_t can_id,
-			    canid_t mask,
-			    void (*func)(struct sk_buff *, void *),
-			    void *data, char *ident);
+int can_rx_register(struct net_device *dev, canid_t can_id, canid_t mask,
+		    void (*func)(struct sk_buff *, void *),
+		    void *data, char *ident, struct sock *sk);
 
 extern void can_rx_unregister(struct net_device *dev, canid_t can_id,
 			      canid_t mask,
diff -druNp --no-dereference linux-libre-4.4.49-gnu/include/linux/netdevice.h linux-libre-4.4.50-gnu/include/linux/netdevice.h
--- linux-libre-4.4.49-gnu/include/linux/netdevice.h	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/include/linux/netdevice.h	2017-02-18 10:39:37.000000000 -0500
@@ -1399,6 +1399,7 @@ enum netdev_priv_flags {
  *	@mtu:		Interface MTU value
  *	@type:		Interface hardware type
  *	@hard_header_len: Maximum hardware header length.
+ *	@min_header_len:  Minimum hardware header length
  *
  *	@needed_headroom: Extra headroom the hardware may need, but not in all
  *			  cases can this be guaranteed
@@ -1619,6 +1620,7 @@ struct net_device {
 	unsigned int		mtu;
 	unsigned short		type;
 	unsigned short		hard_header_len;
+	unsigned short		min_header_len;
 
 	unsigned short		needed_headroom;
 	unsigned short		needed_tailroom;
@@ -2541,6 +2543,8 @@ static inline bool dev_validate_header(c
 {
 	if (likely(len >= dev->hard_header_len))
 		return true;
+	if (len < dev->min_header_len)
+		return false;
 
 	if (capable(CAP_SYS_RAWIO)) {
 		memset(ll_header + len, 0, dev->hard_header_len - len);
diff -druNp --no-dereference linux-libre-4.4.49-gnu/include/net/cipso_ipv4.h linux-libre-4.4.50-gnu/include/net/cipso_ipv4.h
--- linux-libre-4.4.49-gnu/include/net/cipso_ipv4.h	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/include/net/cipso_ipv4.h	2017-02-18 10:39:37.000000000 -0500
@@ -309,6 +309,10 @@ static inline int cipso_v4_validate(cons
 	}
 
 	for (opt_iter = 6; opt_iter < opt_len;) {
+		if (opt_iter + 1 == opt_len) {
+			err_offset = opt_iter;
+			goto out;
+		}
 		tag_len = opt[opt_iter + 1];
 		if ((tag_len == 0) || (tag_len > (opt_len - opt_iter))) {
 			err_offset = opt_iter + 1;
diff -druNp --no-dereference linux-libre-4.4.49-gnu/Makefile linux-libre-4.4.50-gnu/Makefile
--- linux-libre-4.4.49-gnu/Makefile	2017-02-15 21:12:18.000000000 -0500
+++ linux-libre-4.4.50-gnu/Makefile	2017-02-18 12:28:21.000000000 -0500
@@ -1,6 +1,6 @@
 VERSION = 4
 PATCHLEVEL = 4
-SUBLEVEL = 49
+SUBLEVEL = 50
 EXTRAVERSION = -gnu
 NAME = Blurry Fish Butt
 
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/can/af_can.c linux-libre-4.4.50-gnu/net/can/af_can.c
--- linux-libre-4.4.49-gnu/net/can/af_can.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/can/af_can.c	2017-02-18 10:39:37.000000000 -0500
@@ -445,6 +445,7 @@ static struct hlist_head *find_rcv_list(
  * @func: callback function on filter match
  * @data: returned parameter for callback function
  * @ident: string for calling module identification
+ * @sk: socket pointer (might be NULL)
  *
  * Description:
  *  Invokes the callback function with the received sk_buff and the given
@@ -468,7 +469,7 @@ static struct hlist_head *find_rcv_list(
  */
 int can_rx_register(struct net_device *dev, canid_t can_id, canid_t mask,
 		    void (*func)(struct sk_buff *, void *), void *data,
-		    char *ident)
+		    char *ident, struct sock *sk)
 {
 	struct receiver *r;
 	struct hlist_head *rl;
@@ -496,6 +497,7 @@ int can_rx_register(struct net_device *d
 		r->func    = func;
 		r->data    = data;
 		r->ident   = ident;
+		r->sk      = sk;
 
 		hlist_add_head_rcu(&r->list, rl);
 		d->entries++;
@@ -520,8 +522,11 @@ EXPORT_SYMBOL(can_rx_register);
 static void can_rx_delete_receiver(struct rcu_head *rp)
 {
 	struct receiver *r = container_of(rp, struct receiver, rcu);
+	struct sock *sk = r->sk;
 
 	kmem_cache_free(rcv_cache, r);
+	if (sk)
+		sock_put(sk);
 }
 
 /**
@@ -596,8 +601,11 @@ void can_rx_unregister(struct net_device
 	spin_unlock(&can_rcvlists_lock);
 
 	/* schedule the receiver item for deletion */
-	if (r)
+	if (r) {
+		if (r->sk)
+			sock_hold(r->sk);
 		call_rcu(&r->rcu, can_rx_delete_receiver);
+	}
 }
 EXPORT_SYMBOL(can_rx_unregister);
 
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/can/af_can.h linux-libre-4.4.50-gnu/net/can/af_can.h
--- linux-libre-4.4.49-gnu/net/can/af_can.h	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/can/af_can.h	2017-02-18 10:39:37.000000000 -0500
@@ -50,13 +50,14 @@
 
 struct receiver {
 	struct hlist_node list;
-	struct rcu_head rcu;
 	canid_t can_id;
 	canid_t mask;
 	unsigned long matches;
 	void (*func)(struct sk_buff *, void *);
 	void *data;
 	char *ident;
+	struct sock *sk;
+	struct rcu_head rcu;
 };
 
 #define CAN_SFF_RCV_ARRAY_SZ (1 << CAN_SFF_ID_BITS)
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/can/bcm.c linux-libre-4.4.50-gnu/net/can/bcm.c
--- linux-libre-4.4.49-gnu/net/can/bcm.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/can/bcm.c	2017-02-18 10:39:37.000000000 -0500
@@ -1179,7 +1179,7 @@ static int bcm_rx_setup(struct bcm_msg_h
 				err = can_rx_register(dev, op->can_id,
 						      REGMASK(op->can_id),
 						      bcm_rx_handler, op,
-						      "bcm");
+						      "bcm", sk);
 
 				op->rx_reg_dev = dev;
 				dev_put(dev);
@@ -1188,7 +1188,7 @@ static int bcm_rx_setup(struct bcm_msg_h
 		} else
 			err = can_rx_register(NULL, op->can_id,
 					      REGMASK(op->can_id),
-					      bcm_rx_handler, op, "bcm");
+					      bcm_rx_handler, op, "bcm", sk);
 		if (err) {
 			/* this bcm rx op is broken -> remove it */
 			list_del(&op->list);
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/can/gw.c linux-libre-4.4.50-gnu/net/can/gw.c
--- linux-libre-4.4.49-gnu/net/can/gw.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/can/gw.c	2017-02-18 10:39:37.000000000 -0500
@@ -442,7 +442,7 @@ static inline int cgw_register_filter(st
 {
 	return can_rx_register(gwj->src.dev, gwj->ccgw.filter.can_id,
 			       gwj->ccgw.filter.can_mask, can_can_gw_rcv,
-			       gwj, "gw");
+			       gwj, "gw", NULL);
 }
 
 static inline void cgw_unregister_filter(struct cgw_job *gwj)
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/can/raw.c linux-libre-4.4.50-gnu/net/can/raw.c
--- linux-libre-4.4.49-gnu/net/can/raw.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/can/raw.c	2017-02-18 10:39:37.000000000 -0500
@@ -190,7 +190,7 @@ static int raw_enable_filters(struct net
 	for (i = 0; i < count; i++) {
 		err = can_rx_register(dev, filter[i].can_id,
 				      filter[i].can_mask,
-				      raw_rcv, sk, "raw");
+				      raw_rcv, sk, "raw", sk);
 		if (err) {
 			/* clean up successfully registered filters */
 			while (--i >= 0)
@@ -211,7 +211,7 @@ static int raw_enable_errfilter(struct n
 
 	if (err_mask)
 		err = can_rx_register(dev, 0, err_mask | CAN_ERR_FLAG,
-				      raw_rcv, sk, "raw");
+				      raw_rcv, sk, "raw", sk);
 
 	return err;
 }
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/core/dev.c linux-libre-4.4.50-gnu/net/core/dev.c
--- linux-libre-4.4.49-gnu/net/core/dev.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/core/dev.c	2017-02-18 10:39:37.000000000 -0500
@@ -1676,24 +1676,19 @@ EXPORT_SYMBOL_GPL(net_dec_ingress_queue)
 
 static struct static_key netstamp_needed __read_mostly;
 #ifdef HAVE_JUMP_LABEL
-/* We are not allowed to call static_key_slow_dec() from irq context
- * If net_disable_timestamp() is called from irq context, defer the
- * static_key_slow_dec() calls.
- */
 static atomic_t netstamp_needed_deferred;
-#endif
-
-void net_enable_timestamp(void)
+static void netstamp_clear(struct work_struct *work)
 {
-#ifdef HAVE_JUMP_LABEL
 	int deferred = atomic_xchg(&netstamp_needed_deferred, 0);
 
-	if (deferred) {
-		while (--deferred)
-			static_key_slow_dec(&netstamp_needed);
-		return;
-	}
+	while (deferred--)
+		static_key_slow_dec(&netstamp_needed);
+}
+static DECLARE_WORK(netstamp_work, netstamp_clear);
 #endif
+
+void net_enable_timestamp(void)
+{
 	static_key_slow_inc(&netstamp_needed);
 }
 EXPORT_SYMBOL(net_enable_timestamp);
@@ -1701,12 +1696,12 @@ EXPORT_SYMBOL(net_enable_timestamp);
 void net_disable_timestamp(void)
 {
 #ifdef HAVE_JUMP_LABEL
-	if (in_interrupt()) {
-		atomic_inc(&netstamp_needed_deferred);
-		return;
-	}
-#endif
+	/* net_disable_timestamp() can be called from non process context */
+	atomic_inc(&netstamp_needed_deferred);
+	schedule_work(&netstamp_work);
+#else
 	static_key_slow_dec(&netstamp_needed);
+#endif
 }
 EXPORT_SYMBOL(net_disable_timestamp);
 
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/ethernet/eth.c linux-libre-4.4.50-gnu/net/ethernet/eth.c
--- linux-libre-4.4.49-gnu/net/ethernet/eth.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/ethernet/eth.c	2017-02-18 10:39:37.000000000 -0500
@@ -353,6 +353,7 @@ void ether_setup(struct net_device *dev)
 	dev->header_ops		= &eth_header_ops;
 	dev->type		= ARPHRD_ETHER;
 	dev->hard_header_len 	= ETH_HLEN;
+	dev->min_header_len	= ETH_HLEN;
 	dev->mtu		= ETH_DATA_LEN;
 	dev->addr_len		= ETH_ALEN;
 	dev->tx_queue_len	= 1000;	/* Ethernet wants good queues */
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/ipv4/cipso_ipv4.c linux-libre-4.4.50-gnu/net/ipv4/cipso_ipv4.c
--- linux-libre-4.4.49-gnu/net/ipv4/cipso_ipv4.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/ipv4/cipso_ipv4.c	2017-02-18 10:39:37.000000000 -0500
@@ -1657,6 +1657,10 @@ int cipso_v4_validate(const struct sk_bu
 				goto validate_return_locked;
 			}
 
+		if (opt_iter + 1 == opt_len) {
+			err_offset = opt_iter;
+			goto validate_return_locked;
+		}
 		tag_len = tag[1];
 		if (tag_len > (opt_len - opt_iter)) {
 			err_offset = opt_iter + 1;
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/ipv4/ip_sockglue.c linux-libre-4.4.50-gnu/net/ipv4/ip_sockglue.c
--- linux-libre-4.4.49-gnu/net/ipv4/ip_sockglue.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/ipv4/ip_sockglue.c	2017-02-18 10:39:37.000000000 -0500
@@ -1192,7 +1192,14 @@ void ipv4_pktinfo_prepare(const struct s
 		pktinfo->ipi_ifindex = 0;
 		pktinfo->ipi_spec_dst.s_addr = 0;
 	}
-	skb_dst_drop(skb);
+	/* We need to keep the dst for __ip_options_echo()
+	 * We could restrict the test to opt.ts_needtime || opt.srr,
+	 * but the following is good enough as IP options are not often used.
+	 */
+	if (unlikely(IPCB(skb)->opt.optlen))
+		skb_dst_force(skb);
+	else
+		skb_dst_drop(skb);
 }
 
 int ip_setsockopt(struct sock *sk, int level,
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/ipv4/ping.c linux-libre-4.4.50-gnu/net/ipv4/ping.c
--- linux-libre-4.4.49-gnu/net/ipv4/ping.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/ipv4/ping.c	2017-02-18 10:39:37.000000000 -0500
@@ -645,6 +645,8 @@ static int ping_v4_push_pending_frames(s
 {
 	struct sk_buff *skb = skb_peek(&sk->sk_write_queue);
 
+	if (!skb)
+		return 0;
 	pfh->wcheck = csum_partial((char *)&pfh->icmph,
 		sizeof(struct icmphdr), pfh->wcheck);
 	pfh->icmph.checksum = csum_fold(pfh->wcheck);
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/ipv4/tcp.c linux-libre-4.4.50-gnu/net/ipv4/tcp.c
--- linux-libre-4.4.49-gnu/net/ipv4/tcp.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/ipv4/tcp.c	2017-02-18 10:39:37.000000000 -0500
@@ -783,6 +783,12 @@ ssize_t tcp_splice_read(struct socket *s
 				ret = -EAGAIN;
 				break;
 			}
+			/* if __tcp_splice_read() got nothing while we have
+			 * an skb in receive queue, we do not want to loop.
+			 * This might happen with URG data.
+			 */
+			if (!skb_queue_empty(&sk->sk_receive_queue))
+				break;
 			sk_wait_data(sk, &timeo, NULL);
 			if (signal_pending(current)) {
 				ret = sock_intr_errno(timeo);
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/ipv4/tcp_output.c linux-libre-4.4.50-gnu/net/ipv4/tcp_output.c
--- linux-libre-4.4.49-gnu/net/ipv4/tcp_output.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/ipv4/tcp_output.c	2017-02-18 10:39:37.000000000 -0500
@@ -2383,9 +2383,11 @@ u32 __tcp_select_window(struct sock *sk)
 	int full_space = min_t(int, tp->window_clamp, allowed_space);
 	int window;
 
-	if (mss > full_space)
+	if (unlikely(mss > full_space)) {
 		mss = full_space;
-
+		if (mss <= 0)
+			return 0;
+	}
 	if (free_space < (full_space >> 1)) {
 		icsk->icsk_ack.quick = 0;
 
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/ipv6/ip6_gre.c linux-libre-4.4.50-gnu/net/ipv6/ip6_gre.c
--- linux-libre-4.4.49-gnu/net/ipv6/ip6_gre.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/ipv6/ip6_gre.c	2017-02-18 10:39:37.000000000 -0500
@@ -55,6 +55,7 @@
 #include <net/ip6_fib.h>
 #include <net/ip6_route.h>
 #include <net/ip6_tunnel.h>
+#include <net/gre.h>
 
 
 static bool log_ecn_error = true;
@@ -367,35 +368,37 @@ static void ip6gre_tunnel_uninit(struct
 
 
 static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
-		u8 type, u8 code, int offset, __be32 info)
+		       u8 type, u8 code, int offset, __be32 info)
 {
-	const struct ipv6hdr *ipv6h = (const struct ipv6hdr *)skb->data;
-	__be16 *p = (__be16 *)(skb->data + offset);
-	int grehlen = offset + 4;
+	const struct gre_base_hdr *greh;
+	const struct ipv6hdr *ipv6h;
+	int grehlen = sizeof(*greh);
 	struct ip6_tnl *t;
+	int key_off = 0;
 	__be16 flags;
+	__be32 key;
 
-	flags = p[0];
-	if (flags&(GRE_CSUM|GRE_KEY|GRE_SEQ|GRE_ROUTING|GRE_VERSION)) {
-		if (flags&(GRE_VERSION|GRE_ROUTING))
-			return;
-		if (flags&GRE_KEY) {
-			grehlen += 4;
-			if (flags&GRE_CSUM)
-				grehlen += 4;
-		}
+	if (!pskb_may_pull(skb, offset + grehlen))
+		return;
+	greh = (const struct gre_base_hdr *)(skb->data + offset);
+	flags = greh->flags;
+	if (flags & (GRE_VERSION | GRE_ROUTING))
+		return;
+	if (flags & GRE_CSUM)
+		grehlen += 4;
+	if (flags & GRE_KEY) {
+		key_off = grehlen + offset;
+		grehlen += 4;
 	}
 
-	/* If only 8 bytes returned, keyed message will be dropped here */
-	if (!pskb_may_pull(skb, grehlen))
+	if (!pskb_may_pull(skb, offset + grehlen))
 		return;
 	ipv6h = (const struct ipv6hdr *)skb->data;
-	p = (__be16 *)(skb->data + offset);
+	greh = (const struct gre_base_hdr *)(skb->data + offset);
+	key = key_off ? *(__be32 *)(skb->data + key_off) : 0;
 
 	t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr,
-				flags & GRE_KEY ?
-				*(((__be32 *)p) + (grehlen / 4) - 1) : 0,
-				p[1]);
+				 key, greh->protocol);
 	if (!t)
 		return;
 
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/ipv6/ip6_tunnel.c linux-libre-4.4.50-gnu/net/ipv6/ip6_tunnel.c
--- linux-libre-4.4.49-gnu/net/ipv6/ip6_tunnel.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/ipv6/ip6_tunnel.c	2017-02-18 10:39:37.000000000 -0500
@@ -479,18 +479,19 @@ ip6_tnl_dev_uninit(struct net_device *de
 
 __u16 ip6_tnl_parse_tlv_enc_lim(struct sk_buff *skb, __u8 *raw)
 {
-	const struct ipv6hdr *ipv6h = (const struct ipv6hdr *) raw;
-	__u8 nexthdr = ipv6h->nexthdr;
-	__u16 off = sizeof(*ipv6h);
+	const struct ipv6hdr *ipv6h = (const struct ipv6hdr *)raw;
+	unsigned int nhoff = raw - skb->data;
+	unsigned int off = nhoff + sizeof(*ipv6h);
+	u8 next, nexthdr = ipv6h->nexthdr;
 
 	while (ipv6_ext_hdr(nexthdr) && nexthdr != NEXTHDR_NONE) {
-		__u16 optlen = 0;
 		struct ipv6_opt_hdr *hdr;
-		if (raw + off + sizeof(*hdr) > skb->data &&
-		    !pskb_may_pull(skb, raw - skb->data + off + sizeof (*hdr)))
+		u16 optlen;
+
+		if (!pskb_may_pull(skb, off + sizeof(*hdr)))
 			break;
 
-		hdr = (struct ipv6_opt_hdr *) (raw + off);
+		hdr = (struct ipv6_opt_hdr *)(skb->data + off);
 		if (nexthdr == NEXTHDR_FRAGMENT) {
 			struct frag_hdr *frag_hdr = (struct frag_hdr *) hdr;
 			if (frag_hdr->frag_off)
@@ -501,20 +502,29 @@ __u16 ip6_tnl_parse_tlv_enc_lim(struct s
 		} else {
 			optlen = ipv6_optlen(hdr);
 		}
+		/* cache hdr->nexthdr, since pskb_may_pull() might
+		 * invalidate hdr
+		 */
+		next = hdr->nexthdr;
 		if (nexthdr == NEXTHDR_DEST) {
-			__u16 i = off + 2;
+			u16 i = 2;
+
+			/* Remember : hdr is no longer valid at this point. */
+			if (!pskb_may_pull(skb, off + optlen))
+				break;
+
 			while (1) {
 				struct ipv6_tlv_tnl_enc_lim *tel;
 
 				/* No more room for encapsulation limit */
-				if (i + sizeof (*tel) > off + optlen)
+				if (i + sizeof(*tel) > optlen)
 					break;
 
-				tel = (struct ipv6_tlv_tnl_enc_lim *) &raw[i];
+				tel = (struct ipv6_tlv_tnl_enc_lim *)(skb->data + off + i);
 				/* return index of option if found and valid */
 				if (tel->type == IPV6_TLV_TNL_ENCAP_LIMIT &&
 				    tel->length == 1)
-					return i;
+					return i + off - nhoff;
 				/* else jump to next option */
 				if (tel->type)
 					i += tel->length + 2;
@@ -522,7 +532,7 @@ __u16 ip6_tnl_parse_tlv_enc_lim(struct s
 					i++;
 			}
 		}
-		nexthdr = hdr->nexthdr;
+		nexthdr = next;
 		off += optlen;
 	}
 	return 0;
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/ipv6/sit.c linux-libre-4.4.50-gnu/net/ipv6/sit.c
--- linux-libre-4.4.49-gnu/net/ipv6/sit.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/ipv6/sit.c	2017-02-18 10:39:37.000000000 -0500
@@ -1389,6 +1389,7 @@ static int ipip6_tunnel_init(struct net_
 	tunnel->dst_cache = alloc_percpu(struct ip_tunnel_dst);
 	if (!tunnel->dst_cache) {
 		free_percpu(dev->tstats);
+		dev->tstats = NULL;
 		return -ENOMEM;
 	}
 
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/ipv6/tcp_ipv6.c linux-libre-4.4.50-gnu/net/ipv6/tcp_ipv6.c
--- linux-libre-4.4.49-gnu/net/ipv6/tcp_ipv6.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/ipv6/tcp_ipv6.c	2017-02-18 10:39:37.000000000 -0500
@@ -974,6 +974,16 @@ drop:
 	return 0; /* don't send reset */
 }
 
+static void tcp_v6_restore_cb(struct sk_buff *skb)
+{
+	/* We need to move header back to the beginning if xfrm6_policy_check()
+	 * and tcp_v6_fill_cb() are going to be called again.
+	 * ip6_datagram_recv_specific_ctl() also expects IP6CB to be there.
+	 */
+	memmove(IP6CB(skb), &TCP_SKB_CB(skb)->header.h6,
+		sizeof(struct inet6_skb_parm));
+}
+
 static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,
 					 struct request_sock *req,
 					 struct dst_entry *dst,
@@ -1163,8 +1173,10 @@ static struct sock *tcp_v6_syn_recv_sock
 						      sk_gfp_atomic(sk, GFP_ATOMIC));
 			consume_skb(ireq->pktopts);
 			ireq->pktopts = NULL;
-			if (newnp->pktoptions)
+			if (newnp->pktoptions) {
+				tcp_v6_restore_cb(newnp->pktoptions);
 				skb_set_owner_r(newnp->pktoptions, newsk);
+			}
 		}
 	}
 
@@ -1179,16 +1191,6 @@ out:
 	return NULL;
 }
 
-static void tcp_v6_restore_cb(struct sk_buff *skb)
-{
-	/* We need to move header back to the beginning if xfrm6_policy_check()
-	 * and tcp_v6_fill_cb() are going to be called again.
-	 * ip6_datagram_recv_specific_ctl() also expects IP6CB to be there.
-	 */
-	memmove(IP6CB(skb), &TCP_SKB_CB(skb)->header.h6,
-		sizeof(struct inet6_skb_parm));
-}
-
 /* The socket must have it's spinlock held when we get
  * here, unless it is a TCP_LISTEN socket.
  *
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/l2tp/l2tp_core.h linux-libre-4.4.50-gnu/net/l2tp/l2tp_core.h
--- linux-libre-4.4.49-gnu/net/l2tp/l2tp_core.h	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/l2tp/l2tp_core.h	2017-02-18 10:39:37.000000000 -0500
@@ -273,6 +273,7 @@ int l2tp_xmit_skb(struct l2tp_session *s
 int l2tp_nl_register_ops(enum l2tp_pwtype pw_type,
 			 const struct l2tp_nl_cmd_ops *ops);
 void l2tp_nl_unregister_ops(enum l2tp_pwtype pw_type);
+int l2tp_ioctl(struct sock *sk, int cmd, unsigned long arg);
 
 /* Session reference counts. Incremented when code obtains a reference
  * to a session.
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/l2tp/l2tp_ip6.c linux-libre-4.4.50-gnu/net/l2tp/l2tp_ip6.c
--- linux-libre-4.4.49-gnu/net/l2tp/l2tp_ip6.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/l2tp/l2tp_ip6.c	2017-02-18 10:39:37.000000000 -0500
@@ -714,7 +714,7 @@ static struct proto l2tp_ip6_prot = {
 	.bind		   = l2tp_ip6_bind,
 	.connect	   = l2tp_ip6_connect,
 	.disconnect	   = l2tp_ip6_disconnect,
-	.ioctl		   = udp_ioctl,
+	.ioctl		   = l2tp_ioctl,
 	.destroy	   = l2tp_ip6_destroy_sock,
 	.setsockopt	   = ipv6_setsockopt,
 	.getsockopt	   = ipv6_getsockopt,
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/l2tp/l2tp_ip.c linux-libre-4.4.50-gnu/net/l2tp/l2tp_ip.c
--- linux-libre-4.4.49-gnu/net/l2tp/l2tp_ip.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/l2tp/l2tp_ip.c	2017-02-18 10:39:37.000000000 -0500
@@ -11,6 +11,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <asm/ioctls.h>
 #include <linux/icmp.h>
 #include <linux/module.h>
 #include <linux/skbuff.h>
@@ -555,6 +556,30 @@ out:
 	return err ? err : copied;
 }
 
+int l2tp_ioctl(struct sock *sk, int cmd, unsigned long arg)
+{
+	struct sk_buff *skb;
+	int amount;
+
+	switch (cmd) {
+	case SIOCOUTQ:
+		amount = sk_wmem_alloc_get(sk);
+		break;
+	case SIOCINQ:
+		spin_lock_bh(&sk->sk_receive_queue.lock);
+		skb = skb_peek(&sk->sk_receive_queue);
+		amount = skb ? skb->len : 0;
+		spin_unlock_bh(&sk->sk_receive_queue.lock);
+		break;
+
+	default:
+		return -ENOIOCTLCMD;
+	}
+
+	return put_user(amount, (int __user *)arg);
+}
+EXPORT_SYMBOL(l2tp_ioctl);
+
 static struct proto l2tp_ip_prot = {
 	.name		   = "L2TP/IP",
 	.owner		   = THIS_MODULE,
@@ -563,7 +588,7 @@ static struct proto l2tp_ip_prot = {
 	.bind		   = l2tp_ip_bind,
 	.connect	   = l2tp_ip_connect,
 	.disconnect	   = l2tp_ip_disconnect,
-	.ioctl		   = udp_ioctl,
+	.ioctl		   = l2tp_ioctl,
 	.destroy	   = l2tp_ip_destroy_sock,
 	.setsockopt	   = ip_setsockopt,
 	.getsockopt	   = ip_getsockopt,
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/packet/af_packet.c linux-libre-4.4.50-gnu/net/packet/af_packet.c
--- linux-libre-4.4.49-gnu/net/packet/af_packet.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/packet/af_packet.c	2017-02-18 10:39:37.000000000 -0500
@@ -2637,7 +2637,7 @@ static int packet_snd(struct socket *soc
 	int vnet_hdr_len;
 	struct packet_sock *po = pkt_sk(sk);
 	unsigned short gso_type = 0;
-	int hlen, tlen;
+	int hlen, tlen, linear;
 	int extra_len = 0;
 	ssize_t n;
 
@@ -2741,8 +2741,9 @@ static int packet_snd(struct socket *soc
 	err = -ENOBUFS;
 	hlen = LL_RESERVED_SPACE(dev);
 	tlen = dev->needed_tailroom;
-	skb = packet_alloc_skb(sk, hlen + tlen, hlen, len,
-			       __virtio16_to_cpu(vio_le(), vnet_hdr.hdr_len),
+	linear = __virtio16_to_cpu(vio_le(), vnet_hdr.hdr_len);
+	linear = max(linear, min_t(int, len, dev->hard_header_len));
+	skb = packet_alloc_skb(sk, hlen + tlen, hlen, len, linear,
 			       msg->msg_flags & MSG_DONTWAIT, &err);
 	if (skb == NULL)
 		goto out_unlock;
diff -druNp --no-dereference linux-libre-4.4.49-gnu/net/sctp/socket.c linux-libre-4.4.50-gnu/net/sctp/socket.c
--- linux-libre-4.4.49-gnu/net/sctp/socket.c	2017-02-14 18:23:09.000000000 -0500
+++ linux-libre-4.4.50-gnu/net/sctp/socket.c	2017-02-18 10:39:37.000000000 -0500
@@ -6960,7 +6960,8 @@ static int sctp_wait_for_sndbuf(struct s
 		 */
 		release_sock(sk);
 		current_timeo = schedule_timeout(current_timeo);
-		BUG_ON(sk != asoc->base.sk);
+		if (sk != asoc->base.sk)
+			goto do_error;
 		lock_sock(sk);
 
 		*timeo_p = current_timeo;
