From: Greg Kroah-Hartman Date: Thu, 18 May 2017 07:44:05 +0000 (+0200) Subject: 4.10-stable patches X-Git-Tag: v3.18.54~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ccf2b373b97bae5dfa7ba0167b1fbc08d856cc15;p=thirdparty%2Fkernel%2Fstable-queue.git 4.10-stable patches added patches: bluetooth-fix-user-channel-for-32bit-userspace-on-64bit-kernel.patch bluetooth-hci_bcm-add-missing-tty-device-sanity-check.patch bluetooth-hci_intel-add-missing-tty-device-sanity-check.patch dax-prevent-invalidation-of-mapped-dax-entries.patch device-dax-fix-cdev-leak.patch device-dax-fix-sysfs-attribute-deadlock.patch f2fs-fix-fs-corruption-due-to-zero-inode-page.patch fscrypt-fix-context-consistency-check-when-key-s-unavailable.patch libata-reject-passthrough-write-same-requests.patch mm-fix-data-corruption-due-to-stale-mmap-reads.patch serial-omap-fix-runtime-pm-handling-on-unbind.patch serial-omap-suspend-device-on-probe-errors.patch serial-samsung-use-right-device-for-dma-mapping-calls.patch tty-pty-fix-ldisc-flush-after-userspace-become-aware-of-the-data-already.patch --- diff --git a/queue-4.10/bluetooth-fix-user-channel-for-32bit-userspace-on-64bit-kernel.patch b/queue-4.10/bluetooth-fix-user-channel-for-32bit-userspace-on-64bit-kernel.patch new file mode 100644 index 00000000000..1d0fd9f6c4f --- /dev/null +++ b/queue-4.10/bluetooth-fix-user-channel-for-32bit-userspace-on-64bit-kernel.patch @@ -0,0 +1,35 @@ +From ab89f0bdd63a3721f7cd3f064f39fc4ac7ca14d4 Mon Sep 17 00:00:00 2001 +From: Szymon Janc +Date: Mon, 24 Apr 2017 18:25:04 -0700 +Subject: Bluetooth: Fix user channel for 32bit userspace on 64bit kernel + +From: Szymon Janc + +commit ab89f0bdd63a3721f7cd3f064f39fc4ac7ca14d4 upstream. + +Running 32bit userspace on 64bit kernel results in MSG_CMSG_COMPAT being +defined as 0x80000000. This results in sendmsg failure if used from 32bit +userspace running on 64bit kernel. Fix this by accounting for MSG_CMSG_COMPAT +in flags check in hci_sock_sendmsg. + +Signed-off-by: Szymon Janc +Signed-off-by: Marko Kiiskila +Signed-off-by: Marcel Holtmann +Signed-off-by: Greg Kroah-Hartman + +--- + net/bluetooth/hci_sock.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +--- a/net/bluetooth/hci_sock.c ++++ b/net/bluetooth/hci_sock.c +@@ -1680,7 +1680,8 @@ static int hci_sock_sendmsg(struct socke + if (msg->msg_flags & MSG_OOB) + return -EOPNOTSUPP; + +- if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_NOSIGNAL|MSG_ERRQUEUE)) ++ if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_NOSIGNAL|MSG_ERRQUEUE| ++ MSG_CMSG_COMPAT)) + return -EINVAL; + + if (len < 4 || len > HCI_MAX_FRAME_SIZE) diff --git a/queue-4.10/bluetooth-hci_bcm-add-missing-tty-device-sanity-check.patch b/queue-4.10/bluetooth-hci_bcm-add-missing-tty-device-sanity-check.patch new file mode 100644 index 00000000000..ac09d2ebb12 --- /dev/null +++ b/queue-4.10/bluetooth-hci_bcm-add-missing-tty-device-sanity-check.patch @@ -0,0 +1,44 @@ +From 95065a61e9bf25fb85295127fba893200c2bbbd8 Mon Sep 17 00:00:00 2001 +From: Johan Hovold +Date: Wed, 29 Mar 2017 18:15:27 +0200 +Subject: Bluetooth: hci_bcm: add missing tty-device sanity check + +From: Johan Hovold + +commit 95065a61e9bf25fb85295127fba893200c2bbbd8 upstream. + +Make sure to check the tty-device pointer before looking up the sibling +platform device to avoid dereferencing a NULL-pointer when the tty is +one end of a Unix98 pty. + +Fixes: 0395ffc1ee05 ("Bluetooth: hci_bcm: Add PM for BCM devices") +Cc: Frederic Danis +Signed-off-by: Johan Hovold +Signed-off-by: Marcel Holtmann +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/bluetooth/hci_bcm.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +--- a/drivers/bluetooth/hci_bcm.c ++++ b/drivers/bluetooth/hci_bcm.c +@@ -287,6 +287,9 @@ static int bcm_open(struct hci_uart *hu) + + hu->priv = bcm; + ++ if (!hu->tty->dev) ++ goto out; ++ + mutex_lock(&bcm_device_lock); + list_for_each(p, &bcm_device_list) { + struct bcm_device *dev = list_entry(p, struct bcm_device, list); +@@ -307,7 +310,7 @@ static int bcm_open(struct hci_uart *hu) + } + + mutex_unlock(&bcm_device_lock); +- ++out: + return 0; + } + diff --git a/queue-4.10/bluetooth-hci_intel-add-missing-tty-device-sanity-check.patch b/queue-4.10/bluetooth-hci_intel-add-missing-tty-device-sanity-check.patch new file mode 100644 index 00000000000..95ff1b10937 --- /dev/null +++ b/queue-4.10/bluetooth-hci_intel-add-missing-tty-device-sanity-check.patch @@ -0,0 +1,74 @@ +From dcb9cfaa5ea9aa0ec08aeb92582ccfe3e4c719a9 Mon Sep 17 00:00:00 2001 +From: Johan Hovold +Date: Wed, 29 Mar 2017 18:15:28 +0200 +Subject: Bluetooth: hci_intel: add missing tty-device sanity check + +From: Johan Hovold + +commit dcb9cfaa5ea9aa0ec08aeb92582ccfe3e4c719a9 upstream. + +Make sure to check the tty-device pointer before looking up the sibling +platform device to avoid dereferencing a NULL-pointer when the tty is +one end of a Unix98 pty. + +Fixes: 74cdad37cd24 ("Bluetooth: hci_intel: Add runtime PM support") +Fixes: 1ab1f239bf17 ("Bluetooth: hci_intel: Add support for platform driver") +Cc: Loic Poulain +Signed-off-by: Johan Hovold +Signed-off-by: Marcel Holtmann +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/bluetooth/hci_intel.c | 13 ++++++++++++- + 1 file changed, 12 insertions(+), 1 deletion(-) + +--- a/drivers/bluetooth/hci_intel.c ++++ b/drivers/bluetooth/hci_intel.c +@@ -307,6 +307,9 @@ static int intel_set_power(struct hci_ua + struct list_head *p; + int err = -ENODEV; + ++ if (!hu->tty->dev) ++ return err; ++ + mutex_lock(&intel_device_list_lock); + + list_for_each(p, &intel_device_list) { +@@ -379,6 +382,9 @@ static void intel_busy_work(struct work_ + struct intel_data *intel = container_of(work, struct intel_data, + busy_work); + ++ if (!intel->hu->tty->dev) ++ return; ++ + /* Link is busy, delay the suspend */ + mutex_lock(&intel_device_list_lock); + list_for_each(p, &intel_device_list) { +@@ -889,6 +895,8 @@ done: + list_for_each(p, &intel_device_list) { + struct intel_device *dev = list_entry(p, struct intel_device, + list); ++ if (!hu->tty->dev) ++ break; + if (hu->tty->dev->parent == dev->pdev->dev.parent) { + if (device_may_wakeup(&dev->pdev->dev)) { + set_bit(STATE_LPM_ENABLED, &intel->flags); +@@ -1056,6 +1064,9 @@ static int intel_enqueue(struct hci_uart + + BT_DBG("hu %p skb %p", hu, skb); + ++ if (!hu->tty->dev) ++ goto out_enqueue; ++ + /* Be sure our controller is resumed and potential LPM transaction + * completed before enqueuing any packet. + */ +@@ -1072,7 +1083,7 @@ static int intel_enqueue(struct hci_uart + } + } + mutex_unlock(&intel_device_list_lock); +- ++out_enqueue: + skb_queue_tail(&intel->txq, skb); + + return 0; diff --git a/queue-4.10/dax-prevent-invalidation-of-mapped-dax-entries.patch b/queue-4.10/dax-prevent-invalidation-of-mapped-dax-entries.patch new file mode 100644 index 00000000000..dda972f7390 --- /dev/null +++ b/queue-4.10/dax-prevent-invalidation-of-mapped-dax-entries.patch @@ -0,0 +1,134 @@ +From 4636e70bb0a8b871998b6841a2e4b205cf2bc863 Mon Sep 17 00:00:00 2001 +From: Ross Zwisler +Date: Fri, 12 May 2017 15:46:47 -0700 +Subject: dax: prevent invalidation of mapped DAX entries + +From: Ross Zwisler + +commit 4636e70bb0a8b871998b6841a2e4b205cf2bc863 upstream. + +Patch series "mm,dax: Fix data corruption due to mmap inconsistency", +v4. + +This series fixes data corruption that can happen for DAX mounts when +page faults race with write(2) and as a result page tables get out of +sync with block mappings in the filesystem and thus data seen through +mmap is different from data seen through read(2). + +The series passes testing with t_mmap_stale test program from Ross and +also other mmap related tests on DAX filesystem. + +This patch (of 4): + +dax_invalidate_mapping_entry() currently removes DAX exceptional entries +only if they are clean and unlocked. This is done via: + + invalidate_mapping_pages() + invalidate_exceptional_entry() + dax_invalidate_mapping_entry() + +However, for page cache pages removed in invalidate_mapping_pages() +there is an additional criteria which is that the page must not be +mapped. This is noted in the comments above invalidate_mapping_pages() +and is checked in invalidate_inode_page(). + +For DAX entries this means that we can can end up in a situation where a +DAX exceptional entry, either a huge zero page or a regular DAX entry, +could end up mapped but without an associated radix tree entry. This is +inconsistent with the rest of the DAX code and with what happens in the +page cache case. + +We aren't able to unmap the DAX exceptional entry because according to +its comments invalidate_mapping_pages() isn't allowed to block, and +unmap_mapping_range() takes a write lock on the mapping->i_mmap_rwsem. + +Since we essentially never have unmapped DAX entries to evict from the +radix tree, just remove dax_invalidate_mapping_entry(). + +Fixes: c6dcf52c23d2 ("mm: Invalidate DAX radix tree entries only if appropriate") +Link: http://lkml.kernel.org/r/20170510085419.27601-2-jack@suse.cz +Signed-off-by: Ross Zwisler +Signed-off-by: Jan Kara +Reported-by: Jan Kara +Cc: Dan Williams +Signed-off-by: Andrew Morton +Signed-off-by: Linus Torvalds +Signed-off-by: Greg Kroah-Hartman + +--- + fs/dax.c | 29 ----------------------------- + include/linux/dax.h | 1 - + mm/truncate.c | 9 +++------ + 3 files changed, 3 insertions(+), 36 deletions(-) + +--- a/fs/dax.c ++++ b/fs/dax.c +@@ -503,35 +503,6 @@ int dax_delete_mapping_entry(struct addr + } + + /* +- * Invalidate exceptional DAX entry if easily possible. This handles DAX +- * entries for invalidate_inode_pages() so we evict the entry only if we can +- * do so without blocking. +- */ +-int dax_invalidate_mapping_entry(struct address_space *mapping, pgoff_t index) +-{ +- int ret = 0; +- void *entry, **slot; +- struct radix_tree_root *page_tree = &mapping->page_tree; +- +- spin_lock_irq(&mapping->tree_lock); +- entry = __radix_tree_lookup(page_tree, index, NULL, &slot); +- if (!entry || !radix_tree_exceptional_entry(entry) || +- slot_locked(mapping, slot)) +- goto out; +- if (radix_tree_tag_get(page_tree, index, PAGECACHE_TAG_DIRTY) || +- radix_tree_tag_get(page_tree, index, PAGECACHE_TAG_TOWRITE)) +- goto out; +- radix_tree_delete(page_tree, index); +- mapping->nrexceptional--; +- ret = 1; +-out: +- spin_unlock_irq(&mapping->tree_lock); +- if (ret) +- dax_wake_mapping_entry_waiter(mapping, index, entry, true); +- return ret; +-} +- +-/* + * Invalidate exceptional DAX entry if it is clean. + */ + int dax_invalidate_mapping_entry_sync(struct address_space *mapping, +--- a/include/linux/dax.h ++++ b/include/linux/dax.h +@@ -41,7 +41,6 @@ ssize_t dax_iomap_rw(struct kiocb *iocb, + int dax_iomap_fault(struct vm_area_struct *vma, struct vm_fault *vmf, + struct iomap_ops *ops); + int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index); +-int dax_invalidate_mapping_entry(struct address_space *mapping, pgoff_t index); + int dax_invalidate_mapping_entry_sync(struct address_space *mapping, + pgoff_t index); + void dax_wake_mapping_entry_waiter(struct address_space *mapping, +--- a/mm/truncate.c ++++ b/mm/truncate.c +@@ -66,17 +66,14 @@ static void truncate_exceptional_entry(s + + /* + * Invalidate exceptional entry if easily possible. This handles exceptional +- * entries for invalidate_inode_pages() so for DAX it evicts only unlocked and +- * clean entries. ++ * entries for invalidate_inode_pages(). + */ + static int invalidate_exceptional_entry(struct address_space *mapping, + pgoff_t index, void *entry) + { +- /* Handled by shmem itself */ +- if (shmem_mapping(mapping)) ++ /* Handled by shmem itself, or for DAX we do nothing. */ ++ if (shmem_mapping(mapping) || dax_mapping(mapping)) + return 1; +- if (dax_mapping(mapping)) +- return dax_invalidate_mapping_entry(mapping, index); + clear_shadow_entry(mapping, index, entry); + return 1; + } diff --git a/queue-4.10/device-dax-fix-cdev-leak.patch b/queue-4.10/device-dax-fix-cdev-leak.patch new file mode 100644 index 00000000000..623e27c77c4 --- /dev/null +++ b/queue-4.10/device-dax-fix-cdev-leak.patch @@ -0,0 +1,70 @@ +From ed01e50acdd3e4a640cf9ebd28a7e810c3ceca97 Mon Sep 17 00:00:00 2001 +From: Dan Williams +Date: Fri, 17 Mar 2017 12:48:09 -0600 +Subject: device-dax: fix cdev leak + +From: Dan Williams + +commit ed01e50acdd3e4a640cf9ebd28a7e810c3ceca97 upstream. + +If device_add() fails, cleanup the cdev. Otherwise, we leak a kobj_map() +with a stale device number. + +As Jason points out, there is a small possibility that userspace has +opened and mapped the device in the time between cdev_add() and the +device_add() failure. We need a new kill_dax_dev() helper to invalidate +any established mappings. + +Fixes: ba09c01d2fa8 ("dax: convert to the cdev api") +Reported-by: Jason Gunthorpe +Signed-off-by: Dan Williams +Signed-off-by: Logan Gunthorpe +Reviewed-by: Johannes Thumshirn +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/dax/dax.c | 15 +++++++++++---- + 1 file changed, 11 insertions(+), 4 deletions(-) + +--- a/drivers/dax/dax.c ++++ b/drivers/dax/dax.c +@@ -646,13 +646,10 @@ static void dax_dev_release(struct devic + kfree(dax_dev); + } + +-static void unregister_dax_dev(void *dev) ++static void kill_dax_dev(struct dax_dev *dax_dev) + { +- struct dax_dev *dax_dev = to_dax_dev(dev); + struct cdev *cdev = &dax_dev->cdev; + +- dev_dbg(dev, "%s\n", __func__); +- + /* + * Note, rcu is not protecting the liveness of dax_dev, rcu is + * ensuring that any fault handlers that might have seen +@@ -664,6 +661,15 @@ static void unregister_dax_dev(void *dev + synchronize_srcu(&dax_srcu); + unmap_mapping_range(dax_dev->inode->i_mapping, 0, 0, 1); + cdev_del(cdev); ++} ++ ++static void unregister_dax_dev(void *dev) ++{ ++ struct dax_dev *dax_dev = to_dax_dev(dev); ++ ++ dev_dbg(dev, "%s\n", __func__); ++ ++ kill_dax_dev(dax_dev); + device_unregister(dev); + } + +@@ -740,6 +746,7 @@ struct dax_dev *devm_create_dax_dev(stru + dev_set_name(dev, "dax%d.%d", dax_region->id, dax_dev->id); + rc = device_add(dev); + if (rc) { ++ kill_dax_dev(dax_dev); + put_device(dev); + return ERR_PTR(rc); + } diff --git a/queue-4.10/device-dax-fix-sysfs-attribute-deadlock.patch b/queue-4.10/device-dax-fix-sysfs-attribute-deadlock.patch new file mode 100644 index 00000000000..45374d8b655 --- /dev/null +++ b/queue-4.10/device-dax-fix-sysfs-attribute-deadlock.patch @@ -0,0 +1,129 @@ +From 565851c972b50612f3a4542e26879ffb3e906fc2 Mon Sep 17 00:00:00 2001 +From: Dan Williams +Date: Sun, 30 Apr 2017 06:57:01 -0700 +Subject: device-dax: fix sysfs attribute deadlock + +From: Dan Williams + +commit 565851c972b50612f3a4542e26879ffb3e906fc2 upstream. + +Usage of device_lock() for dax_region attributes is unnecessary and +deadlock prone. It's unnecessary because the order of registration / +un-registration guarantees that drvdata is always valid. It's deadlock +prone because it sets up this situation: + + ndctl D 0 2170 2082 0x00000000 + Call Trace: + __schedule+0x31f/0x980 + schedule+0x3d/0x90 + schedule_preempt_disabled+0x15/0x20 + __mutex_lock+0x402/0x980 + ? __mutex_lock+0x158/0x980 + ? align_show+0x2b/0x80 [dax] + ? kernfs_seq_start+0x2f/0x90 + mutex_lock_nested+0x1b/0x20 + align_show+0x2b/0x80 [dax] + dev_attr_show+0x20/0x50 + + ndctl D 0 2186 2079 0x00000000 + Call Trace: + __schedule+0x31f/0x980 + schedule+0x3d/0x90 + __kernfs_remove+0x1f6/0x340 + ? kernfs_remove_by_name_ns+0x45/0xa0 + ? remove_wait_queue+0x70/0x70 + kernfs_remove_by_name_ns+0x45/0xa0 + remove_files.isra.1+0x35/0x70 + sysfs_remove_group+0x44/0x90 + sysfs_remove_groups+0x2e/0x50 + dax_region_unregister+0x25/0x40 [dax] + devm_action_release+0xf/0x20 + release_nodes+0x16d/0x2b0 + devres_release_all+0x3c/0x60 + device_release_driver_internal+0x17d/0x220 + device_release_driver+0x12/0x20 + unbind_store+0x112/0x160 + +ndctl/2170 is trying to acquire the device_lock() to read an attribute, +and ndctl/2186 is holding the device_lock() while trying to drain all +active attribute readers. + +Thanks to Yi Zhang for the reproduction script. + +Fixes: d7fe1a67f658 ("dax: add region 'id', 'size', and 'align' attributes") +Reported-by: Yi Zhang +Signed-off-by: Dan Williams +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/dax/dax.c | 40 ++++++++++++---------------------------- + 1 file changed, 12 insertions(+), 28 deletions(-) + +--- a/drivers/dax/dax.c ++++ b/drivers/dax/dax.c +@@ -76,36 +76,27 @@ struct dax_dev { + struct resource res[0]; + }; + ++/* ++ * Rely on the fact that drvdata is set before the attributes are ++ * registered, and that the attributes are unregistered before drvdata ++ * is cleared to assume that drvdata is always valid. ++ */ + static ssize_t id_show(struct device *dev, + struct device_attribute *attr, char *buf) + { +- struct dax_region *dax_region; +- ssize_t rc = -ENXIO; ++ struct dax_region *dax_region = dev_get_drvdata(dev); + +- device_lock(dev); +- dax_region = dev_get_drvdata(dev); +- if (dax_region) +- rc = sprintf(buf, "%d\n", dax_region->id); +- device_unlock(dev); +- +- return rc; ++ return sprintf(buf, "%d\n", dax_region->id); + } + static DEVICE_ATTR_RO(id); + + static ssize_t region_size_show(struct device *dev, + struct device_attribute *attr, char *buf) + { +- struct dax_region *dax_region; +- ssize_t rc = -ENXIO; +- +- device_lock(dev); +- dax_region = dev_get_drvdata(dev); +- if (dax_region) +- rc = sprintf(buf, "%llu\n", (unsigned long long) +- resource_size(&dax_region->res)); +- device_unlock(dev); ++ struct dax_region *dax_region = dev_get_drvdata(dev); + +- return rc; ++ return sprintf(buf, "%llu\n", (unsigned long long) ++ resource_size(&dax_region->res)); + } + static struct device_attribute dev_attr_region_size = __ATTR(size, 0444, + region_size_show, NULL); +@@ -113,16 +104,9 @@ static struct device_attribute dev_attr_ + static ssize_t align_show(struct device *dev, + struct device_attribute *attr, char *buf) + { +- struct dax_region *dax_region; +- ssize_t rc = -ENXIO; +- +- device_lock(dev); +- dax_region = dev_get_drvdata(dev); +- if (dax_region) +- rc = sprintf(buf, "%u\n", dax_region->align); +- device_unlock(dev); ++ struct dax_region *dax_region = dev_get_drvdata(dev); + +- return rc; ++ return sprintf(buf, "%u\n", dax_region->align); + } + static DEVICE_ATTR_RO(align); + diff --git a/queue-4.10/f2fs-fix-fs-corruption-due-to-zero-inode-page.patch b/queue-4.10/f2fs-fix-fs-corruption-due-to-zero-inode-page.patch new file mode 100644 index 00000000000..8aaa44caefa --- /dev/null +++ b/queue-4.10/f2fs-fix-fs-corruption-due-to-zero-inode-page.patch @@ -0,0 +1,152 @@ +From 9bb02c3627f46e50246bf7ab957b56ffbef623cb Mon Sep 17 00:00:00 2001 +From: Jaegeuk Kim +Date: Tue, 11 Apr 2017 19:01:26 -0700 +Subject: f2fs: fix fs corruption due to zero inode page + +From: Jaegeuk Kim + +commit 9bb02c3627f46e50246bf7ab957b56ffbef623cb upstream. + +This patch fixes the following scenario. + +- f2fs_create/f2fs_mkdir - write_checkpoint + - f2fs_mark_inode_dirty_sync - block_operations + - f2fs_lock_all + - f2fs_sync_inode_meta + - f2fs_unlock_all + - sync_inode_metadata + - f2fs_lock_op + - f2fs_write_inode + - update_inode_page + - get_node_page + return -ENOENT + - new_inode_page + - fill_node_footer + - f2fs_mark_inode_dirty_sync + - ... + - f2fs_unlock_op + - f2fs_inode_synced + - f2fs_lock_all + - do_checkpoint + +In this checkpoint, we can get an inode page which contains zeros having valid +node footer only. + +Signed-off-by: Jaegeuk Kim +Signed-off-by: Greg Kroah-Hartman + +--- + fs/f2fs/inode.c | 2 +- + fs/f2fs/namei.c | 20 ++++++++++---------- + 2 files changed, 11 insertions(+), 11 deletions(-) + +--- a/fs/f2fs/inode.c ++++ b/fs/f2fs/inode.c +@@ -316,7 +316,6 @@ retry: + } else if (err != -ENOENT) { + f2fs_stop_checkpoint(sbi, false); + } +- f2fs_inode_synced(inode); + return 0; + } + ret = update_inode(inode, node_page); +@@ -446,6 +445,7 @@ void handle_failed_inode(struct inode *i + * in a panic when flushing dirty inodes in gdirty_list. + */ + update_inode_page(inode); ++ f2fs_inode_synced(inode); + + /* don't make bad inode, since it becomes a regular file. */ + unlock_new_inode(inode); +--- a/fs/f2fs/namei.c ++++ b/fs/f2fs/namei.c +@@ -148,8 +148,6 @@ static int f2fs_create(struct inode *dir + inode->i_mapping->a_ops = &f2fs_dblock_aops; + ino = inode->i_ino; + +- f2fs_balance_fs(sbi, true); +- + f2fs_lock_op(sbi); + err = f2fs_add_link(dentry, inode); + if (err) +@@ -163,6 +161,8 @@ static int f2fs_create(struct inode *dir + + if (IS_DIRSYNC(dir)) + f2fs_sync_fs(sbi->sb, 1); ++ ++ f2fs_balance_fs(sbi, true); + return 0; + out: + handle_failed_inode(inode); +@@ -423,8 +423,6 @@ static int f2fs_symlink(struct inode *di + inode_nohighmem(inode); + inode->i_mapping->a_ops = &f2fs_dblock_aops; + +- f2fs_balance_fs(sbi, true); +- + f2fs_lock_op(sbi); + err = f2fs_add_link(dentry, inode); + if (err) +@@ -487,6 +485,8 @@ err_out: + } + + kfree(sd); ++ ++ f2fs_balance_fs(sbi, true); + return err; + out: + handle_failed_inode(inode); +@@ -508,8 +508,6 @@ static int f2fs_mkdir(struct inode *dir, + inode->i_mapping->a_ops = &f2fs_dblock_aops; + mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_HIGH_ZERO); + +- f2fs_balance_fs(sbi, true); +- + set_inode_flag(inode, FI_INC_LINK); + f2fs_lock_op(sbi); + err = f2fs_add_link(dentry, inode); +@@ -524,6 +522,8 @@ static int f2fs_mkdir(struct inode *dir, + + if (IS_DIRSYNC(dir)) + f2fs_sync_fs(sbi->sb, 1); ++ ++ f2fs_balance_fs(sbi, true); + return 0; + + out_fail: +@@ -554,8 +554,6 @@ static int f2fs_mknod(struct inode *dir, + init_special_inode(inode, inode->i_mode, rdev); + inode->i_op = &f2fs_special_inode_operations; + +- f2fs_balance_fs(sbi, true); +- + f2fs_lock_op(sbi); + err = f2fs_add_link(dentry, inode); + if (err) +@@ -569,6 +567,8 @@ static int f2fs_mknod(struct inode *dir, + + if (IS_DIRSYNC(dir)) + f2fs_sync_fs(sbi->sb, 1); ++ ++ f2fs_balance_fs(sbi, true); + return 0; + out: + handle_failed_inode(inode); +@@ -595,8 +595,6 @@ static int __f2fs_tmpfile(struct inode * + inode->i_mapping->a_ops = &f2fs_dblock_aops; + } + +- f2fs_balance_fs(sbi, true); +- + f2fs_lock_op(sbi); + err = acquire_orphan_inode(sbi); + if (err) +@@ -622,6 +620,8 @@ static int __f2fs_tmpfile(struct inode * + /* link_count was changed by d_tmpfile as well. */ + f2fs_unlock_op(sbi); + unlock_new_inode(inode); ++ ++ f2fs_balance_fs(sbi, true); + return 0; + + release_out: diff --git a/queue-4.10/fscrypt-fix-context-consistency-check-when-key-s-unavailable.patch b/queue-4.10/fscrypt-fix-context-consistency-check-when-key-s-unavailable.patch new file mode 100644 index 00000000000..2f18201e2ea --- /dev/null +++ b/queue-4.10/fscrypt-fix-context-consistency-check-when-key-s-unavailable.patch @@ -0,0 +1,166 @@ +From 272f98f6846277378e1758a49a49d7bf39343c02 Mon Sep 17 00:00:00 2001 +From: Eric Biggers +Date: Fri, 7 Apr 2017 10:58:37 -0700 +Subject: fscrypt: fix context consistency check when key(s) unavailable + +From: Eric Biggers + +commit 272f98f6846277378e1758a49a49d7bf39343c02 upstream. + +To mitigate some types of offline attacks, filesystem encryption is +designed to enforce that all files in an encrypted directory tree use +the same encryption policy (i.e. the same encryption context excluding +the nonce). However, the fscrypt_has_permitted_context() function which +enforces this relies on comparing struct fscrypt_info's, which are only +available when we have the encryption keys. This can cause two +incorrect behaviors: + +1. If we have the parent directory's key but not the child's key, or + vice versa, then fscrypt_has_permitted_context() returned false, + causing applications to see EPERM or ENOKEY. This is incorrect if + the encryption contexts are in fact consistent. Although we'd + normally have either both keys or neither key in that case since the + master_key_descriptors would be the same, this is not guaranteed + because keys can be added or removed from keyrings at any time. + +2. If we have neither the parent's key nor the child's key, then + fscrypt_has_permitted_context() returned true, causing applications + to see no error (or else an error for some other reason). This is + incorrect if the encryption contexts are in fact inconsistent, since + in that case we should deny access. + +To fix this, retrieve and compare the fscrypt_contexts if we are unable +to set up both fscrypt_infos. + +While this slightly hurts performance when accessing an encrypted +directory tree without the key, this isn't a case we really need to be +optimizing for; access *with* the key is much more important. +Furthermore, the performance hit is barely noticeable given that we are +already retrieving the fscrypt_context and doing two keyring searches in +fscrypt_get_encryption_info(). If we ever actually wanted to optimize +this case we might start by caching the fscrypt_contexts. + +Signed-off-by: Eric Biggers +Signed-off-by: Theodore Ts'o +Signed-off-by: Greg Kroah-Hartman + +--- + fs/crypto/policy.c | 87 +++++++++++++++++++++++++++++++++++++++++------------ + 1 file changed, 68 insertions(+), 19 deletions(-) + +--- a/fs/crypto/policy.c ++++ b/fs/crypto/policy.c +@@ -169,27 +169,61 @@ int fscrypt_ioctl_get_policy(struct file + } + EXPORT_SYMBOL(fscrypt_ioctl_get_policy); + ++/** ++ * fscrypt_has_permitted_context() - is a file's encryption policy permitted ++ * within its directory? ++ * ++ * @parent: inode for parent directory ++ * @child: inode for file being looked up, opened, or linked into @parent ++ * ++ * Filesystems must call this before permitting access to an inode in a ++ * situation where the parent directory is encrypted (either before allowing ++ * ->lookup() to succeed, or for a regular file before allowing it to be opened) ++ * and before any operation that involves linking an inode into an encrypted ++ * directory, including link, rename, and cross rename. It enforces the ++ * constraint that within a given encrypted directory tree, all files use the ++ * same encryption policy. The pre-access check is needed to detect potentially ++ * malicious offline violations of this constraint, while the link and rename ++ * checks are needed to prevent online violations of this constraint. ++ * ++ * Return: 1 if permitted, 0 if forbidden. If forbidden, the caller must fail ++ * the filesystem operation with EPERM. ++ */ + int fscrypt_has_permitted_context(struct inode *parent, struct inode *child) + { +- struct fscrypt_info *parent_ci, *child_ci; ++ const struct fscrypt_operations *cops = parent->i_sb->s_cop; ++ const struct fscrypt_info *parent_ci, *child_ci; ++ struct fscrypt_context parent_ctx, child_ctx; + int res; + +- if ((parent == NULL) || (child == NULL)) { +- printk(KERN_ERR "parent %p child %p\n", parent, child); +- BUG_ON(1); +- } +- + /* No restrictions on file types which are never encrypted */ + if (!S_ISREG(child->i_mode) && !S_ISDIR(child->i_mode) && + !S_ISLNK(child->i_mode)) + return 1; + +- /* no restrictions if the parent directory is not encrypted */ +- if (!parent->i_sb->s_cop->is_encrypted(parent)) ++ /* No restrictions if the parent directory is unencrypted */ ++ if (!cops->is_encrypted(parent)) + return 1; +- /* if the child directory is not encrypted, this is always a problem */ +- if (!parent->i_sb->s_cop->is_encrypted(child)) ++ ++ /* Encrypted directories must not contain unencrypted files */ ++ if (!cops->is_encrypted(child)) + return 0; ++ ++ /* ++ * Both parent and child are encrypted, so verify they use the same ++ * encryption policy. Compare the fscrypt_info structs if the keys are ++ * available, otherwise retrieve and compare the fscrypt_contexts. ++ * ++ * Note that the fscrypt_context retrieval will be required frequently ++ * when accessing an encrypted directory tree without the key. ++ * Performance-wise this is not a big deal because we already don't ++ * really optimize for file access without the key (to the extent that ++ * such access is even possible), given that any attempted access ++ * already causes a fscrypt_context retrieval and keyring search. ++ * ++ * In any case, if an unexpected error occurs, fall back to "forbidden". ++ */ ++ + res = fscrypt_get_encryption_info(parent); + if (res) + return 0; +@@ -198,17 +232,32 @@ int fscrypt_has_permitted_context(struct + return 0; + parent_ci = parent->i_crypt_info; + child_ci = child->i_crypt_info; +- if (!parent_ci && !child_ci) +- return 1; +- if (!parent_ci || !child_ci) ++ ++ if (parent_ci && child_ci) { ++ return memcmp(parent_ci->ci_master_key, child_ci->ci_master_key, ++ FS_KEY_DESCRIPTOR_SIZE) == 0 && ++ (parent_ci->ci_data_mode == child_ci->ci_data_mode) && ++ (parent_ci->ci_filename_mode == ++ child_ci->ci_filename_mode) && ++ (parent_ci->ci_flags == child_ci->ci_flags); ++ } ++ ++ res = cops->get_context(parent, &parent_ctx, sizeof(parent_ctx)); ++ if (res != sizeof(parent_ctx)) ++ return 0; ++ ++ res = cops->get_context(child, &child_ctx, sizeof(child_ctx)); ++ if (res != sizeof(child_ctx)) + return 0; + +- return (memcmp(parent_ci->ci_master_key, +- child_ci->ci_master_key, +- FS_KEY_DESCRIPTOR_SIZE) == 0 && +- (parent_ci->ci_data_mode == child_ci->ci_data_mode) && +- (parent_ci->ci_filename_mode == child_ci->ci_filename_mode) && +- (parent_ci->ci_flags == child_ci->ci_flags)); ++ return memcmp(parent_ctx.master_key_descriptor, ++ child_ctx.master_key_descriptor, ++ FS_KEY_DESCRIPTOR_SIZE) == 0 && ++ (parent_ctx.contents_encryption_mode == ++ child_ctx.contents_encryption_mode) && ++ (parent_ctx.filenames_encryption_mode == ++ child_ctx.filenames_encryption_mode) && ++ (parent_ctx.flags == child_ctx.flags); + } + EXPORT_SYMBOL(fscrypt_has_permitted_context); + diff --git a/queue-4.10/libata-reject-passthrough-write-same-requests.patch b/queue-4.10/libata-reject-passthrough-write-same-requests.patch new file mode 100644 index 00000000000..c374b543857 --- /dev/null +++ b/queue-4.10/libata-reject-passthrough-write-same-requests.patch @@ -0,0 +1,41 @@ +From c6ade20f5e50e188d20b711a618b20dd1d50457e Mon Sep 17 00:00:00 2001 +From: Christoph Hellwig +Date: Tue, 25 Apr 2017 13:39:54 +0200 +Subject: libata: reject passthrough WRITE SAME requests + +From: Christoph Hellwig + +commit c6ade20f5e50e188d20b711a618b20dd1d50457e upstream. + +The WRITE SAME to TRIM translation rewrites the DATA OUT buffer. While +the SCSI code accomodates for this by passing a read-writable buffer +userspace applications don't cater for this behavior. In fact it can +be used to rewrite e.g. a readonly file through mmap and should be +considered as a security fix. + +Signed-off-by: Christoph Hellwig +Reviewed-by: Martin K. Petersen +Signed-off-by: Tejun Heo +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/ata/libata-scsi.c | 8 ++++++++ + 1 file changed, 8 insertions(+) + +--- a/drivers/ata/libata-scsi.c ++++ b/drivers/ata/libata-scsi.c +@@ -3487,6 +3487,14 @@ static unsigned int ata_scsi_write_same_ + if (unlikely(!dev->dma_mode)) + goto invalid_opcode; + ++ /* ++ * We only allow sending this command through the block layer, ++ * as it modifies the DATA OUT buffer, which would corrupt user ++ * memory for SG_IO commands. ++ */ ++ if (unlikely(blk_rq_is_passthrough(scmd->request))) ++ goto invalid_opcode; ++ + if (unlikely(scmd->cmd_len < 16)) { + fp = 15; + goto invalid_fld; diff --git a/queue-4.10/mm-fix-data-corruption-due-to-stale-mmap-reads.patch b/queue-4.10/mm-fix-data-corruption-due-to-stale-mmap-reads.patch new file mode 100644 index 00000000000..4dc2eb2d4e3 --- /dev/null +++ b/queue-4.10/mm-fix-data-corruption-due-to-stale-mmap-reads.patch @@ -0,0 +1,76 @@ +From cd656375f94632d7b5af57bf67b7b5c0270c591c Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Fri, 12 May 2017 15:46:50 -0700 +Subject: mm: fix data corruption due to stale mmap reads + +From: Jan Kara + +commit cd656375f94632d7b5af57bf67b7b5c0270c591c upstream. + +Currently, we didn't invalidate page tables during invalidate_inode_pages2() +for DAX. That could result in e.g. 2MiB zero page being mapped into +page tables while there were already underlying blocks allocated and +thus data seen through mmap were different from data seen by read(2). +The following sequence reproduces the problem: + + - open an mmap over a 2MiB hole + + - read from a 2MiB hole, faulting in a 2MiB zero page + + - write to the hole with write(3p). The write succeeds but we + incorrectly leave the 2MiB zero page mapping intact. + + - via the mmap, read the data that was just written. Since the zero + page mapping is still intact we read back zeroes instead of the new + data. + +Fix the problem by unconditionally calling invalidate_inode_pages2_range() +in dax_iomap_actor() for new block allocations and by properly +invalidating page tables in invalidate_inode_pages2_range() for DAX +mappings. + +Fixes: c6dcf52c23d2d3fb5235cec42d7dd3f786b87d55 +Link: http://lkml.kernel.org/r/20170510085419.27601-3-jack@suse.cz +Signed-off-by: Jan Kara +Signed-off-by: Ross Zwisler +Cc: Dan Williams +Signed-off-by: Andrew Morton +Signed-off-by: Linus Torvalds +Signed-off-by: Greg Kroah-Hartman + +--- + fs/dax.c | 2 +- + mm/truncate.c | 11 +++++++++++ + 2 files changed, 12 insertions(+), 1 deletion(-) + +--- a/fs/dax.c ++++ b/fs/dax.c +@@ -1000,7 +1000,7 @@ dax_iomap_actor(struct inode *inode, lof + * into page tables. We have to tear down these mappings so that data + * written by write(2) is visible in mmap. + */ +- if ((iomap->flags & IOMAP_F_NEW) && inode->i_mapping->nrpages) { ++ if (iomap->flags & IOMAP_F_NEW) { + invalidate_inode_pages2_range(inode->i_mapping, + pos >> PAGE_SHIFT, + (end - 1) >> PAGE_SHIFT); +--- a/mm/truncate.c ++++ b/mm/truncate.c +@@ -682,6 +682,17 @@ int invalidate_inode_pages2_range(struct + cond_resched(); + index++; + } ++ /* ++ * For DAX we invalidate page tables after invalidating radix tree. We ++ * could invalidate page tables while invalidating each entry however ++ * that would be expensive. And doing range unmapping before doesn't ++ * work as we have no cheap way to find whether radix tree entry didn't ++ * get remapped later. ++ */ ++ if (dax_mapping(mapping)) { ++ unmap_mapping_range(mapping, (loff_t)start << PAGE_SHIFT, ++ (loff_t)(end - start + 1) << PAGE_SHIFT, 0); ++ } + cleancache_invalidate_inode(mapping); + return ret; + } diff --git a/queue-4.10/serial-omap-fix-runtime-pm-handling-on-unbind.patch b/queue-4.10/serial-omap-fix-runtime-pm-handling-on-unbind.patch new file mode 100644 index 00000000000..4fdb79c06ac --- /dev/null +++ b/queue-4.10/serial-omap-fix-runtime-pm-handling-on-unbind.patch @@ -0,0 +1,66 @@ +From 099bd73dc17ed77aa8c98323e043613b6e8f54fc Mon Sep 17 00:00:00 2001 +From: Johan Hovold +Date: Mon, 10 Apr 2017 11:21:38 +0200 +Subject: serial: omap: fix runtime-pm handling on unbind + +From: Johan Hovold + +commit 099bd73dc17ed77aa8c98323e043613b6e8f54fc upstream. + +An unbalanced and misplaced synchronous put was used to suspend the +device on driver unbind, something which with a likewise misplaced +pm_runtime_disable leads to external aborts when an open port is being +removed. + +Unhandled fault: external abort on non-linefetch (0x1028) at 0xfa024010 +... +[] (serial_omap_set_mctrl) from [] (uart_update_mctrl+0x50/0x60) +[] (uart_update_mctrl) from [] (uart_shutdown+0xbc/0x138) +[] (uart_shutdown) from [] (uart_hangup+0x94/0x190) +[] (uart_hangup) from [] (__tty_hangup+0x404/0x41c) +[] (__tty_hangup) from [] (tty_vhangup+0x1c/0x20) +[] (tty_vhangup) from [] (uart_remove_one_port+0xec/0x260) +[] (uart_remove_one_port) from [] (serial_omap_remove+0x40/0x60) +[] (serial_omap_remove) from [] (platform_drv_remove+0x34/0x4c) + +Fix this up by resuming the device before deregistering the port and by +suspending and disabling runtime pm only after the port has been +removed. + +Also make sure to disable autosuspend before disabling runtime pm so +that the usage count is balanced and device actually suspended before +returning. + +Note that due to a negative autosuspend delay being set in probe, the +unbalanced put would actually suspend the device on first driver unbind, +while rebinding and again unbinding would result in a negative +power.usage_count. + +Fixes: 7e9c8e7dbf3b ("serial: omap: make sure to suspend device before remove") +Cc: Felipe Balbi +Cc: Santosh Shilimkar +Signed-off-by: Johan Hovold +Acked-by: Tony Lindgren +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/tty/serial/omap-serial.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +--- a/drivers/tty/serial/omap-serial.c ++++ b/drivers/tty/serial/omap-serial.c +@@ -1725,9 +1725,13 @@ static int serial_omap_remove(struct pla + { + struct uart_omap_port *up = platform_get_drvdata(dev); + ++ pm_runtime_get_sync(up->dev); ++ ++ uart_remove_one_port(&serial_omap_reg, &up->port); ++ ++ pm_runtime_dont_use_autosuspend(up->dev); + pm_runtime_put_sync(up->dev); + pm_runtime_disable(up->dev); +- uart_remove_one_port(&serial_omap_reg, &up->port); + pm_qos_remove_request(&up->pm_qos_request); + device_init_wakeup(&dev->dev, false); + diff --git a/queue-4.10/serial-omap-suspend-device-on-probe-errors.patch b/queue-4.10/serial-omap-suspend-device-on-probe-errors.patch new file mode 100644 index 00000000000..2d68f0f5b5a --- /dev/null +++ b/queue-4.10/serial-omap-suspend-device-on-probe-errors.patch @@ -0,0 +1,38 @@ +From 77e6fe7fd2b7cba0bf2f2dc8cde51d7b9a35bf74 Mon Sep 17 00:00:00 2001 +From: Johan Hovold +Date: Mon, 10 Apr 2017 11:21:39 +0200 +Subject: serial: omap: suspend device on probe errors + +From: Johan Hovold + +commit 77e6fe7fd2b7cba0bf2f2dc8cde51d7b9a35bf74 upstream. + +Make sure to actually suspend the device before returning after a failed +(or deferred) probe. + +Note that autosuspend must be disabled before runtime pm is disabled in +order to balance the usage count due to a negative autosuspend delay as +well as to make the final put suspend the device synchronously. + +Fixes: 388bc2622680 ("omap-serial: Fix the error handling in the omap_serial probe") +Cc: Shubhrajyoti D +Signed-off-by: Johan Hovold +Acked-by: Tony Lindgren +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/tty/serial/omap-serial.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +--- a/drivers/tty/serial/omap-serial.c ++++ b/drivers/tty/serial/omap-serial.c +@@ -1712,7 +1712,8 @@ static int serial_omap_probe(struct plat + return 0; + + err_add_port: +- pm_runtime_put(&pdev->dev); ++ pm_runtime_dont_use_autosuspend(&pdev->dev); ++ pm_runtime_put_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); + pm_qos_remove_request(&up->pm_qos_request); + device_init_wakeup(up->dev, false); diff --git a/queue-4.10/serial-samsung-use-right-device-for-dma-mapping-calls.patch b/queue-4.10/serial-samsung-use-right-device-for-dma-mapping-calls.patch new file mode 100644 index 00000000000..2c14206f11f --- /dev/null +++ b/queue-4.10/serial-samsung-use-right-device-for-dma-mapping-calls.patch @@ -0,0 +1,78 @@ +From 768d64f491a530062ddad50e016fb27125f8bd7c Mon Sep 17 00:00:00 2001 +From: Marek Szyprowski +Date: Mon, 3 Apr 2017 08:20:59 +0200 +Subject: serial: samsung: Use right device for DMA-mapping calls + +From: Marek Szyprowski + +commit 768d64f491a530062ddad50e016fb27125f8bd7c upstream. + +Driver should provide its own struct device for all DMA-mapping calls instead +of extracting device pointer from DMA engine channel. Although this is harmless +from the driver operation perspective on ARM architecture, it is always good +to use the DMA mapping API in a proper way. This patch fixes following DMA API +debug warning: + +WARNING: CPU: 0 PID: 0 at lib/dma-debug.c:1241 check_sync+0x520/0x9f4 +samsung-uart 12c20000.serial: DMA-API: device driver tries to sync DMA memory it has not allocated [device address=0x000000006df0f580] [size=64 bytes] +Modules linked in: +CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.11.0-rc1-00137-g07ca963 #51 +Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) +[] (unwind_backtrace) from [] (show_stack+0x20/0x24) +[] (show_stack) from [] (dump_stack+0x84/0xa0) +[] (dump_stack) from [] (__warn+0x14c/0x180) +[] (__warn) from [] (warn_slowpath_fmt+0x48/0x50) +[] (warn_slowpath_fmt) from [] (check_sync+0x520/0x9f4) +[] (check_sync) from [] (debug_dma_sync_single_for_device+0x88/0xc8) +[] (debug_dma_sync_single_for_device) from [] (s3c24xx_serial_start_tx_dma+0x100/0x2f8) +[] (s3c24xx_serial_start_tx_dma) from [] (s3c24xx_serial_tx_chars+0x198/0x33c) + +Reported-by: Seung-Woo Kim +Fixes: 62c37eedb74c8 ("serial: samsung: add dma reqest/release functions") +Signed-off-by: Marek Szyprowski +Reviewed-by: Bartlomiej Zolnierkiewicz +Reviewed-by: Krzysztof Kozlowski +Reviewed-by: Shuah Khan +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/tty/serial/samsung.c | 9 ++++----- + 1 file changed, 4 insertions(+), 5 deletions(-) + +--- a/drivers/tty/serial/samsung.c ++++ b/drivers/tty/serial/samsung.c +@@ -906,14 +906,13 @@ static int s3c24xx_serial_request_dma(st + return -ENOMEM; + } + +- dma->rx_addr = dma_map_single(dma->rx_chan->device->dev, dma->rx_buf, ++ dma->rx_addr = dma_map_single(p->port.dev, dma->rx_buf, + dma->rx_size, DMA_FROM_DEVICE); + + spin_lock_irqsave(&p->port.lock, flags); + + /* TX buffer */ +- dma->tx_addr = dma_map_single(dma->tx_chan->device->dev, +- p->port.state->xmit.buf, ++ dma->tx_addr = dma_map_single(p->port.dev, p->port.state->xmit.buf, + UART_XMIT_SIZE, DMA_TO_DEVICE); + + spin_unlock_irqrestore(&p->port.lock, flags); +@@ -927,7 +926,7 @@ static void s3c24xx_serial_release_dma(s + + if (dma->rx_chan) { + dmaengine_terminate_all(dma->rx_chan); +- dma_unmap_single(dma->rx_chan->device->dev, dma->rx_addr, ++ dma_unmap_single(p->port.dev, dma->rx_addr, + dma->rx_size, DMA_FROM_DEVICE); + kfree(dma->rx_buf); + dma_release_channel(dma->rx_chan); +@@ -936,7 +935,7 @@ static void s3c24xx_serial_release_dma(s + + if (dma->tx_chan) { + dmaengine_terminate_all(dma->tx_chan); +- dma_unmap_single(dma->tx_chan->device->dev, dma->tx_addr, ++ dma_unmap_single(p->port.dev, dma->tx_addr, + UART_XMIT_SIZE, DMA_TO_DEVICE); + dma_release_channel(dma->tx_chan); + dma->tx_chan = NULL; diff --git a/queue-4.10/series b/queue-4.10/series index 41d356a497b..31b1066f9d7 100644 --- a/queue-4.10/series +++ b/queue-4.10/series @@ -71,3 +71,17 @@ cifs-add-misssing-sfm-mapping-for-doublequote.patch ovl-do-not-set-overlay.opaque-on-non-dir-create.patch padata-free-correct-variable.patch md-raid1-avoid-reusing-a-resync-bio-after-error-handling.patch +device-dax-fix-cdev-leak.patch +device-dax-fix-sysfs-attribute-deadlock.patch +dax-prevent-invalidation-of-mapped-dax-entries.patch +mm-fix-data-corruption-due-to-stale-mmap-reads.patch +f2fs-fix-fs-corruption-due-to-zero-inode-page.patch +fscrypt-fix-context-consistency-check-when-key-s-unavailable.patch +serial-samsung-use-right-device-for-dma-mapping-calls.patch +serial-omap-fix-runtime-pm-handling-on-unbind.patch +serial-omap-suspend-device-on-probe-errors.patch +tty-pty-fix-ldisc-flush-after-userspace-become-aware-of-the-data-already.patch +bluetooth-fix-user-channel-for-32bit-userspace-on-64bit-kernel.patch +bluetooth-hci_bcm-add-missing-tty-device-sanity-check.patch +bluetooth-hci_intel-add-missing-tty-device-sanity-check.patch +libata-reject-passthrough-write-same-requests.patch diff --git a/queue-4.10/tty-pty-fix-ldisc-flush-after-userspace-become-aware-of-the-data-already.patch b/queue-4.10/tty-pty-fix-ldisc-flush-after-userspace-become-aware-of-the-data-already.patch new file mode 100644 index 00000000000..dafc9a4a375 --- /dev/null +++ b/queue-4.10/tty-pty-fix-ldisc-flush-after-userspace-become-aware-of-the-data-already.patch @@ -0,0 +1,83 @@ +From 77dae6134440420bac334581a3ccee94cee1c054 Mon Sep 17 00:00:00 2001 +From: Wang YanQing +Date: Wed, 22 Feb 2017 19:37:08 +0800 +Subject: tty: pty: Fix ldisc flush after userspace become aware of the data already + +From: Wang YanQing + +commit 77dae6134440420bac334581a3ccee94cee1c054 upstream. + +While using emacs, cat or others' commands in konsole with recent +kernels, I have met many times that CTRL-C freeze konsole. After +konsole freeze I can't type anything, then I have to open a new one, +it is very annoying. + +See bug report: +https://bugs.kde.org/show_bug.cgi?id=175283 + +The platform in that bug report is Solaris, but now the pty in linux +has the same problem or the same behavior as Solaris :) + +It has high possibility to trigger the problem follow steps below: +Note: In my test, BigFile is a text file whose size is bigger than 1G +1:open konsole +1:cat BigFile +2:CTRL-C + +After some digging, I find out the reason is that commit 1d1d14da12e7 +("pty: Fix buffer flush deadlock") changes the behavior of pty_flush_buffer. + +Thread A Thread B +-------- -------- +1:n_tty_poll return POLLIN + 2:CTRL-C trigger pty_flush_buffer + tty_buffer_flush + n_tty_flush_buffer +3:attempt to check count of chars: + ioctl(fd, TIOCINQ, &available) + available is equal to 0 + +4:read(fd, buffer, avaiable) + return 0 + +5:konsole close fd + +Yes, I know we could use the same patch included in the BUG report as +a workaround for linux platform too. But I think the data in ldisc is +belong to application of another side, we shouldn't clear it when we +want to flush write buffer of this side in pty_flush_buffer. So I think +it is better to disable ldisc flush in pty_flush_buffer, because its new +hehavior bring no benefit except that it mess up the behavior between +POLLIN, and TIOCINQ or FIONREAD. + +Also I find no flush_buffer function in others' tty driver has the +same behavior as current pty_flush_buffer. + +Fixes: 1d1d14da12e7 ("pty: Fix buffer flush deadlock") +Signed-off-by: Wang YanQing +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/tty/pty.c | 7 +------ + 1 file changed, 1 insertion(+), 6 deletions(-) + +--- a/drivers/tty/pty.c ++++ b/drivers/tty/pty.c +@@ -216,16 +216,11 @@ static int pty_signal(struct tty_struct + static void pty_flush_buffer(struct tty_struct *tty) + { + struct tty_struct *to = tty->link; +- struct tty_ldisc *ld; + + if (!to) + return; + +- ld = tty_ldisc_ref(to); +- tty_buffer_flush(to, ld); +- if (ld) +- tty_ldisc_deref(ld); +- ++ tty_buffer_flush(to, NULL); + if (to->packet) { + spin_lock_irq(&tty->ctrl_lock); + tty->ctrl_status |= TIOCPKT_FLUSHWRITE;