diff -druNp --no-dereference linux-libre-3.18.76-gnu/arch/x86/include/asm/tlbflush.h linux-libre-3.18.77-gnu/arch/x86/include/asm/tlbflush.h
--- linux-libre-3.18.76-gnu/arch/x86/include/asm/tlbflush.h	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/arch/x86/include/asm/tlbflush.h	2017-10-21 11:07:27.000000000 -0400
@@ -86,7 +86,14 @@ static inline void cr4_set_bits_and_upda
 
 static inline void __native_flush_tlb(void)
 {
+	/*
+	 * If current->mm == NULL then we borrow a mm which may change during a
+	 * task switch and therefore we must not be preempted while we write CR3
+	 * back:
+	 */
+	preempt_disable();
 	native_write_cr3(native_read_cr3());
+	preempt_enable();
 }
 
 static inline void __native_flush_tlb_global_irq_disabled(void)
diff -druNp --no-dereference linux-libre-3.18.76-gnu/block/bsg-lib.c linux-libre-3.18.77-gnu/block/bsg-lib.c
--- linux-libre-3.18.76-gnu/block/bsg-lib.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/block/bsg-lib.c	2017-10-21 11:07:27.000000000 -0400
@@ -147,6 +147,7 @@ static int bsg_create_job(struct device
 failjob_rls_rqst_payload:
 	kfree(job->request_payload.sg_list);
 failjob_rls_job:
+	kfree(job);
 	return -ENOMEM;
 }
 
diff -druNp --no-dereference linux-libre-3.18.76-gnu/crypto/Kconfig linux-libre-3.18.77-gnu/crypto/Kconfig
--- linux-libre-3.18.76-gnu/crypto/Kconfig	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/crypto/Kconfig	2017-10-21 11:07:27.000000000 -0400
@@ -290,6 +290,7 @@ config CRYPTO_XTS
 	select CRYPTO_BLKCIPHER
 	select CRYPTO_MANAGER
 	select CRYPTO_GF128MUL
+	select CRYPTO_ECB
 	help
 	  XTS: IEEE1619/D16 narrow block cipher use with aes-xts-plain,
 	  key size 256, 384 or 512 bits. This implementation currently
diff -druNp --no-dereference linux-libre-3.18.76-gnu/drivers/gpu/drm/drm_dp_mst_topology.c linux-libre-3.18.77-gnu/drivers/gpu/drm/drm_dp_mst_topology.c
--- linux-libre-3.18.76-gnu/drivers/gpu/drm/drm_dp_mst_topology.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/drivers/gpu/drm/drm_dp_mst_topology.c	2017-10-21 11:07:27.000000000 -0400
@@ -1707,6 +1707,7 @@ int drm_dp_update_payload_part1(struct d
 				return -EINVAL;
 			}
 			req_payload.num_slots = mgr->proposed_vcpis[i]->num_slots;
