Skip to content
Snippets Groups Projects
  1. Jul 12, 2022
    • Duoming Zhou's avatar
      net: rose: fix UAF bug caused by rose_t0timer_expiry · e426d153
      Duoming Zhou authored
      
      commit 148ca045 upstream.
      
      There are UAF bugs caused by rose_t0timer_expiry(). The
      root cause is that del_timer() could not stop the timer
      handler that is running and there is no synchronization.
      One of the race conditions is shown below:
      
          (thread 1)             |        (thread 2)
                                 | rose_device_event
                                 |   rose_rt_device_down
                                 |     rose_remove_neigh
      rose_t0timer_expiry        |       rose_stop_t0timer(rose_neigh)
        ...                      |         del_timer(&neigh->t0timer)
                                 |         kfree(rose_neigh) //[1]FREE
        neigh->dce_mode //[2]USE |
      
      The rose_neigh is deallocated in position [1] and use in
      position [2].
      
      The crash trace triggered by POC is like below:
      
      BUG: KASAN: use-after-free in expire_timers+0x144/0x320
      Write of size 8 at addr ffff888009b19658 by task swapper/0/0
      ...
      Call Trace:
       <IRQ>
       dump_stack_lvl+0xbf/0xee
       print_address_description+0x7b/0x440
       print_report+0x101/0x230
       ? expire_timers+0x144/0x320
       kasan_report+0xed/0x120
       ? expire_timers+0x144/0x320
       expire_timers+0x144/0x320
       __run_timers+0x3ff/0x4d0
       run_timer_softirq+0x41/0x80
       __do_softirq+0x233/0x544
       ...
      
      This patch changes rose_stop_ftimer() and rose_stop_t0timer()
      in rose_remove_neigh() to del_timer_sync() in order that the
      timer handler could be finished before the resources such as
      rose_neigh and so on are deallocated. As a result, the UAF
      bugs could be mitigated.
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarDuoming Zhou <duoming@zju.edu.cn>
      Link: https://lore.kernel.org/r/20220705125610.77971-1-duoming@zju.edu.cn
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e426d153
    • Oliver Neukum's avatar
      usbnet: fix memory leak in error case · d5165e65
      Oliver Neukum authored
      
      commit b55a21b7 upstream.
      
      usbnet_write_cmd_async() mixed up which buffers
      need to be freed in which error case.
      
      v2: add Fixes tag
      v3: fix uninitialized buf pointer
      
      Fixes: 877bd862 ("usbnet: introduce usbnet 3 command helpers")
      Signed-off-by: default avatarOliver Neukum <oneukum@suse.com>
      Link: https://lore.kernel.org/r/20220705125351.17309-1-oneukum@suse.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d5165e65
    • Rhett Aultman's avatar
      can: gs_usb: gs_usb_open/close(): fix memory leak · d9149263
      Rhett Aultman authored
      commit 2bda24ef upstream.
      
      The gs_usb driver appears to suffer from a malady common to many USB
      CAN adapter drivers in that it performs usb_alloc_coherent() to
      allocate a number of USB request blocks (URBs) for RX, and then later
      relies on usb_kill_anchored_urbs() to free them, but this doesn't
      actually free them. As a result, this may be leaking DMA memory that's
      been used by the driver.
      
      This commit is an adaptation of the techniques found in the esd_usb2
      driver where a similar design pattern led to a memory leak. It
      explicitly frees the RX URBs and their DMA memory via a call to
      usb_free_coherent(). Since the RX URBs were allocated in the
      gs_can_open(), we remove them in gs_can_close() rather than in the
      disconnect function as was done in esd_usb2.
      
      For more information, see the 928150fa ("can: esd_usb2: fix memory
      leak").
      
      Link: https://lore.kernel.org/all/alpine.DEB.2.22.394.2206031547001.1630869@thelappy
      
      
      Fixes: d08e973a ("can: gs_usb: Added support for the GS_USB CAN devices")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarRhett Aultman <rhett.aultman@samsara.com>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d9149263
    • Liang He's avatar
      can: grcan: grcan_probe(): remove extra of_node_get() · effa1894
      Liang He authored
      commit 562fed94 upstream.
      
      In grcan_probe(), of_find_node_by_path() has already increased the
      refcount. There is no need to call of_node_get() again, so remove it.
      
      Link: https://lore.kernel.org/all/20220619070257.4067022-1-windhl@126.com
      
      
      Fixes: 1e93ed26 ("can: grcan: grcan_probe(): fix broken system id check for errata workaround needs")
      Cc: stable@vger.kernel.org # v5.18
      Cc: Andreas Larsson <andreas@gaisler.com>
      Signed-off-by: default avatarLiang He <windhl@126.com>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      effa1894
    • Oliver Hartkopp's avatar
      can: bcm: use call_rcu() instead of costly synchronize_rcu() · fbac09a3
      Oliver Hartkopp authored
      commit f1b4e32a upstream.
      
      In commit d5f9023f ("can: bcm: delay release of struct bcm_op
      after synchronize_rcu()") Thadeu Lima de Souza Cascardo introduced two
      synchronize_rcu() calls in bcm_release() (only once at socket close)
      and in bcm_delete_rx_op() (called on removal of each single bcm_op).
      
      Unfortunately this slow removal of the bcm_op's affects user space
      applications like cansniffer where the modification of a filter
      removes 2048 bcm_op's which blocks the cansniffer application for
      40(!) seconds.
      
      In commit 181d4447 ("can: gw: use call_rcu() instead of costly
      synchronize_rcu()") Eric Dumazet replaced the synchronize_rcu() calls
      with several call_rcu()'s to safely remove the data structures after
      the removal of CAN ID subscriptions with can_rx_unregister() calls.
      
      This patch adopts Erics approach for the can-bcm which should be
      applicable since the removal of tasklet_kill() in bcm_remove_op() and
      the introduction of the HRTIMER_MODE_SOFT timer handling in Linux 5.4.
      
      Fixes: d5f9023f ("can: bcm: delay release of struct bcm_op after synchronize_rcu()") # >= 5.4
      Link: https://lore.kernel.org/all/20220520183239.19111-1-socketcan@hartkopp.net
      
      
      Cc: stable@vger.kernel.org
      Cc: Eric Dumazet <edumazet@google.com>
      Cc: Norbert Slusarek <nslusarek@gmx.net>
      Cc: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
      Signed-off-by: default avatarOliver Hartkopp <socketcan@hartkopp.net>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fbac09a3
    • Jann Horn's avatar
      mm/slub: add missing TID updates on slab deactivation · e2b2f0e2
      Jann Horn authored
      
      commit eeaa345e upstream.
      
      The fastpath in slab_alloc_node() assumes that c->slab is stable as long as
      the TID stays the same. However, two places in __slab_alloc() currently
      don't update the TID when deactivating the CPU slab.
      
      If multiple operations race the right way, this could lead to an object
      getting lost; or, in an even more unlikely situation, it could even lead to
      an object being freed onto the wrong slab's freelist, messing up the
      `inuse` counter and eventually causing a page to be freed to the page
      allocator while it still contains slab objects.
      
      (I haven't actually tested these cases though, this is just based on
      looking at the code. Writing testcases for this stuff seems like it'd be
      a pain...)
      
      The race leading to state inconsistency is (all operations on the same CPU
      and kmem_cache):
      
       - task A: begin do_slab_free():
          - read TID
          - read pcpu freelist (==NULL)
          - check `slab == c->slab` (true)
       - [PREEMPT A->B]
       - task B: begin slab_alloc_node():
          - fastpath fails (`c->freelist` is NULL)
          - enter __slab_alloc()
          - slub_get_cpu_ptr() (disables preemption)
          - enter ___slab_alloc()
          - take local_lock_irqsave()
          - read c->freelist as NULL
          - get_freelist() returns NULL
          - write `c->slab = NULL`
          - drop local_unlock_irqrestore()
          - goto new_slab
          - slub_percpu_partial() is NULL
          - get_partial() returns NULL
          - slub_put_cpu_ptr() (enables preemption)
       - [PREEMPT B->A]
       - task A: finish do_slab_free():
          - this_cpu_cmpxchg_double() succeeds()
          - [CORRUPT STATE: c->slab==NULL, c->freelist!=NULL]
      
      From there, the object on c->freelist will get lost if task B is allowed to
      continue from here: It will proceed to the retry_load_slab label,
      set c->slab, then jump to load_freelist, which clobbers c->freelist.
      
      But if we instead continue as follows, we get worse corruption:
      
       - task A: run __slab_free() on object from other struct slab:
          - CPU_PARTIAL_FREE case (slab was on no list, is now on pcpu partial)
       - task A: run slab_alloc_node() with NUMA node constraint:
          - fastpath fails (c->slab is NULL)
          - call __slab_alloc()
          - slub_get_cpu_ptr() (disables preemption)
          - enter ___slab_alloc()
          - c->slab is NULL: goto new_slab
          - slub_percpu_partial() is non-NULL
          - set c->slab to slub_percpu_partial(c)
          - [CORRUPT STATE: c->slab points to slab-1, c->freelist has objects
            from slab-2]
          - goto redo
          - node_match() fails
          - goto deactivate_slab
          - existing c->freelist is passed into deactivate_slab()
          - inuse count of slab-1 is decremented to account for object from
            slab-2
      
      At this point, the inuse count of slab-1 is 1 lower than it should be.
      This means that if we free all allocated objects in slab-1 except for one,
      SLUB will think that slab-1 is completely unused, and may free its page,
      leading to use-after-free.
      
      Fixes: c17dda40 ("slub: Separate out kmem_cache_cpu processing from deactivate_slab")
      Fixes: 03e404af ("slub: fast release on full slab")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Acked-by: default avatarChristoph Lameter <cl@linux.com>
      Acked-by: default avatarDavid Rientjes <rientjes@google.com>
      Reviewed-by: default avatarMuchun Song <songmuchun@bytedance.com>
      Tested-by: default avatarHyeonggon Yoo <42.hyeyoo@gmail.com>
      Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
      Link: https://lore.kernel.org/r/20220608182205.2945720-1-jannh@google.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e2b2f0e2
    • Sabrina Dubroca's avatar
      esp: limit skb_page_frag_refill use to a single page · ef6f83df
      Sabrina Dubroca authored
      
      commit 5bd8baab upstream.
      
      Commit ebe48d36 ("esp: Fix possible buffer overflow in ESP
      transformation") tried to fix skb_page_frag_refill usage in ESP by
      capping allocsize to 32k, but that doesn't completely solve the issue,
      as skb_page_frag_refill may return a single page. If that happens, we
      will write out of bounds, despite the check introduced in the previous
      patch.
      
      This patch forces COW in cases where we would end up calling
      skb_page_frag_refill with a size larger than a page (first in
      esp_output_head with tailen, then in esp_output_tail with
      skb->data_len).
      
      Fixes: cac2661c ("esp4: Avoid skb_cow_data whenever possible")
      Fixes: 03e2a30f ("esp6: Avoid skb_cow_data whenever possible")
      Signed-off-by: default avatarSabrina Dubroca <sd@queasysnail.net>
      Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ef6f83df
  2. Jul 07, 2022
Loading