1. 27 May, 2020 40 commits
    • Colin Ian King's avatar
      platform/x86: alienware-wmi: fix kfree on potentially uninitialized pointer · 5307944a
      Colin Ian King authored
      commit 98e26302 upstream.
      
      Currently the kfree of output.pointer can be potentially freeing
      an uninitalized pointer in the case where out_data is NULL. Fix this
      by reworking the case where out_data is not-null to perform the
      ACPI status check and also the kfree of outpoint.pointer in one block
      and hence ensuring the pointer is only freed when it has been used.
      
      Also replace the if (ptr != NULL) idiom with just if (ptr).
      
      Fixes: ff0e9f26 ("platform/x86: alienware-wmi: Correct a memory leak")
      Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
      Signed-off-by: default avatarDarren Hart (VMware) <dvhart@infradead.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5307944a
    • Arnd Bergmann's avatar
      ubsan: build ubsan.c more conservatively · eff8c033
      Arnd Bergmann authored
      commit af700eae upstream.
      
      objtool points out several conditions that it does not like, depending
      on the combination with other configuration options and compiler
      variants:
      
      stack protector:
        lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch()+0xbf: call to __stack_chk_fail() with UACCESS enabled
        lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch_v1()+0xbe: call to __stack_chk_fail() with UACCESS enabled
      
      stackleak plugin:
        lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch()+0x4a: call to stackleak_track_stack() with UACCESS enabled
        lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch_v1()+0x4a: call to stackleak_track_stack() with UACCESS enabled
      
      kasan:
        lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch()+0x25: call to memcpy() with UACCESS enabled
        lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch_v1()+0x25: call to memcpy() with UACCESS enabled
      
      The stackleak and kasan options just need to be disabled for this file
      as we do for other files already.  For the stack protector, we already
      attempt to disable it, but this fails on clang because the check is
      mixed with the gcc specific -fno-conserve-stack option.  According to
      Andrey Ryabinin, that option is not even needed, dropping it here fixes
      the stackprotector issue.
      
      Link: http://lkml.kernel.org/r/20190722125139.1335385-1-arnd@arndb.de
      Link: https://lore.kernel.org/lkml/20190617123109.667090-1-arnd@arndb.de/t/
      Link: https://lore.kernel.org/lkml/20190722091050.2188664-1-arnd@arndb.de/t/
      Fixes: d08965a2 ("x86/uaccess, ubsan: Fix UBSAN vs. SMAP")
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Reviewed-by: default avatarAndrey Ryabinin <aryabinin@virtuozzo.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.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>
      eff8c033
    • Peter Zijlstra's avatar
      x86/uaccess, ubsan: Fix UBSAN vs. SMAP · bd44630a
      Peter Zijlstra authored
      commit d08965a2 upstream.
      
      UBSAN can insert extra code in random locations; including AC=1
      sections. Typically this code is not safe and needs wrapping.
      
      So far, only __ubsan_handle_type_mismatch* have been observed in AC=1
      sections and therefore only those are annotated.
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      [stable backport: only take the lib/Makefile change to resolve gcc-10
       build issues]
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bd44630a
    • R. Parameswaran's avatar
      l2tp: device MTU setup, tunnel socket needs a lock · e6cfc109
      R. Parameswaran authored
      commit 57240d00 upstream.
      
      The MTU overhead calculation in L2TP device set-up
      merged via commit b784e7eb
      needs to be adjusted to lock the tunnel socket while
      referencing the sub-data structures to derive the
      socket's IP overhead.
      Reported-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Tested-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarR. Parameswaran <rparames@brocade.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Cc: Giuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e6cfc109
    • Christophe JAILLET's avatar
      dmaengine: tegra210-adma: Fix an error handling path in 'tegra_adma_probe()' · 6ec8ac2b
      Christophe JAILLET authored
      commit 3a5fd0db upstream.
      
      Commit b53611fb ("dmaengine: tegra210-adma: Fix crash during probe")
      has moved some code in the probe function and reordered the error handling
      path accordingly.
      However, a goto has been missed.
      
      Fix it and goto the right label if 'dma_async_device_register()' fails, so
      that all resources are released.
      
      Fixes: b53611fb ("dmaengine: tegra210-adma: Fix crash during probe")
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Reviewed-by: default avatarJon Hunter <jonathanh@nvidia.com>
      Acked-by: default avatarThierry Reding <treding@nvidia.com>
      Link: https://lore.kernel.org/r/20200516214205.276266-1-christophe.jaillet@wanadoo.frSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6ec8ac2b
    • Brent Lu's avatar
      ALSA: pcm: fix incorrect hw_base increase · bf77564f
      Brent Lu authored
      commit e7513c57 upstream.
      
      There is a corner case that ALSA keeps increasing the hw_ptr but DMA
      already stop working/updating the position for a long time.
      
      In following log we can see the position returned from DMA driver does
      not move at all but the hw_ptr got increased at some point of time so
      snd_pcm_avail() will return a large number which seems to be a buffer
      underrun event from user space program point of view. The program
      thinks there is space in the buffer and fill more data.
      
      [  418.510086] sound pcmC0D5p: pos 96 hw_ptr 96 appl_ptr 4096 avail 12368
      [  418.510149] sound pcmC0D5p: pos 96 hw_ptr 96 appl_ptr 6910 avail 9554
      ...
      [  418.681052] sound pcmC0D5p: pos 96 hw_ptr 96 appl_ptr 15102 avail 1362
      [  418.681130] sound pcmC0D5p: pos 96 hw_ptr 96 appl_ptr 16464 avail 0
      [  418.726515] sound pcmC0D5p: pos 96 hw_ptr 16464 appl_ptr 16464 avail 16368
      
      This is because the hw_base will be increased by runtime->buffer_size
      frames unconditionally if the hw_ptr is not updated for over half of
      buffer time. As the hw_base increases, so does the hw_ptr increased
      by the same number.
      
      The avail value returned from snd_pcm_avail() could exceed the limit
      (buffer_size) easily becase the hw_ptr itself got increased by same
      buffer_size samples when the corner case happens. In following log,
      the buffer_size is 16368 samples but the avail is 21810 samples so
      CRAS server complains about it.
      
      [  418.851755] sound pcmC0D5p: pos 96 hw_ptr 16464 appl_ptr 27390 avail 5442
      [  418.926491] sound pcmC0D5p: pos 96 hw_ptr 32832 appl_ptr 27390 avail 21810
      
      cras_server[1907]: pcm_avail returned frames larger than buf_size:
      sof-glkda7219max: :0,5: 21810 > 16368
      
      By updating runtime->hw_ptr_jiffies each time the HWSYNC is called,
      the hw_base will keep the same when buffer stall happens at long as
      the interval between each HWSYNC call is shorter than half of buffer
      time.
      
      Following is a log captured by a patched kernel. The hw_base/hw_ptr
      value is fixed in this corner case and user space program should be
      aware of the buffer stall and handle it.
      
      [  293.525543] sound pcmC0D5p: pos 96 hw_ptr 96 appl_ptr 4096 avail 12368
      [  293.525606] sound pcmC0D5p: pos 96 hw_ptr 96 appl_ptr 6880 avail 9584
      [  293.525975] sound pcmC0D5p: pos 96 hw_ptr 96 appl_ptr 10976 avail 5488
      [  293.611178] sound pcmC0D5p: pos 96 hw_ptr 96 appl_ptr 15072 avail 1392
      [  293.696429] sound pcmC0D5p: pos 96 hw_ptr 96 appl_ptr 16464 avail 0
      ...
      [  381.139517] sound pcmC0D5p: pos 96 hw_ptr 96 appl_ptr 16464 avail 0
      Signed-off-by: default avatarBrent Lu <brent.lu@intel.com>
      Reviewed-by: default avatarJaroslav Kysela <perex@perex.cz>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/1589776238-23877-1-git-send-email-brent.lu@intel.comSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bf77564f
    • Guillaume Nault's avatar
      l2tp: initialise PPP sessions before registering them · ad6c13e2
      Guillaume Nault authored
      commit f98be6c6 upstream.
      
      pppol2tp_connect() initialises L2TP sessions after they've been exposed
      to the rest of the system by l2tp_session_register(). This puts
      sessions into transient states that are the source of several races, in
      particular with session's deletion path.
      
      This patch centralises the initialisation code into
      pppol2tp_session_init(), which is called before the registration phase.
      The only field that can't be set before session registration is the
      pppol2tp socket pointer, which has already been converted to RCU. So
      pppol2tp_connect() should now be race-free.
      
      The session's .session_close() callback is now set before registration.
      Therefore, it's always called when l2tp_core deletes the session, even
      if it was created by pppol2tp_session_create() and hasn't been plugged
      to a pppol2tp socket yet. That'd prevent session free because the extra
      reference taken by pppol2tp_session_close() wouldn't be dropped by the
      socket's ->sk_destruct() callback (pppol2tp_session_destruct()).
      We could set .session_close() only while connecting a session to its
      pppol2tp socket, or teach pppol2tp_session_close() to avoid grabbing a
      reference when the session isn't connected, but that'd require adding
      some form of synchronisation to be race free.
      
      Instead of that, we can just let the pppol2tp socket hold a reference
      on the session as soon as it starts depending on it (that is, in
      pppol2tp_connect()). Then we don't need to utilise
      pppol2tp_session_close() to hold a reference at the last moment to
      prevent l2tp_core from dropping it.
      
      When releasing the socket, pppol2tp_release() now deletes the session
      using the standard l2tp_session_delete() function, instead of merely
      removing it from hash tables. l2tp_session_delete() drops the reference
      the sessions holds on itself, but also makes sure it doesn't remove a
      session twice. So it can safely be called, even if l2tp_core already
      tried, or is concurrently trying, to remove the session.
      Finally, pppol2tp_session_destruct() drops the reference held by the
      socket.
      
      Fixes: fd558d18 ("l2tp: Split pppol2tp patch into separate l2tp and ppp parts")
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ad6c13e2
    • Guillaume Nault's avatar
      l2tp: protect sock pointer of struct pppol2tp_session with RCU · 5803ecd7
      Guillaume Nault authored
      commit ee40fb2e upstream.
      
      pppol2tp_session_create() registers sessions that can't have their
      corresponding socket initialised. This socket has to be created by
      userspace, then connected to the session by pppol2tp_connect().
      Therefore, we need to protect the pppol2tp socket pointer of L2TP
      sessions, so that it can safely be updated when userspace is connecting
      or closing the socket. This will eventually allow pppol2tp_connect()
      to avoid generating transient states while initialising its parts of the
      session.
      
      To this end, this patch protects the pppol2tp socket pointer using RCU.
      
      The pppol2tp socket pointer is still set in pppol2tp_connect(), but
      only once we know the function isn't going to fail. It's eventually
      reset by pppol2tp_release(), which now has to wait for a grace period
      to elapse before it can drop the last reference on the socket. This
      ensures that pppol2tp_session_get_sock() can safely grab a reference
      on the socket, even after ps->sk is reset to NULL but before this
      operation actually gets visible from pppol2tp_session_get_sock().
      
      The rest is standard RCU conversion: pppol2tp_recv(), which already
      runs in atomic context, is simply enclosed by rcu_read_lock() and
      rcu_read_unlock(), while other functions are converted to use
      pppol2tp_session_get_sock() followed by sock_put().
      pppol2tp_session_setsockopt() is a special case. It used to retrieve
      the pppol2tp socket from the L2TP session, which itself was retrieved
      from the pppol2tp socket. Therefore we can just avoid dereferencing
      ps->sk and directly use the original socket pointer instead.
      
      With all users of ps->sk now handling NULL and concurrent updates, the
      L2TP ->ref() and ->deref() callbacks aren't needed anymore. Therefore,
      rather than converting pppol2tp_session_sock_hold() and
      pppol2tp_session_sock_put(), we can just drop them.
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5803ecd7
    • Guillaume Nault's avatar
      l2tp: initialise l2tp_eth sessions before registering them · 96985edd
      Guillaume Nault authored
      commit ee28de6b upstream.
      
      Sessions must be initialised before being made externally visible by
      l2tp_session_register(). Otherwise the session may be concurrently
      deleted before being initialised, which can confuse the deletion path
      and eventually lead to kernel oops.
      
      Therefore, we need to move l2tp_session_register() down in
      l2tp_eth_create(), but also handle the intermediate step where only the
      session or the netdevice has been registered.
      
      We can't just call l2tp_session_register() in ->ndo_init() because
      we'd have no way to properly undo this operation in ->ndo_uninit().
      Instead, let's register the session and the netdevice in two different
      steps and protect the session's device pointer with RCU.
      
      And now that we allow the session's .dev field to be NULL, we don't
      need to prevent the netdevice from being removed anymore. So we can
      drop the dev_hold() and dev_put() calls in l2tp_eth_create() and
      l2tp_eth_dev_uninit().
      
      Backporting Notes
      
      l2tp_eth.c: In l2tp_eth_create the "out" label was renamed to "err".
      There was one extra occurrence of "goto out" to update.
      
      Fixes: d9e31d17 ("l2tp: Add L2TP ethernet pseudowire support")
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      96985edd
    • Guillaume Nault's avatar
      l2tp: don't register sessions in l2tp_session_create() · 12b5fb58
      Guillaume Nault authored
      commit 3953ae7b upstream.
      
      Sessions created by l2tp_session_create() aren't fully initialised:
      some pseudo-wire specific operations need to be done before making the
      session usable. Therefore the PPP and Ethernet pseudo-wires continue
      working on the returned l2tp session while it's already been exposed to
      the rest of the system.
      This can lead to various issues. In particular, the session may enter
      the deletion process before having been fully initialised, which will
      confuse the session removal code.
      
      This patch moves session registration out of l2tp_session_create(), so
      that callers can control when the session is exposed to the rest of the
      system. This is done by the new l2tp_session_register() function.
      
      Only pppol2tp_session_create() can be easily converted to avoid
      modifying its session after registration (the debug message is dropped
      in order to avoid the need for holding a reference on the session).
      
      For pppol2tp_connect() and l2tp_eth_create()), more work is needed.
      That'll be done in followup patches. For now, let's just register the
      session right after its creation, like it was done before. The only
      difference is that we can easily take a reference on the session before
      registering it, so, at least, we're sure it's not going to be freed
      while we're working on it.
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      12b5fb58
    • Guillaume Nault's avatar
      l2tp: fix l2tp_eth module loading · 1ede832f
      Guillaume Nault authored
      commit 9f775ead upstream.
      
      The l2tp_eth module crashes if its netlink callbacks are run when the
      pernet data aren't initialised.
      
      We should normally register_pernet_device() before the genl callbacks.
      However, the pernet data only maintain a list of l2tpeth interfaces,
      and this list is never used. So let's just drop pernet handling
      instead.
      
      Fixes: d9e31d17 ("l2tp: Add L2TP ethernet pseudowire support")
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1ede832f
    • Guillaume Nault's avatar
      l2tp: pass tunnel pointer to ->session_create() · feaed88d
      Guillaume Nault authored
      commit f026bc29 upstream.
      
      Using l2tp_tunnel_find() in pppol2tp_session_create() and
      l2tp_eth_create() is racy, because no reference is held on the
      returned session. These functions are only used to implement the
      ->session_create callback which is run by l2tp_nl_cmd_session_create().
      Therefore searching for the parent tunnel isn't necessary because
      l2tp_nl_cmd_session_create() already has a pointer to it and holds a
      reference.
      
      This patch modifies ->session_create()'s prototype to directly pass the
      the parent tunnel as parameter, thus avoiding searching for it in
      pppol2tp_session_create() and l2tp_eth_create().
      
      Since we have to touch the ->session_create() call in
      l2tp_nl_cmd_session_create(), let's also remove the useless conditional:
      we know that ->session_create isn't NULL at this point because it's
      already been checked earlier in this same function.
      
      Finally, one might be tempted to think that the removed
      l2tp_tunnel_find() calls were harmless because they would return the
      same tunnel as the one held by l2tp_nl_cmd_session_create() anyway.
      But that tunnel might be removed and a new one created with same tunnel
      Id before the l2tp_tunnel_find() call. In this case l2tp_tunnel_find()
      would return the new tunnel which wouldn't be protected by the
      reference held by l2tp_nl_cmd_session_create().
      
      Fixes: 309795f4 ("l2tp: Add netlink control API for L2TP")
      Fixes: d9e31d17 ("l2tp: Add L2TP ethernet pseudowire support")
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      feaed88d
    • Guillaume Nault's avatar
      l2tp: prevent creation of sessions on terminated tunnels · 880cd40d
      Guillaume Nault authored
      commit f3c66d4e upstream.
      
      l2tp_tunnel_destruct() sets tunnel->sock to NULL, then removes the
      tunnel from the pernet list and finally closes all its sessions.
      Therefore, it's possible to add a session to a tunnel that is still
      reachable, but for which tunnel->sock has already been reset. This can
      make l2tp_session_create() dereference a NULL pointer when calling
      sock_hold(tunnel->sock).
      
      This patch adds the .acpt_newsess field to struct l2tp_tunnel, which is
      used by l2tp_tunnel_closeall() to prevent addition of new sessions to
      tunnels. Resetting tunnel->sock is done after l2tp_tunnel_closeall()
      returned, so that l2tp_session_add_to_tunnel() can safely take a
      reference on it when .acpt_newsess is true.
      
      The .acpt_newsess field is modified in l2tp_tunnel_closeall(), rather
      than in l2tp_tunnel_destruct(), so that it benefits all tunnel removal
      mechanisms. E.g. on UDP tunnels, a session could be added to a tunnel
      after l2tp_udp_encap_destroy() proceeded. This would prevent the tunnel
      from being removed because of the references held by this new session
      on the tunnel and its socket. Even though the session could be removed
      manually later on, this defeats the purpose of
      commit 9980d001 ("l2tp: add udp encap socket destroy handler").
      
      Fixes: fd558d18 ("l2tp: Split pppol2tp patch into separate l2tp and ppp parts")
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      880cd40d
    • Guillaume Nault's avatar
      l2tp: hold tunnel used while creating sessions with netlink · e20c980a
      Guillaume Nault authored
      commit e702c120 upstream.
      
      Use l2tp_tunnel_get() to retrieve tunnel, so that it can't go away on
      us. Otherwise l2tp_tunnel_destruct() might release the last reference
      count concurrently, thus freeing the tunnel while we're using it.
      
      Fixes: 309795f4 ("l2tp: Add netlink control API for L2TP")
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e20c980a
    • Guillaume Nault's avatar
      l2tp: hold tunnel while handling genl TUNNEL_GET commands · 4c15cdb9
      Guillaume Nault authored
      commit 4e4b21da upstream.
      
      Use l2tp_tunnel_get() instead of l2tp_tunnel_find() so that we get
      a reference on the tunnel, preventing l2tp_tunnel_destruct() from
      freeing it from under us.
      
      Also move l2tp_tunnel_get() below nlmsg_new() so that we only take
      the reference when needed.
      
      Fixes: 309795f4 ("l2tp: Add netlink control API for L2TP")
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4c15cdb9
    • Guillaume Nault's avatar
      l2tp: hold tunnel while handling genl tunnel updates · 00cf4055
      Guillaume Nault authored
      commit 8c0e4215 upstream.
      
      We need to make sure the tunnel is not going to be destroyed by
      l2tp_tunnel_destruct() concurrently.
      
      Fixes: 309795f4 ("l2tp: Add netlink control API for L2TP")
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      00cf4055
    • Guillaume Nault's avatar
      l2tp: hold tunnel while processing genl delete command · 0b21fa70
      Guillaume Nault authored
      commit bb0a32ce upstream.
      
      l2tp_nl_cmd_tunnel_delete() needs to take a reference on the tunnel, to
      prevent it from being concurrently freed by l2tp_tunnel_destruct().
      
      Fixes: 309795f4 ("l2tp: Add netlink control API for L2TP")
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0b21fa70
    • Guillaume Nault's avatar
      l2tp: hold tunnel while looking up sessions in l2tp_netlink · 523e6d7f
      Guillaume Nault authored
      commit 54652eb1 upstream.
      
      l2tp_tunnel_find() doesn't take a reference on the returned tunnel.
      Therefore, it's unsafe to use it because the returned tunnel can go
      away on us anytime.
      
      Fix this by defining l2tp_tunnel_get(), which works like
      l2tp_tunnel_find(), but takes a reference on the returned tunnel.
      Caller then has to drop this reference using l2tp_tunnel_dec_refcount().
      
      As l2tp_tunnel_dec_refcount() needs to be moved to l2tp_core.h, let's
      simplify the patch and not move the L2TP_REFCNT_DEBUG part. This code
      has been broken (not even compiling) in May 2012 by
      commit a4ca44fa ("net: l2tp: Standardize logging styles")
      and fixed more than two years later by
      commit 29abe2fd ("l2tp: fix missing line continuation"). So it
      doesn't appear to be used by anyone.
      
      Same thing for l2tp_tunnel_free(); instead of moving it to l2tp_core.h,
      let's just simplify things and call kfree_rcu() directly in
      l2tp_tunnel_dec_refcount(). Extra assertions and debugging code
      provided by l2tp_tunnel_free() didn't help catching any of the
      reference counting and socket handling issues found while working on
      this series.
      
      Backporting Notes
      
      l2tp_core.c: This patch deletes some code / moves some code to
      l2tp_core.h and follows the patch (not including in this series) that
      switched from atomic to refcount_t. Moved code changed back to atomic.
      
      Fixes: 309795f4 ("l2tp: Add netlink control API for L2TP")
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      523e6d7f
    • Guillaume Nault's avatar
      l2tp: initialise session's refcount before making it reachable · 11a08372
      Guillaume Nault authored
      commit 9ee369a4 upstream.
      
      Sessions must be fully initialised before calling
      l2tp_session_add_to_tunnel(). Otherwise, there's a short time frame
      where partially initialised sessions can be accessed by external users.
      
      Backporting Notes
      
      l2tp_core.c: moving code that had been converted from atomic to
      refcount_t by an earlier change (which isn't being included in this
      patch series).
      
      Fixes: dbdbc73b ("l2tp: fix duplicate session creation")
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      11a08372
    • Guillaume Nault's avatar
      l2tp: define parameters of l2tp_tunnel_find*() as "const" · d4504d1e
      Guillaume Nault authored
      commit 2f858b92 upstream.
      
      l2tp_tunnel_find() and l2tp_tunnel_find_nth() don't modify "net".
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d4504d1e
    • Guillaume Nault's avatar
      l2tp: define parameters of l2tp_session_get*() as "const" · eb61cabd
      Guillaume Nault authored
      commit 9aaef50c upstream.
      
      Make l2tp_pernet()'s parameter constant, so that l2tp_session_get*() can
      declare their "net" variable as "const".
      Also constify "ifname" in l2tp_session_get_by_ifname().
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      eb61cabd
    • Guillaume Nault's avatar
      l2tp: remove l2tp_session_find() · e27738d0
      Guillaume Nault authored
      commit 55a3ce3b upstream.
      
      This function isn't used anymore.
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e27738d0
    • Guillaume Nault's avatar
      l2tp: remove useless duplicate session detection in l2tp_netlink · 6729e733
      Guillaume Nault authored
      commit af87ae46 upstream.
      
      There's no point in checking for duplicate sessions at the beginning of
      l2tp_nl_cmd_session_create(); the ->session_create() callbacks already
      return -EEXIST when the session already exists.
      
      Furthermore, even if l2tp_session_find() returns NULL, a new session
      might be created right after the test. So relying on ->session_create()
      to avoid duplicate session is the only sane behaviour.
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6729e733
    • R. Parameswaran's avatar
      L2TP:Adjust intf MTU, add underlay L3, L2 hdrs. · fa5b41cd
      R. Parameswaran authored
      commit b784e7eb upstream.
      
      Existing L2TP kernel code does not derive the optimal MTU for Ethernet
      pseudowires and instead leaves this to a userspace L2TP daemon or
      operator. If an MTU is not specified, the existing kernel code chooses
      an MTU that does not take account of all tunnel header overheads, which
      can lead to unwanted IP fragmentation. When L2TP is used without a
      control plane (userspace daemon), we would prefer that the kernel does a
      better job of choosing a default pseudowire MTU, taking account of all
      tunnel header overheads, including IP header options, if any. This patch
      addresses this.
      
      Change-set here uses the new kernel function, kernel_sock_ip_overhead(),
      to factor the outer IP overhead on the L2TP tunnel socket (including
      IP Options, if any) when calculating the default MTU for an Ethernet
      pseudowire, along with consideration of the inner Ethernet header.
      Signed-off-by: default avatarR. Parameswaran <rparames@brocade.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fa5b41cd
    • R. Parameswaran's avatar
      New kernel function to get IP overhead on a socket. · b25415f9
      R. Parameswaran authored
      commit 113c3075 upstream.
      
      A new function, kernel_sock_ip_overhead(), is provided
      to calculate the cumulative overhead imposed by the IP
      Header and IP options, if any, on a socket's payload.
      The new function returns an overhead of zero for sockets
      that do not belong to the IPv4 or IPv6 address families.
      This is used in the L2TP code path to compute the
      total outer IP overhead on the L2TP tunnel socket when
      calculating the default MTU for Ethernet pseudowires.
      Signed-off-by: default avatarR. Parameswaran <rparames@brocade.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b25415f9
    • Asbjørn Sloth Tønnesen's avatar
    • Asbjørn Sloth Tønnesen's avatar
      net: l2tp: deprecate PPPOL2TP_MSG_* in favour of L2TP_MSG_* · cc84b4dd
      Asbjørn Sloth Tønnesen authored
      commit 47c3e778 upstream.
      
      PPPOL2TP_MSG_* and L2TP_MSG_* are duplicates, and are being used
      interchangeably in the kernel, so let's standardize on L2TP_MSG_*
      internally, and keep PPPOL2TP_MSG_* defined in UAPI for compatibility.
      Signed-off-by: default avatarAsbjoern Sloth Toennesen <asbjorn@asbjorn.st>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cc84b4dd
    • Asbjørn Sloth Tønnesen's avatar
      net: l2tp: export debug flags to UAPI · 18dc6fbb
      Asbjørn Sloth Tønnesen authored
      commit 41c43fbe upstream.
      
      Move the L2TP_MSG_* definitions to UAPI, as it is part of
      the netlink API.
      Signed-off-by: default avatarAsbjoern Sloth Toennesen <asbjorn@asbjorn.st>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGiuliano Procida <gprocida@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      18dc6fbb
    • Kevin Hao's avatar
      watchdog: Fix the race between the release of watchdog_core_data and cdev · f76905ce
      Kevin Hao authored
      commit 72139dfa upstream.
      
      The struct cdev is embedded in the struct watchdog_core_data. In the
      current code, we manage the watchdog_core_data with a kref, but the
      cdev is manged by a kobject. There is no any relationship between
      this kref and kobject. So it is possible that the watchdog_core_data is
      freed before the cdev is entirely released. We can easily get the
      following call trace with CONFIG_DEBUG_KOBJECT_RELEASE and
      CONFIG_DEBUG_OBJECTS_TIMERS enabled.
        ODEBUG: free active (active state 0) object type: timer_list hint: delayed_work_timer_fn+0x0/0x38
        WARNING: CPU: 23 PID: 1028 at lib/debugobjects.c:481 debug_print_object+0xb0/0xf0
        Modules linked in: softdog(-) deflate ctr twofish_generic twofish_common camellia_generic serpent_generic blowfish_generic blowfish_common cast5_generic cast_common cmac xcbc af_key sch_fq_codel openvswitch nsh nf_conncount nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4
        CPU: 23 PID: 1028 Comm: modprobe Not tainted 5.3.0-next-20190924-yoctodev-standard+ #180
        Hardware name: Marvell OcteonTX CN96XX board (DT)
        pstate: 00400009 (nzcv daif +PAN -UAO)
        pc : debug_print_object+0xb0/0xf0
        lr : debug_print_object+0xb0/0xf0
        sp : ffff80001cbcfc70
        x29: ffff80001cbcfc70 x28: ffff800010ea2128
        x27: ffff800010bad000 x26: 0000000000000000
        x25: ffff80001103c640 x24: ffff80001107b268
        x23: ffff800010bad9e8 x22: ffff800010ea2128
        x21: ffff000bc2c62af8 x20: ffff80001103c600
        x19: ffff800010e867d8 x18: 0000000000000060
        x17: 0000000000000000 x16: 0000000000000000
        x15: ffff000bd7240470 x14: 6e6968207473696c
        x13: 5f72656d6974203a x12: 6570797420746365
        x11: 6a626f2029302065 x10: 7461747320657669
        x9 : 7463612820657669 x8 : 3378302f3078302b
        x7 : 0000000000001d7a x6 : ffff800010fd5889
        x5 : 0000000000000000 x4 : 0000000000000000
        x3 : 0000000000000000 x2 : ffff000bff948548
        x1 : 276a1c9e1edc2300 x0 : 0000000000000000
        Call trace:
         debug_print_object+0xb0/0xf0
         debug_check_no_obj_freed+0x1e8/0x210
         kfree+0x1b8/0x368
         watchdog_cdev_unregister+0x88/0xc8
         watchdog_dev_unregister+0x38/0x48
         watchdog_unregister_device+0xa8/0x100
         softdog_exit+0x18/0xfec4 [softdog]
         __arm64_sys_delete_module+0x174/0x200
         el0_svc_handler+0xd0/0x1c8
         el0_svc+0x8/0xc
      
      This is a common issue when using cdev embedded in a struct.
      Fortunately, we already have a mechanism to solve this kind of issue.
      Please see commit 233ed09d ("chardev: add helper function to
      register char devs with a struct device") for more detail.
      
      In this patch, we choose to embed the struct device into the
      watchdog_core_data, and use the API provided by the commit 233ed09d
      to make sure that the release of watchdog_core_data and cdev are
      in sequence.
      Signed-off-by: default avatarKevin Hao <haokexin@gmail.com>
      Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Link: https://lore.kernel.org/r/20191008112934.29669-1-haokexin@gmail.comSigned-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarWim Van Sebroeck <wim@linux-watchdog.org>
      [bwh: Backported to 4.9:
       - There's no reboot notifier here
       - Adjust context]
      Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f76905ce
    • Christoph Hellwig's avatar
      arm64: fix the flush_icache_range arguments in machine_kexec · a5233a3f
      Christoph Hellwig authored
      Commit d51c2145 upstream.
      
      The second argument is the end "pointer", not the length.
      
      Fixes: d28f6df1 ("arm64/kexec: Add core kexec support")
      Cc: <stable@vger.kernel.org> # 4.8.x-
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a5233a3f
    • Daniel Jordan's avatar
      padata: purge get_cpu and reorder_via_wq from padata_do_serial · bae3b507
      Daniel Jordan authored
      [ Upstream commit 065cf577 ]
      
      With the removal of the padata timer, padata_do_serial no longer
      needs special CPU handling, so remove it.
      Signed-off-by: default avatarDaniel Jordan <daniel.m.jordan@oracle.com>
      Cc: Herbert Xu <herbert@gondor.apana.org.au>
      Cc: Steffen Klassert <steffen.klassert@secunet.com>
      Cc: linux-crypto@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarDaniel Jordan <daniel.m.jordan@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      bae3b507
    • Daniel Jordan's avatar
      padata: initialize pd->cpu with effective cpumask · 52a3af1c
      Daniel Jordan authored
      [ Upstream commit ec9c7d19 ]
      
      Exercising CPU hotplug on a 5.2 kernel with recent padata fixes from
      cryptodev-2.6.git in an 8-CPU kvm guest...
      
          # modprobe tcrypt alg="pcrypt(rfc4106(gcm(aes)))" type=3
          # echo 0 > /sys/devices/system/cpu/cpu1/online
          # echo c > /sys/kernel/pcrypt/pencrypt/parallel_cpumask
          # modprobe tcrypt mode=215
      
      ...caused the following crash:
      
          BUG: kernel NULL pointer dereference, address: 0000000000000000
          #PF: supervisor read access in kernel mode
          #PF: error_code(0x0000) - not-present page
          PGD 0 P4D 0
          Oops: 0000 [#1] SMP PTI
          CPU: 2 PID: 134 Comm: kworker/2:2 Not tainted 5.2.0-padata-base+ #7
          Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-<snip>
          Workqueue: pencrypt padata_parallel_worker
          RIP: 0010:padata_reorder+0xcb/0x180
          ...
          Call Trace:
           padata_do_serial+0x57/0x60
           pcrypt_aead_enc+0x3a/0x50 [pcrypt]
           padata_parallel_worker+0x9b/0xe0
           process_one_work+0x1b5/0x3f0
           worker_thread+0x4a/0x3c0
           ...
      
      In padata_alloc_pd, pd->cpu is set using the user-supplied cpumask
      instead of the effective cpumask, and in this case cpumask_first picked
      an offline CPU.
      
      The offline CPU's reorder->list.next is NULL in padata_reorder because
      the list wasn't initialized in padata_init_pqueues, which only operates
      on CPUs in the effective mask.
      
      Fix by using the effective mask in padata_alloc_pd.
      
      Fixes: 6fc4dbcf ("padata: Replace delayed timer with immediate workqueue in padata_reorder")
      Signed-off-by: default avatarDaniel Jordan <daniel.m.jordan@oracle.com>
      Cc: Herbert Xu <herbert@gondor.apana.org.au>
      Cc: Steffen Klassert <steffen.klassert@secunet.com>
      Cc: linux-crypto@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarDaniel Jordan <daniel.m.jordan@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      52a3af1c
    • Herbert Xu's avatar
      padata: Replace delayed timer with immediate workqueue in padata_reorder · f501513b
      Herbert Xu authored
      [ Upstream commit 6fc4dbcf ]
      
      The function padata_reorder will use a timer when it cannot progress
      while completed jobs are outstanding (pd->reorder_objects > 0).  This
      is suboptimal as if we do end up using the timer then it would have
      introduced a gratuitous delay of one second.
      
      In fact we can easily distinguish between whether completed jobs
      are outstanding and whether we can make progress.  All we have to
      do is look at the next pqueue list.
      
      This patch does that by replacing pd->processed with pd->cpu so
      that the next pqueue is more accessible.
      
      A work queue is used instead of the original try_again to avoid
      hogging the CPU.
      
      Note that we don't bother removing the work queue in
      padata_flush_queues because the whole premise is broken.  You
      cannot flush async crypto requests so it makes no sense to even
      try.  A subsequent patch will fix it by replacing it with a ref
      counting scheme.
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      [dj: - adjust context
           - corrected setup_timer -> timer_setup to delete hunk
           - skip padata_flush_queues() hunk, function already removed
             in 4.9]
      Signed-off-by: default avatarDaniel Jordan <daniel.m.jordan@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f501513b
    • Mathias Krause's avatar
      padata: set cpu_index of unused CPUs to -1 · 251716d9
      Mathias Krause authored
      [ Upstream commit 1bd845bc ]
      
      The parallel queue per-cpu data structure gets initialized only for CPUs
      in the 'pcpu' CPU mask set. This is not sufficient as the reorder timer
      may run on a different CPU and might wrongly decide it's the target CPU
      for the next reorder item as per-cpu memory gets memset(0) and we might
      be waiting for the first CPU in cpumask.pcpu, i.e. cpu_index 0.
      
      Make the '__this_cpu_read(pd->pqueue->cpu_index) == next_queue->cpu_index'
      compare in padata_get_next() fail in this case by initializing the
      cpu_index member of all per-cpu parallel queues. Use -1 for unused ones.
      Signed-off-by: default avatarMathias Krause <minipli@googlemail.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarDaniel Jordan <daniel.m.jordan@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      251716d9
    • Kevin Hao's avatar
      i2c: dev: Fix the race between the release of i2c_dev and cdev · c0d34399
      Kevin Hao authored
      [ Upstream commit 1413ef63 ]
      
      The struct cdev is embedded in the struct i2c_dev. In the current code,
      we would free the i2c_dev struct directly in put_i2c_dev(), but the
      cdev is manged by a kobject, and the release of it is not predictable.
      So it is very possible that the i2c_dev is freed before the cdev is
      entirely released. We can easily get the following call trace with
      CONFIG_DEBUG_KOBJECT_RELEASE and CONFIG_DEBUG_OBJECTS_TIMERS enabled.
        ODEBUG: free active (active state 0) object type: timer_list hint: delayed_work_timer_fn+0x0/0x38
        WARNING: CPU: 19 PID: 1 at lib/debugobjects.c:325 debug_print_object+0xb0/0xf0
        Modules linked in:
        CPU: 19 PID: 1 Comm: swapper/0 Tainted: G        W         5.2.20-yocto-standard+ #120
        Hardware name: Marvell OcteonTX CN96XX board (DT)
        pstate: 80c00089 (Nzcv daIf +PAN +UAO)
        pc : debug_print_object+0xb0/0xf0
        lr : debug_print_object+0xb0/0xf0
        sp : ffff00001292f7d0
        x29: ffff00001292f7d0 x28: ffff800b82151788
        x27: 0000000000000001 x26: ffff800b892c0000
        x25: ffff0000124a2558 x24: 0000000000000000
        x23: ffff00001107a1d8 x22: ffff0000116b5088
        x21: ffff800bdc6afca8 x20: ffff000012471ae8
        x19: ffff00001168f2c8 x18: 0000000000000010
        x17: 00000000fd6f304b x16: 00000000ee79de43
        x15: ffff800bc0e80568 x14: 79616c6564203a74
        x13: 6e6968207473696c x12: 5f72656d6974203a
        x11: ffff0000113f0018 x10: 0000000000000000
        x9 : 000000000000001f x8 : 0000000000000000
        x7 : ffff0000101294cc x6 : 0000000000000000
        x5 : 0000000000000000 x4 : 0000000000000001
        x3 : 00000000ffffffff x2 : 0000000000000000
        x1 : 387fc15c8ec0f200 x0 : 0000000000000000
        Call trace:
         debug_print_object+0xb0/0xf0
         __debug_check_no_obj_freed+0x19c/0x228
         debug_check_no_obj_freed+0x1c/0x28
         kfree+0x250/0x440
         put_i2c_dev+0x68/0x78
         i2cdev_detach_adapter+0x60/0xc8
         i2cdev_notifier_call+0x3c/0x70
         notifier_call_chain+0x8c/0xe8
         blocking_notifier_call_chain+0x64/0x88
         device_del+0x74/0x380
         device_unregister+0x54/0x78
         i2c_del_adapter+0x278/0x2d0
         unittest_i2c_bus_remove+0x3c/0x80
         platform_drv_remove+0x30/0x50
         device_release_driver_internal+0xf4/0x1c0
         driver_detach+0x58/0xa0
         bus_remove_driver+0x84/0xd8
         driver_unregister+0x34/0x60
         platform_driver_unregister+0x20/0x30
         of_unittest_overlay+0x8d4/0xbe0
         of_unittest+0xae8/0xb3c
         do_one_initcall+0xac/0x450
         do_initcall_level+0x208/0x224
         kernel_init_freeable+0x2d8/0x36c
         kernel_init+0x18/0x108
         ret_from_fork+0x10/0x1c
        irq event stamp: 3934661
        hardirqs last  enabled at (3934661): [<ffff00001009fa04>] debug_exception_exit+0x4c/0x58
        hardirqs last disabled at (3934660): [<ffff00001009fb14>] debug_exception_enter+0xa4/0xe0
        softirqs last  enabled at (3934654): [<ffff000010081d94>] __do_softirq+0x46c/0x628
        softirqs last disabled at (3934649): [<ffff0000100b4a1c>] irq_exit+0x104/0x118
      
      This is a common issue when using cdev embedded in a struct.
      Fortunately, we already have a mechanism to solve this kind of issue.
      Please see commit 233ed09d ("chardev: add helper function to
      register char devs with a struct device") for more detail.
      
      In this patch, we choose to embed the struct device into the i2c_dev,
      and use the API provided by the commit 233ed09d to make sure that
      the release of i2c_dev and cdev are in sequence.
      Signed-off-by: default avatarKevin Hao <haokexin@gmail.com>
      Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c0d34399
    • Thomas Gleixner's avatar
      ARM: futex: Address build warning · 7a5c2b73
      Thomas Gleixner authored
      [ Upstream commit 8101b5a1 ]
      
      Stephen reported the following build warning on a ARM multi_v7_defconfig
      build with GCC 9.2.1:
      
      kernel/futex.c: In function 'do_futex':
      kernel/futex.c:1676:17: warning: 'oldval' may be used uninitialized in this function [-Wmaybe-uninitialized]
       1676 |   return oldval == cmparg;
            |          ~~~~~~~^~~~~~~~~
      kernel/futex.c:1652:6: note: 'oldval' was declared here
       1652 |  int oldval, ret;
            |      ^~~~~~
      
      introduced by commit a08971e9 ("futex: arch_futex_atomic_op_inuser()
      calling conventions change").
      
      While that change should not make any difference it confuses GCC which
      fails to work out that oldval is not referenced when the return value is
      not zero.
      
      GCC fails to properly analyze arch_futex_atomic_op_inuser(). It's not the
      early return, the issue is with the assembly macros. GCC fails to detect
      that those either set 'ret' to 0 and set oldval or set 'ret' to -EFAULT
      which makes oldval uninteresting. The store to the callsite supplied oldval
      pointer is conditional on ret == 0.
      
      The straight forward way to solve this is to make the store unconditional.
      
      Aside of addressing the build warning this makes sense anyway because it
      removes the conditional from the fastpath. In the error case the stored
      value is uninteresting and the extra store does not matter at all.
      Reported-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Link: https://lkml.kernel.org/r/87pncao2ph.fsf@nanos.tec.linutronix.deSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      7a5c2b73
    • Hans de Goede's avatar
      platform/x86: asus-nb-wmi: Do not load on Asus T100TA and T200TA · e09cb4c3
      Hans de Goede authored
      [ Upstream commit 3bd12da7 ]
      
      asus-nb-wmi does not add any extra functionality on these Asus
      Transformer books. They have detachable keyboards, so the hotkeys are
      send through a HID device (and handled by the hid-asus driver) and also
      the rfkill functionality is not used on these devices.
      
      Besides not adding any extra functionality, initializing the WMI interface
      on these devices actually has a negative side-effect. For some reason
      the \_SB.ATKD.INIT() function which asus_wmi_platform_init() calls drives
      GPO2 (INT33FC:02) pin 8, which is connected to the front facing webcam LED,
      high and there is no (WMI or other) interface to drive this low again
      causing the LED to be permanently on, even during suspend.
      
      This commit adds a blacklist of DMI system_ids on which not to load the
      asus-nb-wmi and adds these Transformer books to this list. This fixes
      the webcam LED being permanently on under Linux.
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e09cb4c3
    • Alan Stern's avatar
      USB: core: Fix misleading driver bug report · 21851aa8
      Alan Stern authored
      [ Upstream commit ac854131 ]
      
      The syzbot fuzzer found a race between URB submission to endpoint 0
      and device reset.  Namely, during the reset we call usb_ep0_reinit()
      because the characteristics of ep0 may have changed (if the reset
      follows a firmware update, for example).  While usb_ep0_reinit() is
      running there is a brief period during which the pointers stored in
      udev->ep_in[0] and udev->ep_out[0] are set to NULL, and if an URB is
      submitted to ep0 during that period, usb_urb_ep_type_check() will
      report it as a driver bug.  In the absence of those pointers, the
      routine thinks that the endpoint doesn't exist.  The log message looks
      like this:
      
      ------------[ cut here ]------------
      usb 2-1: BOGUS urb xfer, pipe 2 != type 2
      WARNING: CPU: 0 PID: 9241 at drivers/usb/core/urb.c:478
      usb_submit_urb+0x1188/0x1460 drivers/usb/core/urb.c:478
      
      Now, although submitting an URB while the device is being reset is a
      questionable thing to do, it shouldn't count as a driver bug as severe
      as submitting an URB for an endpoint that doesn't exist.  Indeed,
      endpoint 0 always exists, even while the device is in its unconfigured
      state.
      
      To prevent these misleading driver bug reports, this patch updates
      usb_disable_endpoint() to avoid clearing the ep_in[] and ep_out[]
      pointers when the endpoint being disabled is ep0.  There's no danger
      of leaving a stale pointer in place, because the usb_host_endpoint
      structure being pointed to is stored permanently in udev->ep0; it
      doesn't get deallocated until the entire usb_device structure does.
      
      Reported-and-tested-by: syzbot+db339689b2101f6f6071@syzkaller.appspotmail.com
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      
      Link: https://lore.kernel.org/r/Pine.LNX.4.44L0.2005011558590.903-100000@netrider.rowland.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      21851aa8
    • Wu Bo's avatar
      ceph: fix double unlock in handle_cap_export() · 1de356b1
      Wu Bo authored
      [ Upstream commit 4d8e28ff ]
      
      If the ceph_mdsc_open_export_target_session() return fails, it will
      do a "goto retry", but the session mutex has already been unlocked.
      Re-lock the mutex in that case to ensure that we don't unlock it
      twice.
      Signed-off-by: default avatarWu Bo <wubo40@huawei.com>
      Reviewed-by: default avatar"Yan, Zheng" <zyan@redhat.com>
      Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1de356b1
    • Yoshiyuki Kurauchi's avatar
      gtp: set NLM_F_MULTI flag in gtp_genl_dump_pdp() · 2e7f7b28
      Yoshiyuki Kurauchi authored
      [ Upstream commit 846c68f7 ]
      
      In drivers/net/gtp.c, gtp_genl_dump_pdp() should set NLM_F_MULTI
      flag since it returns multipart message.
      This patch adds a new arg "flags" in gtp_genl_fill_info() so that
      flags can be set by the callers.
      Signed-off-by: default avatarYoshiyuki Kurauchi <ahochauwaaaaa@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2e7f7b28