+			req_payload.vcpi = mgr->proposed_vcpis[i]->vcpi;
 		} else {
 			port = NULL;
 			req_payload.num_slots = 0;
@@ -1722,6 +1723,7 @@ int drm_dp_update_payload_part1(struct d
 			if (req_payload.num_slots) {
 				drm_dp_create_payload_step1(mgr, mgr->proposed_vcpis[i]->vcpi, &req_payload);
 				mgr->payloads[i].num_slots = req_payload.num_slots;
+				mgr->payloads[i].vcpi = req_payload.vcpi;
 			} else if (mgr->payloads[i].num_slots) {
 				mgr->payloads[i].num_slots = 0;
 				drm_dp_destroy_payload_step1(mgr, port, port->vcpi.vcpi, &mgr->payloads[i]);
diff -druNp --no-dereference linux-libre-3.18.76-gnu/drivers/iio/adc/xilinx-xadc-core.c linux-libre-3.18.77-gnu/drivers/iio/adc/xilinx-xadc-core.c
--- linux-libre-3.18.76-gnu/drivers/iio/adc/xilinx-xadc-core.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/drivers/iio/adc/xilinx-xadc-core.c	2017-10-21 11:07:27.000000000 -0400
@@ -1223,7 +1223,7 @@ static int xadc_probe(struct platform_de
 
 	ret = xadc->ops->setup(pdev, indio_dev, irq);
 	if (ret)
-		goto err_free_samplerate_trigger;
+		goto err_clk_disable_unprepare;
 
 	ret = request_threaded_irq(irq, xadc->ops->interrupt_handler,
 				xadc->ops->threaded_interrupt_handler,
@@ -1284,6 +1284,8 @@ static int xadc_probe(struct platform_de
 
 err_free_irq:
 	free_irq(irq, indio_dev);
+err_clk_disable_unprepare:
+	clk_disable_unprepare(xadc->clk);
 err_free_samplerate_trigger:
 	if (xadc->ops->flags & XADC_FLAGS_BUFFERED)
 		iio_trigger_free(xadc->samplerate_trigger);
@@ -1293,8 +1295,6 @@ err_free_convst_trigger:
 err_triggered_buffer_cleanup:
 	if (xadc->ops->flags & XADC_FLAGS_BUFFERED)
 		iio_triggered_buffer_cleanup(indio_dev);
-err_clk_disable_unprepare:
-	clk_disable_unprepare(xadc->clk);
 err_device_free:
 	kfree(indio_dev->channels);
 
diff -druNp --no-dereference linux-libre-3.18.76-gnu/drivers/irqchip/irq-crossbar.c linux-libre-3.18.77-gnu/drivers/irqchip/irq-crossbar.c
--- linux-libre-3.18.76-gnu/drivers/irqchip/irq-crossbar.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/drivers/irqchip/irq-crossbar.c	2017-10-21 11:07:27.000000000 -0400
@@ -175,7 +175,8 @@ static const struct irq_domain_ops routa
 
 static int __init crossbar_of_init(struct device_node *node)
 {
-	int i, size, max = 0, reserved = 0, entry;
+	int i, size, reserved = 0;
+	u32 max = 0, entry;
 	const __be32 *irqsr;
 	int ret = -ENOMEM;
 
diff -druNp --no-dereference linux-libre-3.18.76-gnu/drivers/isdn/i4l/isdn_ppp.c linux-libre-3.18.77-gnu/drivers/isdn/i4l/isdn_ppp.c
--- linux-libre-3.18.76-gnu/drivers/isdn/i4l/isdn_ppp.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/drivers/isdn/i4l/isdn_ppp.c	2017-10-21 11:07:27.000000000 -0400
@@ -828,7 +828,6 @@ isdn_ppp_write(int min, struct file *fil
 	isdn_net_local *lp;
 	struct ippp_struct *is;
 	int proto;
-	unsigned char protobuf[4];
 
 	is = file->private_data;
 
@@ -842,24 +841,28 @@ isdn_ppp_write(int min, struct file *fil
 	if (!lp)
 		printk(KERN_DEBUG "isdn_ppp_write: lp == NULL\n");
 	else {
-		/*
-		 * Don't reset huptimer for
-		 * LCP packets. (Echo requests).
-		 */
-		if (copy_from_user(protobuf, buf, 4))
-			return -EFAULT;
-		proto = PPP_PROTOCOL(protobuf);
-		if (proto != PPP_LCP)
-			lp->huptimer = 0;
+		if (lp->isdn_device < 0 || lp->isdn_channel < 0) {
+			unsigned char protobuf[4];
+			/*
+			 * Don't reset huptimer for
+			 * LCP packets. (Echo requests).
+			 */
+			if (copy_from_user(protobuf, buf, 4))
+				return -EFAULT;
+
+			proto = PPP_PROTOCOL(protobuf);
+			if (proto != PPP_LCP)
+				lp->huptimer = 0;
 
-		if (lp->isdn_device < 0 || lp->isdn_channel < 0)
 			return 0;
+		}
 
 		if ((dev->drv[lp->isdn_device]->flags & DRV_FLAG_RUNNING) &&
 		    lp->dialstate == 0 &&
 		    (lp->flags & ISDN_NET_CONNECTED)) {
 			unsigned short hl;
 			struct sk_buff *skb;
+			unsigned char *cpy_buf;
 			/*
 			 * we need to reserve enough space in front of
 			 * sk_buff. old call to dev_alloc_skb only reserved
@@ -872,11 +875,21 @@ isdn_ppp_write(int min, struct file *fil
 				return count;
 			}
 			skb_reserve(skb, hl);
-			if (copy_from_user(skb_put(skb, count), buf, count))
+			cpy_buf = skb_put(skb, count);
+			if (copy_from_user(cpy_buf, buf, count))
 			{
 				kfree_skb(skb);
 				return -EFAULT;
 			}
+
+			/*
+			 * Don't reset huptimer for
+			 * LCP packets. (Echo requests).
+			 */
+			proto = PPP_PROTOCOL(cpy_buf);
+			if (proto != PPP_LCP)
+				lp->huptimer = 0;
+
 			if (is->debug & 0x40) {
 				printk(KERN_DEBUG "ppp xmit: len %d\n", (int) skb->len);
 				isdn_ppp_frame_log("xmit", skb->data, skb->len, 32, is->unit, lp->ppp_slot);
diff -druNp --no-dereference linux-libre-3.18.76-gnu/drivers/net/ethernet/mellanox/mlx4/main.c linux-libre-3.18.77-gnu/drivers/net/ethernet/mellanox/mlx4/main.c
--- linux-libre-3.18.76-gnu/drivers/net/ethernet/mellanox/mlx4/main.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/drivers/net/ethernet/mellanox/mlx4/main.c	2017-10-21 11:07:27.000000000 -0400
@@ -648,8 +648,6 @@ static int mlx4_slave_cap(struct mlx4_de
 		return -ENOSYS;
 	}
 
-	mlx4_log_num_mgm_entry_size = hca_param.log_mc_entry_sz;
-
 	dev->caps.hca_core_clock = hca_param.hca_core_clock;
 
 	memset(&dev_cap, 0, sizeof(dev_cap));
diff -druNp --no-dereference linux-libre-3.18.76-gnu/drivers/scsi/device_handler/scsi_dh_emc.c linux-libre-3.18.77-gnu/drivers/scsi/device_handler/scsi_dh_emc.c
--- linux-libre-3.18.76-gnu/drivers/scsi/device_handler/scsi_dh_emc.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/drivers/scsi/device_handler/scsi_dh_emc.c	2017-10-21 11:07:27.000000000 -0400
@@ -464,7 +464,7 @@ static int clariion_prep_fn(struct scsi_
 static int clariion_std_inquiry(struct scsi_device *sdev,
 				struct clariion_dh_data *csdev)
 {
-	int err;
+	int err = SCSI_DH_OK;
 	char *sp_model;
 
 	err = send_inquiry_cmd(sdev, 0, csdev);
diff -druNp --no-dereference linux-libre-3.18.76-gnu/drivers/target/iscsi/iscsi_target_erl0.c linux-libre-3.18.77-gnu/drivers/target/iscsi/iscsi_target_erl0.c
--- linux-libre-3.18.76-gnu/drivers/target/iscsi/iscsi_target_erl0.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/drivers/target/iscsi/iscsi_target_erl0.c	2017-10-21 11:07:27.000000000 -0400
@@ -45,10 +45,8 @@ void iscsit_set_dataout_sequence_values(
 	 */
 	if (cmd->unsolicited_data) {
 		cmd->seq_start_offset = cmd->write_data_done;
-		cmd->seq_end_offset = (cmd->write_data_done +
-			((cmd->se_cmd.data_length >
-			  conn->sess->sess_ops->FirstBurstLength) ?
-			 conn->sess->sess_ops->FirstBurstLength : cmd->se_cmd.data_length));
+		cmd->seq_end_offset = min(cmd->se_cmd.data_length,
+					conn->sess->sess_ops->FirstBurstLength);
 		return;
 	}
 
diff -druNp --no-dereference linux-libre-3.18.76-gnu/drivers/tty/goldfish.c linux-libre-3.18.77-gnu/drivers/tty/goldfish.c
--- linux-libre-3.18.76-gnu/drivers/tty/goldfish.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/drivers/tty/goldfish.c	2017-10-21 11:07:27.000000000 -0400
@@ -295,7 +295,7 @@ static int goldfish_tty_probe(struct pla
 
 	tty_unregister_device(goldfish_tty_driver, i);
 err_tty_register_device_failed:
-	free_irq(irq, qtty);
+	free_irq(irq, pdev);
 err_request_irq_failed:
 	goldfish_tty_current_line_count--;
 	if (goldfish_tty_current_line_count == 0)
diff -druNp --no-dereference linux-libre-3.18.76-gnu/drivers/watchdog/kempld_wdt.c linux-libre-3.18.77-gnu/drivers/watchdog/kempld_wdt.c
--- linux-libre-3.18.76-gnu/drivers/watchdog/kempld_wdt.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/drivers/watchdog/kempld_wdt.c	2017-10-21 11:07:27.000000000 -0400
@@ -140,12 +140,19 @@ static int kempld_wdt_set_stage_timeout(
 					unsigned int timeout)
 {
 	struct kempld_device_data *pld = wdt_data->pld;
-	u32 prescaler = kempld_prescaler[PRESCALER_21];
+	u32 prescaler;
 	u64 stage_timeout64;
 	u32 stage_timeout;
 	u32 remainder;
 	u8 stage_cfg;
 
+#if GCC_VERSION < 40400
+	/* work around a bug compiling do_div() */
+	prescaler = READ_ONCE(kempld_prescaler[PRESCALER_21]);
+#else
+	prescaler = kempld_prescaler[PRESCALER_21];
+#endif
+
 	if (!stage)
 		return -EINVAL;
 
diff -druNp --no-dereference linux-libre-3.18.76-gnu/fs/btrfs/send.c linux-libre-3.18.77-gnu/fs/btrfs/send.c
--- linux-libre-3.18.76-gnu/fs/btrfs/send.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/fs/btrfs/send.c	2017-10-21 11:07:27.000000000 -0400
@@ -1640,6 +1640,9 @@ static int is_inode_existent(struct send
 {
 	int ret;
 
+	if (ino == BTRFS_FIRST_FREE_OBJECTID)
+		return 1;
+
 	ret = get_cur_inode_state(sctx, ino, gen);
 	if (ret < 0)
 		goto out;
@@ -1825,7 +1828,7 @@ static int will_overwrite_ref(struct sen
 	 * not delted and then re-created, if it was then we have no overwrite
 	 * and we can just unlink this entry.
 	 */
-	if (sctx->parent_root) {
+	if (sctx->parent_root && dir != BTRFS_FIRST_FREE_OBJECTID) {
 		ret = get_inode_info(sctx->parent_root, dir, NULL, &gen, NULL,
 				     NULL, NULL, NULL);
 		if (ret < 0 && ret != -ENOENT)
diff -druNp --no-dereference linux-libre-3.18.76-gnu/fs/ext4/inode.c linux-libre-3.18.77-gnu/fs/ext4/inode.c
--- linux-libre-3.18.76-gnu/fs/ext4/inode.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/fs/ext4/inode.c	2017-10-21 11:07:27.000000000 -0400
@@ -4895,8 +4895,6 @@ int ext4_mark_inode_dirty(handle_t *hand
 						      sbi->s_want_extra_isize,
 						      iloc, handle);
 			if (ret) {
-				ext4_set_inode_state(inode,
-						     EXT4_STATE_NO_EXPAND);
 				if (mnt_count !=
 					le16_to_cpu(sbi->s_es->s_mnt_count)) {
 					ext4_warning(inode->i_sb,
diff -druNp --no-dereference linux-libre-3.18.76-gnu/fs/ext4/xattr.c linux-libre-3.18.77-gnu/fs/ext4/xattr.c
--- linux-libre-3.18.76-gnu/fs/ext4/xattr.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/fs/ext4/xattr.c	2017-10-21 11:07:27.000000000 -0400
@@ -1291,11 +1291,13 @@ int ext4_expand_extra_isize_ea(struct in
 	int s_min_extra_isize = le16_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_min_extra_isize);
 
 	down_write(&EXT4_I(inode)->xattr_sem);
+	/*
+	 * Set EXT4_STATE_NO_EXPAND to avoid recursion when marking inode dirty
+	 */
+	ext4_set_inode_state(inode, EXT4_STATE_NO_EXPAND);
 retry:
-	if (EXT4_I(inode)->i_extra_isize >= new_extra_isize) {
-		up_write(&EXT4_I(inode)->xattr_sem);
-		return 0;
-	}
+	if (EXT4_I(inode)->i_extra_isize >= new_extra_isize)
+		goto out;
 
 	header = IHDR(inode, raw_inode);
 	entry = IFIRST(header);
@@ -1324,8 +1326,7 @@ retry:
 				(void *)header, total_ino,
 				inode->i_sb->s_blocksize);
 		EXT4_I(inode)->i_extra_isize = new_extra_isize;
-		error = 0;
-		goto cleanup;
+		goto out;
 	}
 
 	/*
@@ -1485,6 +1486,8 @@ retry:
 		kfree(bs);
 	}
 	brelse(bh);
+out:
+	ext4_clear_inode_state(inode, EXT4_STATE_NO_EXPAND);
 	up_write(&EXT4_I(inode)->xattr_sem);
 	return 0;
 
@@ -1496,6 +1499,10 @@ cleanup:
 	kfree(is);
 	kfree(bs);
 	brelse(bh);
+	/*
+	 * We deliberately leave EXT4_STATE_NO_EXPAND set here since inode
+	 * size expansion failed.
+	 */
 	up_write(&EXT4_I(inode)->xattr_sem);
 	return error;
 }
diff -druNp --no-dereference linux-libre-3.18.76-gnu/fs/ocfs2/dlmglue.c linux-libre-3.18.77-gnu/fs/ocfs2/dlmglue.c
--- linux-libre-3.18.76-gnu/fs/ocfs2/dlmglue.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/fs/ocfs2/dlmglue.c	2017-10-21 11:07:27.000000000 -0400
@@ -531,6 +531,7 @@ void ocfs2_lock_res_init_once(struct ocf
 	init_waitqueue_head(&res->l_event);
 	INIT_LIST_HEAD(&res->l_blocked_list);
 	INIT_LIST_HEAD(&res->l_mask_waiters);
+	INIT_LIST_HEAD(&res->l_holders);
 }
 
 void ocfs2_inode_lock_res_init(struct ocfs2_lock_res *res,
@@ -748,6 +749,50 @@ void ocfs2_lock_res_free(struct ocfs2_lo
 	res->l_flags = 0UL;
 }
 
+/*
+ * Keep a list of processes who have interest in a lockres.
+ * Note: this is now only uesed for check recursive cluster locking.
+ */
+static inline void ocfs2_add_holder(struct ocfs2_lock_res *lockres,
+				   struct ocfs2_lock_holder *oh)
+{
+	INIT_LIST_HEAD(&oh->oh_list);
+	oh->oh_owner_pid = get_pid(task_pid(current));
+
+	spin_lock(&lockres->l_lock);
+	list_add_tail(&oh->oh_list, &lockres->l_holders);
+	spin_unlock(&lockres->l_lock);
+}
+
+static inline void ocfs2_remove_holder(struct ocfs2_lock_res *lockres,
+				       struct ocfs2_lock_holder *oh)
+{
+	spin_lock(&lockres->l_lock);
+	list_del(&oh->oh_list);
+	spin_unlock(&lockres->l_lock);
+
+	put_pid(oh->oh_owner_pid);
+}
+
+static inline int ocfs2_is_locked_by_me(struct ocfs2_lock_res *lockres)
+{
+	struct ocfs2_lock_holder *oh;
+	struct pid *pid;
+
+	/* look in the list of holders for one with the current task as owner */
+	spin_lock(&lockres->l_lock);
+	pid = task_pid(current);
+	list_for_each_entry(oh, &lockres->l_holders, oh_list) {
+		if (oh->oh_owner_pid == pid) {
+			spin_unlock(&lockres->l_lock);
+			return 1;
+		}
+	}
+	spin_unlock(&lockres->l_lock);
+
+	return 0;
+}
+
 static inline void ocfs2_inc_holders(struct ocfs2_lock_res *lockres,
 				     int level)
 {
@@ -2313,8 +2358,9 @@ int ocfs2_inode_lock_full_nested(struct
 		goto getbh;
 	}
 
-	if (ocfs2_mount_local(osb))
-		goto local;
+	if ((arg_flags & OCFS2_META_LOCK_GETBH) ||
+	    ocfs2_mount_local(osb))
+		goto update;
 
 	if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
 		ocfs2_wait_for_recovery(osb);
@@ -2343,7 +2389,7 @@ int ocfs2_inode_lock_full_nested(struct
 	if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
 		ocfs2_wait_for_recovery(osb);
 
-local:
+update:
 	/*
 	 * We only see this flag if we're being called from
 	 * ocfs2_read_locked_inode(). It means we're locking an inode
@@ -2485,6 +2531,59 @@ void ocfs2_inode_unlock(struct inode *in
 		ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
 }
 
+/*
+ * This _tracker variantes are introduced to deal with the recursive cluster
+ * locking issue. The idea is to keep track of a lock holder on the stack of
+ * the current process. If there's a lock holder on the stack, we know the
+ * task context is already protected by cluster locking. Currently, they're
+ * used in some VFS entry routines.
+ *
+ * return < 0 on error, return == 0 if there's no lock holder on the stack
+ * before this call, return == 1 if this call would be a recursive locking.
+ */
+int ocfs2_inode_lock_tracker(struct inode *inode,
+			     struct buffer_head **ret_bh,
+			     int ex,
+			     struct ocfs2_lock_holder *oh)
+{
+	int status;
+	int arg_flags = 0, has_locked;
+	struct ocfs2_lock_res *lockres;
+
+	lockres = &OCFS2_I(inode)->ip_inode_lockres;
+	has_locked = ocfs2_is_locked_by_me(lockres);
+	/* Just get buffer head if the cluster lock has been taken */
+	if (has_locked)
+		arg_flags = OCFS2_META_LOCK_GETBH;
+
+	if (likely(!has_locked || ret_bh)) {
+		status = ocfs2_inode_lock_full(inode, ret_bh, ex, arg_flags);
+		if (status < 0) {
+			if (status != -ENOENT)
+				mlog_errno(status);
+			return status;
+		}
+	}
+	if (!has_locked)
+		ocfs2_add_holder(lockres, oh);
+
+	return has_locked;
+}
+
+void ocfs2_inode_unlock_tracker(struct inode *inode,
+				int ex,
+				struct ocfs2_lock_holder *oh,
+				int had_lock)
+{
+	struct ocfs2_lock_res *lockres;
+
+	lockres = &OCFS2_I(inode)->ip_inode_lockres;
+	if (!had_lock) {
+		ocfs2_remove_holder(lockres, oh);
+		ocfs2_inode_unlock(inode, ex);
+	}
+}
+
 int ocfs2_orphan_scan_lock(struct ocfs2_super *osb, u32 *seqno)
 {
 	struct ocfs2_lock_res *lockres;
diff -druNp --no-dereference linux-libre-3.18.76-gnu/fs/ocfs2/dlmglue.h linux-libre-3.18.77-gnu/fs/ocfs2/dlmglue.h
--- linux-libre-3.18.76-gnu/fs/ocfs2/dlmglue.h	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/fs/ocfs2/dlmglue.h	2017-10-21 11:07:27.000000000 -0400
@@ -70,6 +70,11 @@ struct ocfs2_orphan_scan_lvb {
 	__be32	lvb_os_seqno;
 };
 
+struct ocfs2_lock_holder {
+	struct list_head oh_list;
+	struct pid *oh_owner_pid;
+};
+
 /* ocfs2_inode_lock_full() 'arg_flags' flags */
 /* don't wait on recovery. */
 #define OCFS2_META_LOCK_RECOVERY	(0x01)
@@ -77,6 +82,8 @@ struct ocfs2_orphan_scan_lvb {
 #define OCFS2_META_LOCK_NOQUEUE		(0x02)
 /* don't block waiting for the downconvert thread, instead return -EAGAIN */
 #define OCFS2_LOCK_NONBLOCK		(0x04)
+/* just get back disk inode bh if we've got cluster lock. */
+#define OCFS2_META_LOCK_GETBH		(0x08)
 
 /* Locking subclasses of inode cluster lock */
 enum {
@@ -170,4 +177,15 @@ void ocfs2_put_dlm_debug(struct ocfs2_dl
 
 /* To set the locking protocol on module initialization */
 void ocfs2_set_locking_protocol(void);
+
+/* The _tracker pair is used to avoid cluster recursive locking */
+int ocfs2_inode_lock_tracker(struct inode *inode,
+			     struct buffer_head **ret_bh,
+			     int ex,
+			     struct ocfs2_lock_holder *oh);
+void ocfs2_inode_unlock_tracker(struct inode *inode,
+				int ex,
+				struct ocfs2_lock_holder *oh,
+				int had_lock);
+
 #endif	/* DLMGLUE_H */
diff -druNp --no-dereference linux-libre-3.18.76-gnu/fs/ocfs2/ocfs2.h linux-libre-3.18.77-gnu/fs/ocfs2/ocfs2.h
--- linux-libre-3.18.76-gnu/fs/ocfs2/ocfs2.h	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/fs/ocfs2/ocfs2.h	2017-10-21 11:07:27.000000000 -0400
@@ -166,6 +166,7 @@ struct ocfs2_lock_res {
 
 	struct list_head         l_blocked_list;
 	struct list_head         l_mask_waiters;
+	struct list_head	 l_holders;
 
 	unsigned long		 l_flags;
 	char                     l_name[OCFS2_LOCK_ID_MAX_LEN];
diff -druNp --no-dereference linux-libre-3.18.76-gnu/include/net/sctp/ulpevent.h linux-libre-3.18.77-gnu/include/net/sctp/ulpevent.h
--- linux-libre-3.18.76-gnu/include/net/sctp/ulpevent.h	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/include/net/sctp/ulpevent.h	2017-10-21 11:07:27.000000000 -0400
@@ -141,8 +141,12 @@ __u16 sctp_ulpevent_get_notification_typ
 static inline int sctp_ulpevent_type_enabled(__u16 sn_type,
 					     struct sctp_event_subscribe *mask)
 {
+	int offset = sn_type - SCTP_SN_TYPE_BASE;
 	char *amask = (char *) mask;
-	return amask[sn_type - SCTP_SN_TYPE_BASE];
+
+	if (offset >= sizeof(struct sctp_event_subscribe))
+		return 0;
+	return amask[offset];
 }
 
 /* Given an event subscription, is this event enabled? */
diff -druNp --no-dereference linux-libre-3.18.76-gnu/include/uapi/linux/mroute6.h linux-libre-3.18.77-gnu/include/uapi/linux/mroute6.h
--- linux-libre-3.18.76-gnu/include/uapi/linux/mroute6.h	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/include/uapi/linux/mroute6.h	2017-10-21 11:07:27.000000000 -0400
@@ -3,6 +3,7 @@
 
 #include <linux/types.h>
 #include <linux/sockios.h>
+#include <linux/in6.h>		/* For struct sockaddr_in6. */
 
 /*
  *	Based on the MROUTING 3.5 defines primarily to keep
diff -druNp --no-dereference linux-libre-3.18.76-gnu/include/uapi/linux/rds.h linux-libre-3.18.77-gnu/include/uapi/linux/rds.h
--- linux-libre-3.18.76-gnu/include/uapi/linux/rds.h	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/include/uapi/linux/rds.h	2017-10-21 11:07:27.000000000 -0400
@@ -35,6 +35,7 @@
 #define _LINUX_RDS_H
 
 #include <linux/types.h>
+#include <linux/socket.h>		/* For __kernel_sockaddr_storage. */
 
 #define RDS_IB_ABI_VERSION		0x301
 
@@ -213,7 +214,7 @@ struct rds_get_mr_args {
 };
 
 struct rds_get_mr_for_dest_args {
-	struct sockaddr_storage	dest_addr;
+	struct __kernel_sockaddr_storage dest_addr;
 	struct rds_iovec 	vec;
 	uint64_t		cookie_addr;
 	uint64_t		flags;
diff -druNp --no-dereference linux-libre-3.18.76-gnu/kernel/bpf/verifier.c linux-libre-3.18.77-gnu/kernel/bpf/verifier.c
--- linux-libre-3.18.76-gnu/kernel/bpf/verifier.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/kernel/bpf/verifier.c	2017-10-21 11:07:27.000000000 -0400
@@ -932,7 +932,8 @@ static int check_alu_op(struct reg_state
 			}
 		} else {
 			if (insn->src_reg != BPF_REG_0 || insn->off != 0 ||
-			    (insn->imm != 16 && insn->imm != 32 && insn->imm != 64)) {
+			    (insn->imm != 16 && insn->imm != 32 && insn->imm != 64) ||
+			    BPF_CLASS(insn->code) == BPF_ALU64) {
 				verbose("BPF_END uses reserved fields\n");
 				return -EINVAL;
 			}
diff -druNp --no-dereference linux-libre-3.18.76-gnu/kernel/locking/lockdep.c linux-libre-3.18.77-gnu/kernel/locking/lockdep.c
--- linux-libre-3.18.76-gnu/kernel/locking/lockdep.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/kernel/locking/lockdep.c	2017-10-21 11:07:27.000000000 -0400
@@ -3107,10 +3107,17 @@ static int __lock_acquire(struct lockdep
 	if (depth) {
 		hlock = curr->held_locks + depth - 1;
 		if (hlock->class_idx == class_idx && nest_lock) {
-			if (hlock->references)
+			if (hlock->references) {
+				/*
+				 * Check: unsigned int references:12, overflow.
+				 */
+				if (DEBUG_LOCKS_WARN_ON(hlock->references == (1 << 12)-1))
+					return 0;
+
 				hlock->references++;
-			else
+			} else {
 				hlock->references = 2;
+			}
 
 			return 1;
 		}
diff -druNp --no-dereference linux-libre-3.18.76-gnu/Makefile linux-libre-3.18.77-gnu/Makefile
--- linux-libre-3.18.76-gnu/Makefile	2017-10-19 04:52:03.000000000 -0400
+++ linux-libre-3.18.77-gnu/Makefile	2017-10-21 21:19:34.000000000 -0400
@@ -1,6 +1,6 @@
 VERSION = 3
 PATCHLEVEL = 18
-SUBLEVEL = 76
+SUBLEVEL = 77
 EXTRAVERSION =-gnu
 NAME = Diseased Newt
 
diff -druNp --no-dereference linux-libre-3.18.76-gnu/net/core/sock.c linux-libre-3.18.77-gnu/net/core/sock.c
--- linux-libre-3.18.76-gnu/net/core/sock.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/net/core/sock.c	2017-10-21 11:07:27.000000000 -0400
@@ -1488,6 +1488,8 @@ struct sock *sk_clone_lock(const struct
 
 		sock_copy(newsk, sk);
 
+		newsk->sk_prot_creator = sk->sk_prot;
+
 		/* SANITY */
 		get_net(sock_net(newsk));
 		sk_node_init(&newsk->sk_node);
diff -druNp --no-dereference linux-libre-3.18.76-gnu/net/ipv4/ip_vti.c linux-libre-3.18.77-gnu/net/ipv4/ip_vti.c
--- linux-libre-3.18.76-gnu/net/ipv4/ip_vti.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/net/ipv4/ip_vti.c	2017-10-21 11:07:27.000000000 -0400
@@ -156,6 +156,7 @@ static netdev_tx_t vti_xmit(struct sk_bu
 	struct ip_tunnel_parm *parms = &tunnel->parms;
 	struct dst_entry *dst = skb_dst(skb);
 	struct net_device *tdev;	/* Device to other host */
+	int pkt_len = skb->len;
 	int err;
 
 	if (!dst) {
@@ -199,7 +200,7 @@ static netdev_tx_t vti_xmit(struct sk_bu
 
 	err = dst_output(skb);
 	if (net_xmit_eval(err) == 0)
-		err = skb->len;
+		err = pkt_len;
 	iptunnel_xmit_stats(err, &dev->stats, dev->tstats);
 	return NETDEV_TX_OK;
 
diff -druNp --no-dereference linux-libre-3.18.76-gnu/net/ipv6/ip6_vti.c linux-libre-3.18.77-gnu/net/ipv6/ip6_vti.c
--- linux-libre-3.18.76-gnu/net/ipv6/ip6_vti.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/net/ipv6/ip6_vti.c	2017-10-21 11:07:27.000000000 -0400
@@ -416,6 +416,7 @@ vti6_xmit(struct sk_buff *skb, struct ne
 	struct net_device_stats *stats = &t->dev->stats;
 	struct dst_entry *dst = skb_dst(skb);
 	struct net_device *tdev;
+	int pkt_len = skb->len;
 	int err = -1;
 
 	if (!dst)
@@ -450,7 +451,7 @@ vti6_xmit(struct sk_buff *skb, struct ne
 		struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
 
 		u64_stats_update_begin(&tstats->syncp);
-		tstats->tx_bytes += skb->len;
+		tstats->tx_bytes += pkt_len;
 		tstats->tx_packets++;
 		u64_stats_update_end(&tstats->syncp);
 	} else {
diff -druNp --no-dereference linux-libre-3.18.76-gnu/net/l2tp/l2tp_core.c linux-libre-3.18.77-gnu/net/l2tp/l2tp_core.c
--- linux-libre-3.18.76-gnu/net/l2tp/l2tp_core.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/net/l2tp/l2tp_core.c	2017-10-21 11:07:27.000000000 -0400
@@ -1317,6 +1317,9 @@ static void l2tp_tunnel_del_work(struct
 	struct sock *sk = NULL;
 
 	tunnel = container_of(work, struct l2tp_tunnel, del_work);
+
+	l2tp_tunnel_closeall(tunnel);
+
 	sk = l2tp_tunnel_sock_lookup(tunnel);
 	if (!sk)
 		goto out;
@@ -1639,15 +1642,12 @@ EXPORT_SYMBOL_GPL(l2tp_tunnel_create);
 
 /* This function is used by the netlink TUNNEL_DELETE command.
  */
-int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel)
+void l2tp_tunnel_delete(struct l2tp_tunnel *tunnel)
 {
-	l2tp_tunnel_inc_refcount(tunnel);
-	l2tp_tunnel_closeall(tunnel);
-	if (false == queue_work(l2tp_wq, &tunnel->del_work)) {
-		l2tp_tunnel_dec_refcount(tunnel);
-		return 1;
+	if (!test_and_set_bit(0, &tunnel->dead)) {
+		l2tp_tunnel_inc_refcount(tunnel);
+		queue_work(l2tp_wq, &tunnel->del_work);
 	}
-	return 0;
 }
 EXPORT_SYMBOL_GPL(l2tp_tunnel_delete);
 
diff -druNp --no-dereference linux-libre-3.18.76-gnu/net/l2tp/l2tp_core.h linux-libre-3.18.77-gnu/net/l2tp/l2tp_core.h
--- linux-libre-3.18.76-gnu/net/l2tp/l2tp_core.h	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/net/l2tp/l2tp_core.h	2017-10-21 11:07:27.000000000 -0400
@@ -169,6 +169,9 @@ struct l2tp_tunnel_cfg {
 
 struct l2tp_tunnel {
 	int			magic;		/* Should be L2TP_TUNNEL_MAGIC */
+
+	unsigned long		dead;
+
 	struct rcu_head rcu;
 	rwlock_t		hlist_lock;	/* protect session_hlist */
 	struct hlist_head	session_hlist[L2TP_HASH_SIZE];
@@ -252,7 +255,7 @@ int l2tp_tunnel_create(struct net *net,
 		       u32 peer_tunnel_id, struct l2tp_tunnel_cfg *cfg,
 		       struct l2tp_tunnel **tunnelp);
 void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel);
-int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel);
+void l2tp_tunnel_delete(struct l2tp_tunnel *tunnel);
 struct l2tp_session *l2tp_session_create(int priv_size,
 					 struct l2tp_tunnel *tunnel,
 					 u32 session_id, u32 peer_session_id,
diff -druNp --no-dereference linux-libre-3.18.76-gnu/net/netfilter/nf_conntrack_expect.c linux-libre-3.18.77-gnu/net/netfilter/nf_conntrack_expect.c
--- linux-libre-3.18.76-gnu/net/netfilter/nf_conntrack_expect.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/net/netfilter/nf_conntrack_expect.c	2017-10-21 11:07:27.000000000 -0400
@@ -392,7 +392,7 @@ static inline int __nf_ct_expect_check(s
 	struct net *net = nf_ct_exp_net(expect);
 	struct hlist_node *next;
 	unsigned int h;
-	int ret = 1;
+	int ret = 0;
 
 	if (!master_help) {
 		ret = -ESHUTDOWN;
@@ -442,7 +442,7 @@ int nf_ct_expect_related_report(struct n
 
 	spin_lock_bh(&nf_conntrack_expect_lock);
 	ret = __nf_ct_expect_check(expect);
-	if (ret <= 0)
+	if (ret < 0)
 		goto out;
 
 	ret = nf_ct_expect_insert(expect);
diff -druNp --no-dereference linux-libre-3.18.76-gnu/net/packet/af_packet.c linux-libre-3.18.77-gnu/net/packet/af_packet.c
--- linux-libre-3.18.76-gnu/net/packet/af_packet.c	2017-10-18 03:15:17.000000000 -0400
+++ linux-libre-3.18.77-gnu/net/packet/af_packet.c	2017-10-21 11:07:27.000000000 -0400
@@ -1429,9 +1429,6 @@ static int fanout_add(struct sock *sk, u
 		return -EINVAL;
 	}
 
-	if (!po->running)
-		return -EINVAL;
-
 	if (po->fanout)
 		return -EALREADY;
 
@@ -1469,7 +1466,10 @@ static int fanout_add(struct sock *sk, u
 		list_add(&match->list, &fanout_list);
 	}
 	err = -EINVAL;
-	if (match->type == type &&
+
+	spin_lock(&po->bind_lock);
+	if (po->running &&
+	    match->type == type &&
 	    match->prot_hook.type == po->prot_hook.type &&
 	    match->prot_hook.dev == po->prot_hook.dev) {
 		err = -ENOSPC;
@@ -1481,6 +1481,13 @@ static int fanout_add(struct sock *sk, u
 			err = 0;
 		}
 	}
+	spin_unlock(&po->bind_lock);
+
+	if (err && !atomic_read(&match->sk_ref)) {
+		list_del(&match->list);
+		kfree(match);
+	}
+
 out:
 	mutex_unlock(&fanout_mutex);
 	return err;
@@ -2655,13 +2662,15 @@ static int packet_do_bind(struct sock *s
 	int ret = 0;
 	bool unlisted = false;
 
-	if (po->fanout)
-		return -EINVAL;
-
 	lock_sock(sk);
 	spin_lock(&po->bind_lock);
 	rcu_read_lock();
 
+	if (po->fanout) {
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
 	if (name) {
 		dev = dev_get_by_name_rcu(sock_net(sk), name);
 		if (!dev) {
