1. 26 12月, 2021 1 次提交
    • X
      sctp: use call_rcu to free endpoint · 5ec7d18d
      Xin Long 提交于
      This patch is to delay the endpoint free by calling call_rcu() to fix
      another use-after-free issue in sctp_sock_dump():
      
        BUG: KASAN: use-after-free in __lock_acquire+0x36d9/0x4c20
        Call Trace:
          __lock_acquire+0x36d9/0x4c20 kernel/locking/lockdep.c:3218
          lock_acquire+0x1ed/0x520 kernel/locking/lockdep.c:3844
          __raw_spin_lock_bh include/linux/spinlock_api_smp.h:135 [inline]
          _raw_spin_lock_bh+0x31/0x40 kernel/locking/spinlock.c:168
          spin_lock_bh include/linux/spinlock.h:334 [inline]
          __lock_sock+0x203/0x350 net/core/sock.c:2253
          lock_sock_nested+0xfe/0x120 net/core/sock.c:2774
          lock_sock include/net/sock.h:1492 [inline]
          sctp_sock_dump+0x122/0xb20 net/sctp/diag.c:324
          sctp_for_each_transport+0x2b5/0x370 net/sctp/socket.c:5091
          sctp_diag_dump+0x3ac/0x660 net/sctp/diag.c:527
          __inet_diag_dump+0xa8/0x140 net/ipv4/inet_diag.c:1049
          inet_diag_dump+0x9b/0x110 net/ipv4/inet_diag.c:1065
          netlink_dump+0x606/0x1080 net/netlink/af_netlink.c:2244
          __netlink_dump_start+0x59a/0x7c0 net/netlink/af_netlink.c:2352
          netlink_dump_start include/linux/netlink.h:216 [inline]
          inet_diag_handler_cmd+0x2ce/0x3f0 net/ipv4/inet_diag.c:1170
          __sock_diag_cmd net/core/sock_diag.c:232 [inline]
          sock_diag_rcv_msg+0x31d/0x410 net/core/sock_diag.c:263
          netlink_rcv_skb+0x172/0x440 net/netlink/af_netlink.c:2477
          sock_diag_rcv+0x2a/0x40 net/core/sock_diag.c:274
      
      This issue occurs when asoc is peeled off and the old sk is freed after
      getting it by asoc->base.sk and before calling lock_sock(sk).
      
      To prevent the sk free, as a holder of the sk, ep should be alive when
      calling lock_sock(). This patch uses call_rcu() and moves sock_put and
      ep free into sctp_endpoint_destroy_rcu(), so that it's safe to try to
      hold the ep under rcu_read_lock in sctp_transport_traverse_process().
      
      If sctp_endpoint_hold() returns true, it means this ep is still alive
      and we have held it and can continue to dump it; If it returns false,
      it means this ep is dead and can be freed after rcu_read_unlock, and
      we should skip it.
      
      In sctp_sock_dump(), after locking the sk, if this ep is different from
      tsp->asoc->ep, it means during this dumping, this asoc was peeled off
      before calling lock_sock(), and the sk should be skipped; If this ep is
      the same with tsp->asoc->ep, it means no peeloff happens on this asoc,
      and due to lock_sock, no peeloff will happen either until release_sock.
      
      Note that delaying endpoint free won't delay the port release, as the
      port release happens in sctp_endpoint_destroy() before calling call_rcu().
      Also, freeing endpoint by call_rcu() makes it safe to access the sk by
      asoc->base.sk in sctp_assocs_seq_show() and sctp_rcv().
      
      Thanks Jones to bring this issue up.
      
      v1->v2:
        - improve the changelog.
        - add kfree(ep) into sctp_endpoint_destroy_rcu(), as Jakub noticed.
      
      Reported-by: syzbot+9276d76e83e3bcde6c99@syzkaller.appspotmail.com
      Reported-by: NLee Jones <lee.jones@linaro.org>
      Fixes: d25adbeb ("sctp: fix an use-after-free issue in sctp_sock_dump")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      5ec7d18d
  2. 14 11月, 2021 1 次提交
    • P
      net,lsm,selinux: revert the security_sctp_assoc_established() hook · 1aa3b220
      Paul Moore 提交于
      This patch reverts two prior patches, e7310c94
      ("security: implement sctp_assoc_established hook in selinux") and
      7c2ef024 ("security: add sctp_assoc_established hook"), which
      create the security_sctp_assoc_established() LSM hook and provide a
      SELinux implementation.  Unfortunately these two patches were merged
      without proper review (the Reviewed-by and Tested-by tags from
      Richard Haines were for previous revisions of these patches that
      were significantly different) and there are outstanding objections
      from the SELinux maintainers regarding these patches.
      
      Work is currently ongoing to correct the problems identified in the
      reverted patches, as well as others that have come up during review,
      but it is unclear at this point in time when that work will be ready
      for inclusion in the mainline kernel.  In the interest of not keeping
      objectionable code in the kernel for multiple weeks, and potentially
      a kernel release, we are reverting the two problematic patches.
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      1aa3b220
  3. 13 11月, 2021 1 次提交
    • P
      net,lsm,selinux: revert the security_sctp_assoc_established() hook · 32a370ab
      Paul Moore 提交于
      This patch reverts two prior patches, e7310c94
      ("security: implement sctp_assoc_established hook in selinux") and
      7c2ef024 ("security: add sctp_assoc_established hook"), which
      create the security_sctp_assoc_established() LSM hook and provide a
      SELinux implementation.  Unfortunately these two patches were merged
      without proper review (the Reviewed-by and Tested-by tags from
      Richard Haines were for previous revisions of these patches that
      were significantly different) and there are outstanding objections
      from the SELinux maintainers regarding these patches.
      
      Work is currently ongoing to correct the problems identified in the
      reverted patches, as well as others that have come up during review,
      but it is unclear at this point in time when that work will be ready
      for inclusion in the mainline kernel.  In the interest of not keeping
      objectionable code in the kernel for multiple weeks, and potentially
      a kernel release, we are reverting the two problematic patches.
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      32a370ab
  4. 08 11月, 2021 1 次提交
  5. 07 11月, 2021 1 次提交
    • M
      include/linux/mm.h: move nr_free_buffer_pages from swap.h to mm.h · a1554c00
      Mianhan Liu 提交于
      nr_free_buffer_pages could be exposed through mm.h instead of swap.h.
      The advantage of this change is that it can reduce the obsolete
      includes.  For example, net/ipv4/tcp.c wouldn't need swap.h any more
      since it has already included mm.h.  Similarly, after checking all the
      other files, it comes that tcp.c, udp.c meter.c ,...  follow the same
      rule, so these files can have swap.h removed too.
      
      Moreover, after preprocessing all the files that use
      nr_free_buffer_pages, it turns out that those files have already
      included mm.h.Thus, we can move nr_free_buffer_pages from swap.h to mm.h
      safely.  This change will not affect the compilation of other files.
      
      Link: https://lkml.kernel.org/r/20210912133640.1624-1-liumh1@shanghaitech.edu.cnSigned-off-by: NMianhan Liu <liumh1@shanghaitech.edu.cn>
      Cc: Jakub Kicinski <kuba@kernel.org>
      CC: Ulf Hansson <ulf.hansson@linaro.org>
      Cc: "David S . Miller" <davem@davemloft.net>
      Cc: Simon Horman <horms@verge.net.au>
      Cc: Pravin B Shelar <pshelar@ovn.org>
      Cc: Vlad Yasevich <vyasevich@gmail.com>
      Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      a1554c00
  6. 03 11月, 2021 3 次提交
  7. 29 10月, 2021 2 次提交
    • X
      sctp: return true only for pathmtu update in sctp_transport_pl_toobig · 75cf662c
      Xin Long 提交于
      sctp_transport_pl_toobig() supposes to return true only if there's
      pathmtu update, so that in sctp_icmp_frag_needed() it would call
      sctp_assoc_sync_pmtu() and sctp_retransmit(). This patch is to fix
      these return places in sctp_transport_pl_toobig().
      
      Fixes: 83696408 ("sctp: do state transition when receiving an icmp TOOBIG packet")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      75cf662c
    • X
      sctp: allow IP fragmentation when PLPMTUD enters Error state · 40171248
      Xin Long 提交于
      Currently when PLPMTUD enters Error state, transport pathmtu will be set
      to MIN_PLPMTU(512) while probe is continuing with BASE_PLPMTU(1200). It
      will cause pathmtu to stay in a very small value, even if the real pmtu
      is some value like 1000.
      
      RFC8899 doesn't clearly say how to set the value in Error state. But one
      possibility could be keep using BASE_PLPMTU for the real pmtu, but allow
      to do IP fragmentation when it's in Error state.
      
      As it says in rfc8899#section-5.4:
      
         Some paths could be unable to sustain packets of the BASE_PLPMTU
         size.  The Error State could be implemented to provide robustness to
         such paths.  This allows fallback to a smaller than desired PLPMTU
         rather than suffer connectivity failure.  This could utilize methods
         such as endpoint IP fragmentation to enable the PL sender to
         communicate using packets smaller than the BASE_PLPMTU.
      
      This patch is to set pmtu to BASE_PLPMTU instead of MIN_PLPMTU for Error
      state in sctp_transport_pl_send/toobig(), and set packet ipfragok for
      non-probe packets when it's in Error state.
      
      Fixes: 1dc68c19 ("sctp: do state transition when PROBE_COUNT == MAX_PROBES on HB send path")
      Reported-by: NYing Xu <yinxu@redhat.com>
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      40171248
  8. 23 10月, 2021 7 次提交
    • X
      sctp: add vtag check in sctp_sf_ootb · 9d02831e
      Xin Long 提交于
      sctp_sf_ootb() is called when processing DATA chunk in closed state,
      and many other places are also using it.
      
      The vtag in the chunk's sctphdr should be verified, otherwise, as
      later in chunk length check, it may send abort with the existent
      asoc's vtag, which can be exploited by one to cook a malicious
      chunk to terminate a SCTP asoc.
      
      When fails to verify the vtag from the chunk, this patch sets asoc
      to NULL, so that the abort will be made with the vtag from the
      received chunk later.
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Acked-by: NMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      9d02831e
    • X
      sctp: add vtag check in sctp_sf_do_8_5_1_E_sa · ef16b173
      Xin Long 提交于
      sctp_sf_do_8_5_1_E_sa() is called when processing SHUTDOWN_ACK chunk
      in cookie_wait and cookie_echoed state.
      
      The vtag in the chunk's sctphdr should be verified, otherwise, as
      later in chunk length check, it may send abort with the existent
      asoc's vtag, which can be exploited by one to cook a malicious
      chunk to terminate a SCTP asoc.
      
      Note that when fails to verify the vtag from SHUTDOWN-ACK chunk,
      SHUTDOWN COMPLETE message will still be sent back to peer, but
      with the vtag from SHUTDOWN-ACK chunk, as said in 5) of
      rfc4960#section-8.4.
      
      While at it, also remove the unnecessary chunk length check from
      sctp_sf_shut_8_4_5(), as it's already done in both places where
      it calls sctp_sf_shut_8_4_5().
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Acked-by: NMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      ef16b173
    • X
      sctp: add vtag check in sctp_sf_violation · aa0f697e
      Xin Long 提交于
      sctp_sf_violation() is called when processing HEARTBEAT_ACK chunk
      in cookie_wait state, and some other places are also using it.
      
      The vtag in the chunk's sctphdr should be verified, otherwise, as
      later in chunk length check, it may send abort with the existent
      asoc's vtag, which can be exploited by one to cook a malicious
      chunk to terminate a SCTP asoc.
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Acked-by: NMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      aa0f697e
    • X
      sctp: fix the processing for COOKIE_ECHO chunk · a64b341b
      Xin Long 提交于
      1. In closed state: in sctp_sf_do_5_1D_ce():
      
        When asoc is NULL, making packet for abort will use chunk's vtag
        in sctp_ootb_pkt_new(). But when asoc exists, vtag from the chunk
        should be verified before using peer.i.init_tag to make packet
        for abort in sctp_ootb_pkt_new(), and just discard it if vtag is
        not correct.
      
      2. In the other states: in sctp_sf_do_5_2_4_dupcook():
      
        asoc always exists, but duplicate cookie_echo's vtag will be
        handled by sctp_tietags_compare() and then take actions, so before
        that we only verify the vtag for the abort sent for invalid chunk
        length.
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Acked-by: NMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      a64b341b
    • X
      sctp: fix the processing for INIT_ACK chunk · 438b95a7
      Xin Long 提交于
      Currently INIT_ACK chunk in non-cookie_echoed state is processed in
      sctp_sf_discard_chunk() to send an abort with the existent asoc's
      vtag if the chunk length is not valid. But the vtag in the chunk's
      sctphdr is not verified, which may be exploited by one to cook a
      malicious chunk to terminal a SCTP asoc.
      
      sctp_sf_discard_chunk() also is called in many other places to send
      an abort, and most of those have this problem. This patch is to fix
      it by sending abort with the existent asoc's vtag only if the vtag
      from the chunk's sctphdr is verified in sctp_sf_discard_chunk().
      
      Note on sctp_sf_do_9_1_abort() and sctp_sf_shutdown_pending_abort(),
      the chunk length has been verified before sctp_sf_discard_chunk(),
      so replace it with sctp_sf_discard(). On sctp_sf_do_asconf_ack() and
      sctp_sf_do_asconf(), move the sctp_chunk_length_valid check ahead of
      sctp_sf_discard_chunk(), then replace it with sctp_sf_discard().
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Acked-by: NMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      438b95a7
    • X
      sctp: fix the processing for INIT chunk · eae57839
      Xin Long 提交于
      This patch fixes the problems below:
      
      1. In non-shutdown_ack_sent states: in sctp_sf_do_5_1B_init() and
         sctp_sf_do_5_2_2_dupinit():
      
        chunk length check should be done before any checks that may cause
        to send abort, as making packet for abort will access the init_tag
        from init_hdr in sctp_ootb_pkt_new().
      
      2. In shutdown_ack_sent state: in sctp_sf_do_9_2_reshutack():
      
        The same checks as does in sctp_sf_do_5_2_2_dupinit() is needed
        for sctp_sf_do_9_2_reshutack().
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Acked-by: NMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      eae57839
    • X
      sctp: use init_tag from inithdr for ABORT chunk · 4f7019c7
      Xin Long 提交于
      Currently Linux SCTP uses the verification tag of the existing SCTP
      asoc when failing to process and sending the packet with the ABORT
      chunk. This will result in the peer accepting the ABORT chunk and
      removing the SCTP asoc. One could exploit this to terminate a SCTP
      asoc.
      
      This patch is to fix it by always using the initiate tag of the
      received INIT chunk for the ABORT chunk to be sent.
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Acked-by: NMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      4f7019c7
  9. 14 10月, 2021 1 次提交
  10. 24 9月, 2021 1 次提交
    • X
      sctp: break out if skb_header_pointer returns NULL in sctp_rcv_ootb · f7e745f8
      Xin Long 提交于
      We should always check if skb_header_pointer's return is NULL before
      using it, otherwise it may cause null-ptr-deref, as syzbot reported:
      
        KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
        RIP: 0010:sctp_rcv_ootb net/sctp/input.c:705 [inline]
        RIP: 0010:sctp_rcv+0x1d84/0x3220 net/sctp/input.c:196
        Call Trace:
        <IRQ>
         sctp6_rcv+0x38/0x60 net/sctp/ipv6.c:1109
         ip6_protocol_deliver_rcu+0x2e9/0x1ca0 net/ipv6/ip6_input.c:422
         ip6_input_finish+0x62/0x170 net/ipv6/ip6_input.c:463
         NF_HOOK include/linux/netfilter.h:307 [inline]
         NF_HOOK include/linux/netfilter.h:301 [inline]
         ip6_input+0x9c/0xd0 net/ipv6/ip6_input.c:472
         dst_input include/net/dst.h:460 [inline]
         ip6_rcv_finish net/ipv6/ip6_input.c:76 [inline]
         NF_HOOK include/linux/netfilter.h:307 [inline]
         NF_HOOK include/linux/netfilter.h:301 [inline]
         ipv6_rcv+0x28c/0x3c0 net/ipv6/ip6_input.c:297
      
      Fixes: 3acb50c1 ("sctp: delay as much as possible skb_linearize")
      Reported-by: syzbot+581aff2ae6b860625116@syzkaller.appspotmail.com
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Acked-by: NMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      f7e745f8
  11. 03 8月, 2021 1 次提交
    • X
      sctp: move the active_key update after sh_keys is added · ae954bbc
      Xin Long 提交于
      In commit 58acd100 ("sctp: update active_key for asoc when old key is
      being replaced"), sctp_auth_asoc_init_active_key() is called to update
      the active_key right after the old key is deleted and before the new key
      is added, and it caused that the active_key could be found with the key_id.
      
      In Ying Xu's testing, the BUG_ON in sctp_auth_asoc_init_active_key() was
      triggered:
      
        [ ] kernel BUG at net/sctp/auth.c:416!
        [ ] RIP: 0010:sctp_auth_asoc_init_active_key.part.8+0xe7/0xf0 [sctp]
        [ ] Call Trace:
        [ ]  sctp_auth_set_key+0x16d/0x1b0 [sctp]
        [ ]  sctp_setsockopt.part.33+0x1ba9/0x2bd0 [sctp]
        [ ]  __sys_setsockopt+0xd6/0x1d0
        [ ]  __x64_sys_setsockopt+0x20/0x30
        [ ]  do_syscall_64+0x5b/0x1a0
      
      So fix it by moving the active_key update after sh_keys is added.
      
      Fixes: 58acd100 ("sctp: update active_key for asoc when old key is being replaced")
      Reported-by: NYing Xu <yinxu@redhat.com>
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      ae954bbc
  12. 28 7月, 2021 1 次提交
  13. 26 7月, 2021 3 次提交
    • C
      sctp: delete addr based on sin6_scope_id · 2ebda027
      Chen Shen 提交于
      sctp_inet6addr_event deletes 'addr' from 'local_addr_list' when setting
      netdev down, but it is possible to delete the incorrect entry (match
      the first one with the same ipaddr, but the different 'ifindex'), if
      there are some netdevs with the same 'local-link' ipaddr added already.
      It should delete the entry depending on 'sin6_addr' and 'sin6_scope_id'
      both. otherwise, the endpoint will call 'sctp_sf_ootb' if it can't find
      the according association when receives 'heartbeat', and finally will
      reply 'abort'.
      
      For example:
      1.when linux startup
      the entries in local_addr_list:
      ifindex:35 addr:fe80::40:43ff:fe80:0 (eths0.201)
      ifindex:36 addr:fe80::40:43ff:fe80:0 (eths0.209)
      ifindex:37 addr:fe80::40:43ff:fe80:0 (eths0.210)
      
      the route table:
      local fe80::40:43ff:fe80:0 dev eths0.201
      local fe80::40:43ff:fe80:0 dev eths0.209
      local fe80::40:43ff:fe80:0 dev eths0.210
      
      2.after 'ifconfig eths0.209 down'
      the entries in local_addr_list:
      ifindex:36 addr:fe80::40:43ff:fe80:0 (eths0.209)
      ifindex:37 addr:fe80::40:43ff:fe80:0 (eths0.210)
      
      the route table:
      local fe80::40:43ff:fe80:0 dev eths0.201
      local fe80::40:43ff:fe80:0 dev eths0.210
      
      3.asoc not found for src:[fe80::40:43ff:fe80:0]:37381 dst:[:1]:53335
      ::1->fe80::40:43ff:fe80:0 HEARTBEAT
      fe80::40:43ff:fe80:0->::1 ABORT
      Signed-off-by: NChen Shen <peterchenshen@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      2ebda027
    • X
      sctp: send pmtu probe only if packet loss in Search Complete state · eacf078c
      Xin Long 提交于
      This patch is to introduce last_rtx_chunks into sctp_transport to detect
      if there's any packet retransmission/loss happened by checking against
      asoc's rtx_data_chunks in sctp_transport_pl_send().
      
      If there is, namely, transport->last_rtx_chunks != asoc->rtx_data_chunks,
      the pmtu probe will be sent out. Otherwise, increment the pl.raise_count
      and return when it's in Search Complete state.
      
      With this patch, if in Search Complete state, which is a long period, it
      doesn't need to keep probing the current pmtu unless there's data packet
      loss. This will save quite some traffic.
      
      v1->v2:
        - add the missing Fixes tag.
      
      Fixes: 0dac127c ("sctp: do black hole detection in search complete state")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      eacf078c
    • X
      sctp: improve the code for pmtu probe send and recv update · 058e6e0e
      Xin Long 提交于
      This patch does 3 things:
      
        - make sctp_transport_pl_send() and sctp_transport_pl_recv()
          return bool type to decide if more probe is needed to send.
      
        - pr_debug() only when probe is really needed to send.
      
        - count pl.raise_count in sctp_transport_pl_send() instead of
          sctp_transport_pl_recv(), and it's only incremented for the
          1st probe for the same size.
      
      These are preparations for the next patch to make probes happen
      only when there's packet loss in Search Complete state.
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      058e6e0e
  14. 22 7月, 2021 1 次提交
  15. 21 7月, 2021 1 次提交
    • X
      sctp: update active_key for asoc when old key is being replaced · 58acd100
      Xin Long 提交于
      syzbot reported a call trace:
      
        BUG: KASAN: use-after-free in sctp_auth_shkey_hold+0x22/0xa0 net/sctp/auth.c:112
        Call Trace:
         sctp_auth_shkey_hold+0x22/0xa0 net/sctp/auth.c:112
         sctp_set_owner_w net/sctp/socket.c:131 [inline]
         sctp_sendmsg_to_asoc+0x152e/0x2180 net/sctp/socket.c:1865
         sctp_sendmsg+0x103b/0x1d30 net/sctp/socket.c:2027
         inet_sendmsg+0x99/0xe0 net/ipv4/af_inet.c:821
         sock_sendmsg_nosec net/socket.c:703 [inline]
         sock_sendmsg+0xcf/0x120 net/socket.c:723
      
      This is an use-after-free issue caused by not updating asoc->shkey after
      it was replaced in the key list asoc->endpoint_shared_keys, and the old
      key was freed.
      
      This patch is to fix by also updating active_key for asoc when old key is
      being replaced with a new one. Note that this issue doesn't exist in
      sctp_auth_del_key_id(), as it's not allowed to delete the active_key
      from the asoc.
      
      Fixes: 1b1e0bc9 ("sctp: add refcnt support for sh_key")
      Reported-by: syzbot+b774577370208727d12b@syzkaller.appspotmail.com
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      58acd100
  16. 19 7月, 2021 1 次提交
    • X
      sctp: trim optlen when it's a huge value in sctp_setsockopt · 2f3fdd8d
      Xin Long 提交于
      After commit ca84bd05 ("sctp: copy the optval from user space in
      sctp_setsockopt"), it does memory allocation in sctp_setsockopt with
      the optlen, and it would fail the allocation and return error if the
      optlen from user space is a huge value.
      
      This breaks some sockopts, like SCTP_HMAC_IDENT, SCTP_RESET_STREAMS and
      SCTP_AUTH_KEY, as when processing these sockopts before, optlen would
      be trimmed to a biggest value it needs when optlen is a huge value,
      instead of failing the allocation and returning error.
      
      This patch is to fix the allocation failure when it's a huge optlen from
      user space by trimming it to the biggest size sctp sockopt may need when
      necessary, and this biggest size is from sctp_setsockopt_reset_streams()
      for SCTP_RESET_STREAMS, which is bigger than those for SCTP_HMAC_IDENT
      and SCTP_AUTH_KEY.
      
      Fixes: ca84bd05 ("sctp: copy the optval from user space in sctp_setsockopt")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      2f3fdd8d
  17. 14 7月, 2021 1 次提交
  18. 02 7月, 2021 3 次提交
  19. 30 6月, 2021 1 次提交
  20. 29 6月, 2021 4 次提交
  21. 25 6月, 2021 2 次提交
    • X
      sctp: send the next probe immediately once the last one is acked · fea1d5b1
      Xin Long 提交于
      These is no need to wait for 'interval' period for the next probe
      if the last probe is already acked in search state. The 'interval'
      period waiting should be only for probe failure timeout and the
      current pmtu check when it's in search complete state.
      
      This change will shorten the probe time a lot in search state, and
      also fix the document accordingly.
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      fea1d5b1
    • X
      sctp: do black hole detection in search complete state · 0dac127c
      Xin Long 提交于
      Currently the PLPMUTD probe will stop for a long period (interval * 30)
      after it enters search complete state. If there's a pmtu change on the
      route path, it takes a long time to be aware if the ICMP TooBig packet
      is lost or filtered.
      
      As it says in rfc8899#section-4.3:
      
        "A DPLPMTUD method MUST NOT rely solely on this method."
        (ICMP PTB message).
      
      This patch is to enable the other method for search complete state:
      
        "A PL can use the DPLPMTUD probing mechanism to periodically
         generate probe packets of the size of the current PLPMTU."
      
      With this patch, the probe will continue with the current pmtu every
      'interval' until the PMTU_RAISE_TIMER 'timeout', which we implement
      by adding raise_count to raise the probe size when it counts to 30
      and removing the SCTP_PL_COMPLETE check for PMTU_RAISE_TIMER.
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      0dac127c
  22. 23 6月, 2021 2 次提交