]> git.baikalelectronics.ru Git - kernel.git/commit
crypto: user - clean up report structure copying
authorEric Biggers <ebiggers@google.com>
Sat, 3 Nov 2018 21:56:03 +0000 (14:56 -0700)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 9 Nov 2018 09:41:39 +0000 (17:41 +0800)
commitca9f4e72517e2bd588e3b46e7e3bb63358b25989
tree2ee519e8fc4e7d04122ec5efbf406ffc8168496a
parent40f8339020a2d7e51be465ee9c2ed9444fa5561a
crypto: user - clean up report structure copying

There have been a pretty ridiculous number of issues with initializing
the report structures that are copied to userspace by NETLINK_CRYPTO.
Commit 8a6f62aec564 ("crypto: user - Prepare for CRYPTO_MAX_ALG_NAME
expansion") replaced some strncpy()s with strlcpy()s, thereby
introducing information leaks.  Later two other people tried to replace
other strncpy()s with strlcpy() too, which would have introduced even
more information leaks:

    - https://lore.kernel.org/patchwork/patch/954991/
    - https://patchwork.kernel.org/patch/10434351/

Commit c5bb87c02c96 ("crypto: user - Implement a generic crypto
statistics") also uses the buggy strlcpy() approach and therefore leaks
uninitialized memory to userspace.  A fix was proposed, but it was
originally incomplete.

Seeing as how apparently no one can get this right with the current
approach, change all the reporting functions to:

- Start by memsetting the report structure to 0.  This guarantees it's
  always initialized, regardless of what happens later.
- Initialize all strings using strscpy().  This is safe after the
  memset, ensures null termination of long strings, avoids unnecessary
  work, and avoids the -Wstringop-truncation warnings from gcc.
- Use sizeof(var) instead of sizeof(type).  This is more robust against
  copy+paste errors.

For simplicity, also reuse the -EMSGSIZE return value from nla_put().

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
13 files changed:
crypto/ablkcipher.c
crypto/acompress.c
crypto/aead.c
crypto/ahash.c
crypto/akcipher.c
crypto/blkcipher.c
crypto/crypto_user_base.c
crypto/crypto_user_stat.c
crypto/kpp.c
crypto/rng.c
crypto/scompress.c
crypto/shash.c
crypto/skcipher.c