1. 13 Oct, 2018 38 commits
    • Chao Yu's avatar
      f2fs: fix invalid memory access · 3a7a9fb6
      Chao Yu authored
      commit d3f07c04 upstream.
      
      syzbot found the following crash on:
      
      HEAD commit:    d9bd94c0bcaa Add linux-next specific files for 20180801
      git tree:       linux-next
      console output: https://syzkaller.appspot.com/x/log.txt?x=1001189c400000
      kernel config:  https://syzkaller.appspot.com/x/.config?x=cc8964ea4d04518c
      dashboard link: https://syzkaller.appspot.com/bug?extid=c966a82db0b14aa37e81
      compiler:       gcc (GCC) 8.0.1 20180413 (experimental)
      
      Unfortunately, I don't have any reproducer for this crash yet.
      
      IMPORTANT: if you fix the bug, please add the following tag to the commit:
      Reported-by: syzbot+c966a82db0b14aa37e81@syzkaller.appspotmail.com
      
      loop7: rw=12288, want=8200, limit=20
      netlink: 65342 bytes leftover after parsing attributes in process `syz-executor4'.
      openvswitch: netlink: Message has 8 unknown bytes.
      kasan: CONFIG_KASAN_INLINE enabled
      kasan: GPF could be caused by NULL-ptr deref or user memory access
      general protection fault: 0000 [#1] SMP KASAN
      CPU: 1 PID: 7615 Comm: syz-executor7 Not tainted 4.18.0-rc7-next-20180801+ #29
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      RIP: 0010:__read_once_size include/linux/compiler.h:188 [inline]
      RIP: 0010:compound_head include/linux/page-flags.h:142 [inline]
      RIP: 0010:PageLocked include/linux/page-flags.h:272 [inline]
      RIP: 0010:f2fs_put_page fs/f2fs/f2fs.h:2011 [inline]
      RIP: 0010:validate_checkpoint+0x66d/0xec0 fs/f2fs/checkpoint.c:835
      Code: e8 58 05 7f fe 4c 8d 6b 80 4d 8d 74 24 08 48 b8 00 00 00 00 00 fc ff df 4c 89 ea 48 c1 ea 03 c6 04 02 00 4c 89 f2 48 c1 ea 03 <80> 3c 02 00 0f 85 f4 06 00 00 4c 89 ea 4d 8b 7c 24 08 48 b8 00 00
      RSP: 0018:ffff8801937cebe8 EFLAGS: 00010246
      RAX: dffffc0000000000 RBX: ffff8801937cef30 RCX: ffffc90006035000
      RDX: 0000000000000000 RSI: ffffffff82fd9658 RDI: 0000000000000005
      RBP: ffff8801937cef58 R08: ffff8801ab254700 R09: fffff94000d9e026
      R10: fffff94000d9e026 R11: ffffea0006cf0137 R12: fffffffffffffffb
      R13: ffff8801937ceeb0 R14: 0000000000000003 R15: ffff880193419b40
      FS:  00007f36a61d5700(0000) GS:ffff8801db100000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007fc04ff93000 CR3: 00000001d0562000 CR4: 00000000001426e0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
       f2fs_get_valid_checkpoint+0x436/0x1ec0 fs/f2fs/checkpoint.c:860
       f2fs_fill_super+0x2d42/0x8110 fs/f2fs/super.c:2883
       mount_bdev+0x314/0x3e0 fs/super.c:1344
       f2fs_mount+0x3c/0x50 fs/f2fs/super.c:3133
       legacy_get_tree+0x131/0x460 fs/fs_context.c:729
       vfs_get_tree+0x1cb/0x5c0 fs/super.c:1743
       do_new_mount fs/namespace.c:2603 [inline]
       do_mount+0x6f2/0x1e20 fs/namespace.c:2927
       ksys_mount+0x12d/0x140 fs/namespace.c:3143
       __do_sys_mount fs/namespace.c:3157 [inline]
       __se_sys_mount fs/namespace.c:3154 [inline]
       __x64_sys_mount+0xbe/0x150 fs/namespace.c:3154
       do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      RIP: 0033:0x45943a
      Code: b8 a6 00 00 00 0f 05 48 3d 01 f0 ff ff 0f 83 bd 8a fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 0f 83 9a 8a fb ff c3 66 0f 1f 84 00 00 00 00 00
      RSP: 002b:00007f36a61d4a88 EFLAGS: 00000206 ORIG_RAX: 00000000000000a5
      RAX: ffffffffffffffda RBX: 00007f36a61d4b30 RCX: 000000000045943a
      RDX: 00007f36a61d4ad0 RSI: 0000000020000100 RDI: 00007f36a61d4af0
      RBP: 0000000020000100 R08: 00007f36a61d4b30 R09: 00007f36a61d4ad0
      R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000000013
      R13: 0000000000000000 R14: 00000000004c8ea0 R15: 0000000000000000
      Modules linked in:
      Dumping ftrace buffer:
         (ftrace buffer empty)
      ---[ end trace bd8550c129352286 ]---
      RIP: 0010:__read_once_size include/linux/compiler.h:188 [inline]
      RIP: 0010:compound_head include/linux/page-flags.h:142 [inline]
      RIP: 0010:PageLocked include/linux/page-flags.h:272 [inline]
      RIP: 0010:f2fs_put_page fs/f2fs/f2fs.h:2011 [inline]
      RIP: 0010:validate_checkpoint+0x66d/0xec0 fs/f2fs/checkpoint.c:835
      Code: e8 58 05 7f fe 4c 8d 6b 80 4d 8d 74 24 08 48 b8 00 00 00 00 00 fc ff df 4c 89 ea 48 c1 ea 03 c6 04 02 00 4c 89 f2 48 c1 ea 03 <80> 3c 02 00 0f 85 f4 06 00 00 4c 89 ea 4d 8b 7c 24 08 48 b8 00 00
      RSP: 0018:ffff8801937cebe8 EFLAGS: 00010246
      RAX: dffffc0000000000 RBX: ffff8801937cef30 RCX: ffffc90006035000
      RDX: 0000000000000000 RSI: ffffffff82fd9658 RDI: 0000000000000005
      netlink: 65342 bytes leftover after parsing attributes in process `syz-executor4'.
      RBP: ffff8801937cef58 R08: ffff8801ab254700 R09: fffff94000d9e026
      openvswitch: netlink: Message has 8 unknown bytes.
      R10: fffff94000d9e026 R11: ffffea0006cf0137 R12: fffffffffffffffb
      R13: ffff8801937ceeb0 R14: 0000000000000003 R15: ffff880193419b40
      FS:  00007f36a61d5700(0000) GS:ffff8801db100000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007fc04ff93000 CR3: 00000001d0562000 CR4: 00000000001426e0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      
      In validate_checkpoint(), if we failed to call get_checkpoint_version(), we
      will pass returned invalid page pointer into f2fs_put_page, cause accessing
      invalid memory, this patch tries to handle error path correctly to fix this
      issue.
      Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      3a7a9fb6
    • Jiri Olsa's avatar
      perf utils: Move is_directory() to path.h · dfe96e30
      Jiri Olsa authored
      commit 06c3f2aa upstream.
      
      So that it can be used more widely, like in the next patch, when it will
      be used to fix a bug in 'perf test' handling of dirent.d_type ==
      DT_UNKNOWN.
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lkml.kernel.org/r/20171206174535.25380-1-jolsa@kernel.org
      [ Split from a larger patch, removed needless includes in path.h ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Ignat Korchagin <ignat@cloudflare.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dfe96e30
    • Harsh Jain's avatar
      crypto: chelsio - Fix memory corruption in DMA Mapped buffers. · 75fc05a2
      Harsh Jain authored
      commit add92a81 upstream.
      
      Update PCI Id in "cpl_rx_phys_dsgl" header. In case pci_chan_id and
      tx_chan_id are not derived from same queue, H/W can send request
      completion indication before completing DMA Transfer.
      
      Herbert, It would be good if fix can be merge to stable tree.
      For 4.14 kernel, It requires some update to avoid mege conficts.
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarHarsh Jain <harsh@chelsio.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      75fc05a2
    • Vineet Gupta's avatar
      ARC: clone syscall to setp r25 as thread pointer · b5dcd4ab
      Vineet Gupta authored
      commit c58a584f upstream.
      
      Per ARC TLS ABI, r25 is designated TP (thread pointer register).
      However so far kernel didn't do any special treatment, like setting up
      usermode r25, even for CLONE_SETTLS. We instead relied on libc runtime
      to do this, in say clone libc wrapper [1]. This was deliberate to keep
      kernel ABI agnostic (userspace could potentially change TP, specially
      for different ARC ISA say ARCompact vs. ARCv2 with different spare
      registers etc)
      
      However userspace setting up r25, after clone syscall opens a race, if
      child is not scheduled and gets a signal instead. It starts off in
      userspace not in clone but in a signal handler and anything TP sepcific
      there such as pthread_self() fails which showed up with uClibc
      testsuite nptl/tst-kill6 [2]
      
      Fix this by having kernel populate r25 to TP value. So this locks in
      ABI, but it was not going to change anyways, and fwiw is same for both
      ARCompact (arc700 core) and ARCvs (HS3x cores)
      
      [1] https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/libc/sysdeps/linux/arc/clone.S
      [2] https://github.com/wbx-github/uclibc-ng-test/blob/master/test/nptl/tst-kill6.c
      
      Fixes: ARC STAR 9001378481
      Cc: stable@vger.kernel.org
      Reported-by: default avatarNikita Sobolev <sobolev@synopsys.com>
      Signed-off-by: default avatarVineet Gupta <vgupta@synopsys.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b5dcd4ab
    • Christophe Leroy's avatar
      powerpc/lib: fix book3s/32 boot failure due to code patching · af1a8101
      Christophe Leroy authored
      commit b45ba4a5 upstream.
      
      Commit 51c3c62b ("powerpc: Avoid code patching freed init
      sections") accesses 'init_mem_is_free' flag too early, before the
      kernel is relocated. This provokes early boot failure (before the
      console is active).
      
      As it is not necessary to do this verification that early, this
      patch moves the test into patch_instruction() instead of
      __patch_instruction().
      
      This modification also has the advantage of avoiding unnecessary
      remappings.
      
      Fixes: 51c3c62b ("powerpc: Avoid code patching freed init sections")
      Cc: stable@vger.kernel.org # 4.13+
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      af1a8101
    • Michael Neuling's avatar
      powerpc: Avoid code patching freed init sections · 609fbedd
      Michael Neuling authored
      commit 51c3c62b upstream.
      
      This stops us from doing code patching in init sections after they've
      been freed.
      
      In this chain:
        kvm_guest_init() ->
          kvm_use_magic_page() ->
            fault_in_pages_readable() ->
      	 __get_user() ->
      	   __get_user_nocheck() ->
      	     barrier_nospec();
      
      We have a code patching location at barrier_nospec() and
      kvm_guest_init() is an init function. This whole chain gets inlined,
      so when we free the init section (hence kvm_guest_init()), this code
      goes away and hence should no longer be patched.
      
      We seen this as userspace memory corruption when using a memory
      checker while doing partition migration testing on powervm (this
      starts the code patching post migration via
      /sys/kernel/mobility/migration). In theory, it could also happen when
      using /sys/kernel/debug/powerpc/barrier_nospec.
      
      Cc: stable@vger.kernel.org # 4.13+
      Signed-off-by: default avatarMichael Neuling <mikey@neuling.org>
      Reviewed-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Reviewed-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      609fbedd
    • Christophe Leroy's avatar
      powerpc/lib/code-patching: refactor patch_instruction() · 4e43fbc8
      Christophe Leroy authored
      commit 8cf4c057 upstream.
      
      patch_instruction() uses almost the same sequence as
      __patch_instruction()
      
      This patch refactor it so that patch_instruction() uses
      __patch_instruction() instead of duplicating code.
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
      Acked-by: default avatarBalbir Singh <bsingharora@gmail.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4e43fbc8
    • James Smart's avatar
      nvme_fc: fix ctrl create failures racing with workq items · 0f6e2f4e
      James Smart authored
      commit cf25809b upstream.
      
      If there are errors during initial controller create, the transport
      will teardown the partially initialized controller struct and free
      the ctlr memory.  Trouble is - most of those errors can occur due
      to asynchronous events happening such io timeouts and subsystem
      connectivity failures. Those failures invoke async workq items to
      reset the controller and attempt reconnect.  Those may be in progress
      as the main thread frees the ctrl memory, resulting in NULL ptr oops.
      
      Prevent this from happening by having the main ctrl failure thread
      changing state to DELETING followed by synchronously cancelling any
      pending queued work item. The change of state will prevent the
      scheduling of resets or reconnect events.
      Signed-off-by: default avatarJames Smart <james.smart@broadcom.com>
      Signed-off-by: default avatarKeith Busch <keith.busch@intel.com>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarAmit Pundir <amit.pundir@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0f6e2f4e
    • Yu Wang's avatar
      ath10k: fix kernel panic issue during pci probe · 1b2ad48a
      Yu Wang authored
      commit 50e79e25 upstream.
      
      If device gone during chip reset, ar->normal_mode_fw.board is not
      initialized, but ath10k_debug_print_hwfw_info() will try to access its
      member, which will cause 'kernel NULL pointer' issue. This was found
      using a faulty device (pci link went down sometimes) in a random
      insmod/rmmod/other-op test.
      To fix it, check ar->normal_mode_fw.board before accessing the member.
      
      pci 0000:02:00.0: BAR 0: assigned [mem 0xf7400000-0xf75fffff 64bit]
      ath10k_pci 0000:02:00.0: enabling device (0000 -> 0002)
      ath10k_pci 0000:02:00.0: pci irq msi oper_irq_mode 2 irq_mode 0 reset_mode 0
      ath10k_pci 0000:02:00.0: failed to read device register, device is gone
      ath10k_pci 0000:02:00.0: failed to wait for target init: -5
      ath10k_pci 0000:02:00.0: failed to warm reset: -5
      ath10k_pci 0000:02:00.0: firmware crashed during chip reset
      ath10k_pci 0000:02:00.0: firmware crashed! (uuid 5d018951-b8e1-404a-8fde-923078b4423a)
      ath10k_pci 0000:02:00.0: (null) target 0x00000000 chip_id 0x00340aff sub 0000:0000
      ath10k_pci 0000:02:00.0: kconfig debug 1 debugfs 1 tracing 1 dfs 1 testmode 1
      ath10k_pci 0000:02:00.0: firmware ver  api 0 features  crc32 00000000
      ...
      BUG: unable to handle kernel NULL pointer dereference at 00000004
      ...
      Call Trace:
       [<fb4e7882>] ath10k_print_driver_info+0x12/0x20 [ath10k_core]
       [<fb62b7dd>] ath10k_pci_fw_crashed_dump+0x6d/0x4d0 [ath10k_pci]
       [<fb629f07>] ? ath10k_pci_sleep.part.19+0x57/0xc0 [ath10k_pci]
       [<fb62c8ee>] ath10k_pci_hif_power_up+0x14e/0x1b0 [ath10k_pci]
       [<c10477fb>] ? do_page_fault+0xb/0x10
       [<fb4eb934>] ath10k_core_register_work+0x24/0x840 [ath10k_core]
       [<c18a00d8>] ? netlbl_unlhsh_remove+0x178/0x410
       [<c10477f0>] ? __do_page_fault+0x480/0x480
       [<c1068e44>] process_one_work+0x114/0x3e0
       [<c1069d07>] worker_thread+0x37/0x4a0
       [<c106e294>] kthread+0xa4/0xc0
       [<c1069cd0>] ? create_worker+0x180/0x180
       [<c106e1f0>] ? kthread_park+0x50/0x50
       [<c18ab4f7>] ret_from_fork+0x1b/0x28
       Code: 78 80 b8 50 09 00 00 00 75 5d 8d 75 94 c7 44 24 08 aa d7 52 fb c7 44 24 04 64 00 00 00
       89 34 24 e8 82 52 e2 c5 8b 83 dc 08 00 00 <8b> 50 04 8b 08 31 c0 e8 20 57 e3 c5 89 44 24 10 8b 83 58 09 00
       EIP: [<fb4e7754>]-
       ath10k_debug_print_board_info+0x34/0xb0 [ath10k_core]
       SS:ESP 0068:f4921d90
       CR2: 0000000000000004
      Signed-off-by: default avatarYu Wang <yyuwang@codeaurora.org>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      [AmitP: Minor rebasing for 4.14.y and 4.9.y]
      Signed-off-by: default avatarAmit Pundir <amit.pundir@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1b2ad48a
    • Carl Huang's avatar
      ath10k: fix use-after-free in ath10k_wmi_cmd_send_nowait · 8146256b
      Carl Huang authored
      commit 9ef0f58e upstream.
      
      The skb may be freed in tx completion context before
      trace_ath10k_wmi_cmd is called. This can be easily captured when
      KASAN(Kernel Address Sanitizer) is enabled. The fix is to move
      trace_ath10k_wmi_cmd before the send operation. As the ret has no
      meaning in trace_ath10k_wmi_cmd then, so remove this parameter too.
      Signed-off-by: default avatarCarl Huang <cjhuang@codeaurora.org>
      Tested-by: default avatarBrian Norris <briannorris@chromium.org>
      Reviewed-by: default avatarBrian Norris <briannorris@chromium.org>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarAmit Pundir <amit.pundir@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8146256b
    • Jiri Olsa's avatar
      perf tools: Fix python extension build for gcc 8 · 327400b3
      Jiri Olsa authored
      commit b7a313d8 upstream.
      
      The gcc 8 compiler won't compile the python extension code with the
      following errors (one example):
      
        python.c:830:15: error: cast between incompatible  function types from              \
        ‘PyObject * (*)(struct pyrf_evsel *, PyObject *, PyObject *)’                       \
        uct _object * (*)(struct pyrf_evsel *, struct _object *, struct _object *)’} to     \
        ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _objeuct \
        _object *)’} [-Werror=cast-function-type]
           .ml_meth  = (PyCFunction)pyrf_evsel__open,
      
      The problem with the PyMethodDef::ml_meth callback is that its type is
      determined based on the PyMethodDef::ml_flags value, which we set as
      METH_VARARGS | METH_KEYWORDS.
      
      That indicates that the callback is expecting an extra PyObject* arg, and is
      actually PyCFunctionWithKeywords type, but the base PyMethodDef::ml_meth type
      stays PyCFunction.
      
      Previous gccs did not find this, gcc8 now does. Fixing this by silencing this
      warning for python.c build.
      
      Commiter notes:
      
      Do not do that for CC=clang, as it breaks the build in some clang
      versions, like the ones in fedora up to fedora27:
      
        fedora:25:error: unknown warning option '-Wno-cast-function-type'; did you mean '-Wno-bad-function-cast'? [-Werror,-Wunknown-warning-option]
        fedora:26:error: unknown warning option '-Wno-cast-function-type'; did you mean '-Wno-bad-function-cast'? [-Werror,-Wunknown-warning-option]
        fedora:27:error: unknown warning option '-Wno-cast-function-type'; did you mean '-Wno-bad-function-cast'? [-Werror,-Wunknown-warning-option]
        #
      
      those have:
      
        clang version 3.9.1 (tags/RELEASE_391/final)
      
      The one in rawhide accepts that:
      
        clang version 6.0.0 (tags/RELEASE_600/final)
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
      Link: http://lkml.kernel.org/r/20180319082902.4518-2-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Ignat Korchagin <ignat@cloudflare.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      327400b3
    • Arnaldo Carvalho de Melo's avatar
      perf annotate: Use asprintf when formatting objdump command line · ec727693
      Arnaldo Carvalho de Melo authored
      commit 6810158d upstream.
      
      We were using a local buffer with an arbitrary size, that would have to
      get increased to avoid truncation as warned by gcc 8:
      
        util/annotate.c: In function 'symbol__disassemble':
        util/annotate.c:1488:4: error: '%s' directive output may be truncated writing up to 4095 bytes into a region of size between 3966 and 8086 [-Werror=format-truncation=]
            "%s %s%s --start-address=0x%016" PRIx64
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        util/annotate.c:1498:20:
            symfs_filename, symfs_filename);
                            ~~~~~~~~~~~~~~
        util/annotate.c:1490:50: note: format string is defined here
            " -l -d %s %s -C \"%s\" 2>/dev/null|grep -v \"%s:\"|expand",
                                                        ^~
        In file included from /usr/include/stdio.h:861,
                         from util/color.h:5,
                         from util/sort.h:8,
                         from util/annotate.c:14:
        /usr/include/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk' output 116 or more bytes (assuming 8331) into a destination of size 8192
           return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                __bos (__s), __fmt, __va_arg_pack ());
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      So switch to asprintf, that will make sure enough space is available.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-qagoy2dmbjpc9gdnaj0r3mml@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Ignat Korchagin <ignat@cloudflare.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ec727693
    • Guenter Roeck's avatar
      of: unittest: Disable interrupt node tests for old world MAC systems · 79f87e09
      Guenter Roeck authored
      commit 88948914 upstream.
      
      On systems with OF_IMAP_OLDWORLD_MAC set in of_irq_workarounds, the
      devicetree interrupt parsing code is different, causing unit tests of
      devicetree interrupt nodes to fail. Due to a bug in unittest code, which
      tries to dereference an uninitialized pointer, this results in a crash.
      
      OF: /testcase-data/phandle-tests/consumer-a: arguments longer than property
      Unable to handle kernel paging request for data at address 0x00bc616e
      Faulting instruction address: 0xc08e9468
      Oops: Kernel access of bad area, sig: 11 [#1]
      BE PREEMPT PowerMac
      Modules linked in:
      CPU: 0 PID: 1 Comm: swapper Not tainted 4.14.72-rc1-yocto-standard+ #1
      task: cf8e0000 task.stack: cf8da000
      NIP:  c08e9468 LR: c08ea5bc CTR: c08ea5ac
      REGS: cf8dbb50 TRAP: 0300   Not tainted  (4.14.72-rc1-yocto-standard+)
      MSR:  00001032 <ME,IR,DR,RI>  CR: 82004044  XER: 00000000
      DAR: 00bc616e DSISR: 40000000
      GPR00: c08ea5bc cf8dbc00 cf8e0000 c13ca517 c13ca517 c13ca8a0 00000066 00000002
      GPR08: 00000063 00bc614e c0b05865 000affff 82004048 00000000 c00047f0 00000000
      GPR16: c0a80000 c0a9cc34 c13ca517 c0ad1134 05ffffff 000affff c0b05860 c0abeef8
      GPR24: cecec278 cecec278 c0a8c4d0 c0a885e0 c13ca8a0 05ffffff c13ca8a0 c13ca517
      
      NIP [c08e9468] device_node_gen_full_name+0x30/0x15c
      LR [c08ea5bc] device_node_string+0x190/0x3c8
      Call Trace:
      [cf8dbc00] [c007f670] trace_hardirqs_on_caller+0x118/0x1fc (unreliable)
      [cf8dbc40] [c08ea5bc] device_node_string+0x190/0x3c8
      [cf8dbcb0] [c08eb794] pointer+0x25c/0x4d0
      [cf8dbd00] [c08ebcbc] vsnprintf+0x2b4/0x5ec
      [cf8dbd60] [c08ec00c] vscnprintf+0x18/0x48
      [cf8dbd70] [c008e268] vprintk_store+0x4c/0x22c
      [cf8dbda0] [c008ecac] vprintk_emit+0x94/0x130
      [cf8dbdd0] [c008ff54] printk+0x5c/0x6c
      [cf8dbe10] [c0b8ddd4] of_unittest+0x2220/0x26f8
      [cf8dbea0] [c0004434] do_one_initcall+0x4c/0x184
      [cf8dbf00] [c0b4534c] kernel_init_freeable+0x13c/0x1d8
      [cf8dbf30] [c0004814] kernel_init+0x24/0x118
      [cf8dbf40] [c0013398] ret_from_kernel_thread+0x5c/0x64
      
      The problem was observed when running a qemu test for the g3beige machine
      with devicetree unittests enabled.
      
      Disable interrupt node tests on affected systems to avoid both false
      unittest failures and the crash.
      
      With this patch in place, unittest on the affected system passes with
      the following message.
      
      	dt-test ### end of unittest - 144 passed, 0 failed
      
      Fixes: 53a42093 ("of: Add device tree selftests")
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Reviewed-by: default avatarFrank Rowand <frank.rowand@sony.com>
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      79f87e09
    • Dmitry Safonov's avatar
      tty: Drop tty->count on tty_reopen() failure · 171f90d4
      Dmitry Safonov authored
      commit fe324167 upstream.
      
      In case of tty_ldisc_reinit() failure, tty->count should be decremented
      back, otherwise we will never release_tty().
      Tetsuo reported that it fixes noisy warnings on tty release like:
        pts pts4033: tty_release: tty->count(10529) != (#fd's(7) + #kopen's(0))
      
      Fixes: commit 892d1fa7 ("tty: Destroy ldisc instance on hangup")
      
      Cc: stable@vger.kernel.org # v4.6+
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Jiri Slaby <jslaby@suse.com>
      Reviewed-by: default avatarJiri Slaby <jslaby@suse.cz>
      Tested-by: default avatarJiri Slaby <jslaby@suse.com>
      Tested-by: default avatarMark Rutland <mark.rutland@arm.com>
      Tested-by: default avatarTetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
      Signed-off-by: default avatarDmitry Safonov <dima@arista.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      171f90d4
    • Romain Izard's avatar
      usb: cdc_acm: Do not leak URB buffers · c92e73b1
      Romain Izard authored
      commit f2924d4b upstream.
      
      When the ACM TTY port is disconnected, the URBs it uses must be killed, and
      then the buffers must be freed. Unfortunately a previous refactor removed
      the code freeing the buffers because it looked extremely similar to the
      code killing the URBs.
      
      As a result, there were many new leaks for each plug/unplug cycle of a
      CDC-ACM device, that were detected by kmemleak.
      
      Restore the missing code, and the memory leak is removed.
      
      Fixes: ba8c931d ("cdc-acm: refactor killing urbs")
      Signed-off-by: default avatarRomain Izard <romain.izard.pro@gmail.com>
      Acked-by: default avatarOliver Neukum <oneukum@suse.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c92e73b1
    • Johan Hovold's avatar
      USB: serial: simple: add Motorola Tetra MTP6550 id · 821c42e7
      Johan Hovold authored
      commit f5fad711 upstream.
      
      Add device-id for the Motorola Tetra radio MTP6550.
      
      Bus 001 Device 004: ID 0cad:9012 Motorola CGISS
      Device Descriptor:
        bLength                18
        bDescriptorType         1
        bcdUSB               2.00
        bDeviceClass            0 (Defined at Interface level)
        bDeviceSubClass         0
        bDeviceProtocol         0
        bMaxPacketSize0        64
        idVendor           0x0cad Motorola CGISS
        idProduct          0x9012
        bcdDevice           24.16
        iManufacturer           1 Motorola Solutions, Inc.
        iProduct                2 TETRA PEI interface
        iSerial                 0
        bNumConfigurations      1
        Configuration Descriptor:
          bLength                 9
          bDescriptorType         2
          wTotalLength           55
          bNumInterfaces          2
          bConfigurationValue     1
          iConfiguration          3 Generic Serial config
          bmAttributes         0x80
            (Bus Powered)
          MaxPower              500mA
          Interface Descriptor:
            bLength                 9
            bDescriptorType         4
            bInterfaceNumber        0
            bAlternateSetting       0
            bNumEndpoints           2
            bInterfaceClass       255 Vendor Specific Class
            bInterfaceSubClass      0
            bInterfaceProtocol      0
            iInterface              0
            Endpoint Descriptor:
              bLength                 7
              bDescriptorType         5
              bEndpointAddress     0x81  EP 1 IN
              bmAttributes            2
                Transfer Type            Bulk
                Synch Type               None
                Usage Type               Data
              wMaxPacketSize     0x0200  1x 512 bytes
              bInterval               0
            Endpoint Descriptor:
              bLength                 7
              bDescriptorType         5
              bEndpointAddress     0x01  EP 1 OUT
              bmAttributes            2
                Transfer Type            Bulk
                Synch Type               None
                Usage Type               Data
              wMaxPacketSize     0x0200  1x 512 bytes
          Interface Descriptor:
            bLength                 9
            bDescriptorType         4
            bInterfaceNumber        1
            bAlternateSetting       0
            bNumEndpoints           2
            bInterfaceClass       255 Vendor Specific Class
            bInterfaceSubClass      0
            bInterfaceProtocol      0
            iInterface              0
            Endpoint Descriptor:
              bLength                 7
              bDescriptorType         5
              bEndpointAddress     0x82  EP 2 IN
              bmAttributes            2
                Transfer Type            Bulk
                Synch Type               None
                Usage Type               Data
              wMaxPacketSize     0x0200  1x 512 bytes
              bInterval               0
            Endpoint Descriptor:
              bLength                 7
              bDescriptorType         5
              bEndpointAddress     0x02  EP 2 OUT
              bmAttributes            2
                Transfer Type            Bulk
                Synch Type               None
                Usage Type               Data
              wMaxPacketSize     0x0200  1x 512 bytes
              bInterval               0
      Device Qualifier (for other device speed):
        bLength                10
        bDescriptorType         6
        bcdUSB               2.00
        bDeviceClass            0 (Defined at Interface level)
        bDeviceSubClass         0
        bDeviceProtocol         0
        bMaxPacketSize0        64
        bNumConfigurations      1
      Device Status:     0x0000
        (Bus Powered)
      Reported-by: default avatarHans Hult <hanshult35@gmail.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      821c42e7
    • Chunfeng Yun's avatar
      usb: xhci-mtk: resume USB3 roothub first · 35123e64
      Chunfeng Yun authored
      commit 555df582 upstream.
      
      Give USB3 devices a better chance to enumerate at USB3 speeds if
      they are connected to a suspended host.
      Porting from "671ffdff xhci: resume USB 3 roothub first"
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarChunfeng Yun <chunfeng.yun@mediatek.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      35123e64
    • Mathias Nyman's avatar
      xhci: Add missing CAS workaround for Intel Sunrise Point xHCI · c096f5c4
      Mathias Nyman authored
      commit ffe84e01 upstream.
      
      The workaround for missing CAS bit is also needed for xHC on Intel
      sunrisepoint PCH. For more details see:
      
      Intel 100/c230 series PCH specification update Doc #332692-006 Errata #8
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c096f5c4
    • Mike Snitzer's avatar
      dm cache: fix resize crash if user doesn't reload cache table · ec6ae632
      Mike Snitzer authored
      commit 5d07384a upstream.
      
      A reload of the cache's DM table is needed during resize because
      otherwise a crash will occur when attempting to access smq policy
      entries associated with the portion of the cache that was recently
      extended.
      
      The reason is cache-size based data structures in the policy will not be
      resized, the only way to safely extend the cache is to allow for a
      proper cache policy initialization that occurs when the cache table is
      loaded.  For example the smq policy's space_init(), init_allocator(),
      calc_hotspot_params() must be sized based on the extended cache size.
      
      The fix for this is to disallow cache resizes of this pattern:
      1) suspend "cache" target's device
      2) resize the fast device used for the cache
      3) resume "cache" target's device
      
      Instead, the last step must be a full reload of the cache's DM table.
      
      Fixes: 66a63635 ("dm cache: add stochastic-multi-queue (smq) policy")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ec6ae632
    • Joe Thornber's avatar
      dm cache metadata: ignore hints array being too small during resize · f11a6abf
      Joe Thornber authored
      commit 4561ffca upstream.
      
      Commit fd2fa954 ("dm cache metadata: save in-core policy_hint_size to
      on-disk superblock") enabled previously written policy hints to be
      used after a cache is reactivated.  But in doing so the cache
      metadata's hint array was left exposed to out of bounds access because
      on resize the metadata's on-disk hint array wasn't ever extended.
      
      Fix this by ignoring that there are no on-disk hints associated with the
      newly added cache blocks.  An expanded on-disk hint array is later
      rewritten upon the next clean shutdown of the cache.
      
      Fixes: fd2fa954 ("dm cache metadata: save in-core policy_hint_size to on-disk superblock")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJoe Thornber <ejt@redhat.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f11a6abf
    • Rafael J. Wysocki's avatar
      PM / core: Clear the direct_complete flag on errors · 1364055c
      Rafael J. Wysocki authored
      commit 69e445ab upstream.
      
      If __device_suspend() runs asynchronously (in which case the device
      passed to it is in dpm_suspended_list at that point) and it returns
      early on an error or pending wakeup, and the power.direct_complete
      flag has been set for the device already, the subsequent
      device_resume() will be confused by that and it will call
      pm_runtime_enable() incorrectly, as runtime PM has not been
      disabled for the device by __device_suspend().
      
      To avoid that, clear power.direct_complete if __device_suspend()
      is not going to disable runtime PM for the device before returning.
      
      Fixes: aae4518b (PM / sleep: Mechanism to avoid resuming runtime-suspended devices unnecessarily)
      Reported-by: default avatarAl Cooper <alcooperx@gmail.com>
      Tested-by: default avatarAl Cooper <alcooperx@gmail.com>
      Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Cc: 3.16+ <stable@vger.kernel.org> # 3.16+
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1364055c
    • Felix Fietkau's avatar
      mac80211: fix setting IEEE80211_KEY_FLAG_RX_MGMT for AP mode keys · 9047696c
      Felix Fietkau authored
      commit 211710ca upstream.
      
      key->sta is only valid after ieee80211_key_link, which is called later
      in this function. Because of that, the IEEE80211_KEY_FLAG_RX_MGMT is
      never set when management frame protection is enabled.
      
      Fixes: e548c49e ("mac80211: add key flag for management keys")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9047696c
    • Daniel Drake's avatar
      PCI: Reprogram bridge prefetch registers on resume · 8ebd6558
      Daniel Drake authored
      commit 08387454 upstream.
      
      On 38+ Intel-based ASUS products, the NVIDIA GPU becomes unusable after S3
      suspend/resume.  The affected products include multiple generations of
      NVIDIA GPUs and Intel SoCs.  After resume, nouveau logs many errors such
      as:
      
        fifo: fault 00 [READ] at 0000005555555000 engine 00 [GR] client 04
              [HUB/FE] reason 4a [] on channel -1 [007fa91000 unknown]
        DRM: failed to idle channel 0 [DRM]
      
      Similarly, the NVIDIA proprietary driver also fails after resume (black
      screen, 100% CPU usage in Xorg process).  We shipped a sample to NVIDIA for
      diagnosis, and their response indicated that it's a problem with the parent
      PCI bridge (on the Intel SoC), not the GPU.
      
      Runtime suspend/resume works fine, only S3 suspend is affected.
      
      We found a workaround: on resume, rewrite the Intel PCI bridge
      'Prefetchable Base Upper 32 Bits' register (PCI_PREF_BASE_UPPER32).  In the
      cases that I checked, this register has value 0 and we just have to rewrite
      that value.
      
      Linux already saves and restores PCI config space during suspend/resume,
      but this register was being skipped because upon resume, it already has
      value 0 (the correct, pre-suspend value).
      
      Intel appear to have previously acknowledged this behaviour and the
      requirement to rewrite this register:
      https://bugzilla.kernel.org/show_bug.cgi?id=116851#c23
      
      Based on that, rewrite the prefetch register values even when that appears
      unnecessary.
      
      We have confirmed this solution on all the affected models we have in-hands
      (X542UQ, UX533FD, X530UN, V272UN).
      
      Additionally, this solves an issue where r8169 MSI-X interrupts were broken
      after S3 suspend/resume on ASUS X441UAR.  This issue was recently worked
      around in commit 7bb05b85 ("r8169: don't use MSI-X on RTL8106e").  It
      also fixes the same issue on RTL6186evl/8111evl on an Aimfor-tech laptop
      that we had not yet patched.  I suspect it will also fix the issue that was
      worked around in commit 7c53a722 ("r8169: don't use MSI-X on
      RTL8168g").
      
      Thomas Martitz reports that this change also solves an issue where the AMD
      Radeon Polaris 10 GPU on the HP Zbook 14u G5 is unresponsive after S3
      suspend/resume.
      
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=201069Signed-off-by: default avatarDaniel Drake <drake@endlessm.com>
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-By: default avatarPeter Wu <peter@lekensteyn.nl>
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8ebd6558
    • Andy Lutomirski's avatar
      x86/vdso: Fix vDSO syscall fallback asm constraint regression · 25bc6e80
      Andy Lutomirski authored
      commit 02e42566 upstream.
      
      When I added the missing memory outputs, I failed to update the
      index of the first argument (ebx) on 32-bit builds, which broke the
      fallbacks.  Somehow I must have screwed up my testing or gotten
      lucky.
      
      Add another test to cover gettimeofday() as well.
      Signed-off-by: default avatarAndy Lutomirski <luto@kernel.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: stable@vger.kernel.org
      Fixes: 715bd9d1 ("x86/vdso: Fix asm constraints on vDSO syscall fallbacks")
      Link: http://lkml.kernel.org/r/21bd45ab04b6d838278fa5bebfa9163eceffa13c.1538608971.git.luto@kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      25bc6e80
    • Andy Lutomirski's avatar
      x86/vdso: Only enable vDSO retpolines when enabled and supported · 1194e838
      Andy Lutomirski authored
      commit 4f166564 upstream.
      
      When I fixed the vDSO build to use inline retpolines, I messed up
      the Makefile logic and made it unconditional.  It should have
      depended on CONFIG_RETPOLINE and on the availability of compiler
      support.  This broke the build on some older compilers.
      
      Reported-by: nikola.ciprich@linuxbox.cz
      Signed-off-by: default avatarAndy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matt Rickard <matt@softrans.com.au>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: jason.vas.dias@gmail.com
      Cc: stable@vger.kernel.org
      Fixes: 2e549b2e ("x86/vdso: Fix vDSO build if a retpoline is emitted")
      Link: http://lkml.kernel.org/r/08a1f29f2c238dd1f493945e702a521f8a5aa3ae.1538540801.git.luto@kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1194e838
    • Andy Lutomirski's avatar
      selftests/x86: Add clock_gettime() tests to test_vdso · 64ff5747
      Andy Lutomirski authored
      commit 7c03e703 upstream.
      
      Now that the vDSO implementation of clock_gettime() is getting
      reworked, add a selftest for it.  This tests that its output is
      consistent with the syscall version.
      
      This is marked for stable to serve as a test for commit
      
        715bd9d1 ("x86/vdso: Fix asm constraints on vDSO syscall fallbacks")
      Signed-off-by: default avatarAndy Lutomirski <luto@kernel.org>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: stable@vger.kernel.org
      Link: https://lkml.kernel.org/r/082399674de2619b2befd8c0dde49b260605b126.1538422295.git.luto@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      64ff5747
    • Andy Lutomirski's avatar
      x86/vdso: Fix asm constraints on vDSO syscall fallbacks · 30500cc7
      Andy Lutomirski authored
      commit 715bd9d1 upstream.
      
      The syscall fallbacks in the vDSO have incorrect asm constraints.
      They are not marked as writing to their outputs -- instead, they are
      marked as clobbering "memory", which is useless.  In particular, gcc
      is smart enough to know that the timespec parameter hasn't escaped,
      so a memory clobber doesn't clobber it.  And passing a pointer as an
      asm *input* does not tell gcc that the pointed-to value is changed.
      
      Add in the fact that the asm instructions weren't volatile, and gcc
      was free to omit them entirely unless their sole output (the return
      value) is used.  Which it is (phew!), but that stops happening with
      some upcoming patches.
      
      As a trivial example, the following code:
      
      void test_fallback(struct timespec *ts)
      {
      	vdso_fallback_gettime(CLOCK_MONOTONIC, ts);
      }
      
      compiles to:
      
      00000000000000c0 <test_fallback>:
        c0:   c3                      retq
      
      To add insult to injury, the RCX and R11 clobbers on 64-bit
      builds were missing.
      
      The "memory" clobber is also unnecessary -- no ordering with respect to
      other memory operations is needed, but that's going to be fixed in a
      separate not-for-stable patch.
      
      Fixes: 2aae950b ("x86_64: Add vDSO for x86-64 with gettimeofday/clock_gettime/getcpu")
      Signed-off-by: default avatarAndy Lutomirski <luto@kernel.org>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: stable@vger.kernel.org
      Link: https://lkml.kernel.org/r/2c0231690551989d2fafa60ed0e7b5cc8b403908.1538422295.git.luto@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      30500cc7
    • Jason Ekstrand's avatar
      drm/syncobj: Don't leak fences when WAIT_FOR_SUBMIT is set · 71a05562
      Jason Ekstrand authored
      commit 337fe9f5 upstream.
      
      We attempt to get fences earlier in the hopes that everything will
      already have fences and no callbacks will be needed.  If we do succeed
      in getting a fence, getting one a second time will result in a duplicate
      ref with no unref.  This is causing memory leaks in Vulkan applications
      that create a lot of fences; playing for a few hours can, apparently,
      bring down the system.
      
      Cc: stable@vger.kernel.org
      Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107899Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
      Signed-off-by: default avatarJason Ekstrand <jason@jlekstrand.net>
      Signed-off-by: default avatarSean Paul <seanpaul@chromium.org>
      Link: https://patchwork.freedesktop.org/patch/msgid/20180926071703.15257-1-jason.ekstrand@intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      71a05562
    • Rex Zhu's avatar
      drm/amdgpu: Fix vce work queue was not cancelled when suspend · 0c0dd182
      Rex Zhu authored
      commit 61ea6f58 upstream.
      
      The vce cancel_delayed_work_sync never be called.
      driver call the function in error path.
      
      This caused the A+A suspend hang when runtime pm enebled.
      As we will visit the smu in the idle queue. this will cause
      smu hang because the dgpu has been suspend, and the dgpu also
      will be waked up. As the smu has been hang, so the dgpu resume
      will failed.
      Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
      Reviewed-by: default avatarFeifei Xu <Feifei.Xu@amd.com>
      Signed-off-by: default avatarRex Zhu <Rex.Zhu@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0c0dd182
    • Jan Beulich's avatar
      xen-netback: fix input validation in xenvif_set_hash_mapping() · 309a1c5c
      Jan Beulich authored
      commit 780e83c2 upstream.
      
      Both len and off are frontend specified values, so we need to make
      sure there's no overflow when adding the two for the bounds check. We
      also want to avoid undefined behavior and hence use off to index into
      ->hash.mapping[] only after bounds checking. This at the same time
      allows to take care of not applying off twice for the bounds checking
      against vif->num_queues.
      
      It is also insufficient to bounds check copy_op.len, as this is len
      truncated to 16 bits.
      
      This is XSA-270 / CVE-2018-15471.
      Reported-by: default avatarFelix Wilhelm <fwilhelm@google.com>
      Signed-off-by: default avatarJan Beulich <jbeulich@suse.com>
      Reviewed-by: default avatarPaul Durrant <paul.durrant@citrix.com>
      Tested-by: default avatarPaul Durrant <paul.durrant@citrix.com>
      Cc: stable@vger.kernel.org [4.7 onwards]
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      309a1c5c
    • Tomi Valkeinen's avatar
      fbdev/omapfb: fix omapfb_memory_read infoleak · f66d8948
      Tomi Valkeinen authored
      commit 1bafcbf5 upstream.
      
      OMAPFB_MEMORY_READ ioctl reads pixels from the LCD's memory and copies
      them to a userspace buffer. The code has two issues:
      
      - The user provided width and height could be large enough to overflow
        the calculations
      - The copy_to_user() can copy uninitialized memory to the userspace,
        which might contain sensitive kernel information.
      
      Fix these by limiting the width & height parameters, and only copying
      the amount of data that we actually received from the LCD.
      Signed-off-by: default avatarTomi Valkeinen <tomi.valkeinen@ti.com>
      Reported-by: default avatarJann Horn <jannh@google.com>
      Cc: stable@vger.kernel.org
      Cc: security@kernel.org
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Jann Horn <jannh@google.com>
      Cc: Tony Lindgren <tony@atomide.com>
      Signed-off-by: default avatarBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f66d8948
    • Alexandre Belloni's avatar
      clocksource/drivers/timer-atmel-pit: Properly handle error cases · 88736169
      Alexandre Belloni authored
      commit 52bf4a90 upstream.
      
      The smatch utility reports a possible leak:
      
      smatch warnings:
      drivers/clocksource/timer-atmel-pit.c:183 at91sam926x_pit_dt_init() warn: possible memory leak of 'data'
      
      Ensure data is freed before exiting with an error.
      Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      88736169
    • Ilya Dryomov's avatar
      blk-mq: I/O and timer unplugs are inverted in blktrace · 8e2e2192
      Ilya Dryomov authored
      commit 587562d0 upstream.
      
      trace_block_unplug() takes true for explicit unplugs and false for
      implicit unplugs.  schedule() unplugs are implicit and should be
      reported as timer unplugs.  While correct in the legacy code, this has
      been inverted in blk-mq since 4.11.
      
      Cc: stable@vger.kernel.org
      Fixes: bd166ef1 ("blk-mq-sched: add framework for MQ capable IO schedulers")
      Reviewed-by: default avatarOmar Sandoval <osandov@fb.com>
      Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8e2e2192
    • Sean Christopherson's avatar
      KVM: x86: fix L1TF's MMIO GFN calculation · 87a9d1cc
      Sean Christopherson authored
      commit daa07cbc upstream.
      
      One defense against L1TF in KVM is to always set the upper five bits
      of the *legal* physical address in the SPTEs for non-present and
      reserved SPTEs, e.g. MMIO SPTEs.  In the MMIO case, the GFN of the
      MMIO SPTE may overlap with the upper five bits that are being usurped
      to defend against L1TF.  To preserve the GFN, the bits of the GFN that
      overlap with the repurposed bits are shifted left into the reserved
      bits, i.e. the GFN in the SPTE will be split into high and low parts.
      When retrieving the GFN from the MMIO SPTE, e.g. to check for an MMIO
      access, get_mmio_spte_gfn() unshifts the affected bits and restores
      the original GFN for comparison.  Unfortunately, get_mmio_spte_gfn()
      neglects to mask off the reserved bits in the SPTE that were used to
      store the upper chunk of the GFN.  As a result, KVM fails to detect
      MMIO accesses whose GPA overlaps the repurprosed bits, which in turn
      causes guest panics and hangs.
      
      Fix the bug by generating a mask that covers the lower chunk of the
      GFN, i.e. the bits that aren't shifted by the L1TF mitigation.  The
      alternative approach would be to explicitly zero the five reserved
      bits that are used to store the upper chunk of the GFN, but that
      requires additional run-time computation and makes an already-ugly
      bit of code even more inscrutable.
      
      I considered adding a WARN_ON_ONCE(low_phys_bits-1 <= PAGE_SHIFT) to
      warn if GENMASK_ULL() generated a nonsensical value, but that seemed
      silly since that would mean a system that supports VMX has less than
      18 bits of physical address space...
      Reported-by: default avatarSakari Ailus <sakari.ailus@iki.fi>
      Fixes: d9b47449c1a1 ("kvm: x86: Set highest physical address bits in non-present/reserved SPTEs")
      Cc: Junaid Shahid <junaids@google.com>
      Cc: Jim Mattson <jmattson@google.com>
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarJunaid Shahid <junaids@google.com>
      Tested-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      87a9d1cc
    • Jann Horn's avatar
      mm/vmstat.c: skip NR_TLB_REMOTE_FLUSH* properly · 5178716b
      Jann Horn authored
      commit 58bc4c34 upstream.
      
      5dd0b16c ("mm/vmstat: Make NR_TLB_REMOTE_FLUSH_RECEIVED available even
      on UP") made the availability of the NR_TLB_REMOTE_FLUSH* counters inside
      the kernel unconditional to reduce #ifdef soup, but (either to avoid
      showing dummy zero counters to userspace, or because that code was missed)
      didn't update the vmstat_array, meaning that all following counters would
      be shown with incorrect values.
      
      This only affects kernel builds with
      CONFIG_VM_EVENT_COUNTERS=y && CONFIG_DEBUG_TLBFLUSH=y && CONFIG_SMP=n.
      
      Link: http://lkml.kernel.org/r/20181001143138.95119-2-jannh@google.com
      Fixes: 5dd0b16c ("mm/vmstat: Make NR_TLB_REMOTE_FLUSH_RECEIVED available even on UP")
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Acked-by: default avatarMichal Hocko <mhocko@suse.com>
      Acked-by: default avatarRoman Gushchin <guro@fb.com>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Christoph Lameter <clameter@sgi.com>
      Cc: Kemi Wang <kemi.wang@intel.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5178716b
    • Kirill A. Shutemov's avatar
      mm, thp: fix mlocking THP page with migration enabled · a2e0493f
      Kirill A. Shutemov authored
      commit e125fe40 upstream.
      
      A transparent huge page is represented by a single entry on an LRU list.
      Therefore, we can only make unevictable an entire compound page, not
      individual subpages.
      
      If a user tries to mlock() part of a huge page, we want the rest of the
      page to be reclaimable.
      
      We handle this by keeping PTE-mapped huge pages on normal LRU lists: the
      PMD on border of VM_LOCKED VMA will be split into PTE table.
      
      Introduction of THP migration breaks[1] the rules around mlocking THP
      pages.  If we had a single PMD mapping of the page in mlocked VMA, the
      page will get mlocked, regardless of PTE mappings of the page.
      
      For tmpfs/shmem it's easy to fix by checking PageDoubleMap() in
      remove_migration_pmd().
      
      Anon THP pages can only be shared between processes via fork().  Mlocked
      page can only be shared if parent mlocked it before forking, otherwise CoW
      will be triggered on mlock().
      
      For Anon-THP, we can fix the issue by munlocking the page on removing PTE
      migration entry for the page.  PTEs for the page will always come after
      mlocked PMD: rmap walks VMAs from oldest to newest.
      
      Test-case:
      
      	#include <unistd.h>
      	#include <sys/mman.h>
      	#include <sys/wait.h>
      	#include <linux/mempolicy.h>
      	#include <numaif.h>
      
      	int main(void)
      	{
      	        unsigned long nodemask = 4;
      	        void *addr;
      
      		addr = mmap((void *)0x20000000UL, 2UL << 20, PROT_READ | PROT_WRITE,
      			MAP_PRIVATE | MAP_ANONYMOUS | MAP_LOCKED, -1, 0);
      
      	        if (fork()) {
      			wait(NULL);
      			return 0;
      	        }
      
      	        mlock(addr, 4UL << 10);
      	        mbind(addr, 2UL << 20, MPOL_PREFERRED | MPOL_F_RELATIVE_NODES,
      	                &nodemask, 4, MPOL_MF_MOVE);
      
      	        return 0;
      	}
      
      [1] https://lkml.kernel.org/r/CAOMGZ=G52R-30rZvhGxEbkTw7rLLwBGadVYeo--iizcD3upL3A@mail.gmail.com
      
      Link: http://lkml.kernel.org/r/20180917133816.43995-1-kirill.shutemov@linux.intel.com
      Fixes: 616b8371 ("mm: thp: enable thp migration in generic path")
      Signed-off-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
      Reported-by: default avatarVegard Nossum <vegard.nossum@oracle.com>
      Reviewed-by: default avatarZi Yan <zi.yan@cs.rutgers.edu>
      Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Cc: <stable@vger.kernel.org>	[4.14+]
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a2e0493f
    • Mike Kravetz's avatar
      mm: migration: fix migration of huge PMD shared pages · 5f4f5b1f
      Mike Kravetz authored
      commit 017b1660 upstream.
      
      The page migration code employs try_to_unmap() to try and unmap the source
      page.  This is accomplished by using rmap_walk to find all vmas where the
      page is mapped.  This search stops when page mapcount is zero.  For shared
      PMD huge pages, the page map count is always 1 no matter the number of
      mappings.  Shared mappings are tracked via the reference count of the PMD
      page.  Therefore, try_to_unmap stops prematurely and does not completely
      unmap all mappings of the source page.
      
      This problem can result is data corruption as writes to the original
      source page can happen after contents of the page are copied to the target
      page.  Hence, data is lost.
      
      This problem was originally seen as DB corruption of shared global areas
      after a huge page was soft offlined due to ECC memory errors.  DB
      developers noticed they could reproduce the issue by (hotplug) offlining
      memory used to back huge pages.  A simple testcase can reproduce the
      problem by creating a shared PMD mapping (note that this must be at least
      PUD_SIZE in size and PUD_SIZE aligned (1GB on x86)), and using
      migrate_pages() to migrate process pages between nodes while continually
      writing to the huge pages being migrated.
      
      To fix, have the try_to_unmap_one routine check for huge PMD sharing by
      calling huge_pmd_unshare for hugetlbfs huge pages.  If it is a shared
      mapping it will be 'unshared' which removes the page table entry and drops
      the reference on the PMD page.  After this, flush caches and TLB.
      
      mmu notifiers are called before locking page tables, but we can not be
      sure of PMD sharing until page tables are locked.  Therefore, check for
      the possibility of PMD sharing before locking so that notifiers can
      prepare for the worst possible case.
      
      Link: http://lkml.kernel.org/r/20180823205917.16297-2-mike.kravetz@oracle.com
      [mike.kravetz@oracle.com: make _range_in_vma() a static inline]
        Link: http://lkml.kernel.org/r/6063f215-a5c8-2f0c-465a-2c515ddc952d@oracle.com
      Fixes: 39dde65c ("shared page table for hugetlb page")
      Signed-off-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Acked-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
      Reviewed-by: default avatarNaoya Horiguchi <n-horiguchi@ah.jp.nec.com>
      Acked-by: default avatarMichal Hocko <mhocko@suse.com>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Jerome Glisse <jglisse@redhat.com>
      Cc: Mike Kravetz <mike.kravetz@oracle.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5f4f5b1f
    • Reinette Chatre's avatar
      perf/core: Add sanity check to deal with pinned event failure · ab18409c
      Reinette Chatre authored
      commit befb1b3c upstream.
      
      It is possible that a failure can occur during the scheduling of a
      pinned event. The initial portion of perf_event_read_local() contains
      the various error checks an event should pass before it can be
      considered valid. Ensure that the potential scheduling failure
      of a pinned event is checked for and have a credible error.
      Suggested-by: default avatarPeter Zijlstra <peterz@infradead.org>
      Signed-off-by: default avatarReinette Chatre <reinette.chatre@intel.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: fenghua.yu@intel.com
      Cc: tony.luck@intel.com
      Cc: acme@kernel.org
      Cc: gavin.hindman@intel.com
      Cc: jithu.joseph@intel.com
      Cc: dave.hansen@intel.com
      Cc: hpa@zytor.com
      Cc: stable@vger.kernel.org
      Link: https://lkml.kernel.org/r/6486385d1f30336e9973b24c8c65f5079543d3d3.1537377064.git.reinette.chatre@intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ab18409c
  2. 10 Oct, 2018 2 commits