Skip to content
Snippets Groups Projects
  1. Sep 05, 2022
  2. Sep 01, 2022
    • Jose Alonso's avatar
      net: usb: ax88179_178a: Fix packet receiving · 24d2149f
      Jose Alonso authored
      stable inclusion
      from stable-v4.19.251
      commit 5fabd32fd5492675e33a7ca972ac158e7b7361ee
      category: bugfix
      bugzilla: https://gitee.com/src-openeuler/kernel/issues/I5NYS6
      
      
      CVE: CVE-2022-2964
      
      ---------------------------
      
      commit f8ebb3ac881b17712e1d5967c97ab1806b16d3d6 upstream.
      
      This patch corrects packet receiving in ax88179_rx_fixup.
      
      - problem observed:
        ifconfig shows allways a lot of 'RX Errors' while packets
        are received normally.
      
        This occurs because ax88179_rx_fixup does not recognise properly
        the usb urb received.
        The packets are normally processed and at the end, the code exits
        with 'return 0', generating RX Errors.
        (pkt_cnt==-2 and ptk_hdr over field rx_hdr trying to identify
         another packet there)
      
        This is a usb urb received by "tcpdump -i usbmon2 -X" on a
        little-endian CPU:
        0x0000:  eeee f8e3 3b19 87a0 94de 80e3 daac 0800
                 ^         packet 1 start (pkt_len = 0x05ec)
                 ^^^^      IP alignment pseudo header
                      ^    ethernet packet start
                 last byte ethernet packet   v
                 padding (8-bytes aligned)     vvvv vvvv
        0x05e0:  c92d d444 1420 8a69 83dd 272f e82b 9811
        0x05f0:  eeee f8e3 3b19 87a0 94de 80e3 daac 0800
        ...      ^ packet 2
        0x0be0:  eeee f8e3 3b19 87a0 94de 80e3 daac 0800
        ...
        0x1130:  9d41 9171 8a38 0ec5 eeee f8e3 3b19 87a0
        ...
        0x1720:  8cfc 15ff 5e4c e85c eeee f8e3 3b19 87a0
        ...
        0x1d10:  ecfa 2a3a 19ab c78c eeee f8e3 3b19 87a0
        ...
        0x2070:  eeee f8e3 3b19 87a0 94de 80e3 daac 0800
        ...      ^ packet 7
        0x2120:  7c88 4ca5 5c57 7dcc 0d34 7577 f778 7e0a
        0x2130:  f032 e093 7489 0740 3008 ec05 0000 0080
                                     ====1==== ====2====
                 hdr_off             ^
                 pkt_len = 0x05ec         ^^^^
                 AX_RXHDR_*=0x00830  ^^^^   ^
                 pkt_len = 0                        ^^^^
                 AX_RXHDR_DROP_ERR=0x80000000  ^^^^   ^
        0x2140:  3008 ec05 0000 0080 3008 5805 0000 0080
        0x2150:  3008 ec05 0000 0080 3008 ec05 0000 0080
        0x2160:  3008 5803 0000 0080 3008 c800 0000 0080
                 ===11==== ===12==== ===13==== ===14====
        0x2170:  0000 0000 0e00 3821
                           ^^^^ ^^^^ rx_hdr
                           ^^^^      pkt_cnt=14
                                ^^^^ hdr_off=0x2138
                 ^^^^ ^^^^           padding
      
        The dump shows that pkt_cnt is the number of entrys in the
        per-packet metadata. It is "2 * packet count".
        Each packet have two entrys. The first have a valid
        value (pkt_len and AX_RXHDR_*) and the second have a
        dummy-header 0x80000000 (pkt_len=0 with AX_RXHDR_DROP_ERR).
        Why exists dummy-header for each packet?!?
        My guess is that this was done probably to align the
        entry for each packet to 64-bits and maintain compatibility
        with old firmware.
        There is also a padding (0x00000000) before the rx_hdr to
        align the end of rx_hdr to 64-bit.
        Note that packets have a alignment of 64-bits (8-bytes).
      
        This patch assumes that the dummy-header and the last
        padding are optional. So it preserves semantics and
        recognises the same valid packets as the current code.
      
        This patch was made using only the dumpfile information and
        tested with only one device:
        0b95:1790 ASIX Electronics Corp. AX88179 Gigabit Ethernet
      
      Fixes: 57bc3d3ae8c1 ("net: usb: ax88179_178a: Fix out-of-bounds accesses in RX fixup")
      Fixes: e2ca90c2 ("ax88179_178a: ASIX AX88179_178A USB 3.0/2.0 to gigabit ethernet adapter driver")
      Signed-off-by: default avatarJose Alonso <joalonsof@gmail.com>
      Acked-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Link: https://lore.kernel.org/r/d6970bb04bf67598af4d316eaeb1792040b18cfd.camel@gmail.com
      
      
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      (cherry picked from commit 5fabd32fd5492675e33a7ca972ac158e7b7361ee)
      Signed-off-by: default avatarLiu Jian <liujian56@huawei.com>
      Reviewed-by: default avatarWei Yongjun <weiyongjun1@huawei.com>
      Reviewed-by: default avatarXiu Jianfeng <xiujianfeng@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      24d2149f
    • Jann Horn's avatar
      net: usb: ax88179_178a: Fix out-of-bounds accesses in RX fixup · b6ca9563
      Jann Horn authored
      stable inclusion
      from stable-v4.19.231
      commit 1668781ed24da43498799aa4f65714a7de201930
      category: bugfix
      bugzilla: https://gitee.com/src-openeuler/kernel/issues/I5NYS6
      
      
      CVE: CVE-2022-2964
      
      ---------------------------
      
      commit 57bc3d3ae8c14df3ceb4e17d26ddf9eeab304581 upstream.
      
      ax88179_rx_fixup() contains several out-of-bounds accesses that can be
      triggered by a malicious (or defective) USB device, in particular:
      
       - The metadata array (hdr_off..hdr_off+2*pkt_cnt) can be out of bounds,
         causing OOB reads and (on big-endian systems) OOB endianness flips.
       - A packet can overlap the metadata array, causing a later OOB
         endianness flip to corrupt data used by a cloned SKB that has already
         been handed off into the network stack.
       - A packet SKB can be constructed whose tail is far beyond its end,
         causing out-of-bounds heap data to be considered part of the SKB's
         data.
      
      I have tested that this can be used by a malicious USB device to send a
      bogus ICMPv6 Echo Request and receive an ICMPv6 Echo Reply in response
      that contains random kernel heap data.
      It's probably also possible to get OOB writes from this on a
      little-endian system somehow - maybe by triggering skb_cow() via IP
      options processing -, but I haven't tested that.
      
      Fixes: e2ca90c2 ("ax88179_178a: ASIX AX88179_178A USB 3.0/2.0 to gigabit ethernet adapter driver")
      Cc: stable@kernel.org
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      (cherry picked from commit 1668781ed24da43498799aa4f65714a7de201930)
      Signed-off-by: default avatarLiu Jian <liujian56@huawei.com>
      Reviewed-by: default avatarWei Yongjun <weiyongjun1@huawei.com>
      Reviewed-by: default avatarXiu Jianfeng <xiujianfeng@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      b6ca9563
    • Jeremy Kerr's avatar
      net: usb: ax88179_178a: fix packet alignment padding · e17f1289
      Jeremy Kerr authored
      stable inclusion
      from stable-v4.19.131
      commit c191f7cf369c0090fdbeff0b6782d5eaa3a179d2
      category: bugfix
      bugzilla: https://gitee.com/src-openeuler/kernel/issues/I5NYS6
      
      
      CVE: CVE-2022-2964
      
      ---------------------------
      
      [ Upstream commit e869e7a1 ]
      
      Using a AX88179 device (0b95:1790), I see two bytes of appended data on
      every RX packet. For example, this 48-byte ping, using 0xff as a
      payload byte:
      
        04:20:22.528472 IP 192.168.1.1 > 192.168.1.2: ICMP echo request, id 2447, seq 1, length 64
      	0x0000:  000a cd35 ea50 000a cd35 ea4f 0800 4500
      	0x0010:  0054 c116 4000 4001 f63e c0a8 0101 c0a8
      	0x0020:  0102 0800 b633 098f 0001 87ea cd5e 0000
      	0x0030:  0000 dcf2 0600 0000 0000 ffff ffff ffff
      	0x0040:  ffff ffff ffff ffff ffff ffff ffff ffff
      	0x0050:  ffff ffff ffff ffff ffff ffff ffff ffff
      	0x0060:  ffff 961f
      
      Those last two bytes - 96 1f - aren't part of the original packet.
      
      In the ax88179 RX path, the usbnet rx_fixup function trims a 2-byte
      'alignment pseudo header' from the start of the packet, and sets the
      length from a per-packet field populated by hardware. It looks like that
      length field *includes* the 2-byte header; the current driver assumes
      that it's excluded.
      
      This change trims the 2-byte alignment header after we've set the packet
      length, so the resulting packet length is correct. While we're moving
      the comment around, this also fixes the spelling of 'pseudo'.
      
      Signed-off-by: default avatarJeremy Kerr <jk@ozlabs.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      (cherry picked from commit c191f7cf369c0090fdbeff0b6782d5eaa3a179d2)
      Signed-off-by: default avatarLiu Jian <liujian56@huawei.com>
      Reviewed-by: default avatarWei Yongjun <weiyongjun1@huawei.com>
      Reviewed-by: default avatarXiu Jianfeng <xiujianfeng@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      e17f1289
  3. Aug 29, 2022
  4. Aug 27, 2022
  5. Aug 26, 2022
  6. Aug 25, 2022
  7. Aug 23, 2022
  8. Aug 19, 2022
    • Pawan Gupta's avatar
      x86/speculation: Add LFENCE to RSB fill sequence · 6586edc6
      Pawan Gupta authored
      stable inclusion
      from stable-v4.19.255
      commit b1c9f470fb724d3cfd6cf8fe4a70c2ec4de2e9f4
      category: bugfix
      bugzilla: 187492, https://gitee.com/src-openeuler/kernel/issues/I5N1SO
      
      
      CVE: CVE-2022-26373
      
      --------------------------------
      
      commit ba6e31af2be96c4d0536f2152ed6f7b6c11bca47 upstream.
      
      RSB fill sequence does not have any protection for miss-prediction of
      conditional branch at the end of the sequence. CPU can speculatively
      execute code immediately after the sequence, while RSB filling hasn't
      completed yet.
      
        #define __FILL_RETURN_BUFFER(reg, nr, sp)	\
        	mov	$(nr/2), reg;			\
        771:						\
        	call	772f;				\
        773:	/* speculation trap */			\
        	pause;					\
        	lfence;					\
        	jmp	773b;				\
        772:						\
        	call	774f;				\
        775:	/* speculation trap */			\
        	pause;					\
        	lfence;					\
        	jmp	775b;				\
        774:						\
        	dec	reg;				\
        	jnz	771b;  <----- CPU can miss-predict here.				\
        	add	$(BITS_PER_LONG/8) * nr, sp;
      
      Before RSB is filled, RETs that come in program order after this macro
      can be executed speculatively, making them vulnerable to RSB-based
      attacks.
      
      Mitigate it by adding an LFENCE after the conditional branch to prevent
      speculation while RSB is being filled.
      
      Suggested-by: default avatarAndrew Cooper <andrew.cooper3@citrix.com>
      Signed-off-by: default avatarPawan Gupta <pawan.kumar.gupta@linux.intel.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarChen Jiahao <chenjiahao16@huawei.com>
      Reviewed-by: default avatarZhang Jianhua <chris.zjh@huawei.com>
      Reviewed-by: default avatarLiao Chang <liaochang1@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
    • Daniel Sneddon's avatar
      x86/speculation: Add RSB VM Exit protections · 42268ea1
      Daniel Sneddon authored
      stable inclusion
      from stable-v4.19.255
      commit b6c5011934a15762cd694e36fe74f2f2f93eac9b
      category: bugfix
      bugzilla: 187492, https://gitee.com/src-openeuler/kernel/issues/I5N1SO
      
      
      CVE: CVE-2022-26373
      
      --------------------------------
      
      commit 2b1299322016731d56807aa49254a5ea3080b6b3 upstream.
      
      tl;dr: The Enhanced IBRS mitigation for Spectre v2 does not work as
      documented for RET instructions after VM exits. Mitigate it with a new
      one-entry RSB stuffing mechanism and a new LFENCE.
      
      == Background ==
      
      Indirect Branch Restricted Speculation (IBRS) was designed to help
      mitigate Branch Target Injection and Speculative Store Bypass, i.e.
      Spectre, attacks. IBRS prevents software run in less privileged modes
      from affecting branch prediction in more privileged modes. IBRS requires
      the MSR to be written on every privilege level change.
      
      To overcome some of the performance issues of IBRS, Enhanced IBRS was
      introduced.  eIBRS is an "always on" IBRS, in other words, just turn
      it on once instead of writing the MSR on every privilege level change.
      When eIBRS is enabled, more privileged modes should be protected from
      less privileged modes, including protecting VMMs from guests.
      
      == Problem ==
      
      Here's a simplification of how guests are run on Linux' KVM:
      
      void run_kvm_guest(void)
      {
      	// Prepare to run guest
      	VMRESUME();
      	// Clean up after guest runs
      }
      
      The execution flow for that would look something like this to the
      processor:
      
      1. Host-side: call run_kvm_guest()
      2. Host-side: VMRESUME
      3. Guest runs, does "CALL guest_function"
      4. VM exit, host runs again
      5. Host might make some "cleanup" function calls
      6. Host-side: RET from run_kvm_guest()
      
      Now, when back on the host, there are a couple of possible scenarios of
      post-guest activity the host needs to do before executing host code:
      
      * on pre-eIBRS hardware (legacy IBRS, or nothing at all), the RSB is not
      touched and Linux has to do a 32-entry stuffing.
      
      * on eIBRS hardware, VM exit with IBRS enabled, or restoring the host
      IBRS=1 shortly after VM exit, has a documented side effect of flushing
      the RSB except in this PBRSB situation where the software needs to stuff
      the last RSB entry "by hand".
      
      IOW, with eIBRS supported, host RET instructions should no longer be
      influenced by guest behavior after the host retires a single CALL
      instruction.
      
      However, if the RET instructions are "unbalanced" with CALLs after a VM
      exit as is the RET in #6, it might speculatively use the address for the
      instruction after the CALL in #3 as an RSB prediction. This is a problem
      since the (untrusted) guest controls this address.
      
      Balanced CALL/RET instruction pairs such as in step #5 are not affected.
      
      == Solution ==
      
      The PBRSB issue affects a wide variety of Intel processors which
      support eIBRS. But not all of them need mitigation. Today,
      X86_FEATURE_RETPOLINE triggers an RSB filling sequence that mitigates
      PBRSB. Systems setting RETPOLINE need no further mitigation - i.e.,
      eIBRS systems which enable retpoline explicitly.
      
      However, such systems (X86_FEATURE_IBRS_ENHANCED) do not set RETPOLINE
      and most of them need a new mitigation.
      
      Therefore, introduce a new feature flag X86_FEATURE_RSB_VMEXIT_LITE
      which triggers a lighter-weight PBRSB mitigation versus RSB Filling at
      vmexit.
      
      The lighter-weight mitigation performs a CALL instruction which is
      immediately followed by a speculative execution barrier (INT3). This
      steers speculative execution to the barrier -- just like a retpoline
      -- which ensures that speculation can never reach an unbalanced RET.
      Then, ensure this CALL is retired before continuing execution with an
      LFENCE.
      
      In other words, the window of exposure is opened at VM exit where RET
      behavior is troublesome. While the window is open, force RSB predictions
      sampling for RET targets to a dead end at the INT3. Close the window
      with the LFENCE.
      
      There is a subset of eIBRS systems which are not vulnerable to PBRSB.
      Add these systems to the cpu_vuln_whitelist[] as NO_EIBRS_PBRSB.
      Future systems that aren't vulnerable will set ARCH_CAP_PBRSB_NO.
      
        [ bp: Massage, incorporate review comments from Andy Cooper. ]
        [ Pawan: Update commit message to replace RSB_VMEXIT with RETPOLINE ]
      
      Signed-off-by: default avatarDaniel Sneddon <daniel.sneddon@linux.intel.com>
      Co-developed-by: default avatarPawan Gupta <pawan.kumar.gupta@linux.intel.com>
      Signed-off-by: default avatarPawan Gupta <pawan.kumar.gupta@linux.intel.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      conflict:
          arch/x86/include/asm/cpufeatures.h
          arch/x86/kernel/cpu/common.c
      
      Signed-off-by: default avatarChen Jiahao <chenjiahao16@huawei.com>
      Reviewed-by: default avatarZhang Jianhua <chris.zjh@huawei.com>
      Reviewed-by: default avatarLiao Chang <liaochang1@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      42268ea1
  9. Aug 18, 2022
  10. Aug 16, 2022
  11. Aug 15, 2022
  12. Aug 12, 2022
    • Bart Van Assche's avatar
      RDMA/ib_srp: Fix a deadlock · b363c74b
      Bart Van Assche authored
      stable inclusion
      from stable-4.19.232
      commit d7997d19dfa7001ca41e971cd9efd091bb195b51
      category: bugfix
      https: https://gitee.com/openeuler/kernel/issues/I5LYLQ
      CVE: NA
      
      --------------------------------
      
      [ Upstream commit 081bdc9fe05bb23248f5effb6f811da3da4b8252 ]
      
      Remove the flush_workqueue(system_long_wq) call since flushing
      system_long_wq is deadlock-prone and since that call is redundant with a
      preceding cancel_work_sync()
      
      Link: https://lore.kernel.org/r/20220215210511.28303-3-bvanassche@acm.org
      
      
      Fixes: ef6c49d8 ("IB/srp: Eliminate state SRP_TARGET_DEAD")
      Reported-by: default avatar <syzbot+831661966588c802aae9@syzkaller.appspotmail.com>
      Signed-off-by: default avatarBart Van Assche <bvanassche@acm.org>
      Reviewed-by: default avatarLeon Romanovsky <leonro@nvidia.com>
      Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      Signed-off-by: default avatarLuo Meng <luomeng12@huawei.com>
      Reviewed-by: default avatarJason Yan <yanaijie@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      b363c74b
    • Jann Horn's avatar
      mm/slub: add missing TID updates on slab deactivation · d1ac93cf
      Jann Horn authored
      stable inclusion
      from stable-4.19.252
      commit e2b2f0e2e34d71ae6c2a1114fd3c525930e84bc7
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5LJH1
      
      
      CVE: NA
      
      --------------------------------
      
      commit eeaa345e128515135ccb864c04482180c08e3259 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>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      d1ac93cf
  13. Aug 09, 2022