1. 11 4月, 2022 6 次提交
  2. 08 4月, 2022 10 次提交
  3. 01 4月, 2022 1 次提交
    • Z
      net/tls: fix slab-out-of-bounds bug in decrypt_internal · 9381fe8c
      Ziyang Xuan 提交于
      The memory size of tls_ctx->rx.iv for AES128-CCM is 12 setting in
      tls_set_sw_offload(). The return value of crypto_aead_ivsize()
      for "ccm(aes)" is 16. So memcpy() require 16 bytes from 12 bytes
      memory space will trigger slab-out-of-bounds bug as following:
      
      ==================================================================
      BUG: KASAN: slab-out-of-bounds in decrypt_internal+0x385/0xc40 [tls]
      Read of size 16 at addr ffff888114e84e60 by task tls/10911
      
      Call Trace:
       <TASK>
       dump_stack_lvl+0x34/0x44
       print_report.cold+0x5e/0x5db
       ? decrypt_internal+0x385/0xc40 [tls]
       kasan_report+0xab/0x120
       ? decrypt_internal+0x385/0xc40 [tls]
       kasan_check_range+0xf9/0x1e0
       memcpy+0x20/0x60
       decrypt_internal+0x385/0xc40 [tls]
       ? tls_get_rec+0x2e0/0x2e0 [tls]
       ? process_rx_list+0x1a5/0x420 [tls]
       ? tls_setup_from_iter.constprop.0+0x2e0/0x2e0 [tls]
       decrypt_skb_update+0x9d/0x400 [tls]
       tls_sw_recvmsg+0x3c8/0xb50 [tls]
      
      Allocated by task 10911:
       kasan_save_stack+0x1e/0x40
       __kasan_kmalloc+0x81/0xa0
       tls_set_sw_offload+0x2eb/0xa20 [tls]
       tls_setsockopt+0x68c/0x700 [tls]
       __sys_setsockopt+0xfe/0x1b0
      
      Replace the crypto_aead_ivsize() with prot->iv_size + prot->salt_size
      when memcpy() iv value in TLS_1_3_VERSION scenario.
      
      Fixes: f295b3ae ("net/tls: Add support of AES128-CCM based ciphers")
      Signed-off-by: NZiyang Xuan <william.xuanziyang@huawei.com>
      Reviewed-by: NJakub Kicinski <kuba@kernel.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      9381fe8c
  4. 22 3月, 2022 2 次提交
  5. 04 2月, 2022 1 次提交
    • J
      tls: cap the output scatter list to something reasonable · b93235e6
      Jakub Kicinski 提交于
      TLS recvmsg() passes user pages as destination for decrypt.
      The decrypt operation is repeated record by record, each
      record being 16kB, max. TLS allocates an sg_table and uses
      iov_iter_get_pages() to populate it with enough pages to
      fit the decrypted record.
      
      Even though we decrypt a single message at a time we size
      the sg_table based on the entire length of the iovec.
      This leads to unnecessarily large allocations, risking
      triggering OOM conditions.
      
      Use iov_iter_truncate() / iov_iter_reexpand() to construct
      a "capped" version of iov_iter_npages(). Alternatively we
      could parametrize iov_iter_npages() to take the size as
      arg instead of using i->count, or do something else..
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      b93235e6
  6. 17 1月, 2022 1 次提交
  7. 08 1月, 2022 1 次提交
    • G
      net/tls: Fix skb memory leak when running kTLS traffic · ffef737f
      Gal Pressman 提交于
      The cited Fixes commit introduced a memory leak when running kTLS
      traffic (with/without hardware offloads).
      I'm running nginx on the server side and wrk on the client side and get
      the following:
      
        unreferenced object 0xffff8881935e9b80 (size 224):
        comm "softirq", pid 0, jiffies 4294903611 (age 43.204s)
        hex dump (first 32 bytes):
          80 9b d0 36 81 88 ff ff 00 00 00 00 00 00 00 00  ...6............
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<00000000efe2a999>] build_skb+0x1f/0x170
          [<00000000ef521785>] mlx5e_skb_from_cqe_mpwrq_linear+0x2bc/0x610 [mlx5_core]
          [<00000000945d0ffe>] mlx5e_handle_rx_cqe_mpwrq+0x264/0x9e0 [mlx5_core]
          [<00000000cb675b06>] mlx5e_poll_rx_cq+0x3ad/0x17a0 [mlx5_core]
          [<0000000018aac6a9>] mlx5e_napi_poll+0x28c/0x1b60 [mlx5_core]
          [<000000001f3369d1>] __napi_poll+0x9f/0x560
          [<00000000cfa11f72>] net_rx_action+0x357/0xa60
          [<000000008653b8d7>] __do_softirq+0x282/0x94e
          [<00000000644923c6>] __irq_exit_rcu+0x11f/0x170
          [<00000000d4085f8f>] irq_exit_rcu+0xa/0x20
          [<00000000d412fef4>] common_interrupt+0x7d/0xa0
          [<00000000bfb0cebc>] asm_common_interrupt+0x1e/0x40
          [<00000000d80d0890>] default_idle+0x53/0x70
          [<00000000f2b9780e>] default_idle_call+0x8c/0xd0
          [<00000000c7659e15>] do_idle+0x394/0x450
      
      I'm not familiar with these areas of the code, but I've added this
      sk_defer_free_flush() to tls_sw_recvmsg() based on a hunch and it
      resolved the issue.
      
      Fixes: f35f8219 ("tcp: defer skb freeing after socket lock is released")
      Signed-off-by: NGal Pressman <gal@nvidia.com>
      Reviewed-by: NEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20220102081253.9123-1-gal@nvidia.comSigned-off-by: NJakub Kicinski <kuba@kernel.org>
      ffef737f
  8. 30 11月, 2021 1 次提交
  9. 29 11月, 2021 1 次提交
  10. 26 11月, 2021 3 次提交
    • J
      tls: fix replacing proto_ops · f3911f73
      Jakub Kicinski 提交于
      We replace proto_ops whenever TLS is configured for RX. But our
      replacement also overrides sendpage_locked, which will crash
      unless TX is also configured. Similarly we plug both of those
      in for TLS_HW (NIC crypto offload) even tho TLS_HW has a completely
      different implementation for TX.
      
      Last but not least we always plug in something based on inet_stream_ops
      even though a few of the callbacks differ for IPv6 (getname, release,
      bind).
      
      Use a callback building method similar to what we do for struct proto.
      
      Fixes: c46234eb ("tls: RX path for ktls")
      Fixes: d4ffb02d ("net/tls: enable sk_msg redirect to tls socket egress")
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      f3911f73
    • J
      tls: splice_read: fix accessing pre-processed records · e062fe99
      Jakub Kicinski 提交于
      recvmsg() will put peek()ed and partially read records onto the rx_list.
      splice_read() needs to consult that list otherwise it may miss data.
      Align with recvmsg() and also put partially-read records onto rx_list.
      tls_sw_advance_skb() is pretty pointless now and will be removed in
      net-next.
      
      Fixes: 692d7b5d ("tls: Fix recvmsg() to be able to peek across multiple records")
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      e062fe99
    • J
      tls: splice_read: fix record type check · 520493f6
      Jakub Kicinski 提交于
      We don't support splicing control records. TLS 1.3 changes moved
      the record type check into the decrypt if(). The skb may already
      be decrypted and still be an alert.
      
      Note that decrypt_skb_update() is idempotent and updates ctx->decrypted
      so the if() is pointless.
      
      Reorder the check for decryption errors with the content type check
      while touching them. This part is not really a bug, because if
      decryption failed in TLS 1.3 content type will be DATA, and for
      TLS 1.2 it will be correct. Nevertheless its strange to touch output
      before checking if the function has failed.
      
      Fixes: fedf201e ("net: tls: Refactor control message handling on recv")
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      520493f6
  11. 28 10月, 2021 2 次提交
    • D
      net/tls: Fix flipped sign in async_wait.err assignment · 1d9d6fd2
      Daniel Jordan 提交于
      sk->sk_err contains a positive number, yet async_wait.err wants the
      opposite.  Fix the missed sign flip, which Jakub caught by inspection.
      
      Fixes: a42055e8 ("net/tls: Add support for async encryption of records for performance")
      Suggested-by: NJakub Kicinski <kuba@kernel.org>
      Signed-off-by: NDaniel Jordan <daniel.m.jordan@oracle.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      1d9d6fd2
    • D
      net/tls: Fix flipped sign in tls_err_abort() calls · da353fac
      Daniel Jordan 提交于
      sk->sk_err appears to expect a positive value, a convention that ktls
      doesn't always follow and that leads to memory corruption in other code.
      For instance,
      
          [kworker]
          tls_encrypt_done(..., err=<negative error from crypto request>)
            tls_err_abort(.., err)
              sk->sk_err = err;
      
          [task]
          splice_from_pipe_feed
            ...
              tls_sw_do_sendpage
                if (sk->sk_err) {
                  ret = -sk->sk_err;  // ret is positive
      
          splice_from_pipe_feed (continued)
            ret = actor(...)  // ret is still positive and interpreted as bytes
                              // written, resulting in underflow of buf->len and
                              // sd->len, leading to huge buf->offset and bogus
                              // addresses computed in later calls to actor()
      
      Fix all tls_err_abort() callers to pass a negative error code
      consistently and centralize the error-prone sign flip there, throwing in
      a warning to catch future misuse and uninlining the function so it
      really does only warn once.
      
      Cc: stable@vger.kernel.org
      Fixes: c46234eb ("tls: RX path for ktls")
      Reported-by: syzbot+b187b77c8474f9648fae@syzkaller.appspotmail.com
      Signed-off-by: NDaniel Jordan <daniel.m.jordan@oracle.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      da353fac
  12. 27 10月, 2021 1 次提交
  13. 25 10月, 2021 1 次提交
  14. 28 9月, 2021 1 次提交
  15. 16 9月, 2021 1 次提交
  16. 22 6月, 2021 1 次提交
  17. 08 6月, 2021 1 次提交
  18. 02 6月, 2021 2 次提交
    • M
      net/tls: Fix use-after-free after the TLS device goes down and up · c55dcdd4
      Maxim Mikityanskiy 提交于
      When a netdev with active TLS offload goes down, tls_device_down is
      called to stop the offload and tear down the TLS context. However, the
      socket stays alive, and it still points to the TLS context, which is now
      deallocated. If a netdev goes up, while the connection is still active,
      and the data flow resumes after a number of TCP retransmissions, it will
      lead to a use-after-free of the TLS context.
      
      This commit addresses this bug by keeping the context alive until its
      normal destruction, and implements the necessary fallbacks, so that the
      connection can resume in software (non-offloaded) kTLS mode.
      
      On the TX side tls_sw_fallback is used to encrypt all packets. The RX
      side already has all the necessary fallbacks, because receiving
      non-decrypted packets is supported. The thing needed on the RX side is
      to block resync requests, which are normally produced after receiving
      non-decrypted packets.
      
      The necessary synchronization is implemented for a graceful teardown:
      first the fallbacks are deployed, then the driver resources are released
      (it used to be possible to have a tls_dev_resync after tls_dev_del).
      
      A new flag called TLS_RX_DEV_DEGRADED is added to indicate the fallback
      mode. It's used to skip the RX resync logic completely, as it becomes
      useless, and some objects may be released (for example, resync_async,
      which is allocated and freed by the driver).
      
      Fixes: e8f69799 ("net/tls: Add generic NIC offload infrastructure")
      Signed-off-by: NMaxim Mikityanskiy <maximmi@nvidia.com>
      Reviewed-by: NTariq Toukan <tariqt@nvidia.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      c55dcdd4
    • M
      net/tls: Replace TLS_RX_SYNC_RUNNING with RCU · 05fc8b6c
      Maxim Mikityanskiy 提交于
      RCU synchronization is guaranteed to finish in finite time, unlike a
      busy loop that polls a flag. This patch is a preparation for the bugfix
      in the next patch, where the same synchronize_net() call will also be
      used to sync with the TX datapath.
      Signed-off-by: NMaxim Mikityanskiy <maximmi@nvidia.com>
      Reviewed-by: NTariq Toukan <tariqt@nvidia.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      05fc8b6c
  19. 15 5月, 2021 1 次提交
  20. 13 5月, 2021 1 次提交
  21. 28 4月, 2021 1 次提交