1. 25 Aug, 2019 40 commits
    • Daniel Borkmann's avatar
      bpf: get rid of pure_initcall dependency to enable jits · 5124abda
      Daniel Borkmann authored
      commit fa9dd599 upstream.
      
      Having a pure_initcall() callback just to permanently enable BPF
      JITs under CONFIG_BPF_JIT_ALWAYS_ON is unnecessary and could leave
      a small race window in future where JIT is still disabled on boot.
      Since we know about the setting at compilation time anyway, just
      initialize it properly there. Also consolidate all the individual
      bpf_jit_enable variables into a single one and move them under one
      location. Moreover, don't allow for setting unspecified garbage
      values on them.
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      [bwh: Backported to 4.9 as dependency of commit 2e4a3098
       "bpf: restrict access to core bpf sysctls":
       - Drop change in arch/mips/net/ebpf_jit.c
       - Drop change to bpf_jit_kallsyms
       - Adjust filenames, context]
      Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5124abda
    • Miles Chen's avatar
      mm/memcontrol.c: fix use after free in mem_cgroup_iter() · 43729e6f
      Miles Chen authored
      commit 54a83d6b upstream.
      
      This patch is sent to report an use after free in mem_cgroup_iter()
      after merging commit be265775 ("mm: memcg: fix use after free in
      mem_cgroup_iter()").
      
      I work with android kernel tree (4.9 & 4.14), and commit be265775
      ("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 be265775.  (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: default avatarMiles Chen <miles.chen@mediatek.com>
      Signed-off-by: default avatarQian Cai <cai@lca.pw>
      Acked-by: default avatarMichal 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: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      43729e6f
    • Isaac J. Manjarres's avatar
      mm/usercopy: use memory range to be accessed for wraparound check · faf6760c
      Isaac J. Manjarres authored
      commit 95153169 upstream.
      
      Currently, when checking to see if accessing n bytes starting at address
      "ptr" will cause a wraparound in the memory addresses, the check in
      check_bogus_address() adds an extra byte, which is incorrect, as the
      range of addresses that will be accessed is [ptr, ptr + (n - 1)].
      
      This can lead to incorrectly detecting a wraparound in the memory
      address, when trying to read 4 KB from memory that is mapped to the the
      last possible page in the virtual address space, when in fact, accessing
      that range of memory would not cause a wraparound to occur.
      
      Use the memory range that will actually be accessed when considering if
      accessing a certain amount of bytes will cause the memory address to
      wrap around.
      
      Link: http://lkml.kernel.org/r/1564509253-23287-1-git-send-email-isaacm@codeaurora.org
      Fixes: f5509cc1 ("mm: Hardened usercopy")
      Signed-off-by: default avatarPrasad Sodagudi <psodagud@codeaurora.org>
      Signed-off-by: default avatarIsaac J. Manjarres <isaacm@codeaurora.org>
      Co-developed-by: default avatarPrasad Sodagudi <psodagud@codeaurora.org>
      Reviewed-by: default avatarWilliam Kucharski <william.kucharski@oracle.com>
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Trilok Soni <tsoni@codeaurora.org>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      [kees: backport to v4.9]
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      faf6760c
    • Gustavo A. R. Silva's avatar
      sh: kernel: hw_breakpoint: Fix missing break in switch statement · 694457ee
      Gustavo A. R. Silva authored
      commit 1ee1119d 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: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
      Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      694457ee
    • Suganath Prabu's avatar
      scsi: mpt3sas: Use 63-bit DMA addressing on SAS35 HBA · 718ce1eb
      Suganath Prabu authored
      commit df9a6061 upstream.
      
      Although SAS3 & SAS3.5 IT HBA controllers support 64-bit DMA addressing, as
      per hardware design, if DMA-able range contains all 64-bits
      set (0xFFFFFFFF-FFFFFFFF) then it results in a firmware fault.
      
      E.g. SGE's start address is 0xFFFFFFFF-FFFF000 and data length is 0x1000
      bytes. when HBA tries to DMA the data at 0xFFFFFFFF-FFFFFFFF location then
      HBA will fault the firmware.
      
      Driver will set 63-bit DMA mask to ensure the above address will not be
      used.
      
      Cc: <stable@vger.kernel.org> # 5.1.20+
      Signed-off-by: default avatarSuganath Prabu <suganath-prabu.subramani@broadcom.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      718ce1eb
    • Emmanuel Grumbach's avatar
      iwlwifi: don't unmap as page memory that was mapped as single · 0d7ed7f4
      Emmanuel Grumbach authored
      commit 87e7e25a 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: default avatarEmmanuel Grumbach <emmanuel.grumbach@intel.com>
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0d7ed7f4
    • Brian Norris's avatar
      mwifiex: fix 802.11n/WPA detection · fefc9e10
      Brian Norris authored
      commit df612421 upstream.
      
      Commit 63d7ef36 ("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 63d7ef36 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: 63d7ef36 ("mwifiex: Don't abort on small, spec-compliant vendor IEs")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarBrian Norris <briannorris@chromium.org>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fefc9e10
    • Steve French's avatar
      smb3: send CAP_DFS capability during session setup · 92225e41
      Steve French authored
      commit 8d33096a 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: default avatarSteve French <stfrench@microsoft.com>
      Reviewed-off-by: default avatarRonnie Sahlberg <lsahlber@redhat.com>
      Reviewed-by: default avatarPavel Shilovsky <pshilov@microsoft.com>
      CC: Stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      92225e41
    • Pavel Shilovsky's avatar
      SMB3: Fix deadlock in validate negotiate hits reconnect · 84bdf5e2
      Pavel Shilovsky authored
      commit e99c63e4 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: default avatarPavel Shilovsky <pshilov@microsoft.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Reviewed-by: default avatarRonnie Sahlberg <lsahlber@redhat.com>
      CC: Stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      84bdf5e2
    • Brian Norris's avatar
      mac80211: don't WARN on short WMM parameters from AP · c7b1a1e9
      Brian Norris authored
      commit 05aaa5c9 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: default avatarBrian Norris <briannorris@chromium.org>
      Link: https://lore.kernel.org/r/20190726224758.210953-1-briannorris@chromium.orgSigned-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c7b1a1e9
    • Takashi Iwai's avatar
      ALSA: hda - Don't override global PCM hw info flag · 542233bd
      Takashi Iwai authored
      commit c1c6c877 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: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      542233bd
    • Wenwen Wang's avatar
      ALSA: firewire: fix a memory leak bug · dbb4f2d5
      Wenwen Wang authored
      commit 1be3c1fa 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: default avatarWenwen Wang <wenwen@cs.uga.edu>
      Reviewed-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
      Cc: <stable@vger.kernel.org> # v2.6.39+
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dbb4f2d5
    • Guenter Roeck's avatar
      hwmon: (nct7802) Fix wrong detection of in4 presence · d3d1b67f
      Guenter Roeck authored
      commit 38ada2f4 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: default avatarGilles 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: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d3d1b67f
    • Tomas Bortoli's avatar
      can: peak_usb: pcan_usb_fd: Fix info-leaks to USB devices · 127ab64c
      Tomas Bortoli authored
      commit 30a8beeb upstream.
      
      Uninitialized Kernel memory can leak to USB devices.
      
      Fix by using kzalloc() instead of kmalloc() on the affected buffers.
      Signed-off-by: default avatarTomas 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: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      127ab64c
    • Tomas Bortoli's avatar
      can: peak_usb: pcan_usb_pro: Fix info-leaks to USB devices · 0cad79bf
      Tomas Bortoli authored
      commit ead16e53 upstream.
      
      Uninitialized Kernel memory can leak to USB devices.
      
      Fix by using kzalloc() instead of kmalloc() on the affected buffers.
      Signed-off-by: default avatarTomas 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: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0cad79bf
    • Leonard Crestez's avatar
      perf/core: Fix creating kernel counters for PMUs that override event->cpu · ac370f1e
      Leonard Crestez authored
      [ Upstream commit 4ce54af8 ]
      
      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: default avatarLeonard Crestez <leonard.crestez@nxp.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Reviewed-by: default avatarMark 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: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ac370f1e
    • Peter Zijlstra's avatar
      tty/ldsem, locking/rwsem: Add missing ACQUIRE to read_failed sleep loop · a59873b5
      Peter Zijlstra authored
      [ Upstream commit 952041a8 ]
      
      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: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Acked-by: default avatarWill 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: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a59873b5
    • Hannes Reinecke's avatar
      scsi: scsi_dh_alua: always use a 2 second delay before retrying RTPG · 5bf03ad9
      Hannes Reinecke authored
      [ Upstream commit 20122994 ]
      
      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: default avatarHannes Reinecke <hare@suse.com>
      Tested-by: default avatarZhangguanghui <zhang.guanghui@h3c.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5bf03ad9
    • Tyrel Datwyler's avatar
      scsi: ibmvfc: fix WARN_ON during event pool release · b3a0c297
      Tyrel Datwyler authored
      [ Upstream commit 5578257c ]
      
      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: default avatarAbdul Haleem <abdhalee@linux.vnet.ibm.com>
      Signed-off-by: default avatarTyrel Datwyler <tyreld@linux.vnet.ibm.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b3a0c297
    • Junxiao Bi's avatar
      scsi: megaraid_sas: fix panic on loading firmware crashdump · d80a03c7
      Junxiao Bi authored
      [ Upstream commit 3b5f307e ]
      
      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: default avatarJunxiao Bi <junxiao.bi@oracle.com>
      Acked-by: default avatarSumit Saxena <sumit.saxena@broadcom.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d80a03c7
    • Arnd Bergmann's avatar
      ARM: davinci: fix sleep.S build error on ARMv4 · 67b14bd2
      Arnd Bergmann authored
      [ Upstream commit d64b212e ]
      
      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: default avatarSekhar Nori <nsekhar@ti.com>
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarOlof Johansson <olof@lixom.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      67b14bd2
    • Lorenzo Pieralisi's avatar
      ACPI/IORT: Fix off-by-one check in iort_dev_find_its_id() · ab1ab88e
      Lorenzo Pieralisi authored
      [ Upstream commit 5a46d3f7 ]
      
      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: default avatarHanjun Guo <guohanjun@huawei.com>
      Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: default avatarLorenzo 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: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ab1ab88e
    • Arnd Bergmann's avatar
      drbd: dynamically allocate shash descriptor · dfaf368e
      Arnd Bergmann authored
      [ Upstream commit 77ce56e2 ]
      
      Building with clang and KASAN, we get a warning about an overly large
      stack frame on 32-bit architectures:
      
      drivers/block/drbd/drbd_receiver.c:921:31: error: stack frame size of 1280 bytes in function 'conn_connect'
            [-Werror,-Wframe-larger-than=]
      
      We already allocate other data dynamically in this function, so
      just do the same for the shash descriptor, which makes up most of
      this memory.
      
      Link: https://lore.kernel.org/lkml/20190617132440.2721536-1-arnd@arndb.de/Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Reviewed-by: default avatarRoland Kammerer <roland.kammerer@linbit.com>
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      dfaf368e
    • Arnaldo Carvalho de Melo's avatar
      perf probe: Avoid calling freeing routine multiple times for same pointer · 217c5221
      Arnaldo Carvalho de Melo authored
      [ Upstream commit d95daf5a ]
      
      When perf_add_probe_events() we call cleanup_perf_probe_events() for the
      pev pointer it receives, then, as part of handling this failure the main
      'perf probe' goes on and calls cleanup_params() and that will again call
      cleanup_perf_probe_events()for the same pointer, so just set nevents to
      zero when handling the failure of perf_add_probe_events() to avoid the
      double free.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-x8qgma4g813z96dvtw9w219q@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      217c5221
    • Charles Keepax's avatar
      ALSA: compress: Be more restrictive about when a drain is allowed · 13810c47
      Charles Keepax authored
      [ Upstream commit 3b817994 ]
      
      Draining makes little sense in the situation of hardware overrun, as the
      hardware will have consumed all its available samples. Additionally,
      draining whilst the stream is paused would presumably get stuck as no
      data is being consumed on the DSP side.
      Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Acked-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      13810c47
    • Charles Keepax's avatar
      ALSA: compress: Don't allow paritial drain operations on capture streams · cbc76c3b
      Charles Keepax authored
      [ Upstream commit a70ab8a8 ]
      
      Partial drain and next track are intended for gapless playback and
      don't really have an obvious interpretation for a capture stream, so
      makes sense to not allow those operations on capture streams.
      Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Acked-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      cbc76c3b
    • Charles Keepax's avatar
      ALSA: compress: Prevent bypasses of set_params · 8d25080f
      Charles Keepax authored
      [ Upstream commit 26c3f154 ]
      
      Currently, whilst in SNDRV_PCM_STATE_OPEN it is possible to call
      snd_compr_stop, snd_compr_drain and snd_compr_partial_drain, which
      allow a transition to SNDRV_PCM_STATE_SETUP. The stream should
      only be able to move to the setup state once it has received a
      SNDRV_COMPRESS_SET_PARAMS ioctl. Fix this issue by not allowing
      those ioctls whilst in the open state.
      Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Acked-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8d25080f
    • Charles Keepax's avatar
      ALSA: compress: Fix regression on compressed capture streams · daa60696
      Charles Keepax authored
      [ Upstream commit 4475f8c4 ]
      
      A previous fix to the stop handling on compressed capture streams causes
      some knock on issues. The previous fix updated snd_compr_drain_notify to
      set the state back to PREPARED for capture streams. This causes some
      issues however as the handling for snd_compr_poll differs between the
      two states and some user-space applications were relying on the poll
      failing after the stream had been stopped.
      
      To correct this regression whilst still fixing the original problem the
      patch was addressing, update the capture handling to skip the PREPARED
      state rather than skipping the SETUP state as it has done until now.
      
      Fixes: 4f2ab5e1 ("ALSA: compress: Fix stop handling on compressed capture streams")
      Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Acked-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      daa60696
    • Julian Wiedmann's avatar
      s390/qdio: add sanity checks to the fast-requeue path · 657c648a
      Julian Wiedmann authored
      [ Upstream commit a6ec414a ]
      
      If the device driver were to send out a full queue's worth of SBALs,
      current code would end up discovering the last of those SBALs as PRIMED
      and erroneously skip the SIGA-w. This immediately stalls the queue.
      
      Add a check to not attempt fast-requeue in this case. While at it also
      make sure that the state of the previous SBAL was successfully extracted
      before inspecting it.
      Signed-off-by: default avatarJulian Wiedmann <jwi@linux.ibm.com>
      Reviewed-by: default avatarJens Remus <jremus@linux.ibm.com>
      Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      657c648a
    • Wen Yang's avatar
      cpufreq/pasemi: fix use-after-free in pas_cpufreq_cpu_init() · 260718ad
      Wen Yang authored
      [ Upstream commit e0a12445 ]
      
      The cpu variable is still being used in the of_get_property() call
      after the of_node_put() call, which may result in use-after-free.
      
      Fixes: a9acc26b ("cpufreq/pasemi: fix possible object reference leak")
      Signed-off-by: default avatarWen Yang <wen.yang99@zte.com.cn>
      Acked-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      260718ad
    • Björn Gerhart's avatar
      hwmon: (nct6775) Fix register address and added missed tolerance for nct6106 · 71faaeb1
      Björn Gerhart authored
      [ Upstream commit f3d43e2e ]
      
      Fixed address of third NCT6106_REG_WEIGHT_DUTY_STEP, and
      added missed NCT6106_REG_TOLERANCE_H.
      
      Fixes: 6c009501 ("hwmon: (nct6775) Add support for NCT6102D/6106D")
      Signed-off-by: default avatarBjoern Gerhart <gerhart@posteo.de>
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      71faaeb1
    • Brian Norris's avatar
      mac80211: don't warn about CW params when not using them · 760b12a7
      Brian Norris authored
      [ Upstream commit d2b3fe42 ]
      
      ieee80211_set_wmm_default() normally sets up the initial CW min/max for
      each queue, except that it skips doing this if the driver doesn't
      support ->conf_tx. We still end up calling drv_conf_tx() in some cases
      (e.g., ieee80211_reconfig()), which also still won't do anything
      useful...except it complains here about the invalid CW parameters.
      
      Let's just skip the WARN if we weren't going to do anything useful with
      the parameters.
      Signed-off-by: default avatarBrian Norris <briannorris@chromium.org>
      Link: https://lore.kernel.org/r/20190718015712.197499-1-briannorris@chromium.orgSigned-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      760b12a7
    • Thomas Tai's avatar
      iscsi_ibft: make ISCSI_IBFT dependson ACPI instead of ISCSI_IBFT_FIND · 2b9ac213
      Thomas Tai authored
      [ Upstream commit 94bccc34 ]
      
      iscsi_ibft can use ACPI to find the iBFT entry during bootup,
      currently, ISCSI_IBFT depends on ISCSI_IBFT_FIND which is
      a X86 legacy way to find the iBFT by searching through the
      low memory. This patch changes the dependency so that other
      arch like ARM64 can use ISCSI_IBFT as long as the arch supports
      ACPI.
      
      ibft_init() needs to use the global variable ibft_addr declared
      in iscsi_ibft_find.c. A #ifndef CONFIG_ISCSI_IBFT_FIND is needed
      to declare the variable if CONFIG_ISCSI_IBFT_FIND is not selected.
      Moving ibft_addr into the iscsi_ibft.c does not work because if
      ISCSI_IBFT is selected as a module, the arch/x86/kernel/setup.c won't
      be able to find the variable at compile time.
      Signed-off-by: default avatarThomas Tai <thomas.tai@oracle.com>
      Signed-off-by: default avatarKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2b9ac213
    • Florian Westphal's avatar
      netfilter: nfnetlink: avoid deadlock due to synchronous request_module · 43e4ea5b
      Florian Westphal authored
      [ Upstream commit 1b0890cd ]
      
      Thomas and Juliana report a deadlock when running:
      
      (rmmod nf_conntrack_netlink/xfrm_user)
      
        conntrack -e NEW -E &
        modprobe -v xfrm_user
      
      They provided following analysis:
      
      conntrack -e NEW -E
          netlink_bind()
              netlink_lock_table() -> increases "nl_table_users"
                  nfnetlink_bind()
                  # does not unlock the table as it's locked by netlink_bind()
                      __request_module()
                          call_usermodehelper_exec()
      
      This triggers "modprobe nf_conntrack_netlink" from kernel, netlink_bind()
      won't return until modprobe process is done.
      
      "modprobe xfrm_user":
          xfrm_user_init()
              register_pernet_subsys()
                  -> grab pernet_ops_rwsem
                      ..
                      netlink_table_grab()
                          calls schedule() as "nl_table_users" is non-zero
      
      so modprobe is blocked because netlink_bind() increased
      nl_table_users while also holding pernet_ops_rwsem.
      
      "modprobe nf_conntrack_netlink" runs and inits nf_conntrack_netlink:
          ctnetlink_init()
              register_pernet_subsys()
                  -> blocks on "pernet_ops_rwsem" thanks to xfrm_user module
      
      both modprobe processes wait on one another -- neither can make
      progress.
      
      Switch netlink_bind() to "nowait" modprobe -- this releases the netlink
      table lock, which then allows both modprobe instances to complete.
      Reported-by: default avatarThomas Jarosch <thomas.jarosch@intra2net.com>
      Reported-by: default avatarJuliana Rodrigueiro <juliana.rodrigueiro@intra2net.com>
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      43e4ea5b
    • Stephane Grosjean's avatar
      can: peak_usb: fix potential double kfree_skb() · 13350c22
      Stephane Grosjean authored
      commit fee6a892 upstream.
      
      When closing the CAN device while tx skbs are inflight, echo skb could
      be released twice. By calling close_candev() before unlinking all
      pending tx urbs, then the internal echo_skb[] array is fully and
      correctly cleared before the USB write callback and, therefore,
      can_get_echo_skb() are called, for each aborted URB.
      
      Fixes: bb478555 ("can: usb: PEAK-System Technik USB adapters driver core")
      Signed-off-by: default avatarStephane Grosjean <s.grosjean@peak-system.com>
      Cc: linux-stable <stable@vger.kernel.org>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      13350c22
    • Suzuki K Poulose's avatar
      usb: yurex: Fix use-after-free in yurex_delete · e253114f
      Suzuki K Poulose authored
      commit fc05481b upstream.
      
      syzbot reported the following crash [0]:
      
      BUG: KASAN: use-after-free in usb_free_coherent+0x79/0x80
      drivers/usb/core/usb.c:928
      Read of size 8 at addr ffff8881b18599c8 by task syz-executor.4/16007
      
      CPU: 0 PID: 16007 Comm: syz-executor.4 Not tainted 5.3.0-rc2+ #23
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
      Google 01/01/2011
      Call Trace:
        __dump_stack lib/dump_stack.c:77 [inline]
        dump_stack+0xca/0x13e lib/dump_stack.c:113
        print_address_description+0x6a/0x32c mm/kasan/report.c:351
        __kasan_report.cold+0x1a/0x33 mm/kasan/report.c:482
        kasan_report+0xe/0x12 mm/kasan/common.c:612
        usb_free_coherent+0x79/0x80 drivers/usb/core/usb.c:928
        yurex_delete+0x138/0x330 drivers/usb/misc/yurex.c:100
        kref_put include/linux/kref.h:65 [inline]
        yurex_release+0x66/0x90 drivers/usb/misc/yurex.c:392
        __fput+0x2d7/0x840 fs/file_table.c:280
        task_work_run+0x13f/0x1c0 kernel/task_work.c:113
        tracehook_notify_resume include/linux/tracehook.h:188 [inline]
        exit_to_usermode_loop+0x1d2/0x200 arch/x86/entry/common.c:163
        prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
        syscall_return_slowpath arch/x86/entry/common.c:274 [inline]
        do_syscall_64+0x45f/0x580 arch/x86/entry/common.c:299
        entry_SYSCALL_64_after_hwframe+0x49/0xbe
      RIP: 0033:0x413511
      Code: 75 14 b8 03 00 00 00 0f 05 48 3d 01 f0 ff ff 0f 83 04 1b 00 00 c3 48
      83 ec 08 e8 0a fc ff ff 48 89 04 24 b8 03 00 00 00 0f 05 <48> 8b 3c 24 48
      89 c2 e8 53 fc ff ff 48 89 d0 48 83 c4 08 48 3d 01
      RSP: 002b:00007ffc424ea2e0 EFLAGS: 00000293 ORIG_RAX: 0000000000000003
      RAX: 0000000000000000 RBX: 0000000000000007 RCX: 0000000000413511
      RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000006
      RBP: 0000000000000001 R08: 0000000029a2fc22 R09: 0000000029a2fc26
      R10: 00007ffc424ea3c0 R11: 0000000000000293 R12: 000000000075c9a0
      R13: 000000000075c9a0 R14: 0000000000761938 R15: ffffffffffffffff
      
      Allocated by task 2776:
        save_stack+0x1b/0x80 mm/kasan/common.c:69
        set_track mm/kasan/common.c:77 [inline]
        __kasan_kmalloc mm/kasan/common.c:487 [inline]
        __kasan_kmalloc.constprop.0+0xbf/0xd0 mm/kasan/common.c:460
        kmalloc include/linux/slab.h:552 [inline]
        kzalloc include/linux/slab.h:748 [inline]
        usb_alloc_dev+0x51/0xf95 drivers/usb/core/usb.c:583
        hub_port_connect drivers/usb/core/hub.c:5004 [inline]
        hub_port_connect_change drivers/usb/core/hub.c:5213 [inline]
        port_event drivers/usb/core/hub.c:5359 [inline]
        hub_event+0x15c0/0x3640 drivers/usb/core/hub.c:5441
        process_one_work+0x92b/0x1530 kernel/workqueue.c:2269
        worker_thread+0x96/0xe20 kernel/workqueue.c:2415
        kthread+0x318/0x420 kernel/kthread.c:255
        ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352
      
      Freed by task 16007:
        save_stack+0x1b/0x80 mm/kasan/common.c:69
        set_track mm/kasan/common.c:77 [inline]
        __kasan_slab_free+0x130/0x180 mm/kasan/common.c:449
        slab_free_hook mm/slub.c:1423 [inline]
        slab_free_freelist_hook mm/slub.c:1470 [inline]
        slab_free mm/slub.c:3012 [inline]
        kfree+0xe4/0x2f0 mm/slub.c:3953
        device_release+0x71/0x200 drivers/base/core.c:1064
        kobject_cleanup lib/kobject.c:693 [inline]
        kobject_release lib/kobject.c:722 [inline]
        kref_put include/linux/kref.h:65 [inline]
        kobject_put+0x171/0x280 lib/kobject.c:739
        put_device+0x1b/0x30 drivers/base/core.c:2213
        usb_put_dev+0x1f/0x30 drivers/usb/core/usb.c:725
        yurex_delete+0x40/0x330 drivers/usb/misc/yurex.c:95
        kref_put include/linux/kref.h:65 [inline]
        yurex_release+0x66/0x90 drivers/usb/misc/yurex.c:392
        __fput+0x2d7/0x840 fs/file_table.c:280
        task_work_run+0x13f/0x1c0 kernel/task_work.c:113
        tracehook_notify_resume include/linux/tracehook.h:188 [inline]
        exit_to_usermode_loop+0x1d2/0x200 arch/x86/entry/common.c:163
        prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
        syscall_return_slowpath arch/x86/entry/common.c:274 [inline]
        do_syscall_64+0x45f/0x580 arch/x86/entry/common.c:299
        entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      The buggy address belongs to the object at ffff8881b1859980
        which belongs to the cache kmalloc-2k of size 2048
      The buggy address is located 72 bytes inside of
        2048-byte region [ffff8881b1859980, ffff8881b185a180)
      The buggy address belongs to the page:
      page:ffffea0006c61600 refcount:1 mapcount:0 mapping:ffff8881da00c000
      index:0x0 compound_mapcount: 0
      flags: 0x200000000010200(slab|head)
      raw: 0200000000010200 0000000000000000 0000000100000001 ffff8881da00c000
      raw: 0000000000000000 00000000000f000f 00000001ffffffff 0000000000000000
      page dumped because: kasan: bad access detected
      
      Memory state around the buggy address:
        ffff8881b1859880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
        ffff8881b1859900: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      > ffff8881b1859980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                     ^
        ffff8881b1859a00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
        ffff8881b1859a80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      ==================================================================
      
      A quick look at the yurex_delete() shows that we drop the reference
      to the usb_device before releasing any buffers associated with the
      device. Delay the reference drop until we have finished the cleanup.
      
      [0] https://lore.kernel.org/lkml/0000000000003f86d8058f0bd671@google.com/
      
      Fixes: 6bc235a2 ("USB: add driver for Meywa-Denki & Kayac YUREX")
      Cc: Jiri Kosina <jkosina@suse.cz>
      Cc: Tomoki Sekiyama <tomoki.sekiyama@gmail.com>
      Cc: Oliver Neukum <oneukum@suse.com>
      Cc: andreyknvl@google.com
      Cc: gregkh@linuxfoundation.org
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Cc: syzkaller-bugs@googlegroups.com
      Cc: dtor@chromium.org
      Reported-by: syzbot+d1fedb1c1fdb07fca507@syzkaller.appspotmail.com
      Signed-off-by: default avatarSuzuki K Poulose <suzuki.poulose@arm.com>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20190805111528.6758-1-suzuki.poulose@arm.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e253114f
    • Thomas Richter's avatar
      perf record: Fix module size on s390 · 0d7f7102
      Thomas Richter authored
      commit 12a6d294 upstream.
      
      On s390 the modules loaded in memory have the text segment located after
      the GOT and Relocation table. This can be seen with this output:
      
        [root@m35lp76 perf]# fgrep qeth /proc/modules
        qeth 151552 1 qeth_l2, Live 0x000003ff800b2000
        ...
        [root@m35lp76 perf]# cat /sys/module/qeth/sections/.text
        0x000003ff800b3990
        [root@m35lp76 perf]#
      
      There is an offset of 0x1990 bytes. The size of the qeth module is
      151552 bytes (0x25000 in hex).
      
      The location of the GOT/relocation table at the beginning of a module is
      unique to s390.
      
      commit 203d8a4a ("perf s390: Fix 'start' address of module's map")
      adjusts the start address of a module in the map structures, but does
      not adjust the size of the modules. This leads to overlapping of module
      maps as this example shows:
      
      [root@m35lp76 perf] # ./perf report -D
           0 0 0xfb0 [0xa0]: PERF_RECORD_MMAP -1/0: [0x3ff800b3990(0x25000)
                @ 0]:  x /lib/modules/.../qeth.ko.xz
           0 0 0x1050 [0xb0]: PERF_RECORD_MMAP -1/0: [0x3ff800d85a0(0x8000)
                @ 0]:  x /lib/modules/.../ip6_tables.ko.xz
      
      The module qeth.ko has an adjusted start address modified to b3990, but
      its size is unchanged and the module ends at 0x3ff800d8990.  This end
      address overlaps with the next modules start address of 0x3ff800d85a0.
      
      When the size of the leading GOT/Relocation table stored in the
      beginning of the text segment (0x1990 bytes) is subtracted from module
      qeth end address, there are no overlaps anymore:
      
         0x3ff800d8990 - 0x1990 = 0x0x3ff800d7000
      
      which is the same as
      
         0x3ff800b2000 + 0x25000 = 0x0x3ff800d7000.
      
      To fix this issue, also adjust the modules size in function
      arch__fix_module_text_start(). Add another function parameter named size
      and reduce the size of the module when the text segment start address is
      changed.
      
      Output after:
           0 0 0xfb0 [0xa0]: PERF_RECORD_MMAP -1/0: [0x3ff800b3990(0x23670)
                @ 0]:  x /lib/modules/.../qeth.ko.xz
           0 0 0x1050 [0xb0]: PERF_RECORD_MMAP -1/0: [0x3ff800d85a0(0x7a60)
                @ 0]:  x /lib/modules/.../ip6_tables.ko.xz
      Reported-by: default avatarStefan Liebler <stli@linux.ibm.com>
      Signed-off-by: default avatarThomas Richter <tmricht@linux.ibm.com>
      Acked-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Hendrik Brueckner <brueckner@linux.ibm.com>
      Cc: Vasily Gorbik <gor@linux.ibm.com>
      Cc: stable@vger.kernel.org
      Fixes: 203d8a4a ("perf s390: Fix 'start' address of module's map")
      Link: http://lkml.kernel.org/r/20190724122703.3996-1-tmricht@linux.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0d7f7102
    • Adrian Hunter's avatar
      perf db-export: Fix thread__exec_comm() · 708eac3b
      Adrian Hunter authored
      commit 3de7ae0b upstream.
      
      Threads synthesized from /proc have comms with a start time of zero, and
      not marked as "exec". Currently, there can be 2 such comms. The first is
      created by processing a synthesized fork event and is set to the
      parent's comm string, and the second by processing a synthesized comm
      event set to the thread's current comm string.
      
      In the absence of an "exec" comm, thread__exec_comm() picks the last
      (oldest) comm, which, in the case above, is the parent's comm string.
      For a main thread, that is very probably wrong. Use the second-to-last
      in that case.
      
      This affects only db-export because it is the only user of
      thread__exec_comm().
      
      Example:
      
        $ sudo perf record -a -o pt-a-sleep-1 -e intel_pt//u -- sleep 1
        $ sudo chown ahunter pt-a-sleep-1
      
      Before:
      
        $ perf script -i pt-a-sleep-1 --itrace=bep -s tools/perf/scripts/python/export-to-sqlite.py pt-a-sleep-1.db branches calls
        $ sqlite3 -header -column pt-a-sleep-1.db 'select * from comm_threads_view'
        comm_id     command     thread_id   pid         tid
        ----------  ----------  ----------  ----------  ----------
        1           swapper     1           0           0
        2           rcu_sched   2           10          10
        3           kthreadd    3           78          78
        5           sudo        4           15180       15180
        5           sudo        5           15180       15182
        7           kworker/4:  6           10335       10335
        8           kthreadd    7           55          55
        10          systemd     8           865         865
        10          systemd     9           865         875
        13          perf        10          15181       15181
        15          sleep       10          15181       15181
        16          kworker/3:  11          14179       14179
        17          kthreadd    12          29376       29376
        19          systemd     13          746         746
        21          systemd     14          401         401
        23          systemd     15          879         879
        23          systemd     16          879         945
        25          kthreadd    17          556         556
        27          kworker/u1  18          14136       14136
        28          kworker/u1  19          15021       15021
        29          kthreadd    20          509         509
        31          systemd     21          836         836
        31          systemd     22          836         967
        33          systemd     23          1148        1148
        33          systemd     24          1148        1163
        35          kworker/2:  25          17988       17988
        36          kworker/0:  26          13478       13478
      
      After:
      
        $ perf script -i pt-a-sleep-1 --itrace=bep -s tools/perf/scripts/python/export-to-sqlite.py pt-a-sleep-1b.db branches calls
        $ sqlite3 -header -column pt-a-sleep-1b.db 'select * from comm_threads_view'
        comm_id     command     thread_id   pid         tid
        ----------  ----------  ----------  ----------  ----------
        1           swapper     1           0           0
        2           rcu_sched   2           10          10
        3           kswapd0     3           78          78
        4           perf        4           15180       15180
        4           perf        5           15180       15182
        6           kworker/4:  6           10335       10335
        7           kcompactd0  7           55          55
        8           accounts-d  8           865         865
        8           accounts-d  9           865         875
        10          perf        10          15181       15181
        12          sleep       10          15181       15181
        13          kworker/3:  11          14179       14179
        14          kworker/1:  12          29376       29376
        15          haveged     13          746         746
        16          systemd-jo  14          401         401
        17          NetworkMan  15          879         879
        17          NetworkMan  16          879         945
        19          irq/131-iw  17          556         556
        20          kworker/u1  18          14136       14136
        21          kworker/u1  19          15021       15021
        22          kworker/u1  20          509         509
        23          thermald    21          836         836
        23          thermald    22          836         967
        25          unity-sett  23          1148        1148
        25          unity-sett  24          1148        1163
        27          kworker/2:  25          17988       17988
        28          kworker/0:  26          13478       13478
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: stable@vger.kernel.org
      Fixes: 65de51f9 ("perf tools: Identify which comms are from exec")
      Link: http://lkml.kernel.org/r/20190808064823.14846-1-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      708eac3b
    • Thomas Richter's avatar
      perf record: Fix wrong size in perf_record_mmap for last kernel module · 624c2b36
      Thomas Richter authored
      commit 9ad4652b upstream.
      
      During work on perf report for s390 I ran into the following issue:
      
      0 0x318 [0x78]: PERF_RECORD_MMAP -1/0:
              [0x3ff804d6990(0xfffffc007fb2966f) @ 0]:
              x /lib/modules/4.12.0perf1+/kernel/drivers/s390/net/qeth_l2.ko
      
      This is a PERF_RECORD_MMAP entry of the perf.data file with an invalid
      module size for qeth_l2.ko (the s390 ethernet device driver).
      
      Even a mainframe does not have 0xfffffc007fb2966f bytes of main memory.
      
      It turned out that this wrong size is created by the perf record
      command.  What happens is this function call sequence from
      __cmd_record():
      
        perf_session__new():
          perf_session__create_kernel_maps():
            machine__create_kernel_maps():
              machine__create_modules():   Creates map for all loaded kernel modules.
                modules__parse():   Reads /proc/modules and extracts module name and
                                    load address (1st and last column)
                  machine__create_module():   Called for every module found in /proc/modules.
                                    Creates a new map for every module found and enters
                                    module name and start address into the map. Since the
                                    module end address is unknown it is set to zero.
      
      This ends up with a kernel module map list sorted by module start
      addresses.  All module end addresses are zero.
      
      Last machine__create_kernel_maps() calls function map_groups__fixup_end().
      This function iterates through the maps and assigns each map entry's
      end address the successor map entry start address. The last entry of the
      map group has no successor, so ~0 is used as end to consume the remaining
      memory.
      
      Later __cmd_record calls function record__synthesize() which in turn calls
      perf_event__synthesize_kernel_mmap() and perf_event__synthesize_modules()
      to create PERF_REPORT_MMAP entries into the perf.data file.
      
      On s390 this results in the last module qeth_l2.ko
      (which has highest start address, see module table:
              [root@s8360047 perf]# cat /proc/modules
              qeth_l2 86016 1 - Live 0x000003ff804d6000
              qeth 266240 1 qeth_l2, Live 0x000003ff80296000
              ccwgroup 24576 1 qeth, Live 0x000003ff80218000
              vmur 36864 0 - Live 0x000003ff80182000
              qdio 143360 2 qeth_l2,qeth, Live 0x000003ff80002000
              [root@s8360047 perf]# )
      to be the last entry and its map has an end address of ~0.
      
      When the PERF_RECORD_MMAP entry is created for kernel module qeth_l2.ko
      its start address and length is written. The length is calculated in line:
          event->mmap.len   = pos->end - pos->start;
      and results in 0xffffffffffffffff - 0x3ff804d6990(*) = 0xfffffc007fb2966f
      
      (*) On s390 the module start address is actually determined by a __weak function
      named arch__fix_module_text_start() in machine__create_module().
      
      I think this improvable. We can use the module size (2nd column of /proc/modules)
      to get each loaded kernel module size and calculate its end address.
      Only for map entries which do not have a valid end address (end is still zero)
      we can use the heuristic we have now, that is use successor start address or ~0.
      Signed-off-by: default avatarThomas-Mich Richter <tmricht@linux.vnet.ibm.com>
      Reviewed-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
      Cc: Thomas-Mich Richter <tmricht@linux.vnet.ibm.com>
      Cc: Zvonko Kosic <zvonko.kosic@de.ibm.com>
      LPU-Reference: 20170803134902.47207-2-tmricht@linux.vnet.ibm.com
      Link: http://lkml.kernel.org/n/tip-nmoqij5b5vxx7rq2ckwu8iaj@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Daniel Daz <daniel.diaz@linaro.org>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      624c2b36
    • Joerg Roedel's avatar
      mm/vmalloc: Sync unmappings in __purge_vmap_area_lazy() · 6c8f40d2
      Joerg Roedel authored
      commit 3f8fd02b upstream.
      
      On x86-32 with PTI enabled, parts of the kernel page-tables are not shared
      between processes. This can cause mappings in the vmalloc/ioremap area to
      persist in some page-tables after the region is unmapped and released.
      
      When the region is re-used the processes with the old mappings do not fault
      in the new mappings but still access the old ones.
      
      This causes undefined behavior, in reality often data corruption, kernel
      oopses and panics and even spontaneous reboots.
      
      Fix this problem by activly syncing unmaps in the vmalloc/ioremap area to
      all page-tables in the system before the regions can be re-used.
      
      References: https://bugzilla.suse.com/show_bug.cgi?id=1118689
      Fixes: 5d72b4fb ('x86, mm: support huge I/O mapping capability I/F')
      Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
      Link: https://lkml.kernel.org/r/20190719184652.11391-4-joro@8bytes.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6c8f40d2