1. 03 Aug, 2018 29 commits
    • Trond Myklebust's avatar
      pnfs: Don't release the sequence slot until we've processed layoutget on open · b05c460a
      Trond Myklebust authored
      [ Upstream commit ae55e59d ]
      
      If the server recalls the layout that was just handed out, we risk hitting
      a race as described in RFC5661 Section 2.10.6.3 unless we ensure that we
      release the sequence slot after processing the LAYOUTGET operation that
      was sent as part of the OPEN compound.
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b05c460a
    • Alexey Kodanev's avatar
      netfilter: nf_tables: check msg_type before nft_trans_set(trans) · 759fb7f9
      Alexey Kodanev authored
      [ Upstream commit 9c7f96fd ]
      
      The patch moves the "trans->msg_type == NFT_MSG_NEWSET" check before
      using nft_trans_set(trans). Otherwise we can get out of bounds read.
      
      For example, KASAN reported the one when running 0001_cache_handling_0 nft
      test. In this case "trans->msg_type" was NFT_MSG_NEWTABLE:
      
      [75517.177808] BUG: KASAN: slab-out-of-bounds in nft_set_lookup_global+0x22f/0x270 [nf_tables]
      [75517.279094] Read of size 8 at addr ffff881bdb643fc8 by task nft/7356
      ...
      [75517.375605] CPU: 26 PID: 7356 Comm: nft Tainted: G  E   4.17.0-rc7.1.x86_64 #1
      [75517.489587] Hardware name: Oracle Corporation SUN SERVER X4-2
      [75517.618129] Call Trace:
      [75517.648821]  dump_stack+0xd1/0x13b
      [75517.691040]  ? show_regs_print_info+0x5/0x5
      [75517.742519]  ? kmsg_dump_rewind_nolock+0xf5/0xf5
      [75517.799300]  ? lock_acquire+0x143/0x310
      [75517.846738]  print_address_description+0x85/0x3a0
      [75517.904547]  kasan_report+0x18d/0x4b0
      [75517.949892]  ? nft_set_lookup_global+0x22f/0x270 [nf_tables]
      [75518.019153]  ? nft_set_lookup_global+0x22f/0x270 [nf_tables]
      [75518.088420]  ? nft_set_lookup_global+0x22f/0x270 [nf_tables]
      [75518.157689]  nft_set_lookup_global+0x22f/0x270 [nf_tables]
      [75518.224869]  nf_tables_newsetelem+0x1a5/0x5d0 [nf_tables]
      [75518.291024]  ? nft_add_set_elem+0x2280/0x2280 [nf_tables]
      [75518.357154]  ? nla_parse+0x1a5/0x300
      [75518.401455]  ? kasan_kmalloc+0xa6/0xd0
      [75518.447842]  nfnetlink_rcv+0xc43/0x1bdf [nfnetlink]
      [75518.507743]  ? nfnetlink_rcv+0x7a5/0x1bdf [nfnetlink]
      [75518.569745]  ? nfnl_err_reset+0x3c0/0x3c0 [nfnetlink]
      [75518.631711]  ? lock_acquire+0x143/0x310
      [75518.679133]  ? netlink_deliver_tap+0x9b/0x1070
      [75518.733840]  ? kasan_unpoison_shadow+0x31/0x40
      [75518.788542]  netlink_unicast+0x45d/0x680
      [75518.837111]  ? __isolate_free_page+0x890/0x890
      [75518.891913]  ? netlink_attachskb+0x6b0/0x6b0
      [75518.944542]  netlink_sendmsg+0x6fa/0xd30
      [75518.993107]  ? netlink_unicast+0x680/0x680
      [75519.043758]  ? netlink_unicast+0x680/0x680
      [75519.094402]  sock_sendmsg+0xd9/0x160
      [75519.138810]  ___sys_sendmsg+0x64d/0x980
      [75519.186234]  ? copy_msghdr_from_user+0x350/0x350
      [75519.243118]  ? lock_downgrade+0x650/0x650
      [75519.292738]  ? do_raw_spin_unlock+0x5d/0x250
      [75519.345456]  ? _raw_spin_unlock+0x24/0x30
      [75519.395065]  ? __handle_mm_fault+0xbde/0x3410
      [75519.448830]  ? sock_setsockopt+0x3d2/0x1940
      [75519.500516]  ? __lock_acquire.isra.25+0xdc/0x19d0
      [75519.558448]  ? lock_downgrade+0x650/0x650
      [75519.608057]  ? __audit_syscall_entry+0x317/0x720
      [75519.664960]  ? __fget_light+0x58/0x250
      [75519.711325]  ? __sys_sendmsg+0xde/0x170
      [75519.758850]  __sys_sendmsg+0xde/0x170
      [75519.804193]  ? __ia32_sys_shutdown+0x90/0x90
      [75519.856725]  ? syscall_trace_enter+0x897/0x10e0
      [75519.912354]  ? trace_event_raw_event_sys_enter+0x920/0x920
      [75519.979432]  ? __audit_syscall_entry+0x720/0x720
      [75520.036118]  do_syscall_64+0xa3/0x3d0
      [75520.081248]  ? prepare_exit_to_usermode+0x47/0x1d0
      [75520.139904]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      [75520.201680] RIP: 0033:0x7fc153320ba0
      [75520.245772] RSP: 002b:00007ffe294c3638 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
      [75520.337708] RAX: ffffffffffffffda RBX: 00007ffe294c4820 RCX: 00007fc153320ba0
      [75520.424547] RDX: 0000000000000000 RSI: 00007ffe294c46b0 RDI: 0000000000000003
      [75520.511386] RBP: 00007ffe294c47b0 R08: 0000000000000004 R09: 0000000002114090
      [75520.598225] R10: 00007ffe294c30a0 R11: 0000000000000246 R12: 00007ffe294c3660
      [75520.684961] R13: 0000000000000001 R14: 00007ffe294c3650 R15: 0000000000000001
      
      [75520.790946] Allocated by task 7356:
      [75520.833994]  kasan_kmalloc+0xa6/0xd0
      [75520.878088]  __kmalloc+0x189/0x450
      [75520.920107]  nft_trans_alloc_gfp+0x20/0x190 [nf_tables]
      [75520.983961]  nf_tables_newtable+0xcd0/0x1bd0 [nf_tables]
      [75521.048857]  nfnetlink_rcv+0xc43/0x1bdf [nfnetlink]
      [75521.108655]  netlink_unicast+0x45d/0x680
      [75521.157013]  netlink_sendmsg+0x6fa/0xd30
      [75521.205271]  sock_sendmsg+0xd9/0x160
      [75521.249365]  ___sys_sendmsg+0x64d/0x980
      [75521.296686]  __sys_sendmsg+0xde/0x170
      [75521.341822]  do_syscall_64+0xa3/0x3d0
      [75521.386957]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      [75521.467867] Freed by task 23454:
      [75521.507804]  __kasan_slab_free+0x132/0x180
      [75521.558137]  kfree+0x14d/0x4d0
      [75521.596005]  free_rt_sched_group+0x153/0x280
      [75521.648410]  sched_autogroup_create_attach+0x19a/0x520
      [75521.711330]  ksys_setsid+0x2ba/0x400
      [75521.755529]  __ia32_sys_setsid+0xa/0x10
      [75521.802850]  do_syscall_64+0xa3/0x3d0
      [75521.848090]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      [75521.929000] The buggy address belongs to the object at ffff881bdb643f80
       which belongs to the cache kmalloc-96 of size 96
      [75522.079797] The buggy address is located 72 bytes inside of
       96-byte region [ffff881bdb643f80, ffff881bdb643fe0)
      [75522.221234] The buggy address belongs to the page:
      [75522.280100] page:ffffea006f6d90c0 count:1 mapcount:0 mapping:0000000000000000 index:0x0
      [75522.377443] flags: 0x2fffff80000100(slab)
      [75522.426956] raw: 002fffff80000100 0000000000000000 0000000000000000 0000000180200020
      [75522.521275] raw: ffffea006e6fafc0 0000000c0000000c ffff881bf180f400 0000000000000000
      [75522.615601] page dumped because: kasan: bad access detected
      
      Fixes: 37a9cc52 ("netfilter: nf_tables: add generation mask to sets")
      Signed-off-by: default avatarAlexey Kodanev <alexey.kodanev@oracle.com>
      Acked-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      759fb7f9
    • Leon Romanovsky's avatar
      RDMA/mad: Convert BUG_ONs to error flows · efb4dd6a
      Leon Romanovsky authored
      [ Upstream commit 2468b82d ]
      
      Let's perform checks in-place instead of BUG_ONs.
      Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
      Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      efb4dd6a
    • Nicholas Piggin's avatar
      powerpc/64s: Fix compiler store ordering to SLB shadow area · ea8e4ff3
      Nicholas Piggin authored
      [ Upstream commit 926bc2f1 ]
      
      The stores to update the SLB shadow area must be made as they appear
      in the C code, so that the hypervisor does not see an entry with
      mismatched vsid and esid. Use WRITE_ONCE for this.
      
      GCC has been observed to elide the first store to esid in the update,
      which means that if the hypervisor interrupts the guest after storing
      to vsid, it could see an entry with old esid and new vsid, which may
      possibly result in memory corruption.
      Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ea8e4ff3
    • Stewart Smith's avatar
      hvc_opal: don't set tb_ticks_per_usec in udbg_init_opal_common() · c3e34725
      Stewart Smith authored
      [ Upstream commit 447808bf ]
      
      time_init() will set up tb_ticks_per_usec based on reality.
      time_init() is called *after* udbg_init_opal_common() during boot.
      
      from arch/powerpc/kernel/time.c:
        unsigned long tb_ticks_per_usec = 100; /* sane default */
      
      Currently, all powernv systems have a timebase frequency of 512mhz
      (512000000/1000000 == 0x200) - although there's nothing written
      down anywhere that I can find saying that we couldn't make that
      different based on the requirements in the ISA.
      
      So, we've been (accidentally) thwacking the (currently) correct
      (for powernv at least) value for tb_ticks_per_usec earlier than
      we otherwise would have.
      
      The "sane default" seems to be adequate for our purposes between
      udbg_init_opal_common() and time_init() being called, and if it isn't,
      then we should probably be setting it somewhere that isn't hvc_opal.c!
      Signed-off-by: default avatarStewart Smith <stewart@linux.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c3e34725
    • Sam Bobroff's avatar
      powerpc/eeh: Fix use-after-release of EEH driver · ee245de4
      Sam Bobroff authored
      [ Upstream commit 46d4be41 ]
      
      Correct two cases where eeh_pcid_get() is used to reference the driver's
      module but the reference is dropped before the driver pointer is used.
      
      In eeh_rmv_device() also refactor a little so that only two calls to
      eeh_pcid_put() are needed, rather than three and the reference isn't
      taken at all if it wasn't needed.
      Signed-off-by: default avatarSam Bobroff <sbobroff@linux.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ee245de4
    • Cong Wang's avatar
      infiniband: fix a possible use-after-free bug · 73298a82
      Cong Wang authored
      [ Upstream commit cb2595c1 ]
      
      ucma_process_join() will free the new allocated "mc" struct,
      if there is any error after that, especially the copy_to_user().
      
      But in parallel, ucma_leave_multicast() could find this "mc"
      through idr_find() before ucma_process_join() frees it, since it
      is already published.
      
      So "mc" could be used in ucma_leave_multicast() after it is been
      allocated and freed in ucma_process_join(), since we don't refcnt
      it.
      
      Fix this by separating "publish" from ID allocation, so that we
      can get an ID first and publish it later after copy_to_user().
      
      Fixes: c8f6a362 ("RDMA/cma: Add multicast communication support")
      Reported-by: default avatarNoam Rathaus <noamr@beyondsecurity.com>
      Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
      Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      73298a82
    • Jozsef Kadlecsik's avatar
      netfilter: ipset: List timing out entries with "timeout 1" instead of zero · 6e02c062
      Jozsef Kadlecsik authored
      [ Upstream commit bd975e69 ]
      
      When listing sets with timeout support, there's a probability that
      just timing out entries with "0" timeout value is listed/saved.
      However when restoring the saved list, the zero timeout value means
      permanent elelements.
      
      The new behaviour is that timing out entries are listed with "timeout 1"
      instead of zero.
      
      Fixes netfilter bugzilla #1258.
      Signed-off-by: default avatarJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6e02c062
    • Jiri Olsa's avatar
      perf tools: Fix pmu events parsing rule · 56295051
      Jiri Olsa authored
      [ Upstream commit ceac7b79 ]
      
      Currently all the event parsing fails end up
      in the event_pmu rule, and display misleading
      help like:
      
        $ perf stat -e inst kill
        event syntax error: 'inst'
                             \___ Cannot find PMU `inst'. Missing kernel support?
        ...
      
      The reason is that the event_pmu is too strong
      and match also single string. Changing it to
      force the '/' separators to be part of the rule,
      and getting the proper error now:
      
        $ perf stat -e inst kill
        event syntax error: 'inst'
                             \___ parser error
        Run 'perf list' for a list of valid events
        ...
      Suggested-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lkml.kernel.org/r/20180605121416.31645-1-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      56295051
    • Alexandre Belloni's avatar
      rtc: ensure rtc_set_alarm fails when alarms are not supported · fda8caa9
      Alexandre Belloni authored
      [ Upstream commit abfdff44 ]
      
      When using RTC_ALM_SET or RTC_WKALM_SET with rtc_wkalrm.enabled not set,
      rtc_timer_enqueue() is not called and rtc_set_alarm() may succeed but the
      subsequent RTC_AIE_ON ioctl will fail. RTC_ALM_READ would also fail in that
      case.
      
      Ensure rtc_set_alarm() fails when alarms are not supported to avoid letting
      programs think the alarms are working for a particular RTC when they are
      not.
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fda8caa9
    • Mathieu Malaterre's avatar
      mm/slub.c: add __printf verification to slab_err() · c99dbd95
      Mathieu Malaterre authored
      [ Upstream commit a38965bf ]
      
      __printf is useful to verify format and arguments.  Remove the following
      warning (with W=1):
      
        mm/slub.c:721:2: warning: function might be possible candidate for `gnu_printf' format attribute [-Wsuggest-attribute=format]
      
      Link: http://lkml.kernel.org/r/20180505200706.19986-1-malat@debian.orgSigned-off-by: default avatarMathieu Malaterre <malat@debian.org>
      Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c99dbd95
    • Chintan Pandya's avatar
      mm: vmalloc: avoid racy handling of debugobjects in vunmap · e18d3280
      Chintan Pandya authored
      [ Upstream commit f3c01d2f ]
      
      Currently, __vunmap flow is,
       1) Release the VM area
       2) Free the debug objects corresponding to that vm area.
      
      This leave some race window open.
       1) Release the VM area
       1.5) Some other client gets the same vm area
       1.6) This client allocates new debug objects on the same
            vm area
       2) Free the debug objects corresponding to this vm area.
      
      Here, we actually free 'other' client's debug objects.
      
      Fix this by freeing the debug objects first and then releasing the VM
      area.
      
      Link: http://lkml.kernel.org/r/1523961828-9485-2-git-send-email-cpandya@codeaurora.orgSigned-off-by: default avatarChintan Pandya <cpandya@codeaurora.org>
      Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Byungchul Park <byungchul.park@lge.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Florian Fainelli <f.fainelli@gmail.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: Laura Abbott <labbott@redhat.com>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Wei Yang <richard.weiyang@gmail.com>
      Cc: Yisheng Xie <xieyisheng1@huawei.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e18d3280
    • Geert Uytterhoeven's avatar
      vfio: platform: Fix reset module leak in error path · c6e81163
      Geert Uytterhoeven authored
      [ Upstream commit 28a68387 ]
      
      If the IOMMU group setup fails, the reset module is not released.
      
      Fixes: b5add544 ("vfio, platform: make reset driver a requirement by default")
      Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
      Reviewed-by: default avatarEric Auger <eric.auger@redhat.com>
      Reviewed-by: default avatarSimon Horman <horms+renesas@verge.net.au>
      Acked-by: default avatarEric Auger <eric.auger@redhat.com>
      Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c6e81163
    • Scott Mayhew's avatar
      nfsd: fix potential use-after-free in nfsd4_decode_getdeviceinfo · 8bccc6c9
      Scott Mayhew authored
      [ Upstream commit 3171822f ]
      
      When running a fuzz tester against a KASAN-enabled kernel, the following
      splat periodically occurs.
      
      The problem occurs when the test sends a GETDEVICEINFO request with a
      malformed xdr array (size but no data) for gdia_notify_types and the
      array size is > 0x3fffffff, which results in an overflow in the value of
      nbytes which is passed to read_buf().
      
      If the array size is 0x40000000, 0x80000000, or 0xc0000000, then after
      the overflow occurs, the value of nbytes 0, and when that happens the
      pointer returned by read_buf() points to the end of the xdr data (i.e.
      argp->end) when really it should be returning NULL.
      
      Fix this by returning NFS4ERR_BAD_XDR if the array size is > 1000 (this
      value is arbitrary, but it's the same threshold used by
      nfsd4_decode_bitmap()... in could really be any value >= 1 since it's
      expected to get at most a single bitmap in gdia_notify_types).
      
      [  119.256854] ==================================================================
      [  119.257611] BUG: KASAN: use-after-free in nfsd4_decode_getdeviceinfo+0x5a4/0x5b0 [nfsd]
      [  119.258422] Read of size 4 at addr ffff880113ada000 by task nfsd/538
      
      [  119.259146] CPU: 0 PID: 538 Comm: nfsd Not tainted 4.17.0+ #1
      [  119.259662] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.9.3-1.fc25 04/01/2014
      [  119.261202] Call Trace:
      [  119.262265]  dump_stack+0x71/0xab
      [  119.263371]  print_address_description+0x6a/0x270
      [  119.264609]  kasan_report+0x258/0x380
      [  119.265854]  ? nfsd4_decode_getdeviceinfo+0x5a4/0x5b0 [nfsd]
      [  119.267291]  nfsd4_decode_getdeviceinfo+0x5a4/0x5b0 [nfsd]
      [  119.268549]  ? nfs4svc_decode_compoundargs+0xa5b/0x13c0 [nfsd]
      [  119.269873]  ? nfsd4_decode_sequence+0x490/0x490 [nfsd]
      [  119.271095]  nfs4svc_decode_compoundargs+0xa5b/0x13c0 [nfsd]
      [  119.272393]  ? nfsd4_release_compoundargs+0x1b0/0x1b0 [nfsd]
      [  119.273658]  nfsd_dispatch+0x183/0x850 [nfsd]
      [  119.274918]  svc_process+0x161c/0x31a0 [sunrpc]
      [  119.276172]  ? svc_printk+0x190/0x190 [sunrpc]
      [  119.277386]  ? svc_xprt_release+0x451/0x680 [sunrpc]
      [  119.278622]  nfsd+0x2b9/0x430 [nfsd]
      [  119.279771]  ? nfsd_destroy+0x1c0/0x1c0 [nfsd]
      [  119.281157]  kthread+0x2db/0x390
      [  119.282347]  ? kthread_create_worker_on_cpu+0xc0/0xc0
      [  119.283756]  ret_from_fork+0x35/0x40
      
      [  119.286041] Allocated by task 436:
      [  119.287525]  kasan_kmalloc+0xa0/0xd0
      [  119.288685]  kmem_cache_alloc+0xe9/0x1f0
      [  119.289900]  get_empty_filp+0x7b/0x410
      [  119.291037]  path_openat+0xca/0x4220
      [  119.292242]  do_filp_open+0x182/0x280
      [  119.293411]  do_sys_open+0x216/0x360
      [  119.294555]  do_syscall_64+0xa0/0x2f0
      [  119.295721]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      [  119.298068] Freed by task 436:
      [  119.299271]  __kasan_slab_free+0x130/0x180
      [  119.300557]  kmem_cache_free+0x78/0x210
      [  119.301823]  rcu_process_callbacks+0x35b/0xbd0
      [  119.303162]  __do_softirq+0x192/0x5ea
      
      [  119.305443] The buggy address belongs to the object at ffff880113ada000
                      which belongs to the cache filp of size 256
      [  119.308556] The buggy address is located 0 bytes inside of
                      256-byte region [ffff880113ada000, ffff880113ada100)
      [  119.311376] The buggy address belongs to the page:
      [  119.312728] page:ffffea00044eb680 count:1 mapcount:0 mapping:0000000000000000 index:0xffff880113ada780
      [  119.314428] flags: 0x17ffe000000100(slab)
      [  119.315740] raw: 0017ffe000000100 0000000000000000 ffff880113ada780 00000001000c0001
      [  119.317379] raw: ffffea0004553c60 ffffea00045c11e0 ffff88011b167e00 0000000000000000
      [  119.319050] page dumped because: kasan: bad access detected
      
      [  119.321652] Memory state around the buggy address:
      [  119.322993]  ffff880113ad9f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      [  119.324515]  ffff880113ad9f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      [  119.326087] >ffff880113ada000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  119.327547]                    ^
      [  119.328730]  ffff880113ada080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  119.330218]  ffff880113ada100: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb
      [  119.331740] ==================================================================
      Signed-off-by: default avatarScott Mayhew <smayhew@redhat.com>
      Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8bccc6c9
    • Zhouyang Jia's avatar
      ALSA: fm801: add error handling for snd_ctl_add · ca08131e
      Zhouyang Jia authored
      [ Upstream commit ef1ffbe7 ]
      
      When snd_ctl_add fails, the lack of error-handling code may
      cause unexpected results.
      
      This patch adds error-handling code after calling snd_ctl_add.
      Signed-off-by: default avatarZhouyang Jia <jiazhouyang09@gmail.com>
      Acked-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ca08131e
    • Zhouyang Jia's avatar
      ALSA: emu10k1: add error handling for snd_ctl_add · 9f9e506d
      Zhouyang Jia authored
      [ Upstream commit 6d531e7b ]
      
      When snd_ctl_add fails, the lack of error-handling code may
      cause unexpected results.
      
      This patch adds error-handling code after calling snd_ctl_add.
      Signed-off-by: default avatarZhouyang Jia <jiazhouyang09@gmail.com>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9f9e506d
    • Juergen Gross's avatar
      xen/netfront: raise max number of slots in xennet_get_responses() · acd9aba8
      Juergen Gross authored
      [ Upstream commit 57f230ab ]
      
      The max number of slots used in xennet_get_responses() is set to
      MAX_SKB_FRAGS + (rx->status <= RX_COPY_THRESHOLD).
      
      In old kernel-xen MAX_SKB_FRAGS was 18, while nowadays it is 17. This
      difference is resulting in frequent messages "too many slots" and a
      reduced network throughput for some workloads (factor 10 below that of
      a kernel-xen based guest).
      
      Replacing MAX_SKB_FRAGS by XEN_NETIF_NR_SLOTS_MIN for calculation of
      the max number of slots to use solves that problem (tests showed no
      more messages "too many slots" and throughput was as high as with the
      kernel-xen based guest system).
      
      Replace MAX_SKB_FRAGS-2 by XEN_NETIF_NR_SLOTS_MIN-1 in
      netfront_tx_slot_available() for making it clearer what is really being
      tested without actually modifying the tested value.
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      Reviewed-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      acd9aba8
    • Mark Rutland's avatar
      kcov: ensure irq code sees a valid area · 31ad104d
      Mark Rutland authored
      [ Upstream commit c9484b98 ]
      
      Patch series "kcov: fix unexpected faults".
      
      These patches fix a few issues where KCOV code could trigger recursive
      faults, discovered while debugging a patch enabling KCOV for arch/arm:
      
      * On CONFIG_PREEMPT kernels, there's a small race window where
        __sanitizer_cov_trace_pc() can see a bogus kcov_area.
      
      * Lazy faulting of the vmalloc area can cause mutual recursion between
        fault handling code and __sanitizer_cov_trace_pc().
      
      * During the context switch, switching the mm can cause the kcov_area to
        be transiently unmapped.
      
      These are prerequisites for enabling KCOV on arm, but the issues
      themsevles are generic -- we just happen to avoid them by chance rather
      than design on x86-64 and arm64.
      
      This patch (of 3):
      
      For kernels built with CONFIG_PREEMPT, some C code may execute before or
      after the interrupt handler, while the hardirq count is zero.  In these
      cases, in_task() can return true.
      
      A task can be interrupted in the middle of a KCOV_DISABLE ioctl while it
      resets the task's kcov data via kcov_task_init().  Instrumented code
      executed during this period will call __sanitizer_cov_trace_pc(), and as
      in_task() returns true, will inspect t->kcov_mode before trying to write
      to t->kcov_area.
      
      In kcov_init_task() we update t->kcov_{mode,area,size} with plain stores,
      which may be re-ordered, torn, etc.  Thus __sanitizer_cov_trace_pc() may
      see bogus values for any of these fields, and may attempt to write to
      memory which is not mapped.
      
      Let's avoid this by using WRITE_ONCE() to set t->kcov_mode, with a
      barrier() to ensure this is ordered before we clear t->kov_{area,size}.
      This ensures that any code execute while kcov_init_task() is preempted
      will either see valid values for t->kcov_{area,size}, or will see that
      t->kcov_mode is KCOV_MODE_DISABLED, and bail out without touching
      t->kcov_area.
      
      Link: http://lkml.kernel.org/r/20180504135535.53744-2-mark.rutland@arm.comSigned-off-by: default avatarMark Rutland <mark.rutland@arm.com>
      Acked-by: default avatarAndrey Ryabinin <aryabinin@virtuozzo.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.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 avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      31ad104d
    • Antti Seppälä's avatar
      usb: dwc2: Fix DMA alignment to start at allocated boundary · 7ff1861f
      Antti Seppälä authored
      commit 56406e01 upstream.
      
      The commit 3bc04e28 ("usb: dwc2: host: Get aligned DMA in a more
      supported way") introduced a common way to align DMA allocations.
      The code in the commit aligns the struct dma_aligned_buffer but the
      actual DMA address pointed by data[0] gets aligned to an offset from
      the allocated boundary by the kmalloc_ptr and the old_xfer_buffer
      pointers.
      
      This is against the recommendation in Documentation/DMA-API.txt which
      states:
      
        Therefore, it is recommended that driver writers who don't take
        special care to determine the cache line size at run time only map
        virtual regions that begin and end on page boundaries (which are
        guaranteed also to be cache line boundaries).
      
      The effect of this is that architectures with non-coherent DMA caches
      may run into memory corruption or kernel crashes with Unhandled
      kernel unaligned accesses exceptions.
      
      Fix the alignment by positioning the DMA area in front of the allocation
      and use memory at the end of the area for storing the orginal
      transfer_buffer pointer. This may have the added benefit of increased
      performance as the DMA area is now fully aligned on all architectures.
      
      Tested with Lantiq xRX200 (MIPS) and RPi Model B Rev 2 (ARM).
      
      Fixes: 3bc04e28 ("usb: dwc2: host: Get aligned DMA in a more supported way")
      Cc: <stable@vger.kernel.org>
      Reviewed-by: default avatarDouglas Anderson <dianders@chromium.org>
      [ Antti: backported to 4.9: edited difference in whitespace ]
      Signed-off-by: default avatarAntti Seppälä <a.seppala@gmail.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7ff1861f
    • Johannes Weiner's avatar
      arm64: fix vmemmap BUILD_BUG_ON() triggering on !vmemmap setups · e8d77bd7
      Johannes Weiner authored
      commit 7b0eb6b4 upstream.
      
      Arnd reports the following arm64 randconfig build error with the PSI
      patches that add another page flag:
      
        /git/arm-soc/arch/arm64/mm/init.c: In function 'mem_init':
        /git/arm-soc/include/linux/compiler.h:357:38: error: call to
        '__compiletime_assert_618' declared with attribute error: BUILD_BUG_ON
        failed: sizeof(struct page) > (1 << STRUCT_PAGE_MAX_SHIFT)
      
      The additional page flag causes other information stored in
      page->flags to get bumped into their own struct page member:
      
        #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT+LAST_CPUPID_SHIFT <=
        BITS_PER_LONG - NR_PAGEFLAGS
        #define LAST_CPUPID_WIDTH LAST_CPUPID_SHIFT
        #else
        #define LAST_CPUPID_WIDTH 0
        #endif
      
        #if defined(CONFIG_NUMA_BALANCING) && LAST_CPUPID_WIDTH == 0
        #define LAST_CPUPID_NOT_IN_PAGE_FLAGS
        #endif
      
      which in turn causes the struct page size to exceed the size set in
      STRUCT_PAGE_MAX_SHIFT. This value is an an estimate used to size the
      VMEMMAP page array according to address space and struct page size.
      
      However, the check is performed - and triggers here - on a !VMEMMAP
      config, which consumes an additional 22 page bits for the sparse
      section id. When VMEMMAP is enabled, those bits are returned, cpupid
      doesn't need its own member, and the page passes the VMEMMAP check.
      
      Restrict that check to the situation it was meant to check: that we
      are sizing the VMEMMAP page array correctly.
      
      Says Arnd:
      
          Further experiments show that the build error already existed before,
          but was only triggered with larger values of CONFIG_NR_CPU and/or
          CONFIG_NODES_SHIFT that might be used in actual configurations but
          not in randconfig builds.
      
          With longer CPU and node masks, I could recreate the problem with
          kernels as old as linux-4.7 when arm64 NUMA support got added.
      Reported-by: default avatarArnd Bergmann <arnd@arndb.de>
      Tested-by: default avatarArnd Bergmann <arnd@arndb.de>
      Cc: stable@vger.kernel.org
      Fixes: 1a2db300 ("arm64, numa: Add NUMA support for arm64 platforms.")
      Fixes: 3e1907d5 ("arm64: mm: move vmemmap region right below the linear region")
      Signed-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e8d77bd7
    • Steven Rostedt (VMware)'s avatar
      tracing: Quiet gcc warning about maybe unused link variable · b985a730
      Steven Rostedt (VMware) authored
      commit 2519c1bb upstream.
      
      Commit 57ea2a34 ("tracing/kprobes: Fix trace_probe flags on
      enable_trace_kprobe() failure") added an if statement that depends on another
      if statement that gcc doesn't see will initialize the "link" variable and
      gives the warning:
      
       "warning: 'link' may be used uninitialized in this function"
      
      It is really a false positive, but to quiet the warning, and also to make
      sure that it never actually is used uninitialized, initialize the "link"
      variable to NULL and add an if (!WARN_ON_ONCE(!link)) where the compiler
      thinks it could be used uninitialized.
      
      Cc: stable@vger.kernel.org
      Fixes: 57ea2a34 ("tracing/kprobes: Fix trace_probe flags on enable_trace_kprobe() failure")
      Reported-by: default avatarkbuild test robot <lkp@intel.com>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b985a730
    • Artem Savkov's avatar
      tracing/kprobes: Fix trace_probe flags on enable_trace_kprobe() failure · 987e425a
      Artem Savkov authored
      commit 57ea2a34 upstream.
      
      If enable_trace_kprobe fails to enable the probe in enable_k(ret)probe
      it returns an error, but does not unset the tp flags it set previously.
      This results in a probe being considered enabled and failures like being
      unable to remove the probe through kprobe_events file since probes_open()
      expects every probe to be disabled.
      
      Link: http://lkml.kernel.org/r/20180725102826.8300-1-asavkov@redhat.com
      Link: http://lkml.kernel.org/r/20180725142038.4765-1-asavkov@redhat.com
      
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: stable@vger.kernel.org
      Fixes: 41a7dd42 ("tracing/kprobes: Support ftrace_event_file base multibuffer")
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Reviewed-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      Signed-off-by: default avatarArtem Savkov <asavkov@redhat.com>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      987e425a
    • Snild Dolkow's avatar
      kthread, tracing: Don't expose half-written comm when creating kthreads · b38f8292
      Snild Dolkow authored
      commit 3e536e22 upstream.
      
      There is a window for racing when printing directly to task->comm,
      allowing other threads to see a non-terminated string. The vsnprintf
      function fills the buffer, counts the truncated chars, then finally
      writes the \0 at the end.
      
      	creator                     other
      	vsnprintf:
      	  fill (not terminated)
      	  count the rest            trace_sched_waking(p):
      	  ...                         memcpy(comm, p->comm, TASK_COMM_LEN)
      	  write \0
      
      The consequences depend on how 'other' uses the string. In our case,
      it was copied into the tracing system's saved cmdlines, a buffer of
      adjacent TASK_COMM_LEN-byte buffers (note the 'n' where 0 should be):
      
      	crash-arm64> x/1024s savedcmd->saved_cmdlines | grep 'evenk'
      	0xffffffd5b3818640:     "irq/497-pwr_evenkworker/u16:12"
      
      ...and a strcpy out of there would cause stack corruption:
      
      	[224761.522292] Kernel panic - not syncing: stack-protector:
      	    Kernel stack is corrupted in: ffffff9bf9783c78
      
      	crash-arm64> kbt | grep 'comm\|trace_print_context'
      	#6  0xffffff9bf9783c78 in trace_print_context+0x18c(+396)
      	      comm (char [16]) =  "irq/497-pwr_even"
      
      	crash-arm64> rd 0xffffffd4d0e17d14 8
      	ffffffd4d0e17d14:  2f71726900000000 5f7277702d373934   ....irq/497-pwr_
      	ffffffd4d0e17d24:  726f776b6e657665 3a3631752f72656b   evenkworker/u16:
      	ffffffd4d0e17d34:  f9780248ff003231 cede60e0ffffff9b   12..H.x......`..
      	ffffffd4d0e17d44:  cede60c8ffffffd4 00000fffffffffd4   .....`..........
      
      The workaround in e09e2867 (use strlcpy in __trace_find_cmdline) was
      likely needed because of this same bug.
      
      Solved by vsnprintf:ing to a local buffer, then using set_task_comm().
      This way, there won't be a window where comm is not terminated.
      
      Link: http://lkml.kernel.org/r/20180726071539.188015-1-snild@sony.com
      
      Cc: stable@vger.kernel.org
      Fixes: bc0c38d1 ("ftrace: latency tracer infrastructure")
      Reviewed-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarSnild Dolkow <snild@sony.com>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b38f8292
    • Steven Rostedt (VMware)'s avatar
      tracing: Fix possible double free in event_enable_trigger_func() · a9737bb9
      Steven Rostedt (VMware) authored
      commit 15cc7864 upstream.
      
      There was a case that triggered a double free in event_trigger_callback()
      due to the called reg() function freeing the trigger_data and then it
      getting freed again by the error return by the caller. The solution there
      was to up the trigger_data ref count.
      
      Code inspection found that event_enable_trigger_func() has the same issue,
      but is not as easy to trigger (requires harder to trigger failures). It
      needs to be solved slightly different as it needs more to clean up when the
      reg() function fails.
      
      Link: http://lkml.kernel.org/r/20180725124008.7008e586@gandalf.local.home
      
      Cc: stable@vger.kernel.org
      Fixes: 7862ad18 ("tracing: Add 'enable_event' and 'disable_event' event trigger commands")
      Reivewed-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a9737bb9
    • Steven Rostedt (VMware)'s avatar
      tracing: Fix double free of event_trigger_data · 2a0ce1ff
      Steven Rostedt (VMware) authored
      commit 1863c387 upstream.
      
      Running the following:
      
       # cd /sys/kernel/debug/tracing
       # echo 500000 > buffer_size_kb
      [ Or some other number that takes up most of memory ]
       # echo snapshot > events/sched/sched_switch/trigger
      
      Triggers the following bug:
      
       ------------[ cut here ]------------
       kernel BUG at mm/slub.c:296!
       invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC PTI
       CPU: 6 PID: 6878 Comm: bash Not tainted 4.18.0-rc6-test+ #1066
       Hardware name: Hewlett-Packard HP Compaq Pro 6300 SFF/339A, BIOS K01 v03.03 07/14/2016
       RIP: 0010:kfree+0x16c/0x180
       Code: 05 41 0f b6 72 51 5b 5d 41 5c 4c 89 d7 e9 ac b3 f8 ff 48 89 d9 48 89 da 41 b8 01 00 00 00 5b 5d 41 5c 4c 89 d6 e9 f4 f3 ff ff <0f> 0b 0f 0b 48 8b 3d d9 d8 f9 00 e9 c1 fe ff ff 0f 1f 40 00 0f 1f
       RSP: 0018:ffffb654436d3d88 EFLAGS: 00010246
       RAX: ffff91a9d50f3d80 RBX: ffff91a9d50f3d80 RCX: ffff91a9d50f3d80
       RDX: 00000000000006a4 RSI: ffff91a9de5a60e0 RDI: ffff91a9d9803500
       RBP: ffffffff8d267c80 R08: 00000000000260e0 R09: ffffffff8c1a56be
       R10: fffff0d404543cc0 R11: 0000000000000389 R12: ffffffff8c1a56be
       R13: ffff91a9d9930e18 R14: ffff91a98c0c2890 R15: ffffffff8d267d00
       FS:  00007f363ea64700(0000) GS:ffff91a9de580000(0000) knlGS:0000000000000000
       CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
       CR2: 000055c1cacc8e10 CR3: 00000000d9b46003 CR4: 00000000001606e0
       Call Trace:
        event_trigger_callback+0xee/0x1d0
        event_trigger_write+0xfc/0x1a0
        __vfs_write+0x33/0x190
        ? handle_mm_fault+0x115/0x230
        ? _cond_resched+0x16/0x40
        vfs_write+0xb0/0x190
        ksys_write+0x52/0xc0
        do_syscall_64+0x5a/0x160
        entry_SYSCALL_64_after_hwframe+0x49/0xbe
       RIP: 0033:0x7f363e16ab50
       Code: 73 01 c3 48 8b 0d 38 83 2c 00 f7 d8 64 89 01 48 83 c8 ff c3 66 0f 1f 44 00 00 83 3d 79 db 2c 00 00 75 10 b8 01 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 31 c3 48 83 ec 08 e8 1e e3 01 00 48 89 04 24
       RSP: 002b:00007fff9a4c6378 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
       RAX: ffffffffffffffda RBX: 0000000000000009 RCX: 00007f363e16ab50
       RDX: 0000000000000009 RSI: 000055c1cacc8e10 RDI: 0000000000000001
       RBP: 000055c1cacc8e10 R08: 00007f363e435740 R09: 00007f363ea64700
       R10: 0000000000000073 R11: 0000000000000246 R12: 0000000000000009
       R13: 0000000000000001 R14: 00007f363e4345e0 R15: 00007f363e4303c0
       Modules linked in: ip6table_filter ip6_tables snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic snd_hda_intel snd_hda_codec snd_hwdep snd_hda_core snd_seq snd_seq_device i915 snd_pcm snd_timer i2c_i801 snd soundcore i2c_algo_bit drm_kms_helper
      86_pkg_temp_thermal video kvm_intel kvm irqbypass wmi e1000e
       ---[ end trace d301afa879ddfa25 ]---
      
      The cause is because the register_snapshot_trigger() call failed to
      allocate the snapshot buffer, and then called unregister_trigger()
      which freed the data that was passed to it. Then on return to the
      function that called register_snapshot_trigger(), as it sees it
      failed to register, it frees the trigger_data again and causes
      a double free.
      
      By calling event_trigger_init() on the trigger_data (which only ups
      the reference counter for it), and then event_trigger_free() afterward,
      the trigger_data would not get freed by the registering trigger function
      as it would only up and lower the ref count for it. If the register
      trigger function fails, then the event_trigger_free() called after it
      will free the trigger data normally.
      
      Link: http://lkml.kernel.org/r/20180724191331.738eb819@gandalf.local.home
      
      Cc: stable@vger.kerne.org
      Fixes: 93e31ffb ("tracing: Add 'snapshot' event trigger command")
      Reported-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Reviewed-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2a0ce1ff
    • Shakeel Butt's avatar
      kvm, mm: account shadow page tables to kmemcg · eb025250
      Shakeel Butt authored
      commit d97e5e61 upstream.
      
      The size of kvm's shadow page tables corresponds to the size of the
      guest virtual machines on the system.  Large VMs can spend a significant
      amount of memory as shadow page tables which can not be left as system
      memory overhead.  So, account shadow page tables to the kmemcg.
      
      [shakeelb@google.com: replace (GFP_KERNEL|__GFP_ACCOUNT) with GFP_KERNEL_ACCOUNT]
        Link: http://lkml.kernel.org/r/20180629140224.205849-1-shakeelb@google.com
      Link: http://lkml.kernel.org/r/20180627181349.149778-1-shakeelb@google.comSigned-off-by: default avatarShakeel Butt <shakeelb@google.com>
      Cc: Michal Hocko <mhocko@kernel.org>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Greg Thelen <gthelen@google.com>
      Cc: Radim Krčmář <rkrcmar@redhat.com>
      Cc: Peter Feiner <pfeiner@google.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>
      eb025250
    • KT Liao's avatar
      Input: elan_i2c - add another ACPI ID for Lenovo Ideapad 330-15AST · 6ed569ed
      KT Liao authored
      commit 6f88a643 upstream.
      
      Add ELAN0622 to ACPI mapping table to support Elan touchpad found in
      Ideapad 330-15AST.
      Signed-off-by: default avatarKT Liao <kt.liao@emc.com.tw>
      Reported-by: default avatarAnant Shende <anantshende@gmail.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6ed569ed
    • Chen-Yu Tsai's avatar
      Input: i8042 - add Lenovo LaVie Z to the i8042 reset list · 79f4095a
      Chen-Yu Tsai authored
      commit 384cf428 upstream.
      
      The Lenovo LaVie Z laptop requires i8042 to be reset in order to
      consistently detect its Elantech touchpad. The nomux and kbdreset
      quirks are not sufficient.
      
      It's possible the other LaVie Z models from NEC require this as well.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarChen-Yu Tsai <wens@csie.org>
      Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      79f4095a
    • Donald Shanty III's avatar
      Input: elan_i2c - add ACPI ID for lenovo ideapad 330 · 19e28842
      Donald Shanty III authored
      commit 938f4500 upstream.
      
      This allows Elan driver to bind to the touchpad found in Lenovo Ideapad 330
      series laptops.
      Signed-off-by: default avatarDonald Shanty III <dshanty@protonmail.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      19e28842
  2. 28 Jul, 2018 11 commits
    • Greg Kroah-Hartman's avatar
      Linux 4.9.116 · 94c67449
      Greg Kroah-Hartman authored
      94c67449
    • Arnd Bergmann's avatar
      exec: avoid gcc-8 warning for get_task_comm · b9dd1348
      Arnd Bergmann authored
      commit 3756f640 upstream.
      
      gcc-8 warns about using strncpy() with the source size as the limit:
      
        fs/exec.c:1223:32: error: argument to 'sizeof' in 'strncpy' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
      
      This is indeed slightly suspicious, as it protects us from source
      arguments without NUL-termination, but does not guarantee that the
      destination is terminated.
      
      This keeps the strncpy() to ensure we have properly padded target
      buffer, but ensures that we use the correct length, by passing the
      actual length of the destination buffer as well as adding a build-time
      check to ensure it is exactly TASK_COMM_LEN.
      
      There are only 23 callsites which I all reviewed to ensure this is
      currently the case.  We could get away with doing only the check or
      passing the right length, but it doesn't hurt to do both.
      
      Link: http://lkml.kernel.org/r/20171205151724.1764896-1-arnd@arndb.deSigned-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Suggested-by: default avatarKees Cook <keescook@chromium.org>
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Acked-by: default avatarIngo Molnar <mingo@kernel.org>
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Serge Hallyn <serge@hallyn.com>
      Cc: James Morris <james.l.morris@oracle.com>
      Cc: Aleksa Sarai <asarai@suse.de>
      Cc: "Eric W. Biederman" <ebiederm@xmission.com>
      Cc: Frederic Weisbecker <frederic@kernel.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      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>
      b9dd1348
    • Arnd Bergmann's avatar
      turn off -Wattribute-alias · b1a1d9bd
      Arnd Bergmann authored
      Starting with gcc-8.1, we get a warning about all system call definitions,
      which use an alias between functions with incompatible prototypes, e.g.:
      
      In file included from ../mm/process_vm_access.c:19:
      ../include/linux/syscalls.h:211:18: warning: 'sys_process_vm_readv' alias between functions of incompatible types 'long int(pid_t,  const struct iovec *, long unsigned int,  const struct iovec *, long unsigned int,  long unsigned int)' {aka 'long int(int,  const struct iovec *, long unsigned int,  const struct iovec *, long unsigned int,  long unsigned int)'} and 'long int(long int,  long int,  long int,  long int,  long int,  long int)' [-Wattribute-alias]
        asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
                        ^~~
      ../include/linux/syscalls.h:207:2: note: in expansion of macro '__SYSCALL_DEFINEx'
        __SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
        ^~~~~~~~~~~~~~~~~
      ../include/linux/syscalls.h:201:36: note: in expansion of macro 'SYSCALL_DEFINEx'
       #define SYSCALL_DEFINE6(name, ...) SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
                                          ^~~~~~~~~~~~~~~
      ../mm/process_vm_access.c:300:1: note: in expansion of macro 'SYSCALL_DEFINE6'
       SYSCALL_DEFINE6(process_vm_readv, pid_t, pid, const struct iovec __user *, lvec,
       ^~~~~~~~~~~~~~~
      ../include/linux/syscalls.h:215:18: note: aliased declaration here
        asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
                        ^~~
      ../include/linux/syscalls.h:207:2: note: in expansion of macro '__SYSCALL_DEFINEx'
        __SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
        ^~~~~~~~~~~~~~~~~
      ../include/linux/syscalls.h:201:36: note: in expansion of macro 'SYSCALL_DEFINEx'
       #define SYSCALL_DEFINE6(name, ...) SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
                                          ^~~~~~~~~~~~~~~
      ../mm/process_vm_access.c:300:1: note: in expansion of macro 'SYSCALL_DEFINE6'
       SYSCALL_DEFINE6(process_vm_readv, pid_t, pid, const struct iovec __user *, lvec,
      
      This is really noisy and does not indicate a real problem. In the latest
      mainline kernel, this was addressed by commit bee20031 ("disable
      -Wattribute-alias warning for SYSCALL_DEFINEx()"), which seems too invasive
      to backport.
      
      This takes a much simpler approach and just disables the warning across the
      kernel.
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b1a1d9bd
    • Anssi Hannula's avatar
      can: xilinx_can: fix RX overflow interrupt not being enabled · b2019f0f
      Anssi Hannula authored
      commit 83997997 upstream.
      
      RX overflow interrupt (RXOFLW) is disabled even though xcan_interrupt()
      processes it. This means that an RX overflow interrupt will only be
      processed when another interrupt gets asserted (e.g. for RX/TX).
      
      Fix that by enabling the RXOFLW interrupt.
      
      Fixes: b1201e44 ("can: xilinx CAN controller support")
      Signed-off-by: default avatarAnssi Hannula <anssi.hannula@bitwise.fi>
      Cc: Michal Simek <michal.simek@xilinx.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b2019f0f
    • Anssi Hannula's avatar
      can: xilinx_can: fix incorrect clear of non-processed interrupts · 9f730843
      Anssi Hannula authored
      commit 2f4f0f33 upstream.
      
      xcan_interrupt() clears ERROR|RXOFLV|BSOFF|ARBLST interrupts if any of
      them is asserted. This does not take into account that some of them
      could have been asserted between interrupt status read and interrupt
      clear, therefore clearing them without handling them.
      
      Fix the code to only clear those interrupts that it knows are asserted
      and therefore going to be processed in xcan_err_interrupt().
      
      Fixes: b1201e44 ("can: xilinx CAN controller support")
      Signed-off-by: default avatarAnssi Hannula <anssi.hannula@bitwise.fi>
      Cc: Michal Simek <michal.simek@xilinx.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9f730843
    • Anssi Hannula's avatar
      can: xilinx_can: keep only 1-2 frames in TX FIFO to fix TX accounting · bee7ff7e
      Anssi Hannula authored
      commit 620050d9 upstream.
      
      The xilinx_can driver assumes that the TXOK interrupt only clears after
      it has been acknowledged as many times as there have been successfully
      sent frames.
      
      However, the documentation does not mention such behavior, instead
      saying just that the interrupt is cleared when the clear bit is set.
      
      Similarly, testing seems to also suggest that it is immediately cleared
      regardless of the amount of frames having been sent. Performing some
      heavy TX load and then going back to idle has the tx_head drifting
      further away from tx_tail over time, steadily reducing the amount of
      frames the driver keeps in the TX FIFO (but not to zero, as the TXOK
      interrupt always frees up space for 1 frame from the driver's
      perspective, so frames continue to be sent) and delaying the local echo
      frames.
      
      The TX FIFO tracking is also otherwise buggy as it does not account for
      TX FIFO being cleared after software resets, causing
        BUG!, TX FIFO full when queue awake!
      messages to be output.
      
      There does not seem to be any way to accurately track the state of the
      TX FIFO for local echo support while using the full TX FIFO.
      
      The Zynq version of the HW (but not the soft-AXI version) has watermark
      programming support and with it an additional TX-FIFO-empty interrupt
      bit.
      
      Modify the driver to only put 1 frame into TX FIFO at a time on soft-AXI
      and 2 frames at a time on Zynq. On Zynq the TXFEMP interrupt bit is used
      to detect whether 1 or 2 frames have been sent at interrupt processing
      time.
      
      Tested with the integrated CAN on Zynq-7000 SoC. The 1-frame-FIFO mode
      was also tested.
      
      An alternative way to solve this would be to drop local echo support but
      keep using the full TX FIFO.
      
      v2: Add FIFO space check before TX queue wake with locking to
      synchronize with queue stop. This avoids waking the queue when xmit()
      had just filled it.
      
      v3: Keep local echo support and reduce the amount of frames in FIFO
      instead as suggested by Marc Kleine-Budde.
      
      Fixes: b1201e44 ("can: xilinx CAN controller support")
      Signed-off-by: default avatarAnssi Hannula <anssi.hannula@bitwise.fi>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bee7ff7e
    • Anssi Hannula's avatar
      can: xilinx_can: fix device dropping off bus on RX overrun · 1fd9fa57
      Anssi Hannula authored
      commit 2574fe54 upstream.
      
      The xilinx_can driver performs a software reset when an RX overrun is
      detected. This causes the device to enter Configuration mode where no
      messages are received or transmitted.
      
      The documentation does not mention any need to perform a reset on an RX
      overrun, and testing by inducing an RX overflow also indicated that the
      device continues to work just fine without a reset.
      
      Remove the software reset.
      
      Tested with the integrated CAN on Zynq-7000 SoC.
      
      Fixes: b1201e44 ("can: xilinx CAN controller support")
      Signed-off-by: default avatarAnssi Hannula <anssi.hannula@bitwise.fi>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1fd9fa57
    • Anssi Hannula's avatar
      can: xilinx_can: fix recovery from error states not being propagated · c98f5772
      Anssi Hannula authored
      commit 877e0b75 upstream.
      
      The xilinx_can driver contains no mechanism for propagating recovery
      from CAN_STATE_ERROR_WARNING and CAN_STATE_ERROR_PASSIVE.
      
      Add such a mechanism by factoring the handling of
      XCAN_STATE_ERROR_PASSIVE and XCAN_STATE_ERROR_WARNING out of
      xcan_err_interrupt and checking for recovery after RX and TX if the
      interface is in one of those states.
      
      Tested with the integrated CAN on Zynq-7000 SoC.
      
      Fixes: b1201e44 ("can: xilinx CAN controller support")
      Signed-off-by: default avatarAnssi Hannula <anssi.hannula@bitwise.fi>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c98f5772
    • Anssi Hannula's avatar
      can: xilinx_can: fix power management handling · 1fadfbd9
      Anssi Hannula authored
      commit 8ebd83bd upstream.
      
      There are several issues with the suspend/resume handling code of the
      driver:
      
      - The device is attached and detached in the runtime_suspend() and
        runtime_resume() callbacks if the interface is running. However,
        during xcan_chip_start() the interface is considered running,
        causing the resume handler to incorrectly call netif_start_queue()
        at the beginning of xcan_chip_start(), and on xcan_chip_start() error
        return the suspend handler detaches the device leaving the user
        unable to bring-up the device anymore.
      
      - The device is not brought properly up on system resume. A reset is
        done and the code tries to determine the bus state after that.
        However, after reset the device is always in Configuration mode
        (down), so the state checking code does not make sense and
        communication will also not work.
      
      - The suspend callback tries to set the device to sleep mode (low-power
        mode which monitors the bus and brings the device back to normal mode
        on activity), but then immediately disables the clocks (possibly
        before the device reaches the sleep mode), which does not make sense
        to me. If a clean shutdown is wanted before disabling clocks, we can
        just bring it down completely instead of only sleep mode.
      
      Reorganize the PM code so that only the clock logic remains in the
      runtime PM callbacks and the system PM callbacks contain the device
      bring-up/down logic. This makes calling the runtime PM callbacks during
      e.g. xcan_chip_start() safe.
      
      The system PM callbacks now simply call common code to start/stop the
      HW if the interface was running, replacing the broken code from before.
      
      xcan_chip_stop() is updated to use the common reset code so that it will
      wait for the reset to complete. Reset also disables all interrupts so do
      not do that separately.
      
      Also, the device_may_wakeup() checks are removed as the driver does not
      have wakeup support.
      
      Tested on Zynq-7000 integrated CAN.
      Signed-off-by: default avatarAnssi Hannula <anssi.hannula@bitwise.fi>
      Cc: Michal Simek <michal.simek@xilinx.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1fadfbd9
    • Anssi Hannula's avatar
      can: xilinx_can: fix RX loop if RXNEMP is asserted without RXOK · de2219a8
      Anssi Hannula authored
      commit 32852c56 upstream.
      
      If the device gets into a state where RXNEMP (RX FIFO not empty)
      interrupt is asserted without RXOK (new frame received successfully)
      interrupt being asserted, xcan_rx_poll() will continue to try to clear
      RXNEMP without actually reading frames from RX FIFO. If the RX FIFO is
      not empty, the interrupt will not be cleared and napi_schedule() will
      just be called again.
      
      This situation can occur when:
      
      (a) xcan_rx() returns without reading RX FIFO due to an error condition.
      The code tries to clear both RXOK and RXNEMP but RXNEMP will not clear
      due to a frame still being in the FIFO. The frame will never be read
      from the FIFO as RXOK is no longer set.
      
      (b) A frame is received between xcan_rx_poll() reading interrupt status
      and clearing RXOK. RXOK will be cleared, but RXNEMP will again remain
      set as the new message is still in the FIFO.
      
      I'm able to trigger case (b) by flooding the bus with frames under load.
      
      There does not seem to be any benefit in using both RXNEMP and RXOK in
      the way the driver does, and the polling example in the reference manual
      (UG585 v1.10 18.3.7 Read Messages from RxFIFO) also says that either
      RXOK or RXNEMP can be used for detecting incoming messages.
      
      Fix the issue and simplify the RX processing by only using RXNEMP
      without RXOK.
      
      Tested with the integrated CAN on Zynq-7000 SoC.
      
      Fixes: b1201e44 ("can: xilinx CAN controller support")
      Signed-off-by: default avatarAnssi Hannula <anssi.hannula@bitwise.fi>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      de2219a8
    • Rafael J. Wysocki's avatar
      driver core: Partially revert "driver core: correct device's shutdown order" · bf0070e2
      Rafael J. Wysocki authored
      commit 722e5f2b upstream.
      
      Commit 52cdbdd4 (driver core: correct device's shutdown order)
      introduced a regression by breaking device shutdown on some systems.
      
      Namely, the devices_kset_move_last() call in really_probe() added by
      that commit is a mistake as it may cause parents to follow children
      in the devices_kset list which then causes shutdown to fail.  For
      example, if a device has children before really_probe() is called
      for it (which is not uncommon), that call will cause it to be
      reordered after the children in the devices_kset list and the
      ordering of that list will not reflect the correct device shutdown
      order any more.
      
      Also it causes the devices_kset list to be constantly reordered
      until all drivers have been probed which is totally pointless
      overhead in the majority of cases and it only covered an issue
      with system shutdown, while system-wide suspend/resume potentially
      had the same issue on the affected platforms (which was not covered).
      
      Moreover, the shutdown issue originally addressed by the change in
      really_probe() made by commit 52cdbdd4 is not present in 4.18-rc
      any more, since dra7 started to use the sdhci-omap driver which
      doesn't disable any regulators during shutdown, so the really_probe()
      part of commit 52cdbdd4 can be safely reverted.  [The original
      issue was related to the omap_hsmmc driver used by dra7 previously.]
      
      For the above reasons, revert the really_probe() modifications made
      by commit 52cdbdd4.
      
      The other code changes made by commit 52cdbdd4 are useful and
      they need not be reverted.
      
      Fixes: 52cdbdd4 (driver core: correct device's shutdown order)
      Link: https://lore.kernel.org/lkml/CAFgQCTt7VfqM=UyCnvNFxrSw8Z6cUtAi3HUwR4_xPAc03SgHjQ@mail.gmail.com/Reported-by: default avatarPingfan Liu <kernelfans@gmail.com>
      Tested-by: default avatarPingfan Liu <kernelfans@gmail.com>
      Reviewed-by: default avatarKishon Vijay Abraham I <kishon@ti.com>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bf0070e2