Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
  1. May 31, 2024
    • Jeff Johnson's avatar
      crypto: Add missing MODULE_DESCRIPTION() macros · 7c699fe9
      Jeff Johnson authored
      
      Fix the 'make W=1' warnings:
      WARNING: modpost: missing MODULE_DESCRIPTION() in crypto/cast_common.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in crypto/af_alg.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in crypto/algif_hash.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in crypto/algif_skcipher.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in crypto/ecc.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in crypto/curve25519-generic.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in crypto/xor.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in crypto/crypto_simd.o
      
      Signed-off-by: default avatarJeff Johnson <quic_jjohnson@quicinc.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      7c699fe9
  2. May 13, 2024
  3. Mar 29, 2024
  4. Dec 07, 2023
  5. Aug 18, 2023
    • Pavel Skripkin's avatar
      crypto: fix uninit-value in af_alg_free_resources · 080aa61e
      Pavel Skripkin authored
      Syzbot was able to trigger use of uninitialized memory in
      af_alg_free_resources.
      
      Bug is caused by missing initialization of rsgl->sgl.need_unpin before
      adding to rsgl_list. Then in case of extract_iter_to_sg() failure, rsgl
      is left with uninitialized need_unpin which is read during clean up
      
      BUG: KMSAN: uninit-value in af_alg_free_sg crypto/af_alg.c:545 [inline]
      BUG: KMSAN: uninit-value in af_alg_free_areq_sgls crypto/af_alg.c:778 [inline]
      BUG: KMSAN: uninit-value in af_alg_free_resources+0x3d1/0xf60 crypto/af_alg.c:1117
       af_alg_free_sg crypto/af_alg.c:545 [inline]
       af_alg_free_areq_sgls crypto/af_alg.c:778 [inline]
       af_alg_free_resources+0x3d1/0xf60 crypto/af_alg.c:1117
       _skcipher_recvmsg crypto/algif_skcipher.c:144 [inline]
      ...
      
      Uninit was created at:
       slab_post_alloc_hook+0x12f/0xb70 mm/slab.h:767
       slab_alloc_node mm/slub.c:3470 [inline]
       __kmem_cache_alloc_node+0x536/0x8d0 mm/slub.c:3509
       __do_kmalloc_node mm/slab_common.c:984 [inline]
       __kmalloc+0x121/0x3c0 mm/slab_common.c:998
       kmalloc include/linux/slab.h:586 [inline]
       sock_kmalloc+0x128/0x1c0 net/core/sock.c:2683
       af_alg_alloc_areq+0x41/0x2a0 crypto/af_alg.c:1188
       _skcipher_recvmsg crypto/algif_skcipher.c:71 [inline]
      
      Fixes: c1abe6f5
      
       ("crypto: af_alg: Use extract_iter_to_sg() to create scatterlists")
      Reported-and-tested-by: default avatar <syzbot+cba21d50095623218389@syzkaller.appspotmail.com>
      Closes: https://syzkaller.appspot.com/bug?extid=cba21d50095623218389
      
      
      Signed-off-by: default avatarPavel Skripkin <paskripkin@gmail.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      080aa61e
  6. Aug 11, 2023
  7. Aug 04, 2023
    • David Howells's avatar
      crypto: af_alg - Fix missing initialisation affecting gcm-aes-s390 · 6a4b8aa0
      David Howells authored
      Fix af_alg_alloc_areq() to initialise areq->first_rsgl.sgl.sgt.sgl to point
      to the scatterlist array in areq->first_rsgl.sgl.sgl.
      
      Without this, the gcm-aes-s390 driver will oops when it tries to do
      gcm_walk_start() on req->dst because req->dst is set to the value of
      areq->first_rsgl.sgl.sgl by _aead_recvmsg() calling
      aead_request_set_crypt().
      
      The problem comes if an empty ciphertext is passed: the loop in
      af_alg_get_rsgl() just passes straight out and doesn't set areq->first_rsgl
      up.
      
      This isn't a problem on x86_64 using gcmaes_crypt_by_sg() because, as far
      as I can tell, that ignores req->dst and only uses req->src[*].
      
      [*] Is this a bug in aesni-intel_glue.c?
      
      The s390x oops looks something like:
      
       Unable to handle kernel pointer dereference in virtual kernel address space
       Failing address: 0000000a00000000 TEID: 0000000a00000803
       Fault in home space mode while using kernel ASCE.
       AS:00000000a43a0007 R3:0000000000000024
       Oops: 003b ilc:2 [#1] SMP
       ...
       Call Trace:
        [<000003ff7fc3d47e>] gcm_walk_start+0x16/0x28 [aes_s390]
        [<00000000a2a342f2>] crypto_aead_decrypt+0x9a/0xb8
        [<00000000a2a60888>] aead_recvmsg+0x478/0x698
        [<00000000a2e519a0>] sock_recvmsg+0x70/0xb0
        [<00000000a2e51a56>] sock_read_iter+0x76/0xa0
        [<00000000a273e066>] vfs_read+0x26e/0x2a8
        [<00000000a273e8c4>] ksys_read+0xbc/0x100
        [<00000000a311d808>] __do_syscall+0x1d0/0x1f8
        [<00000000a312ff30>] system_call+0x70/0x98
       Last Breaking-Event-Address:
        [<000003ff7fc3e6b4>] gcm_aes_crypt+0x104/0xa68 [aes_s390]
      
      Fixes: c1abe6f5
      
       ("crypto: af_alg: Use extract_iter_to_sg() to create scatterlists")
      Reported-by: default avatarOndrej Mosnáček <omosnacek@gmail.com>
      Link: https://lore.kernel.org/r/CAAUqJDuRkHE8fPgZJGaKjUjd3QfGwzfumuJBmStPqBhubxyk_A@mail.gmail.com/
      
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Herbert Xu <herbert@gondor.apana.org.au>
      cc: Sven Schnelle <svens@linux.ibm.com>
      cc: Harald Freudenberger <freude@linux.vnet.ibm.com>
      cc: "David S. Miller" <davem@davemloft.net>
      cc: Paolo Abeni <pabeni@redhat.com>
      cc: linux-crypto@vger.kernel.org
      cc: linux-s390@vger.kernel.org
      cc: regressions@lists.linux.dev
      Tested-by: default avatarSven Schnelle <svens@linux.ibm.com>
      Tested-by: default avatarOndrej Mosnáček <omosnacek@gmail.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      6a4b8aa0
  8. Jul 05, 2023
  9. Jun 24, 2023
  10. Jun 18, 2023
    • David Howells's avatar
      crypto: Fix af_alg_sendmsg(MSG_SPLICE_PAGES) sglist limit · 43804992
      David Howells authored
      When af_alg_sendmsg() calls extract_iter_to_sg(), it passes MAX_SGL_ENTS as
      the maximum number of elements that may be written to, but some of the
      elements may already have been used (as recorded in sgl->cur), so
      extract_iter_to_sg() may end up overrunning the scatterlist.
      
      Fix this to limit the number of elements to "MAX_SGL_ENTS - sgl->cur".
      
      Note: It probably makes sense in future to alter the behaviour of
      extract_iter_to_sg() to stop if "sgtable->nents >= sg_max" instead, but
      this is a smaller fix for now.
      
      The bug causes errors looking something like:
      
      BUG: KASAN: slab-out-of-bounds in sg_assign_page include/linux/scatterlist.h:109 [inline]
      BUG: KASAN: slab-out-of-bounds in sg_set_page include/linux/scatterlist.h:139 [inline]
      BUG: KASAN: slab-out-of-bounds in extract_bvec_to_sg lib/scatterlist.c:1183 [inline]
      BUG: KASAN: slab-out-of-bounds in extract_iter_to_sg lib/scatterlist.c:1352 [inline]
      BUG: KASAN: slab-out-of-bounds in extract_iter_to_sg+0x17a6/0x1960 lib/scatterlist.c:1339
      
      Fixes: bf63e250
      
       ("crypto: af_alg: Support MSG_SPLICE_PAGES")
      Reported-by: default avatar <syzbot+6efc50cc1f8d718d6cb7@syzkaller.appspotmail.com>
      Link: https://lore.kernel.org/r/000000000000b2585a05fdeb8379@google.com/
      
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Tested-by: default avatar <syzbot+6efc50cc1f8d718d6cb7@syzkaller.appspotmail.com>
      cc: Herbert Xu <herbert@gondor.apana.org.au>
      cc: "David S. Miller" <davem@davemloft.net>
      cc: Eric Dumazet <edumazet@google.com>
      cc: Jakub Kicinski <kuba@kernel.org>
      cc: Paolo Abeni <pabeni@redhat.com>
      cc: Jens Axboe <axboe@kernel.dk>
      cc: Matthew Wilcox <willy@infradead.org>
      cc: linux-crypto@vger.kernel.org
      cc: netdev@vger.kernel.org
      Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      43804992
  11. Jun 08, 2023
    • David Howells's avatar
      crypto: af_alg/hash: Support MSG_SPLICE_PAGES · c662b043
      David Howells authored
      
      Make AF_ALG sendmsg() support MSG_SPLICE_PAGES in the hashing code.  This
      causes pages to be spliced from the source iterator if possible.
      
      This allows ->sendpage() to be replaced by something that can handle
      multiple multipage folios in a single transaction.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Herbert Xu <herbert@gondor.apana.org.au>
      cc: "David S. Miller" <davem@davemloft.net>
      cc: Eric Dumazet <edumazet@google.com>
      cc: Jakub Kicinski <kuba@kernel.org>
      cc: Paolo Abeni <pabeni@redhat.com>
      cc: Jens Axboe <axboe@kernel.dk>
      cc: Matthew Wilcox <willy@infradead.org>
      cc: linux-crypto@vger.kernel.org
      cc: netdev@vger.kernel.org
      Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      c662b043
    • David Howells's avatar
      crypto: af_alg: Convert af_alg_sendpage() to use MSG_SPLICE_PAGES · fb800fa4
      David Howells authored
      
      Convert af_alg_sendpage() to use sendmsg() with MSG_SPLICE_PAGES rather
      than directly splicing in the pages itself.
      
      This allows ->sendpage() to be replaced by something that can handle
      multiple multipage folios in a single transaction.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Herbert Xu <herbert@gondor.apana.org.au>
      cc: "David S. Miller" <davem@davemloft.net>
      cc: Eric Dumazet <edumazet@google.com>
      cc: Jakub Kicinski <kuba@kernel.org>
      cc: Paolo Abeni <pabeni@redhat.com>
      cc: Jens Axboe <axboe@kernel.dk>
      cc: Matthew Wilcox <willy@infradead.org>
      cc: linux-crypto@vger.kernel.org
      cc: netdev@vger.kernel.org
      Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      fb800fa4
    • David Howells's avatar
      crypto: af_alg: Support MSG_SPLICE_PAGES · bf63e250
      David Howells authored
      
      Make AF_ALG sendmsg() support MSG_SPLICE_PAGES.  This causes pages to be
      spliced from the source iterator.
      
      This allows ->sendpage() to be replaced by something that can handle
      multiple multipage folios in a single transaction.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Herbert Xu <herbert@gondor.apana.org.au>
      cc: "David S. Miller" <davem@davemloft.net>
      cc: Eric Dumazet <edumazet@google.com>
      cc: Jakub Kicinski <kuba@kernel.org>
      cc: Paolo Abeni <pabeni@redhat.com>
      cc: Jens Axboe <axboe@kernel.dk>
      cc: Matthew Wilcox <willy@infradead.org>
      cc: linux-crypto@vger.kernel.org
      cc: netdev@vger.kernel.org
      Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      bf63e250
    • David Howells's avatar
      crypto: af_alg: Indent the loop in af_alg_sendmsg() · 73d7409c
      David Howells authored
      
      Put the loop in af_alg_sendmsg() into an if-statement to indent it to make
      the next patch easier to review as that will add another branch to handle
      MSG_SPLICE_PAGES to the if-statement.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Herbert Xu <herbert@gondor.apana.org.au>
      cc: "David S. Miller" <davem@davemloft.net>
      cc: Eric Dumazet <edumazet@google.com>
      cc: Jakub Kicinski <kuba@kernel.org>
      cc: Paolo Abeni <pabeni@redhat.com>
      cc: Jens Axboe <axboe@kernel.dk>
      cc: Matthew Wilcox <willy@infradead.org>
      cc: linux-crypto@vger.kernel.org
      cc: netdev@vger.kernel.org
      Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      73d7409c
    • David Howells's avatar
      crypto: af_alg: Use extract_iter_to_sg() to create scatterlists · c1abe6f5
      David Howells authored
      
      Use extract_iter_to_sg() to decant the destination iterator into a
      scatterlist in af_alg_get_rsgl().  af_alg_make_sg() can then be removed.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Herbert Xu <herbert@gondor.apana.org.au>
      cc: "David S. Miller" <davem@davemloft.net>
      cc: Eric Dumazet <edumazet@google.com>
      cc: Jakub Kicinski <kuba@kernel.org>
      cc: Paolo Abeni <pabeni@redhat.com>
      cc: Jens Axboe <axboe@kernel.dk>
      cc: Matthew Wilcox <willy@infradead.org>
      cc: linux-crypto@vger.kernel.org
      cc: netdev@vger.kernel.org
      Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      c1abe6f5
    • David Howells's avatar
      crypto: af_alg: Pin pages rather than ref'ing if appropriate · f9e7a5fa
      David Howells authored
      
      Convert AF_ALG to use iov_iter_extract_pages() instead of
      iov_iter_get_pages().  This will pin pages or leave them unaltered rather
      than getting a ref on them as appropriate to the iterator.
      
      The pages need to be pinned for DIO-read rather than having refs taken on
      them to prevent VM copy-on-write from malfunctioning during a concurrent
      fork() (the result of the I/O would otherwise end up only visible to the
      child process and not the parent).
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Herbert Xu <herbert@gondor.apana.org.au>
      cc: "David S. Miller" <davem@davemloft.net>
      cc: Eric Dumazet <edumazet@google.com>
      cc: Jakub Kicinski <kuba@kernel.org>
      cc: Paolo Abeni <pabeni@redhat.com>
      cc: Jens Axboe <axboe@kernel.dk>
      cc: Matthew Wilcox <willy@infradead.org>
      cc: linux-crypto@vger.kernel.org
      cc: netdev@vger.kernel.org
      Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      f9e7a5fa
  12. Feb 13, 2023
  13. Oct 28, 2022
    • Frederick Lawler's avatar
      crypto: af_alg - Support symmetric encryption via keyring keys · 7984ceb1
      Frederick Lawler authored
      
      We want to leverage keyring to store sensitive keys, and then use those
      keys for symmetric encryption via the crypto API. Among the key types we
      wish to support are: user, logon, encrypted, and trusted.
      
      User key types are already able to have their data copied to user space,
      but logon does not support this. Further, trusted and encrypted keys will
      return their encrypted data back to user space on read, which does not
      make them ideal for symmetric encryption.
      
      To support symmetric encryption for these key types, add a new
      ALG_SET_KEY_BY_KEY_SERIAL setsockopt() option to the crypto API. This
      allows users to pass a key_serial_t to the crypto API to perform
      symmetric encryption. The behavior is the same as ALG_SET_KEY, but
      the crypto key data is copied in kernel space from a keyring key,
      which allows for the support of logon, encrypted, and trusted key types.
      
      Keyring keys must have the KEY_(POS|USR|GRP|OTH)_SEARCH permission set
      to leverage this feature. This follows the asymmetric_key type where key
      lookup calls eventually lead to keyring_search_rcu() without the
      KEYRING_SEARCH_NO_CHECK_PERM flag set.
      
      Signed-off-by: default avatarFrederick Lawler <fred@cloudflare.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      7984ceb1
  14. Aug 08, 2022
  15. Feb 15, 2022
    • Eric Dumazet's avatar
      crypto: af_alg - get rid of alg_memory_allocated · 25206111
      Eric Dumazet authored
      alg_memory_allocated does not seem to be really used.
      
      alg_proto does have a .memory_allocated field, but no
      corresponding .sysctl_mem.
      
      This means sk_has_account() returns true, but all sk_prot_mem_limits()
      users will trigger a NULL dereference [1].
      
      THis was not a problem until SO_RESERVE_MEM addition.
      
      general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] PREEMPT SMP KASAN
      KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
      CPU: 1 PID: 3591 Comm: syz-executor153 Not tainted 5.17.0-rc3-syzkaller-00316-gb81b1829e7e3 #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      RIP: 0010:sk_prot_mem_limits include/net/sock.h:1523 [inline]
      RIP: 0010:sock_reserve_memory+0x1d7/0x330 net/core/sock.c:1000
      Code: 08 00 74 08 48 89 ef e8 27 20 bb f9 4c 03 7c 24 10 48 8b 6d 00 48 83 c5 08 48 89 e8 48 c1 e8 03 48 b9 00 00 00 00 00 fc ff df <80> 3c 08 00 74 08 48 89 ef e8 fb 1f bb f9 48 8b 6d 00 4c 89 ff 48
      RSP: 0018:ffffc90001f1fb68 EFLAGS: 00010202
      RAX: 0000000000000001 RBX: ffff88814aabc000 RCX: dffffc0000000000
      RDX: 0000000000000001 RSI: 0000000000000008 RDI: ffffffff90e18120
      RBP: 0000000000000008 R08: dffffc0000000000 R09: fffffbfff21c3025
      R10: fffffbfff21c3025 R11: 0000000000000000 R12: ffffffff8d109840
      R13: 0000000000001002 R14: 0000000000000001 R15: 0000000000000001
      FS:  0000555556e08300(0000) GS:ffff8880b9b00000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007fc74416f130 CR3: 0000000073d9e000 CR4: 00000000003506e0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
       <TASK>
       sock_setsockopt+0x14a9/0x3a30 net/core/sock.c:1446
       __sys_setsockopt+0x5af/0x980 net/socket.c:2176
       __do_sys_setsockopt net/socket.c:2191 [inline]
       __se_sys_setsockopt net/socket.c:2188 [inline]
       __x64_sys_setsockopt+0xb1/0xc0 net/socket.c:2188
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae
      RIP: 0033:0x7fc7440fddc9
      Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 51 15 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
      RSP: 002b:00007ffe98f07968 EFLAGS: 00000246 ORIG_RAX: 0000000000000036
      RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007fc7440fddc9
      RDX: 0000000000000049 RSI: 0000000000000001 RDI: 0000000000000004
      RBP: 0000000000000000 R08: 0000000000000004 R09: 00007ffe98f07990
      R10: 0000000020000000 R11: 0000000000000246 R12: 00007ffe98f0798c
      R13: 00007ffe98f079a0 R14: 00007ffe98f079e0 R15: 0000000000000000
       </TASK>
      Modules linked in:
      ---[ end trace 0000000000000000 ]---
      RIP: 0010:sk_prot_mem_limits include/net/sock.h:1523 [inline]
      RIP: 0010:sock_reserve_memory+0x1d7/0x330 net/core/sock.c:1000
      Code: 08 00 74 08 48 89 ef e8 27 20 bb f9 4c 03 7c 24 10 48 8b 6d 00 48 83 c5 08 48 89 e8 48 c1 e8 03 48 b9 00 00 00 00 00 fc ff df <80> 3c 08 00 74 08 48 89 ef e8 fb 1f bb f9 48 8b 6d 00 4c 89 ff 48
      RSP: 0018:ffffc90001f1fb68 EFLAGS: 00010202
      RAX: 0000000000000001 RBX: ffff88814aabc000 RCX: dffffc0000000000
      RDX: 0000000000000001 RSI: 0000000000000008 RDI: ffffffff90e18120
      RBP: 0000000000000008 R08: dffffc0000000000 R09: fffffbfff21c3025
      R10: fffffbfff21c3025 R11: 0000000000000000 R12: ffffffff8d109840
      R13: 0000000000001002 R14: 0000000000000001 R15: 0000000000000001
      FS:  0000555556e08300(0000) GS:ffff8880b9b00000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007fc74416f130 CR3: 0000000073d9e000 CR4: 00000000003506e0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      
      Fixes: 2bb2f5fb
      
       ("net: add new socket option SO_RESERVE_MEM")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Cc: Wei Wang <weiwan@google.com>
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      25206111
  16. Jan 06, 2022
  17. Oct 25, 2021
  18. Jun 03, 2021
  19. Apr 22, 2021
    • Randy Dunlap's avatar
      crypto: doc - fix kernel-doc notation in chacha.c and af_alg.c · b2a4411a
      Randy Dunlap authored
      Fix function name in chacha.c kernel-doc comment to remove a warning.
      
      Convert af_alg.c to kernel-doc notation to eliminate many kernel-doc
      warnings.
      
      ../lib/crypto/chacha.c:77: warning: expecting prototype for chacha_block(). Prototype was for chacha_block_generic() instead
      chacha.c:104: warning: Excess function parameter 'out' description in 'hchacha_block_generic'
      
      af_alg.c:498: warning: Function parameter or member 'sk' not described in 'af_alg_alloc_tsgl'
      ../crypto/af_alg.c:539: warning: expecting prototype for aead_count_tsgl(). Prototype was for af_alg_count_tsgl() instead
      ../crypto/af_alg.c:596: warning: expecting prototype for aead_pull_tsgl(). Prototype was for af_alg_pull_tsgl() instead
      af_alg.c:663: warning: Function parameter or member 'areq' not described in 'af_alg_free_areq_sgls'
      af_alg.c:700: warning: Function parameter or member 'sk' not described in 'af_alg_wait_for_wmem'
      af_alg.c:700: warning: Function parameter or member '...
      b2a4411a
  20. Nov 05, 2020
    • Eric Biggers's avatar
      crypto: af_alg - avoid undefined behavior accessing salg_name · 92eb6c30
      Eric Biggers authored
      Commit 3f69cc60 ("crypto: af_alg - Allow arbitrarily long algorithm
      names") made the kernel start accepting arbitrarily long algorithm names
      in sockaddr_alg.  However, the actual length of the salg_name field
      stayed at the original 64 bytes.
      
      This is broken because the kernel can access indices >= 64 in salg_name,
      which is undefined behavior -- even though the memory that is accessed
      is still located within the sockaddr structure.  It would only be
      defined behavior if the array were properly marked as arbitrary-length
      (either by making it a flexible array, which is the recommended way
      these days, or by making it an array of length 0 or 1).
      
      We can't simply change salg_name into a flexible array, since that would
      break source compatibility with userspace programs that embed
      sockaddr_alg into another struct, or (more commonly) declare a
      sockaddr_alg like 'struct sockaddr_alg sa = { .salg_name = "foo" };'.
      
      One solution would be to change salg_name into a flexible array only
      when '#ifdef __KERNEL__'.  However, that would keep userspace without an
      easy way to actually use the longer algorithm names.
      
      Instead, add a new structure 'sockaddr_alg_new' that has the flexible
      array field, and expose it to both userspace and the kernel.
      Make the kernel use it correctly in alg_bind().
      
      This addresses the syzbot report
      "UBSAN: array-index-out-of-bounds in alg_bind"
      (https://syzkaller.appspot.com/bug?extid=92ead4eb8e26a26d465e
      
      ).
      
      Reported-by: default avatar <syzbot+92ead4eb8e26a26d465e@syzkaller.appspotmail.com>
      Fixes: 3f69cc60
      
       ("crypto: af_alg - Allow arbitrarily long algorithm names")
      Cc: <stable@vger.kernel.org> # v4.12+
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      92eb6c30
  21. Sep 25, 2020
  22. Aug 27, 2020
    • Herbert Xu's avatar
      crypto: af_alg - Work around empty control messages without MSG_MORE · c195d66a
      Herbert Xu authored
      
      The iwd daemon uses libell which sets up the skcipher operation with
      two separate control messages.  As the first control message is sent
      without MSG_MORE, it is interpreted as an empty request.
      
      While libell should be fixed to use MSG_MORE where appropriate, this
      patch works around the bug in the kernel so that existing binaries
      continue to work.
      
      We will print a warning however.
      
      A separate issue is that the new kernel code no longer allows the
      control message to be sent twice within the same request.  This
      restriction is obviously incompatible with what iwd was doing (first
      setting an IV and then sending the real control message).  This
      patch changes the kernel so that this is explicitly allowed.
      
      Reported-by: default avatarCaleb Jorden <caljorden@hotmail.com>
      Fixes: f3c802a1
      
       ("crypto: algif_aead - Only wake up when...")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      c195d66a
  23. Jul 24, 2020
  24. Jul 19, 2020
  25. Jul 09, 2020
  26. Jun 18, 2020
  27. Mar 29, 2020
  28. Feb 03, 2020
  29. Dec 11, 2019
  30. Oct 10, 2019
  31. May 30, 2019
  32. Feb 28, 2019
  33. Feb 18, 2019
    • Mao Wenan's avatar
      net: crypto set sk to NULL when af_alg_release. · 9060cb71
      Mao Wenan authored
      KASAN has found use-after-free in sockfs_setattr.
      The existed commit 6d8c50dc ("socket: close race condition between sock_close()
      and sockfs_setattr()") is to fix this simillar issue, but it seems to ignore
      that crypto module forgets to set the sk to NULL after af_alg_release.
      
      KASAN report details as below:
      BUG: KASAN: use-after-free in sockfs_setattr+0x120/0x150
      Write of size 4 at addr ffff88837b956128 by task syz-executor0/4186
      
      CPU: 2 PID: 4186 Comm: syz-executor0 Not tainted xxx + #1
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
      1.10.2-1ubuntu1 04/01/2014
      Call Trace:
       dump_stack+0xca/0x13e
       print_address_description+0x79/0x330
       ? vprintk_func+0x5e/0xf0
       kasan_report+0x18a/0x2e0
       ? sockfs_setattr+0x120/0x150
       sockfs_setattr+0x120/0x150
       ? sock_register+0x2d0/0x2d0
       notify_change+0x90c/0xd40
       ? chown_common+0x2ef/0x510
       chown_common+0x2ef/0x510
       ? chmod_common+0x3b0/0x3b0
       ? __lock_is_held+0xbc/0x160
       ? __sb_start_write+0x13d/0x2b0
       ? __mnt_want_write+0x19a/0x250
       do_fchownat+0x15c/0x190
       ? __ia32_sys_chmod+0x80/0x80
       ? trace_hardirqs_on_thunk+0x1a/0x1c
       __x64_sys_fchownat+0xbf/0x160
       ? lockdep_hardirqs_on+0x39a/0x5e0
       do_syscall_64+0xc8/0x580
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      RIP: 0033:0x462589
      Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 f8 48 89
      f7 48 89 d6 48 89
      ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3
      48 c7 c1 bc ff ff
      ff f7 d8 64 89 01 48
      RSP: 002b:00007fb4b2c83c58 EFLAGS: 00000246 ORIG_RAX: 0000000000000104
      RAX: ffffffffffffffda RBX: 000000000072bfa0 RCX: 0000000000462589
      RDX: 0000000000000000 RSI: 00000000200000c0 RDI: 0000000000000007
      RBP: 0000000000000005 R08: 0000000000001000 R09: 0000000000000000
      R10: 0000000000000000 R11: 0000000000000246 R12: 00007fb4b2c846bc
      R13: 00000000004bc733 R14: 00000000006f5138 R15: 00000000ffffffff
      
      Allocated by task 4185:
       kasan_kmalloc+0xa0/0xd0
       __kmalloc+0x14a/0x350
       sk_prot_alloc+0xf6/0x290
       sk_alloc+0x3d/0xc00
       af_alg_accept+0x9e/0x670
       hash_accept+0x4a3/0x650
       __sys_accept4+0x306/0x5c0
       __x64_sys_accept4+0x98/0x100
       do_syscall_64+0xc8/0x580
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      Freed by task 4184:
       __kasan_slab_free+0x12e/0x180
       kfree+0xeb/0x2f0
       __sk_destruct+0x4e6/0x6a0
       sk_destruct+0x48/0x70
       __sk_free+0xa9/0x270
       sk_free+0x2a/0x30
       af_alg_release+0x5c/0x70
       __sock_release+0xd3/0x280
       sock_close+0x1a/0x20
       __fput+0x27f/0x7f0
       task_work_run+0x136/0x1b0
       exit_to_usermode_loop+0x1a7/0x1d0
       do_syscall_64+0x461/0x580
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      Syzkaller reproducer:
      r0 = perf_event_open(&(0x7f0000000000)={0x0, 0x70, 0x0, 0x0, 0x0, 0x0,
      0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
      0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
      0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @perf_config_ext}, 0x0, 0x0,
      0xffffffffffffffff, 0x0)
      r1 = socket$alg(0x26, 0x5, 0x0)
      getrusage(0x0, 0x0)
      bind(r1, &(0x7f00000001c0)=@alg={0x26, 'hash\x00', 0x0, 0x0,
      'sha256-ssse3\x00'}, 0x80)
      r2 = accept(r1, 0x0, 0x0)
      r3 = accept4$unix(r2, 0x0, 0x0, 0x0)
      r4 = dup3(r3, r0, 0x0)
      fchownat(r4, &(0x7f00000000c0)='\x00', 0x0, 0x0, 0x1000)
      
      Fixes: 6d8c50dc
      
       ("socket: close race condition between sock_close() and sockfs_setattr()")
      Signed-off-by: default avatarMao Wenan <maowenan@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      9060cb71
  34. Jan 18, 2019