1. 14 6月, 2022 2 次提交
  2. 28 5月, 2022 3 次提交
  3. 28 4月, 2022 1 次提交
  4. 27 4月, 2022 6 次提交
  5. 19 10月, 2021 1 次提交
  6. 15 10月, 2021 4 次提交
  7. 13 10月, 2021 3 次提交
  8. 26 4月, 2021 6 次提交
  9. 09 2月, 2021 3 次提交
    • V
      xfrm: Fix wraparound in xfrm_policy_addr_delta() · 87a4e388
      Visa Hankala 提交于
      stable inclusion
      from stable-5.10.13
      commit 6daa52884c3fd8f534b7ebfd784111cea69daa9d
      bugzilla: 47995
      
      --------------------------------
      
      [ Upstream commit da64ae2d ]
      
      Use three-way comparison for address components to avoid integer
      wraparound in the result of xfrm_policy_addr_delta(). This ensures
      that the search trees are built and traversed correctly.
      
      Treat IPv4 and IPv6 similarly by returning 0 when prefixlen == 0.
      Prefix /0 has only one equivalence class.
      
      Fixes: 9cf545eb ("xfrm: policy: store inexact policies in a tree ordered by destination address")
      Signed-off-by: NVisa Hankala <visa@hankala.org>
      Acked-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      87a4e388
    • E
      xfrm: fix disable_xfrm sysctl when used on xfrm interfaces · 2aa7cdb6
      Eyal Birger 提交于
      stable inclusion
      from stable-5.10.13
      commit 2f7ecc841daac6394bdd9b3bea69a87c25226c50
      bugzilla: 47995
      
      --------------------------------
      
      [ Upstream commit 9f8550e4 ]
      
      The disable_xfrm flag signals that xfrm should not be performed during
      routing towards a device before reaching device xmit.
      
      For xfrm interfaces this is usually desired as they perform the outbound
      policy lookup as part of their xmit using their if_id.
      
      Before this change enabling this flag on xfrm interfaces prevented them
      from xmitting as xfrm_lookup_with_ifid() would not perform a policy lookup
      in case the original dst had the DST_NOXFRM flag.
      
      This optimization is incorrect when the lookup is done by the xfrm
      interface xmit logic.
      
      Fix by performing policy lookup when invoked by xfrmi as if_id != 0.
      
      Similarly it's unlikely for the 'no policy exists on net' check to yield
      any performance benefits when invoked from xfrmi.
      
      Fixes: f203b76d ("xfrm: Add virtual xfrm interfaces")
      Signed-off-by: NEyal Birger <eyal.birger@gmail.com>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      2aa7cdb6
    • S
      xfrm: Fix oops in xfrm_replay_advance_bmp · bb053814
      Shmulik Ladkani 提交于
      stable inclusion
      from stable-5.10.13
      commit f632d34091e645266fb435240cda3dada8464d1b
      bugzilla: 47995
      
      --------------------------------
      
      [ Upstream commit 56ce7c25 ]
      
      When setting xfrm replay_window to values higher than 32, a rare
      page-fault occurs in xfrm_replay_advance_bmp:
      
        BUG: unable to handle page fault for address: ffff8af350ad7920
        #PF: supervisor write access in kernel mode
        #PF: error_code(0x0002) - not-present page
        PGD ad001067 P4D ad001067 PUD 0
        Oops: 0002 [#1] SMP PTI
        CPU: 3 PID: 30 Comm: ksoftirqd/3 Kdump: loaded Not tainted 5.4.52-050452-generic #202007160732
        Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-2.el7 04/01/2014
        RIP: 0010:xfrm_replay_advance_bmp+0xbb/0x130
        RSP: 0018:ffffa1304013ba40 EFLAGS: 00010206
        RAX: 000000000000010d RBX: 0000000000000002 RCX: 00000000ffffff4b
        RDX: 0000000000000018 RSI: 00000000004c234c RDI: 00000000ffb3dbff
        RBP: ffffa1304013ba50 R08: ffff8af330ad7920 R09: 0000000007fffffa
        R10: 0000000000000800 R11: 0000000000000010 R12: ffff8af29d6258c0
        R13: ffff8af28b95c700 R14: 0000000000000000 R15: ffff8af29d6258fc
        FS:  0000000000000000(0000) GS:ffff8af339ac0000(0000) knlGS:0000000000000000
        CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
        CR2: ffff8af350ad7920 CR3: 0000000015ee4000 CR4: 00000000001406e0
        Call Trace:
         xfrm_input+0x4e5/0xa10
         xfrm4_rcv_encap+0xb5/0xe0
         xfrm4_udp_encap_rcv+0x140/0x1c0
      
      Analysis revealed offending code is when accessing:
      
      	replay_esn->bmp[nr] |= (1U << bitnr);
      
      with 'nr' being 0x07fffffa.
      
      This happened in an SMP system when reordering of packets was present;
      A packet arrived with a "too old" sequence number (outside the window,
      i.e 'diff > replay_window'), and therefore the following calculation:
      
      			bitnr = replay_esn->replay_window - (diff - pos);
      
      yields a negative result, but since bitnr is u32 we get a large unsigned
      quantity (in crash dump above: 0xffffff4b seen in ecx).
      
      This was supposed to be protected by xfrm_input()'s former call to:
      
      		if (x->repl->check(x, skb, seq)) {
      
      However, the state's spinlock x->lock is *released* after '->check()'
      is performed, and gets re-acquired before '->advance()' - which gives a
      chance for a different core to update the xfrm state, e.g. by advancing
      'replay_esn->seq' when it encounters more packets - leading to a
      'diff > replay_window' situation when original core continues to
      xfrm_replay_advance_bmp().
      
      An attempt to fix this issue was suggested in commit bcf66bf5
      ("xfrm: Perform a replay check after return from async codepaths"),
      by calling 'x->repl->recheck()' after lock is re-acquired, but fix
      applied only to asyncronous crypto algorithms.
      
      Augment the fix, by *always* calling 'recheck()' - irrespective if we're
      using async crypto.
      
      Fixes: 0ebea8ef ("[IPSEC]: Move state lock into x->type->input")
      Signed-off-by: NShmulik Ladkani <shmulik.ladkani@gmail.com>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      bb053814
  10. 10 11月, 2020 1 次提交
  11. 09 11月, 2020 3 次提交
    • D
      xfrm/compat: Don't allocate memory with __GFP_ZERO · ad37f77f
      Dmitry Safonov 提交于
      32-bit to 64-bit messages translator zerofies needed paddings in the
      translation, the rest is the actual payload.
      Don't allocate zero pages as they are not needed.
      
      Fixes: 5106f4a8 ("xfrm/compat: Add 32=>64-bit messages translator")
      Signed-off-by: NDmitry Safonov <dima@arista.com>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      ad37f77f
    • D
      xfrm/compat: memset(0) 64-bit padding at right place · d1949d04
      Dmitry Safonov 提交于
      32-bit messages translated by xfrm_compat can have attributes attached.
      For all, but XFRMA_SA, XFRMA_POLICY the size of payload is the same
      in 32-bit UABI and 64-bit UABI. For XFRMA_SA (struct xfrm_usersa_info)
      and XFRMA_POLICY (struct xfrm_userpolicy_info) it's only tail-padding
      that is present in 64-bit payload, but not in 32-bit.
      The proper size for destination nlattr is already calculated by
      xfrm_user_rcv_calculate_len64() and allocated with kvmalloc().
      
      xfrm_attr_cpy32() copies 32-bit copy_len into 64-bit attribute
      translated payload, zero-filling possible padding for SA/POLICY.
      Due to a typo, *pos already has 64-bit payload size, in a result next
      memset(0) is called on the memory after the translated attribute, not on
      the tail-padding of it.
      
      Fixes: 5106f4a8 ("xfrm/compat: Add 32=>64-bit messages translator")
      Reported-by: syzbot+c43831072e7df506a646@syzkaller.appspotmail.com
      Signed-off-by: NDmitry Safonov <dima@arista.com>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      d1949d04
    • D
      xfrm/compat: Translate by copying XFRMA_UNSPEC attribute · dbd7ae51
      Dmitry Safonov 提交于
      xfrm_xlate32() translates 64-bit message provided by kernel to be sent
      for 32-bit listener (acknowledge or monitor). Translator code doesn't
      expect XFRMA_UNSPEC attribute as it doesn't know its payload.
      Kernel never attaches such attribute, but a user can.
      
      I've searched if any opensource does it and the answer is no.
      Nothing on github and google finds only tfcproject that has such code
      commented-out.
      
      What will happen if a user sends a netlink message with XFRMA_UNSPEC
      attribute? Ipsec code ignores this attribute. But if there is a
      monitor-process or 32-bit user requested ack - kernel will try to
      translate such message and will hit WARN_ONCE() in xfrm_xlate64_attr().
      
      Deal with XFRMA_UNSPEC by copying the attribute payload with
      xfrm_nla_cpy(). In result, the default switch-case in xfrm_xlate64_attr()
      becomes an unused code. Leave those 3 lines in case a new xfrm attribute
      will be added.
      
      Fixes: 5461fc0c ("xfrm/compat: Add 64=>32-bit messages translator")
      Reported-by: syzbot+a7e701c8385bd8543074@syzkaller.appspotmail.com
      Signed-off-by: NDmitry Safonov <dima@arista.com>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      dbd7ae51
  12. 23 10月, 2020 1 次提交
    • Z
      net: xfrm: fix a race condition during allocing spi · a779d913
      zhuoliang zhang 提交于
      we found that the following race condition exists in
      xfrm_alloc_userspi flow:
      
      user thread                                    state_hash_work thread
      ----                                           ----
      xfrm_alloc_userspi()
       __find_acq_core()
         /*alloc new xfrm_state:x*/
         xfrm_state_alloc()
         /*schedule state_hash_work thread*/
         xfrm_hash_grow_check()   	               xfrm_hash_resize()
       xfrm_alloc_spi                                  /*hold lock*/
            x->id.spi = htonl(spi)                     spin_lock_bh(&net->xfrm.xfrm_state_lock)
            /*waiting lock release*/                     xfrm_hash_transfer()
            spin_lock_bh(&net->xfrm.xfrm_state_lock)      /*add x into hlist:net->xfrm.state_byspi*/
      	                                                hlist_add_head_rcu(&x->byspi)
                                                       spin_unlock_bh(&net->xfrm.xfrm_state_lock)
      
          /*add x into hlist:net->xfrm.state_byspi 2 times*/
          hlist_add_head_rcu(&x->byspi)
      
      1. a new state x is alloced in xfrm_state_alloc() and added into the bydst hlist
      in  __find_acq_core() on the LHS;
      2. on the RHS, state_hash_work thread travels the old bydst and tranfers every xfrm_state
      (include x) into the new bydst hlist and new byspi hlist;
      3. user thread on the LHS gets the lock and adds x into the new byspi hlist again.
      
      So the same xfrm_state (x) is added into the same list_hash
      (net->xfrm.state_byspi) 2 times that makes the list_hash become
      an inifite loop.
      
      To fix the race, x->id.spi = htonl(spi) in the xfrm_alloc_spi() is moved
      to the back of spin_lock_bh, sothat state_hash_work thread no longer add x
      which id.spi is zero into the hash_list.
      
      Fixes: f034b5d4 ("[XFRM]: Dynamic xfrm_state hash table sizing.")
      Signed-off-by: Nzhuoliang zhang <zhuoliang.zhang@mediatek.com>
      Acked-by: NHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      a779d913
  13. 14 10月, 2020 1 次提交
  14. 09 10月, 2020 1 次提交
    • X
      xfrm: interface: fix the priorities for ipip and ipv6 tunnels · 7fe94612
      Xin Long 提交于
      As Nicolas noticed in his case, when xfrm_interface module is installed
      the standard IP tunnels will break in receiving packets.
      
      This is caused by the IP tunnel handlers with a higher priority in xfrm
      interface processing incoming packets by xfrm_input(), which would drop
      the packets and return 0 instead when anything wrong happens.
      
      Rather than changing xfrm_input(), this patch is to adjust the priority
      for the IP tunnel handlers in xfrm interface, so that the packets would
      go to xfrmi's later than the others', as the others' would not drop the
      packets when the handlers couldn't process them.
      
      Note that IPCOMP also defines its own IPIP tunnel handler and it calls
      xfrm_input() as well, so we must make its priority lower than xfrmi's,
      which means having xfrmi loaded would still break IPCOMP. We may seek
      another way to fix it in xfrm_input() in the future.
      Reported-by: NNicolas Dichtel <nicolas.dichtel@6wind.com>
      Tested-by: NNicolas Dichtel <nicolas.dichtel@6wind.com>
      Fixes: da9bbf05 ("xfrm: interface: support IPIP and IPIP6 tunnels processing with .cb_handler")
      FIxes: d7b360c2 ("xfrm: interface: support IP6IP6 and IP6IP tunnels processing with .cb_handler")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      7fe94612
  15. 06 10月, 2020 1 次提交
  16. 25 9月, 2020 1 次提交
    • H
      xfrm: Use correct address family in xfrm_state_find · e94ee171
      Herbert Xu 提交于
      The struct flowi must never be interpreted by itself as its size
      depends on the address family.  Therefore it must always be grouped
      with its original family value.
      
      In this particular instance, the original family value is lost in
      the function xfrm_state_find.  Therefore we get a bogus read when
      it's coupled with the wrong family which would occur with inter-
      family xfrm states.
      
      This patch fixes it by keeping the original family value.
      
      Note that the same bug could potentially occur in LSM through
      the xfrm_state_pol_flow_match hook.  I checked the current code
      there and it seems to be safe for now as only secid is used which
      is part of struct flowi_common.  But that API should be changed
      so that so that we don't get new bugs in the future.  We could
      do that by replacing fl with just secid or adding a family field.
      
      Reported-by: syzbot+577fbac3145a6eb2e7a5@syzkaller.appspotmail.com
      Fixes: 48b8d783 ("[XFRM]: State selection update to use inner...")
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      e94ee171
  17. 24 9月, 2020 2 次提交