1. 25 8月, 2019 6 次提交
    • M
      mm/memcontrol.c: fix use after free in mem_cgroup_iter() · c8282f1b
      Miles Chen 提交于
      commit 54a83d6bcbf8f4700013766b974bf9190d40b689 upstream.
      
      This patch is sent to report an use after free in mem_cgroup_iter()
      after merging commit be2657752e9e ("mm: memcg: fix use after free in
      mem_cgroup_iter()").
      
      I work with android kernel tree (4.9 & 4.14), and commit be2657752e9e
      ("mm: memcg: fix use after free in mem_cgroup_iter()") has been merged
      to the trees.  However, I can still observe use after free issues
      addressed in the commit be2657752e9e.  (on low-end devices, a few times
      this month)
      
      backtrace:
              css_tryget <- crash here
              mem_cgroup_iter
              shrink_node
              shrink_zones
              do_try_to_free_pages
              try_to_free_pages
              __perform_reclaim
              __alloc_pages_direct_reclaim
              __alloc_pages_slowpath
              __alloc_pages_nodemask
      
      To debug, I poisoned mem_cgroup before freeing it:
      
        static void __mem_cgroup_free(struct mem_cgroup *memcg)
              for_each_node(node)
              free_mem_cgroup_per_node_info(memcg, node);
              free_percpu(memcg->stat);
        +     /* poison memcg before freeing it */
        +     memset(memcg, 0x78, sizeof(struct mem_cgroup));
              kfree(memcg);
        }
      
      The coredump shows the position=0xdbbc2a00 is freed.
      
        (gdb) p/x ((struct mem_cgroup_per_node *)0xe5009e00)->iter[8]
        $13 = {position = 0xdbbc2a00, generation = 0x2efd}
      
        0xdbbc2a00:     0xdbbc2e00      0x00000000      0xdbbc2800      0x00000100
        0xdbbc2a10:     0x00000200      0x78787878      0x00026218      0x00000000
        0xdbbc2a20:     0xdcad6000      0x00000001      0x78787800      0x00000000
        0xdbbc2a30:     0x78780000      0x00000000      0x0068fb84      0x78787878
        0xdbbc2a40:     0x78787878      0x78787878      0x78787878      0xe3fa5cc0
        0xdbbc2a50:     0x78787878      0x78787878      0x00000000      0x00000000
        0xdbbc2a60:     0x00000000      0x00000000      0x00000000      0x00000000
        0xdbbc2a70:     0x00000000      0x00000000      0x00000000      0x00000000
        0xdbbc2a80:     0x00000000      0x00000000      0x00000000      0x00000000
        0xdbbc2a90:     0x00000001      0x00000000      0x00000000      0x00100000
        0xdbbc2aa0:     0x00000001      0xdbbc2ac8      0x00000000      0x00000000
        0xdbbc2ab0:     0x00000000      0x00000000      0x00000000      0x00000000
        0xdbbc2ac0:     0x00000000      0x00000000      0xe5b02618      0x00001000
        0xdbbc2ad0:     0x00000000      0x78787878      0x78787878      0x78787878
        0xdbbc2ae0:     0x78787878      0x78787878      0x78787878      0x78787878
        0xdbbc2af0:     0x78787878      0x78787878      0x78787878      0x78787878
        0xdbbc2b00:     0x78787878      0x78787878      0x78787878      0x78787878
        0xdbbc2b10:     0x78787878      0x78787878      0x78787878      0x78787878
        0xdbbc2b20:     0x78787878      0x78787878      0x78787878      0x78787878
        0xdbbc2b30:     0x78787878      0x78787878      0x78787878      0x78787878
        0xdbbc2b40:     0x78787878      0x78787878      0x78787878      0x78787878
        0xdbbc2b50:     0x78787878      0x78787878      0x78787878      0x78787878
        0xdbbc2b60:     0x78787878      0x78787878      0x78787878      0x78787878
        0xdbbc2b70:     0x78787878      0x78787878      0x78787878      0x78787878
        0xdbbc2b80:     0x78787878      0x78787878      0x00000000      0x78787878
        0xdbbc2b90:     0x78787878      0x78787878      0x78787878      0x78787878
        0xdbbc2ba0:     0x78787878      0x78787878      0x78787878      0x78787878
      
      In the reclaim path, try_to_free_pages() does not setup
      sc.target_mem_cgroup and sc is passed to do_try_to_free_pages(), ...,
      shrink_node().
      
      In mem_cgroup_iter(), root is set to root_mem_cgroup because
      sc->target_mem_cgroup is NULL.  It is possible to assign a memcg to
      root_mem_cgroup.nodeinfo.iter in mem_cgroup_iter().
      
              try_to_free_pages
              	struct scan_control sc = {...}, target_mem_cgroup is 0x0;
              do_try_to_free_pages
              shrink_zones
              shrink_node
              	 mem_cgroup *root = sc->target_mem_cgroup;
              	 memcg = mem_cgroup_iter(root, NULL, &reclaim);
              mem_cgroup_iter()
              	if (!root)
              		root = root_mem_cgroup;
              	...
      
              	css = css_next_descendant_pre(css, &root->css);
              	memcg = mem_cgroup_from_css(css);
              	cmpxchg(&iter->position, pos, memcg);
      
      My device uses memcg non-hierarchical mode.  When we release a memcg:
      invalidate_reclaim_iterators() reaches only dead_memcg and its parents.
      If non-hierarchical mode is used, invalidate_reclaim_iterators() never
      reaches root_mem_cgroup.
      
        static void invalidate_reclaim_iterators(struct mem_cgroup *dead_memcg)
        {
              struct mem_cgroup *memcg = dead_memcg;
      
              for (; memcg; memcg = parent_mem_cgroup(memcg)
              ...
        }
      
      So the use after free scenario looks like:
      
        CPU1						CPU2
      
        try_to_free_pages
        do_try_to_free_pages
        shrink_zones
        shrink_node
        mem_cgroup_iter()
            if (!root)
            	root = root_mem_cgroup;
            ...
            css = css_next_descendant_pre(css, &root->css);
            memcg = mem_cgroup_from_css(css);
            cmpxchg(&iter->position, pos, memcg);
      
              				invalidate_reclaim_iterators(memcg);
              				...
              				__mem_cgroup_free()
              					kfree(memcg);
      
        try_to_free_pages
        do_try_to_free_pages
        shrink_zones
        shrink_node
        mem_cgroup_iter()
            if (!root)
            	root = root_mem_cgroup;
            ...
            mz = mem_cgroup_nodeinfo(root, reclaim->pgdat->node_id);
            iter = &mz->iter[reclaim->priority];
            pos = READ_ONCE(iter->position);
            css_tryget(&pos->css) <- use after free
      
      To avoid this, we should also invalidate root_mem_cgroup.nodeinfo.iter
      in invalidate_reclaim_iterators().
      
      [cai@lca.pw: fix -Wparentheses compilation warning]
        Link: http://lkml.kernel.org/r/1564580753-17531-1-git-send-email-cai@lca.pw
      Link: http://lkml.kernel.org/r/20190730015729.4406-1-miles.chen@mediatek.com
      Fixes: 5ac8fb31 ("mm: memcontrol: convert reclaim iterator to simple css refcounting")
      Signed-off-by: NMiles Chen <miles.chen@mediatek.com>
      Signed-off-by: NQian Cai <cai@lca.pw>
      Acked-by: NMichal Hocko <mhocko@suse.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c8282f1b
    • Y
      mm: mempolicy: handle vma with unmovable pages mapped correctly in mbind · 3c0cb90e
      Yang Shi 提交于
      commit a53190a4aaa36494f4d7209fd1fcc6f2ee08e0e0 upstream.
      
      When running syzkaller internally, we ran into the below bug on 4.9.x
      kernel:
      
        kernel BUG at mm/huge_memory.c:2124!
        invalid opcode: 0000 [#1] SMP KASAN
        CPU: 0 PID: 1518 Comm: syz-executor107 Not tainted 4.9.168+ #2
        Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.5.1 01/01/2011
        task: ffff880067b34900 task.stack: ffff880068998000
        RIP: split_huge_page_to_list+0x8fb/0x1030 mm/huge_memory.c:2124
        Call Trace:
          split_huge_page include/linux/huge_mm.h:100 [inline]
          queue_pages_pte_range+0x7e1/0x1480 mm/mempolicy.c:538
          walk_pmd_range mm/pagewalk.c:50 [inline]
          walk_pud_range mm/pagewalk.c:90 [inline]
          walk_pgd_range mm/pagewalk.c:116 [inline]
          __walk_page_range+0x44a/0xdb0 mm/pagewalk.c:208
          walk_page_range+0x154/0x370 mm/pagewalk.c:285
          queue_pages_range+0x115/0x150 mm/mempolicy.c:694
          do_mbind mm/mempolicy.c:1241 [inline]
          SYSC_mbind+0x3c3/0x1030 mm/mempolicy.c:1370
          SyS_mbind+0x46/0x60 mm/mempolicy.c:1352
          do_syscall_64+0x1d2/0x600 arch/x86/entry/common.c:282
          entry_SYSCALL_64_after_swapgs+0x5d/0xdb
        Code: c7 80 1c 02 00 e8 26 0a 76 01 <0f> 0b 48 c7 c7 40 46 45 84 e8 4c
        RIP  [<ffffffff81895d6b>] split_huge_page_to_list+0x8fb/0x1030 mm/huge_memory.c:2124
         RSP <ffff88006899f980>
      
      with the below test:
      
        uint64_t r[1] = {0xffffffffffffffff};
      
        int main(void)
        {
              syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
                                      intptr_t res = 0;
              res = syscall(__NR_socket, 0x11, 3, 0x300);
              if (res != -1)
                      r[0] = res;
              *(uint32_t*)0x20000040 = 0x10000;
              *(uint32_t*)0x20000044 = 1;
              *(uint32_t*)0x20000048 = 0xc520;
              *(uint32_t*)0x2000004c = 1;
              syscall(__NR_setsockopt, r[0], 0x107, 0xd, 0x20000040, 0x10);
              syscall(__NR_mmap, 0x20fed000, 0x10000, 0, 0x8811, r[0], 0);
              *(uint64_t*)0x20000340 = 2;
              syscall(__NR_mbind, 0x20ff9000, 0x4000, 0x4002, 0x20000340, 0x45d4, 3);
              return 0;
        }
      
      Actually the test does:
      
        mmap(0x20000000, 16777216, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x20000000
        socket(AF_PACKET, SOCK_RAW, 768)        = 3
        setsockopt(3, SOL_PACKET, PACKET_TX_RING, {block_size=65536, block_nr=1, frame_size=50464, frame_nr=1}, 16) = 0
        mmap(0x20fed000, 65536, PROT_NONE, MAP_SHARED|MAP_FIXED|MAP_POPULATE|MAP_DENYWRITE, 3, 0) = 0x20fed000
        mbind(..., MPOL_MF_STRICT|MPOL_MF_MOVE) = 0
      
      The setsockopt() would allocate compound pages (16 pages in this test)
      for packet tx ring, then the mmap() would call packet_mmap() to map the
      pages into the user address space specified by the mmap() call.
      
      When calling mbind(), it would scan the vma to queue the pages for
      migration to the new node.  It would split any huge page since 4.9
      doesn't support THP migration, however, the packet tx ring compound
      pages are not THP and even not movable.  So, the above bug is triggered.
      
      However, the later kernel is not hit by this issue due to commit
      d44d363f ("mm: don't assume anonymous pages have SwapBacked flag"),
      which just removes the PageSwapBacked check for a different reason.
      
      But, there is a deeper issue.  According to the semantic of mbind(), it
      should return -EIO if MPOL_MF_MOVE or MPOL_MF_MOVE_ALL was specified and
      MPOL_MF_STRICT was also specified, but the kernel was unable to move all
      existing pages in the range.  The tx ring of the packet socket is
      definitely not movable, however, mbind() returns success for this case.
      
      Although the most socket file associates with non-movable pages, but XDP
      may have movable pages from gup.  So, it sounds not fine to just check
      the underlying file type of vma in vma_migratable().
      
      Change migrate_page_add() to check if the page is movable or not, if it
      is unmovable, just return -EIO.  But do not abort pte walk immediately,
      since there may be pages off LRU temporarily.  We should migrate other
      pages if MPOL_MF_MOVE* is specified.  Set has_unmovable flag if some
      paged could not be not moved, then return -EIO for mbind() eventually.
      
      With this change the above test would return -EIO as expected.
      
      [yang.shi@linux.alibaba.com: fix review comments from Vlastimil]
        Link: http://lkml.kernel.org/r/1563556862-54056-3-git-send-email-yang.shi@linux.alibaba.com
      Link: http://lkml.kernel.org/r/1561162809-59140-3-git-send-email-yang.shi@linux.alibaba.comSigned-off-by: NYang Shi <yang.shi@linux.alibaba.com>
      Reviewed-by: NVlastimil Babka <vbabka@suse.cz>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Mel Gorman <mgorman@techsingularity.net>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3c0cb90e
    • Y
      mm: mempolicy: make the behavior consistent when MPOL_MF_MOVE* and MPOL_MF_STRICT were specified · cd825d87
      Yang Shi 提交于
      commit d883544515aae54842c21730b880172e7894fde9 upstream.
      
      When both MPOL_MF_MOVE* and MPOL_MF_STRICT was specified, mbind() should
      try best to migrate misplaced pages, if some of the pages could not be
      migrated, then return -EIO.
      
      There are three different sub-cases:
       1. vma is not migratable
       2. vma is migratable, but there are unmovable pages
       3. vma is migratable, pages are movable, but migrate_pages() fails
      
      If #1 happens, kernel would just abort immediately, then return -EIO,
      after a7f40cfe3b7a ("mm: mempolicy: make mbind() return -EIO when
      MPOL_MF_STRICT is specified").
      
      If #3 happens, kernel would set policy and migrate pages with
      best-effort, but won't rollback the migrated pages and reset the policy
      back.
      
      Before that commit, they behaves in the same way.  It'd better to keep
      their behavior consistent.  But, rolling back the migrated pages and
      resetting the policy back sounds not feasible, so just make #1 behave as
      same as #3.
      
      Userspace will know that not everything was successfully migrated (via
      -EIO), and can take whatever steps it deems necessary - attempt
      rollback, determine which exact page(s) are violating the policy, etc.
      
      Make queue_pages_range() return 1 to indicate there are unmovable pages
      or vma is not migratable.
      
      The #2 is not handled correctly in the current kernel, the following
      patch will fix it.
      
      [yang.shi@linux.alibaba.com: fix review comments from Vlastimil]
        Link: http://lkml.kernel.org/r/1563556862-54056-2-git-send-email-yang.shi@linux.alibaba.com
      Link: http://lkml.kernel.org/r/1561162809-59140-2-git-send-email-yang.shi@linux.alibaba.comSigned-off-by: NYang Shi <yang.shi@linux.alibaba.com>
      Reviewed-by: NVlastimil Babka <vbabka@suse.cz>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Mel Gorman <mgorman@techsingularity.net>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cd825d87
    • R
      mm/hmm: fix bad subpage pointer in try_to_unmap_one · f0fed828
      Ralph Campbell 提交于
      commit 1de13ee59225dfc98d483f8cce7d83f97c0b31de upstream.
      
      When migrating an anonymous private page to a ZONE_DEVICE private page,
      the source page->mapping and page->index fields are copied to the
      destination ZONE_DEVICE struct page and the page_mapcount() is
      increased.  This is so rmap_walk() can be used to unmap and migrate the
      page back to system memory.
      
      However, try_to_unmap_one() computes the subpage pointer from a swap pte
      which computes an invalid page pointer and a kernel panic results such
      as:
      
        BUG: unable to handle page fault for address: ffffea1fffffffc8
      
      Currently, only single pages can be migrated to device private memory so
      no subpage computation is needed and it can be set to "page".
      
      [rcampbell@nvidia.com: add comment]
        Link: http://lkml.kernel.org/r/20190724232700.23327-4-rcampbell@nvidia.com
      Link: http://lkml.kernel.org/r/20190719192955.30462-4-rcampbell@nvidia.com
      Fixes: a5430dda ("mm/migrate: support un-addressable ZONE_DEVICE page in migration")
      Signed-off-by: NRalph Campbell <rcampbell@nvidia.com>
      Cc: "Jérôme Glisse" <jglisse@redhat.com>
      Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
      Cc: Mike Kravetz <mike.kravetz@oracle.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Jason Gunthorpe <jgg@mellanox.com>
      Cc: John Hubbard <jhubbard@nvidia.com>
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: Dan Williams <dan.j.williams@intel.com>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Ira Weiny <ira.weiny@intel.com>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Lai Jiangshan <jiangshanlai@gmail.com>
      Cc: Logan Gunthorpe <logang@deltatee.com>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Mel Gorman <mgorman@techsingularity.net>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f0fed828
    • N
      seq_file: fix problem when seeking mid-record · 3858cca1
      NeilBrown 提交于
      commit 6a2aeab59e97101b4001bac84388fc49a992f87e upstream.
      
      If you use lseek or similar (e.g.  pread) to access a location in a
      seq_file file that is within a record, rather than at a record boundary,
      then the first read will return the remainder of the record, and the
      second read will return the whole of that same record (instead of the
      next record).  When seeking to a record boundary, the next record is
      correctly returned.
      
      This bug was introduced by a recent patch (identified below).  Before
      that patch, seq_read() would increment m->index when the last of the
      buffer was returned (m->count == 0).  After that patch, we rely on
      ->next to increment m->index after filling the buffer - but there was
      one place where that didn't happen.
      
      Link: https://lkml.kernel.org/lkml/877e7xl029.fsf@notabene.neil.brown.name/
      Fixes: 1f4aace6 ("fs/seq_file.c: simplify seq_file iteration code and interface")
      Signed-off-by: NNeilBrown <neilb@suse.com>
      Reported-by: NSergei Turchanov <turchanov@farpost.com>
      Tested-by: NSergei Turchanov <turchanov@farpost.com>
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: Markus Elfring <Markus.Elfring@web.de>
      Cc: <stable@vger.kernel.org>	[4.19+]
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3858cca1
    • G
      sh: kernel: hw_breakpoint: Fix missing break in switch statement · 50d15197
      Gustavo A. R. Silva 提交于
      commit 1ee1119d184bb06af921b48c3021d921bbd85bac upstream.
      
      Add missing break statement in order to prevent the code from falling
      through to case SH_BREAKPOINT_WRITE.
      
      Fixes: 09a07294 ("sh: hw-breakpoints: Add preliminary support for SH-4A UBC.")
      Cc: stable@vger.kernel.org
      Reviewed-by: NGeert Uytterhoeven <geert+renesas@glider.be>
      Reviewed-by: NGuenter Roeck <linux@roeck-us.net>
      Tested-by: NGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: NGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      50d15197
  2. 16 8月, 2019 34 次提交
    • G
      Linux 4.19.67 · a5aa8058
      Greg Kroah-Hartman 提交于
      a5aa8058
    • L
      iwlwifi: mvm: fix version check for GEO_TX_POWER_LIMIT support · ac295111
      Luca Coelho 提交于
      commit f5a47fae6aa3eb06f100e701d2342ee56b857bee upstream.
      
      We erroneously added a check for FW API version 41 before sending
      GEO_TX_POWER_LIMIT, but this was already implemented in version 38.
      Additionally, it was cherry-picked to older versions, namely 17, 26
      and 29, so check for those as well.
      
      Cc: stable@vger.kernel.org
      Fixes: eca1e56ceedd ("iwlwifi: mvm: don't send GEO_TX_POWER_LIMIT to old firmwares")
      Signed-off-by: NLuca Coelho <luciano.coelho@intel.com>
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ac295111
    • L
      iwlwifi: mvm: don't send GEO_TX_POWER_LIMIT on version < 41 · 6a81677a
      Luca Coelho 提交于
      commit 39bd984c203e86f3109b49c2a2e20677c4d3ab65 upstream.
      
      Firmware versions before 41 don't support the GEO_TX_POWER_LIMIT
      command, and sending it to the firmware will cause a firmware crash.
      We allow this via debugfs, so we need to return an error value in case
      it's not supported.
      
      This had already been fixed during init, when we send the command if
      the ACPI WGDS table is present.  Fix it also for the other,
      userspace-triggered case.
      
      Cc: stable@vger.kernel.org
      Fixes: 7fe90e0e ("iwlwifi: mvm: refactor geo init")
      Signed-off-by: NLuca Coelho <luciano.coelho@intel.com>
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6a81677a
    • E
      iwlwifi: mvm: fix an out-of-bound access · 80bac45e
      Emmanuel Grumbach 提交于
      commit ba3224db78034435e9ff0247277cce7c7bb1756c upstream.
      
      The index for the elements of the ACPI object we dereference
      was static. This means that if we called the function twice
      we wouldn't start from 3 again, but rather from the latest
      index we reached in the previous call.
      This was dutifully reported by KASAN.
      
      Fix this.
      
      Cc: stable@vger.kernel.org
      Fixes: 69964905 ("iwlwifi: mvm: add support for EWRD (Dynamic SAR) ACPI table")
      Signed-off-by: NEmmanuel Grumbach <emmanuel.grumbach@intel.com>
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      80bac45e
    • E
      iwlwifi: don't unmap as page memory that was mapped as single · 7626b510
      Emmanuel Grumbach 提交于
      commit 87e7e25aee6b59fef740856f4e86d4b60496c9e1 upstream.
      
      In order to remember how to unmap a memory (as single or
      as page), we maintain a bit per Transmit Buffer (TBs) in
      the meta data (structure iwl_cmd_meta).
      We maintain a bitmap: 1 bit per TB.
      If the TB is set, we will free the memory as a page.
      This bitmap was never cleared. Fix this.
      
      Cc: stable@vger.kernel.org
      Fixes: 3cd1980b ("iwlwifi: pcie: introduce new tfd and tb formats")
      Signed-off-by: NEmmanuel Grumbach <emmanuel.grumbach@intel.com>
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7626b510
    • B
      mwifiex: fix 802.11n/WPA detection · b38c56b7
      Brian Norris 提交于
      commit df612421fe2566654047769c6852ffae1a31df16 upstream.
      
      Commit 63d7ef36103d ("mwifiex: Don't abort on small, spec-compliant
      vendor IEs") adjusted the ieee_types_vendor_header struct, which
      inadvertently messed up the offsets used in
      mwifiex_is_wpa_oui_present(). Add that offset back in, mirroring
      mwifiex_is_rsn_oui_present().
      
      As it stands, commit 63d7ef36103d breaks compatibility with WPA (not
      WPA2) 802.11n networks, since we hit the "info: Disable 11n if AES is
      not supported by AP" case in mwifiex_is_network_compatible().
      
      Fixes: 63d7ef36103d ("mwifiex: Don't abort on small, spec-compliant vendor IEs")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NBrian Norris <briannorris@chromium.org>
      Signed-off-by: NKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b38c56b7
    • W
      KVM: Fix leak vCPU's VMCS value into other pCPU · 2bc73d91
      Wanpeng Li 提交于
      commit 17e433b54393a6269acbcb792da97791fe1592d8 upstream.
      
      After commit d73eb57b80b (KVM: Boost vCPUs that are delivering interrupts), a
      five years old bug is exposed. Running ebizzy benchmark in three 80 vCPUs VMs
      on one 80 pCPUs Skylake server, a lot of rcu_sched stall warning splatting
      in the VMs after stress testing:
      
       INFO: rcu_sched detected stalls on CPUs/tasks: { 4 41 57 62 77} (detected by 15, t=60004 jiffies, g=899, c=898, q=15073)
       Call Trace:
         flush_tlb_mm_range+0x68/0x140
         tlb_flush_mmu.part.75+0x37/0xe0
         tlb_finish_mmu+0x55/0x60
         zap_page_range+0x142/0x190
         SyS_madvise+0x3cd/0x9c0
         system_call_fastpath+0x1c/0x21
      
      swait_active() sustains to be true before finish_swait() is called in
      kvm_vcpu_block(), voluntarily preempted vCPUs are taken into account
      by kvm_vcpu_on_spin() loop greatly increases the probability condition
      kvm_arch_vcpu_runnable(vcpu) is checked and can be true, when APICv
      is enabled the yield-candidate vCPU's VMCS RVI field leaks(by
      vmx_sync_pir_to_irr()) into spinning-on-a-taken-lock vCPU's current
      VMCS.
      
      This patch fixes it by checking conservatively a subset of events.
      
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Radim Krčmář <rkrcmar@redhat.com>
      Cc: Christian Borntraeger <borntraeger@de.ibm.com>
      Cc: Marc Zyngier <Marc.Zyngier@arm.com>
      Cc: stable@vger.kernel.org
      Fixes: 98f4a146 (KVM: add kvm_arch_vcpu_runnable() test to kvm_vcpu_on_spin() loop)
      Signed-off-by: NWanpeng Li <wanpengli@tencent.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2bc73d91
    • T
      NFSv4: Fix an Oops in nfs4_do_setattr · d1489f0b
      Trond Myklebust 提交于
      commit 09a54f0ebfe263bc27c90bbd80187b9a93283887 upstream.
      
      If the user specifies an open mode of 3, then we don't have a NFSv4 state
      attached to the context, and so we Oops when we try to dereference it.
      Reported-by: NOlga Kornievskaia <aglo@umich.edu>
      Fixes: 29b59f94 ("NFSv4: change nfs4_do_setattr to take...")
      Signed-off-by: NTrond Myklebust <trond.myklebust@hammerspace.com>
      Cc: stable@vger.kernel.org # v4.10: 991eedb1: NFSv4: Only pass the...
      Cc: stable@vger.kernel.org # v4.10+
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d1489f0b
    • S
      smb3: send CAP_DFS capability during session setup · 898c19f1
      Steve French 提交于
      commit 8d33096a460d5b9bd13300f01615df5bb454db10 upstream.
      
      We had a report of a server which did not do a DFS referral
      because the session setup Capabilities field was set to 0
      (unlike negotiate protocol where we set CAP_DFS).  Better to
      send it session setup in the capabilities as well (this also
      more closely matches Windows client behavior).
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      Reviewed-off-by: NRonnie Sahlberg <lsahlber@redhat.com>
      Reviewed-by: NPavel Shilovsky <pshilov@microsoft.com>
      CC: Stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      898c19f1
    • P
      SMB3: Fix deadlock in validate negotiate hits reconnect · 50831f1a
      Pavel Shilovsky 提交于
      commit e99c63e4d86d3a94818693147b469fa70de6f945 upstream.
      
      Currently we skip SMB2_TREE_CONNECT command when checking during
      reconnect because Tree Connect happens when establishing
      an SMB session. For SMB 3.0 protocol version the code also calls
      validate negotiate which results in SMB2_IOCL command being sent
      over the wire. This may deadlock on trying to acquire a mutex when
      checking for reconnect. Fix this by skipping SMB2_IOCL command
      when doing the reconnect check.
      Signed-off-by: NPavel Shilovsky <pshilov@microsoft.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      Reviewed-by: NRonnie Sahlberg <lsahlber@redhat.com>
      CC: Stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      50831f1a
    • V
      dax: dax_layout_busy_page() should not unmap cow pages · 2afa6c13
      Vivek Goyal 提交于
      commit d75996dd022b6d83bd14af59b2775b1aa639e4b9 upstream.
      
      Vivek:
      
          "As of now dax_layout_busy_page() calls unmap_mapping_range() with last
           argument as 1, which says even unmap cow pages. I am wondering who needs
           to get rid of cow pages as well.
      
           I noticed one interesting side affect of this. I mount xfs with -o dax and
           mmaped a file with MAP_PRIVATE and wrote some data to a page which created
           cow page. Then I called fallocate() on that file to zero a page of file.
           fallocate() called dax_layout_busy_page() which unmapped cow pages as well
           and then I tried to read back the data I wrote and what I get is old
           data from persistent memory. I lost the data I had written. This
           read basically resulted in new fault and read back the data from
           persistent memory.
      
           This sounds wrong. Are there any users which need to unmap cow pages
           as well? If not, I am proposing changing it to not unmap cow pages.
      
           I noticed this while while writing virtio_fs code where when I tried
           to reclaim a memory range and that corrupted the executable and I
           was running from virtio-fs and program got segment violation."
      
      Dan:
      
          "In fact the unmap_mapping_range() in this path is only to synchronize
           against get_user_pages_fast() and force it to call back into the
           filesystem to re-establish the mapping. COW pages should be left
           untouched by dax_layout_busy_page()."
      
      Cc: <stable@vger.kernel.org>
      Fixes: 5fac7408 ("mm, fs, dax: handle layout changes to pinned dax mappings")
      Signed-off-by: NVivek Goyal <vgoyal@redhat.com>
      Link: https://lore.kernel.org/r/20190802192956.GA3032@redhat.comSigned-off-by: NDan Williams <dan.j.williams@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2afa6c13
    • B
      mac80211: don't WARN on short WMM parameters from AP · a566750c
      Brian Norris 提交于
      commit 05aaa5c97dce4c10a9e7eae2f1569a684e0c5ced upstream.
      
      In a very similar spirit to commit c470bdc1 ("mac80211: don't WARN
      on bad WMM parameters from buggy APs"), an AP may not transmit a
      fully-formed WMM IE. For example, it may miss or repeat an Access
      Category. The above loop won't catch that and will instead leave one of
      the four ACs zeroed out. This triggers the following warning in
      drv_conf_tx()
      
        wlan0: invalid CW_min/CW_max: 0/0
      
      and it may leave one of the hardware queues unconfigured. If we detect
      such a case, let's just print a warning and fall back to the defaults.
      
      Tested with a hacked version of hostapd, intentionally corrupting the
      IEs in hostapd_eid_wmm().
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NBrian Norris <briannorris@chromium.org>
      Link: https://lore.kernel.org/r/20190726224758.210953-1-briannorris@chromium.orgSigned-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a566750c
    • T
      ALSA: hda - Workaround for crackled sound on AMD controller (1022:1457) · af9d64f8
      Takashi Iwai 提交于
      commit c02f77d32d2c45cfb1b2bb99eabd8a78f5ecc7db upstream.
      
      A long-time problem on the recent AMD chip (X370, X470, B450, etc with
      PCI ID 1022:1457) with Realtek codecs is the crackled or distorted
      sound for capture streams, as well as occasional playback hiccups.
      After lengthy debugging sessions, the workarounds we've found are like
      the following:
      
      - Set up the proper driver caps for this controller, similar as the
        other AMD controller.
      
      - Correct the DMA position reporting with the fixed FIFO size, which
        is similar like as workaround used for VIA chip set.
      
      - Even after the position correction, PulseAudio still shows
        mysterious stalls of playback streams when a capture is triggered in
        timer-scheduled mode.  Since we have no clear way to eliminate the
        stall, pass the BATCH PCM flag for PA to suppress the tsched mode as
        a temporary workaround.
      
      This patch implements the workarounds.  For the driver caps, it
      defines a new preset, AXZ_DCAPS_PRESET_AMD_SB.  It enables the FIFO-
      corrected position reporting (corresponding to the new position_fix=6)
      and enforces the SNDRV_PCM_INFO_BATCH flag.
      
      Note that the current implementation is merely a workaround.
      Hopefully we'll find a better alternative in future, especially about
      removing the BATCH flag hack again.
      
      BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=195303
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      af9d64f8
    • T
      ALSA: hda - Don't override global PCM hw info flag · 06f0bcac
      Takashi Iwai 提交于
      commit c1c6c877b0c79fd7e05c931435aa42211eaeebaf upstream.
      
      The commit bfcba288 ("ALSA - hda: Add support for link audio time
      reporting") introduced the conditional PCM hw info setup, but it
      overwrites the global azx_pcm_hw object.  This will cause a problem if
      any other HD-audio controller, as it'll inherit the same bit flag
      although another controller doesn't support that feature.
      
      Fix the bug by setting the PCM hw info flag locally.
      
      Fixes: bfcba288 ("ALSA - hda: Add support for link audio time reporting")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      06f0bcac
    • W
      ALSA: hiface: fix multiple memory leak bugs · 1c286e4e
      Wenwen Wang 提交于
      commit 3d92aa45fbfd7319e3a19f4ec59fd32b3862b723 upstream.
      
      In hiface_pcm_init(), 'rt' is firstly allocated through kzalloc(). Later
      on, hiface_pcm_init_urb() is invoked to initialize 'rt->out_urbs[i]'. In
      hiface_pcm_init_urb(), 'rt->out_urbs[i].buffer' is allocated through
      kzalloc().  However, if hiface_pcm_init_urb() fails, both 'rt' and
      'rt->out_urbs[i].buffer' are not deallocated, leading to memory leak bugs.
      Also, 'rt->out_urbs[i].buffer' is not deallocated if snd_pcm_new() fails.
      
      To fix the above issues, free 'rt' and 'rt->out_urbs[i].buffer'.
      
      Fixes: a91c3fb2 ("Add M2Tech hiFace USB-SPDIF driver")
      Signed-off-by: NWenwen Wang <wenwen@cs.uga.edu>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1c286e4e
    • W
      ALSA: firewire: fix a memory leak bug · bc972b6b
      Wenwen Wang 提交于
      commit 1be3c1fae6c1e1f5bb982b255d2034034454527a upstream.
      
      In iso_packets_buffer_init(), 'b->packets' is allocated through
      kmalloc_array(). Then, the aligned packet size is checked. If it is
      larger than PAGE_SIZE, -EINVAL will be returned to indicate the error.
      However, the allocated 'b->packets' is not deallocated on this path,
      leading to a memory leak.
      
      To fix the above issue, free 'b->packets' before returning the error code.
      
      Fixes: 31ef9134 ("ALSA: add LaCie FireWire Speakers/Griffin FireWave Surround driver")
      Signed-off-by: NWenwen Wang <wenwen@cs.uga.edu>
      Reviewed-by: NTakashi Sakamoto <o-takashi@sakamocchi.jp>
      Cc: <stable@vger.kernel.org> # v2.6.39+
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bc972b6b
    • S
      drm/i915: Fix wrong escape clock divisor init for GLK · edc38856
      Stanislav Lisovskiy 提交于
      commit 73a0ff0b30af79bf0303d557eb82f1d1945bb6ee upstream.
      
      According to Bspec clock divisor registers in GeminiLake
      should be initialized by shifting 1(<<) to amount of correspondent
      divisor. While i915 was writing all this time that value as is.
      
      Surprisingly that it by accident worked, until we met some issues
      with Microtech Etab.
      
      v2: Added Fixes tag and cc
      v3: Added stable to cc as well.
      Signed-off-by: NStanislav Lisovskiy <stanislav.lisovskiy@intel.com>
      Reviewed-by: NVandita Kulkarni <vandita.kulkarni@intel.com>
      Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=108826
      Fixes: bcc65700 ("drm/i915/glk: Program txesc clock divider for GLK")
      Cc: Deepak M <m.deepak@intel.com>
      Cc: Madhav Chauhan <madhav.chauhan@intel.com>
      Cc: Jani Nikula <jani.nikula@intel.com>
      Cc: Jani Nikula <jani.nikula@linux.intel.com>
      Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
      Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
      Cc: intel-gfx@lists.freedesktop.org
      Cc: stable@vger.kernel.org
      Signed-off-by: NJani Nikula <jani.nikula@intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20190712081938.14185-1-stanislav.lisovskiy@intel.com
      (cherry picked from commit ce52ad5dd52cfaf3398058384e0ff94134bbd89c)
      Signed-off-by: NJani Nikula <jani.nikula@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      edc38856
    • G
      hwmon: (nct7802) Fix wrong detection of in4 presence · a7302720
      Guenter Roeck 提交于
      commit 38ada2f406a9b81fb1249c5c9227fa657e7d5671 upstream.
      
      The code to detect if in4 is present is wrong; if in4 is not present,
      the in4_input sysfs attribute is still present.
      
      In detail:
      
      - Ihen RTD3_MD=11 (VSEN3 present), everything is as expected (no bug).
      - If we have RTD3_MD!=11 (no VSEN3), we unexpectedly have a in4_input
        file under /sys and the "sensors" command displays in4_input.
        But as expected, we have no in4_min, in4_max, in4_alarm, in4_beep.
      
      Fix is_visible function to detect and report in4_input visibility
      as expected.
      Reported-by: NGilles Buloz <Gilles.Buloz@kontron.com>
      Cc: Gilles Buloz <Gilles.Buloz@kontron.com>
      Cc: stable@vger.kernel.org
      Fixes: 3434f378 ("hwmon: Driver for Nuvoton NCT7802Y")
      Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a7302720
    • T
      can: peak_usb: pcan_usb_fd: Fix info-leaks to USB devices · 9ce1b3eb
      Tomas Bortoli 提交于
      commit 30a8beeb3042f49d0537b7050fd21b490166a3d9 upstream.
      
      Uninitialized Kernel memory can leak to USB devices.
      
      Fix by using kzalloc() instead of kmalloc() on the affected buffers.
      Signed-off-by: NTomas Bortoli <tomasbortoli@gmail.com>
      Reported-by: syzbot+513e4d0985298538bf9b@syzkaller.appspotmail.com
      Fixes: 0a25e1f4 ("can: peak_usb: add support for PEAK new CANFD USB adapters")
      Cc: linux-stable <stable@vger.kernel.org>
      Signed-off-by: NMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9ce1b3eb
    • T
      can: peak_usb: pcan_usb_pro: Fix info-leaks to USB devices · cab569a4
      Tomas Bortoli 提交于
      commit ead16e53c2f0ed946d82d4037c630e2f60f4ab69 upstream.
      
      Uninitialized Kernel memory can leak to USB devices.
      
      Fix by using kzalloc() instead of kmalloc() on the affected buffers.
      Signed-off-by: NTomas Bortoli <tomasbortoli@gmail.com>
      Reported-by: syzbot+d6a5a1a3657b596ef132@syzkaller.appspotmail.com
      Fixes: f14e2243 ("net: can: peak_usb: Do not do dma on the stack")
      Cc: linux-stable <stable@vger.kernel.org>
      Signed-off-by: NMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cab569a4
    • W
      ALSA: usb-audio: fix a memory leak bug · d4d904e4
      Wenwen Wang 提交于
      commit a67060201b746a308b1674f66bf289c9faef6d09 upstream.
      
      In snd_usb_get_audioformat_uac3(), a structure for channel maps 'chmap' is
      allocated through kzalloc() before the execution goto 'found_clock'.
      However, this structure is not deallocated if the memory allocation for
      'pd' fails, leading to a memory leak bug.
      
      To fix the above issue, free 'fp->chmap' before returning NULL.
      
      Fixes: 7edf3b5e ("ALSA: usb-audio: AudioStreaming Power Domain parsing")
      Signed-off-by: NWenwen Wang <wenwen@cs.uga.edu>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d4d904e4
    • N
      x86/purgatory: Do not use __builtin_memcpy and __builtin_memset · e0d262a5
      Nick Desaulniers 提交于
      commit 4ce97317f41d38584fb93578e922fcd19e535f5b upstream.
      
      Implementing memcpy and memset in terms of __builtin_memcpy and
      __builtin_memset is problematic.
      
      GCC at -O2 will replace calls to the builtins with calls to memcpy and
      memset (but will generate an inline implementation at -Os).  Clang will
      replace the builtins with these calls regardless of optimization level.
      $ llvm-objdump -dr arch/x86/purgatory/string.o | tail
      
      0000000000000339 memcpy:
           339: 48 b8 00 00 00 00 00 00 00 00 movabsq $0, %rax
                      000000000000033b:  R_X86_64_64  memcpy
           343: ff e0                         jmpq    *%rax
      
      0000000000000345 memset:
           345: 48 b8 00 00 00 00 00 00 00 00 movabsq $0, %rax
                      0000000000000347:  R_X86_64_64  memset
           34f: ff e0
      
      Such code results in infinite recursion at runtime. This is observed
      when doing kexec.
      
      Instead, reuse an implementation from arch/x86/boot/compressed/string.c.
      This requires to implement a stub function for warn(). Also, Clang may
      lower memcmp's that compare against 0 to bcmp's, so add a small definition,
      too. See also: commit 5f074f3e192f ("lib/string.c: implement a basic bcmp")
      
      Fixes: 8fc5b4d4 ("purgatory: core purgatory functionality")
      Reported-by: NVaibhav Rustagi <vaibhavrustagi@google.com>
      Debugged-by: NVaibhav Rustagi <vaibhavrustagi@google.com>
      Debugged-by: NManoj Gupta <manojgupta@google.com>
      Suggested-by: NAlistair Delva <adelva@google.com>
      Signed-off-by: NNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Tested-by: NVaibhav Rustagi <vaibhavrustagi@google.com>
      Cc: stable@vger.kernel.org
      Link: https://bugs.chromium.org/p/chromium/issues/detail?id=984056
      Link: https://lkml.kernel.org/r/20190807221539.94583-1-ndesaulniers@google.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e0d262a5
    • R
      HID: sony: Fix race condition between rumble and device remove. · 11829307
      Roderick Colenbrander 提交于
      commit e0f6974a54d3f7f1b5fdf5a593bd43ce9206ec04 upstream.
      
      Valve reported a kernel crash on Ubuntu 18.04 when disconnecting a DS4
      gamepad while rumble is enabled. This issue is reproducible with a
      frequency of 1 in 3 times in the game Borderlands 2 when using an
      automatic weapon, which triggers many rumble operations.
      
      We found the issue to be a race condition between sony_remove and the
      final device destruction by the HID / input system. The problem was
      that sony_remove didn't clean some of its work_item state in
      "struct sony_sc". After sony_remove work, the corresponding evdev
      node was around for sufficient time for applications to still queue
      rumble work after "sony_remove".
      
      On pre-4.19 kernels the race condition caused a kernel crash due to a
      NULL-pointer dereference as "sc->output_report_dmabuf" got freed during
      sony_remove. On newer kernels this crash doesn't happen due the buffer
      now being allocated using devm_kzalloc. However we can still queue work,
      while the driver is an undefined state.
      
      This patch fixes the described problem, by guarding the work_item
      "state_worker" with an initialized variable, which we are setting back
      to 0 on cleanup.
      Signed-off-by: NRoderick Colenbrander <roderick.colenbrander@sony.com>
      CC: stable@vger.kernel.org
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      11829307
    • H
      s390/dma: provide proper ARCH_ZONE_DMA_BITS value · 5c4689cb
      Halil Pasic 提交于
      [ Upstream commit 1a2dcff881059dedc14fafc8a442664c8dbd60f1 ]
      
      On s390 ZONE_DMA is up to 2G, i.e. ARCH_ZONE_DMA_BITS should be 31 bits.
      The current value is 24 and makes __dma_direct_alloc_pages() take a
      wrong turn first (but __dma_direct_alloc_pages() recovers then).
      
      Let's correct ARCH_ZONE_DMA_BITS value and avoid wrong turns.
      Signed-off-by: NHalil Pasic <pasic@linux.ibm.com>
      Reported-by: NPetr Tesarik <ptesarik@suse.cz>
      Fixes: c61e9637 ("dma-direct: add support for allocation from ZONE_DMA and ZONE_DMA32")
      Signed-off-by: NHeiko Carstens <heiko.carstens@de.ibm.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      5c4689cb
    • L
      perf/core: Fix creating kernel counters for PMUs that override event->cpu · d7681739
      Leonard Crestez 提交于
      [ Upstream commit 4ce54af8b33d3e21ca935fc1b89b58cbba956051 ]
      
      Some hardware PMU drivers will override perf_event.cpu inside their
      event_init callback. This causes a lockdep splat when initialized through
      the kernel API:
      
       WARNING: CPU: 0 PID: 250 at kernel/events/core.c:2917 ctx_sched_out+0x78/0x208
       pc : ctx_sched_out+0x78/0x208
       Call trace:
        ctx_sched_out+0x78/0x208
        __perf_install_in_context+0x160/0x248
        remote_function+0x58/0x68
        generic_exec_single+0x100/0x180
        smp_call_function_single+0x174/0x1b8
        perf_install_in_context+0x178/0x188
        perf_event_create_kernel_counter+0x118/0x160
      
      Fix this by calling perf_install_in_context with event->cpu, just like
      perf_event_open
      Signed-off-by: NLeonard Crestez <leonard.crestez@nxp.com>
      Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Reviewed-by: NMark Rutland <mark.rutland@arm.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
      Cc: Frank Li <Frank.li@nxp.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Will Deacon <will@kernel.org>
      Link: https://lkml.kernel.org/r/c4ebe0503623066896d7046def4d6b1e06e0eb2e.1563972056.git.leonard.crestez@nxp.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      d7681739
    • P
      tty/ldsem, locking/rwsem: Add missing ACQUIRE to read_failed sleep loop · 06dc9214
      Peter Zijlstra 提交于
      [ Upstream commit 952041a8639a7a3a73a2b6573cb8aa8518bc39f8 ]
      
      While reviewing rwsem down_slowpath, Will noticed ldsem had a copy of
      a bug we just found for rwsem.
      
        X = 0;
      
        CPU0			CPU1
      
        rwsem_down_read()
          for (;;) {
            set_current_state(TASK_UNINTERRUPTIBLE);
      
                              X = 1;
                              rwsem_up_write();
                                rwsem_mark_wake()
                                  atomic_long_add(adjustment, &sem->count);
                                  smp_store_release(&waiter->task, NULL);
      
            if (!waiter.task)
              break;
      
            ...
          }
      
        r = X;
      
      Allows 'r == 0'.
      Reported-by: NWill Deacon <will@kernel.org>
      Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Acked-by: NWill Deacon <will@kernel.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Hurley <peter@hurleysoftware.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Fixes: 4898e640 ("tty: Add timed, writer-prioritized rw semaphore")
      Signed-off-by: NIngo Molnar <mingo@kernel.org>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      06dc9214
    • W
      test_firmware: fix a memory leak bug · 0ba69e96
      Wenwen Wang 提交于
      [ Upstream commit d4fddac5a51c378c5d3e68658816c37132611e1f ]
      
      In test_firmware_init(), the buffer pointed to by the global pointer
      'test_fw_config' is allocated through kzalloc(). Then, the buffer is
      initialized in __test_firmware_config_init(). In the case that the
      initialization fails, the following execution in test_firmware_init() needs
      to be terminated with an error code returned to indicate this failure.
      However, the allocated buffer is not freed on this execution path, leading
      to a memory leak bug.
      
      To fix the above issue, free the allocated buffer before returning from
      test_firmware_init().
      Signed-off-by: NWenwen Wang <wenwen@cs.uga.edu>
      Link: https://lore.kernel.org/r/1563084696-6865-1-git-send-email-wang6495@umn.eduSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      0ba69e96
    • H
      scsi: scsi_dh_alua: always use a 2 second delay before retrying RTPG · cdd92ebe
      Hannes Reinecke 提交于
      [ Upstream commit 20122994e38aef0ae50555884d287adde6641c94 ]
      
      Retrying immediately after we've received a 'transitioning' sense code is
      pretty much pointless, we should always use a delay before retrying.  So
      ensure the default delay is applied before retrying.
      Signed-off-by: NHannes Reinecke <hare@suse.com>
      Tested-by: NZhangguanghui <zhang.guanghui@h3c.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      cdd92ebe
    • T
      scsi: ibmvfc: fix WARN_ON during event pool release · b620c6d5
      Tyrel Datwyler 提交于
      [ Upstream commit 5578257ca0e21056821e6481bd534ba267b84e58 ]
      
      While removing an ibmvfc client adapter a WARN_ON like the following
      WARN_ON is seen in the kernel log:
      
      WARNING: CPU: 6 PID: 5421 at ./include/linux/dma-mapping.h:541
      ibmvfc_free_event_pool+0x12c/0x1f0 [ibmvfc]
      CPU: 6 PID: 5421 Comm: rmmod Tainted: G            E     4.17.0-rc1-next-20180419-autotest #1
      NIP:  d00000000290328c LR: d00000000290325c CTR: c00000000036ee20
      REGS: c000000288d1b7e0 TRAP: 0700   Tainted: G            E      (4.17.0-rc1-next-20180419-autotest)
      MSR:  800000010282b033 <SF,VEC,VSX,EE,FP,ME,IR,DR,RI,LE,TM[E]>  CR: 44008828  XER: 20000000
      CFAR: c00000000036e408 SOFTE: 1
      GPR00: d00000000290325c c000000288d1ba60 d000000002917900 c000000289d75448
      GPR04: 0000000000000071 c0000000ff870000 0000000018040000 0000000000000001
      GPR08: 0000000000000000 c00000000156e838 0000000000000001 d00000000290c640
      GPR12: c00000000036ee20 c00000001ec4dc00 0000000000000000 0000000000000000
      GPR16: 0000000000000000 0000000000000000 00000100276901e0 0000000010020598
      GPR20: 0000000010020550 0000000010020538 0000000010020578 00000000100205b0
      GPR24: 0000000000000000 0000000000000000 0000000010020590 5deadbeef0000100
      GPR28: 5deadbeef0000200 d000000002910b00 0000000000000071 c0000002822f87d8
      NIP [d00000000290328c] ibmvfc_free_event_pool+0x12c/0x1f0 [ibmvfc]
      LR [d00000000290325c] ibmvfc_free_event_pool+0xfc/0x1f0 [ibmvfc]
      Call Trace:
      [c000000288d1ba60] [d00000000290325c] ibmvfc_free_event_pool+0xfc/0x1f0 [ibmvfc] (unreliable)
      [c000000288d1baf0] [d000000002909390] ibmvfc_abort_task_set+0x7b0/0x8b0 [ibmvfc]
      [c000000288d1bb70] [c0000000000d8c68] vio_bus_remove+0x68/0x100
      [c000000288d1bbb0] [c0000000007da7c4] device_release_driver_internal+0x1f4/0x2d0
      [c000000288d1bc00] [c0000000007da95c] driver_detach+0x7c/0x100
      [c000000288d1bc40] [c0000000007d8af4] bus_remove_driver+0x84/0x140
      [c000000288d1bcb0] [c0000000007db6ac] driver_unregister+0x4c/0xa0
      [c000000288d1bd20] [c0000000000d6e7c] vio_unregister_driver+0x2c/0x50
      [c000000288d1bd50] [d00000000290ba0c] cleanup_module+0x24/0x15e0 [ibmvfc]
      [c000000288d1bd70] [c0000000001dadb0] sys_delete_module+0x220/0x2d0
      [c000000288d1be30] [c00000000000b284] system_call+0x58/0x6c
      Instruction dump:
      e8410018 e87f0068 809f0078 e8bf0080 e8df0088 2fa30000 419e008c e9230200
      2fa90000 419e0080 894d098a 794a07e0 <0b0a0000> e9290008 2fa90000 419e0028
      
      This is tripped as a result of irqs being disabled during the call to
      dma_free_coherent() by ibmvfc_free_event_pool(). At this point in the code path
      we have quiesced the adapter and its overly paranoid anyways to be holding the
      host lock.
      Reported-by: NAbdul Haleem <abdhalee@linux.vnet.ibm.com>
      Signed-off-by: NTyrel Datwyler <tyreld@linux.vnet.ibm.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      b620c6d5
    • J
      scsi: megaraid_sas: fix panic on loading firmware crashdump · f254faed
      Junxiao Bi 提交于
      [ Upstream commit 3b5f307ef3cb5022bfe3c8ca5b8f2114d5bf6c29 ]
      
      While loading fw crashdump in function fw_crash_buffer_show(), left bytes
      in one dma chunk was not checked, if copying size over it, overflow access
      will cause kernel panic.
      Signed-off-by: NJunxiao Bi <junxiao.bi@oracle.com>
      Acked-by: NSumit Saxena <sumit.saxena@broadcom.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      f254faed
    • A
      ARM: dts: bcm: bcm47094: add missing #cells for mdio-bus-mux · bb41940c
      Arnd Bergmann 提交于
      [ Upstream commit 3a9d2569e45cb02769cda26fee4a02126867c934 ]
      
      The mdio-bus-mux has no #address-cells/#size-cells property,
      which causes a few dtc warnings:
      
      arch/arm/boot/dts/bcm47094-linksys-panamera.dts:129.4-18: Warning (reg_format): /mdio-bus-mux/mdio@200:reg: property has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
      arch/arm/boot/dts/bcm47094-linksys-panamera.dtb: Warning (pci_device_bus_num): Failed prerequisite 'reg_format'
      arch/arm/boot/dts/bcm47094-linksys-panamera.dtb: Warning (i2c_bus_reg): Failed prerequisite 'reg_format'
      arch/arm/boot/dts/bcm47094-linksys-panamera.dtb: Warning (spi_bus_reg): Failed prerequisite 'reg_format'
      arch/arm/boot/dts/bcm47094-linksys-panamera.dts:128.22-132.5: Warning (avoid_default_addr_size): /mdio-bus-mux/mdio@200: Relying on default #address-cells value
      arch/arm/boot/dts/bcm47094-linksys-panamera.dts:128.22-132.5: Warning (avoid_default_addr_size): /mdio-bus-mux/mdio@200: Relying on default #size-cells value
      
      Add the normal cell numbers.
      
      Link: https://lore.kernel.org/r/20190722145618.1155492-1-arnd@arndb.de
      Fixes: 2bebdfcd ("ARM: dts: BCM5301X: Add support for Linksys EA9500")
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NOlof Johansson <olof@lixom.net>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      bb41940c
    • A
      ARM: davinci: fix sleep.S build error on ARMv4 · 19e7df3e
      Arnd Bergmann 提交于
      [ Upstream commit d64b212ea960db4276a1d8372bd98cb861dfcbb0 ]
      
      When building a multiplatform kernel that includes armv4 support,
      the default target CPU does not support the blx instruction,
      which leads to a build failure:
      
      arch/arm/mach-davinci/sleep.S: Assembler messages:
      arch/arm/mach-davinci/sleep.S:56: Error: selected processor does not support `blx ip' in ARM mode
      
      Add a .arch statement in the sources to make this file build.
      
      Link: https://lore.kernel.org/r/20190722145211.1154785-1-arnd@arndb.deAcked-by: NSekhar Nori <nsekhar@ti.com>
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NOlof Johansson <olof@lixom.net>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      19e7df3e
    • M
      nvme: fix multipath crash when ANA is deactivated · bdce5621
      Marta Rybczynska 提交于
      [ Upstream commit 66b20ac0a1a10769d059d6903202f53494e3d902 ]
      
      Fix a crash with multipath activated. It happends when ANA log
      page is larger than MDTS and because of that ANA is disabled.
      The driver then tries to access unallocated buffer when connecting
      to a nvme target. The signature is as follows:
      
      [  300.433586] nvme nvme0: ANA log page size (8208) larger than MDTS (8192).
      [  300.435387] nvme nvme0: disabling ANA support.
      [  300.437835] nvme nvme0: creating 4 I/O queues.
      [  300.459132] nvme nvme0: new ctrl: NQN "nqn.0.0.0", addr 10.91.0.1:8009
      [  300.464609] BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
      [  300.466342] #PF error: [normal kernel read fault]
      [  300.467385] PGD 0 P4D 0
      [  300.467987] Oops: 0000 [#1] SMP PTI
      [  300.468787] CPU: 3 PID: 50 Comm: kworker/u8:1 Not tainted 5.0.20kalray+ #4
      [  300.470264] Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011
      [  300.471532] Workqueue: nvme-wq nvme_scan_work [nvme_core]
      [  300.472724] RIP: 0010:nvme_parse_ana_log+0x21/0x140 [nvme_core]
      [  300.474038] Code: 45 01 d2 d8 48 98 c3 66 90 0f 1f 44 00 00 41 57 41 56 41 55 41 54 55 53 48 89 fb 48 83 ec 08 48 8b af 20 0a 00 00 48 89 34 24 <66> 83 7d 08 00 0f 84 c6 00 00 00 44 8b 7d 14 49 89 d5 8b 55 10 48
      [  300.477374] RSP: 0018:ffffa50e80fd7cb8 EFLAGS: 00010296
      [  300.478334] RAX: 0000000000000001 RBX: ffff9130f1872258 RCX: 0000000000000000
      [  300.479784] RDX: ffffffffc06c4c30 RSI: ffff9130edad4280 RDI: ffff9130f1872258
      [  300.481488] RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000044
      [  300.483203] R10: 0000000000000220 R11: 0000000000000040 R12: ffff9130f18722c0
      [  300.484928] R13: ffff9130f18722d0 R14: ffff9130edad4280 R15: ffff9130f18722c0
      [  300.486626] FS:  0000000000000000(0000) GS:ffff9130f7b80000(0000) knlGS:0000000000000000
      [  300.488538] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [  300.489907] CR2: 0000000000000008 CR3: 00000002365e6000 CR4: 00000000000006e0
      [  300.491612] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      [  300.493303] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      [  300.494991] Call Trace:
      [  300.495645]  nvme_mpath_add_disk+0x5c/0xb0 [nvme_core]
      [  300.496880]  nvme_validate_ns+0x2ef/0x550 [nvme_core]
      [  300.498105]  ? nvme_identify_ctrl.isra.45+0x6a/0xb0 [nvme_core]
      [  300.499539]  nvme_scan_work+0x2b4/0x370 [nvme_core]
      [  300.500717]  ? __switch_to_asm+0x35/0x70
      [  300.501663]  process_one_work+0x171/0x380
      [  300.502340]  worker_thread+0x49/0x3f0
      [  300.503079]  kthread+0xf8/0x130
      [  300.503795]  ? max_active_store+0x80/0x80
      [  300.504690]  ? kthread_bind+0x10/0x10
      [  300.505502]  ret_from_fork+0x35/0x40
      [  300.506280] Modules linked in: nvme_tcp nvme_rdma rdma_cm iw_cm ib_cm ib_core nvme_fabrics nvme_core xt_physdev ip6table_raw ip6table_mangle ip6table_filter ip6_tables xt_comment iptable_nat nf_nat_ipv4 nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 xt_CHECKSUM iptable_mangle iptable_filter veth ebtable_filter ebtable_nat ebtables iptable_raw vxlan ip6_udp_tunnel udp_tunnel sunrpc joydev pcspkr virtio_balloon br_netfilter bridge stp llc ip_tables xfs libcrc32c ata_generic pata_acpi virtio_net virtio_console net_failover virtio_blk failover ata_piix serio_raw libata virtio_pci virtio_ring virtio
      [  300.514984] CR2: 0000000000000008
      [  300.515569] ---[ end trace faa2eefad7e7f218 ]---
      [  300.516354] RIP: 0010:nvme_parse_ana_log+0x21/0x140 [nvme_core]
      [  300.517330] Code: 45 01 d2 d8 48 98 c3 66 90 0f 1f 44 00 00 41 57 41 56 41 55 41 54 55 53 48 89 fb 48 83 ec 08 48 8b af 20 0a 00 00 48 89 34 24 <66> 83 7d 08 00 0f 84 c6 00 00 00 44 8b 7d 14 49 89 d5 8b 55 10 48
      [  300.520353] RSP: 0018:ffffa50e80fd7cb8 EFLAGS: 00010296
      [  300.521229] RAX: 0000000000000001 RBX: ffff9130f1872258 RCX: 0000000000000000
      [  300.522399] RDX: ffffffffc06c4c30 RSI: ffff9130edad4280 RDI: ffff9130f1872258
      [  300.523560] RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000044
      [  300.524734] R10: 0000000000000220 R11: 0000000000000040 R12: ffff9130f18722c0
      [  300.525915] R13: ffff9130f18722d0 R14: ffff9130edad4280 R15: ffff9130f18722c0
      [  300.527084] FS:  0000000000000000(0000) GS:ffff9130f7b80000(0000) knlGS:0000000000000000
      [  300.528396] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [  300.529440] CR2: 0000000000000008 CR3: 00000002365e6000 CR4: 00000000000006e0
      [  300.530739] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      [  300.531989] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      [  300.533264] Kernel panic - not syncing: Fatal exception
      [  300.534338] Kernel Offset: 0x17c00000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff)
      [  300.536227] ---[ end Kernel panic - not syncing: Fatal exception ]---
      
      Condition check refactoring from Christoph Hellwig.
      Signed-off-by: NMarta Rybczynska <marta.rybczynska@kalray.eu>
      Tested-by: NJean-Baptiste Riaux <jbriaux@kalray.eu>
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      bdce5621
    • L
      ACPI/IORT: Fix off-by-one check in iort_dev_find_its_id() · b1689742
      Lorenzo Pieralisi 提交于
      [ Upstream commit 5a46d3f71d5e5a9f82eabc682f996f1281705ac7 ]
      
      Static analysis identified that index comparison against ITS entries in
      iort_dev_find_its_id() is off by one.
      
      Update the comparison condition and clarify the resulting error
      message.
      
      Fixes: 4bf2efd2 ("ACPI: Add new IORT functions to support MSI domain handling")
      Link: https://lore.kernel.org/linux-arm-kernel/20190613065410.GB16334@mwanda/Reviewed-by: NHanjun Guo <guohanjun@huawei.com>
      Reported-by: NDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Cc: Dan Carpenter <dan.carpenter@oracle.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Hanjun Guo <guohanjun@huawei.com>
      Cc: Sudeep Holla <sudeep.holla@arm.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Robin Murphy <robin.murphy@arm.com>
      Signed-off-by: NWill Deacon <will@kernel.org>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      b1689742