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. 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
  5. 17 1月, 2022 1 次提交
  6. 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
  7. 30 11月, 2021 1 次提交
  8. 29 11月, 2021 1 次提交
  9. 26 11月, 2021 2 次提交
    • 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
  10. 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
  11. 27 10月, 2021 1 次提交
  12. 28 9月, 2021 1 次提交
  13. 16 9月, 2021 1 次提交
  14. 22 6月, 2021 1 次提交
  15. 15 5月, 2021 1 次提交
  16. 13 5月, 2021 1 次提交
  17. 02 4月, 2021 1 次提交
  18. 28 11月, 2020 3 次提交
  19. 21 11月, 2020 1 次提交
    • V
      net/tls: missing received data after fast remote close · 20ffc7ad
      Vadim Fedorenko 提交于
      In case when tcp socket received FIN after some data and the
      parser haven't started before reading data caller will receive
      an empty buffer. This behavior differs from plain TCP socket and
      leads to special treating in user-space.
      The flow that triggers the race is simple. Server sends small
      amount of data right after the connection is configured to use TLS
      and closes the connection. In this case receiver sees TLS Handshake
      data, configures TLS socket right after Change Cipher Spec record.
      While the configuration is in process, TCP socket receives small
      Application Data record, Encrypted Alert record and FIN packet. So
      the TCP socket changes sk_shutdown to RCV_SHUTDOWN and sk_flag with
      SK_DONE bit set. The received data is not parsed upon arrival and is
      never sent to user-space.
      
      Patch unpauses parser directly if we have unparsed data in tcp
      receive queue.
      
      Fixes: fcf4793e ("tls: check RCV_SHUTDOWN in tls_wait_data")
      Signed-off-by: NVadim Fedorenko <vfedorenko@novek.ru>
      Link: https://lore.kernel.org/r/1605801588-12236-1-git-send-email-vfedorenko@novek.ruSigned-off-by: NJakub Kicinski <kuba@kernel.org>
      20ffc7ad
  20. 17 11月, 2020 1 次提交
  21. 25 9月, 2020 1 次提交
    • R
      net/tls: race causes kernel panic · 38f7e1c0
      Rohit Maheshwari 提交于
      BUG: kernel NULL pointer dereference, address: 00000000000000b8
       #PF: supervisor read access in kernel mode
       #PF: error_code(0x0000) - not-present page
       PGD 80000008b6fef067 P4D 80000008b6fef067 PUD 8b6fe6067 PMD 0
       Oops: 0000 [#1] SMP PTI
       CPU: 12 PID: 23871 Comm: kworker/12:80 Kdump: loaded Tainted: G S
       5.9.0-rc3+ #1
       Hardware name: Supermicro X10SRA-F/X10SRA-F, BIOS 2.1 03/29/2018
       Workqueue: events tx_work_handler [tls]
       RIP: 0010:tx_work_handler+0x1b/0x70 [tls]
       Code: dc fe ff ff e8 16 d4 a3 f6 66 0f 1f 44 00 00 0f 1f 44 00 00 55 53 48 8b
       6f 58 48 8b bd a0 04 00 00 48 85 ff 74 1c 48 8b 47 28 <48> 8b 90 b8 00 00 00 83
       e2 02 75 0c f0 48 0f ba b0 b8 00 00 00 00
       RSP: 0018:ffffa44ace61fe88 EFLAGS: 00010286
       RAX: 0000000000000000 RBX: ffff91da9e45cc30 RCX: dead000000000122
       RDX: 0000000000000001 RSI: ffff91da9e45cc38 RDI: ffff91d95efac200
       RBP: ffff91da133fd780 R08: 0000000000000000 R09: 000073746e657665
       R10: 8080808080808080 R11: 0000000000000000 R12: ffff91dad7d30700
       R13: ffff91dab6561080 R14: 0ffff91dad7d3070 R15: ffff91da9e45cc38
       FS:  0000000000000000(0000) GS:ffff91dad7d00000(0000) knlGS:0000000000000000
       CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
       CR2: 00000000000000b8 CR3: 0000000906478003 CR4: 00000000003706e0
       DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
       DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
       Call Trace:
        process_one_work+0x1a7/0x370
        worker_thread+0x30/0x370
        ? process_one_work+0x370/0x370
        kthread+0x114/0x130
        ? kthread_park+0x80/0x80
        ret_from_fork+0x22/0x30
      
      tls_sw_release_resources_tx() waits for encrypt_pending, which
      can have race, so we need similar changes as in commit
      0cada332 here as well.
      
      Fixes: a42055e8 ("net/tls: Add support for async encryption of records for performance")
      Signed-off-by: NRohit Maheshwari <rohitm@chelsio.com>
      Acked-by: NJakub Kicinski <kuba@kernel.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      38f7e1c0
  22. 08 8月, 2020 1 次提交
    • R
      net/tls: allow MSG_CMSG_COMPAT in sendmsg · 1c3b63f1
      Rouven Czerwinski 提交于
      Trying to use ktls on a system with 32-bit userspace and 64-bit kernel
      results in a EOPNOTSUPP message during sendmsg:
      
        setsockopt(3, SOL_TLS, TLS_TX, …, 40) = 0
        sendmsg(3, …, msg_flags=0}, 0) = -1 EOPNOTSUPP (Operation not supported)
      
      The tls_sw implementation does strict flag checking and does not allow
      the MSG_CMSG_COMPAT flag, which is set if the message comes in through
      the compat syscall.
      
      This patch adds MSG_CMSG_COMPAT to the flag check to allow the usage of
      the TLS SW implementation on systems using the compat syscall path.
      
      Note that the same check is present in the sendmsg path for the TLS
      device implementation, however the flag hasn't been added there for lack
      of testing hardware.
      Signed-off-by: NRouven Czerwinski <r.czerwinski@pengutronix.de>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      1c3b63f1