All of lore.kernel.org
 help / color / mirror / Atom feed
* [dhowells-fs:crypto-krb5 26/35] crypto/krb5/rfc8009_aes2.c:70 rfc8009_calc_KDF_HMAC_SHA2() warn: is 'buffer' large enough for 'struct 0
@ 2020-11-13 19:55 kernel test robot
  0 siblings, 0 replies; only message in thread
From: kernel test robot @ 2020-11-13 19:55 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 7772 bytes --]

CC: kbuild-all(a)lists.01.org
TO: David Howells <dhowells@redhat.com>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git crypto-krb5
head:   355656a6fe584cb0b68ebc1ca2e56be073b706d0
commit: cd30f38cac77a83cfe6a7023acacb4d385d58dfa [26/35] crypto/krb5: Implement the AES enctypes from rfc8009
:::::: branch date: 31 hours ago
:::::: commit date: 31 hours ago
config: x86_64-randconfig-m001-20201113 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
crypto/krb5/rfc8009_aes2.c:70 rfc8009_calc_KDF_HMAC_SHA2() warn: is 'buffer' large enough for 'struct shash_desc'? 0

vim +70 crypto/krb5/rfc8009_aes2.c

cd30f38cac77a83 David Howells 2020-09-24   16  
cd30f38cac77a83 David Howells 2020-09-24   17  /*
cd30f38cac77a83 David Howells 2020-09-24   18   * Calculate the key derivation function KDF-HMAC-SHA2(key, label, [context,] k)
cd30f38cac77a83 David Howells 2020-09-24   19   *
cd30f38cac77a83 David Howells 2020-09-24   20   *	KDF-HMAC-SHA2(key, label, [context,] k) = k-truncate(K1)
cd30f38cac77a83 David Howells 2020-09-24   21   *
cd30f38cac77a83 David Howells 2020-09-24   22   *	Using the appropriate one of:
cd30f38cac77a83 David Howells 2020-09-24   23   *		K1 = HMAC-SHA-256(key, 0x00000001 | label | 0x00 | k)
cd30f38cac77a83 David Howells 2020-09-24   24   *		K1 = HMAC-SHA-384(key, 0x00000001 | label | 0x00 | k)
cd30f38cac77a83 David Howells 2020-09-24   25   *		K1 = HMAC-SHA-256(key, 0x00000001 | label | 0x00 | context | k)
cd30f38cac77a83 David Howells 2020-09-24   26   *		K1 = HMAC-SHA-384(key, 0x00000001 | label | 0x00 | context | k)
cd30f38cac77a83 David Howells 2020-09-24   27   *	[rfc8009 sec 3]
cd30f38cac77a83 David Howells 2020-09-24   28   */
cd30f38cac77a83 David Howells 2020-09-24   29  static int rfc8009_calc_KDF_HMAC_SHA2(const struct krb5_enctype *krb5,
cd30f38cac77a83 David Howells 2020-09-24   30  				      const struct krb5_buffer *key,
cd30f38cac77a83 David Howells 2020-09-24   31  				      const struct krb5_buffer *label,
cd30f38cac77a83 David Howells 2020-09-24   32  				      const struct krb5_buffer *context,
cd30f38cac77a83 David Howells 2020-09-24   33  				      unsigned int k,
cd30f38cac77a83 David Howells 2020-09-24   34  				      struct krb5_buffer *result,
cd30f38cac77a83 David Howells 2020-09-24   35  				      gfp_t gfp)
cd30f38cac77a83 David Howells 2020-09-24   36  {
cd30f38cac77a83 David Howells 2020-09-24   37  	struct crypto_shash *shash;
cd30f38cac77a83 David Howells 2020-09-24   38  	struct krb5_buffer K1, data;
cd30f38cac77a83 David Howells 2020-09-24   39  	struct shash_desc *desc;
cd30f38cac77a83 David Howells 2020-09-24   40  	__be32 tmp;
cd30f38cac77a83 David Howells 2020-09-24   41  	size_t bsize;
cd30f38cac77a83 David Howells 2020-09-24   42  	void *buffer;
cd30f38cac77a83 David Howells 2020-09-24   43  	u8 *p;
cd30f38cac77a83 David Howells 2020-09-24   44  	int ret = -ENOMEM;
cd30f38cac77a83 David Howells 2020-09-24   45  
cd30f38cac77a83 David Howells 2020-09-24   46  	if (WARN_ON(result->len != k / 8))
cd30f38cac77a83 David Howells 2020-09-24   47  		return -EINVAL;
cd30f38cac77a83 David Howells 2020-09-24   48  
cd30f38cac77a83 David Howells 2020-09-24   49  	shash = crypto_alloc_shash(krb5->cksum_name, 0, 0);
cd30f38cac77a83 David Howells 2020-09-24   50  	if (IS_ERR(shash))
cd30f38cac77a83 David Howells 2020-09-24   51  		return (PTR_ERR(shash) == -ENOENT) ? -ENOPKG : PTR_ERR(shash);
cd30f38cac77a83 David Howells 2020-09-24   52  	ret = crypto_shash_setkey(shash, key->data, key->len);
cd30f38cac77a83 David Howells 2020-09-24   53  	if (ret < 0)
cd30f38cac77a83 David Howells 2020-09-24   54  		goto error_shash;
cd30f38cac77a83 David Howells 2020-09-24   55  
cd30f38cac77a83 David Howells 2020-09-24   56  	ret = -EINVAL;
cd30f38cac77a83 David Howells 2020-09-24   57  	if (WARN_ON(crypto_shash_digestsize(shash) * 8 < k))
cd30f38cac77a83 David Howells 2020-09-24   58  		goto error_shash;
cd30f38cac77a83 David Howells 2020-09-24   59  
cd30f38cac77a83 David Howells 2020-09-24   60  	ret = -ENOMEM;
cd30f38cac77a83 David Howells 2020-09-24   61  	data.len = 4 + label->len + 1 + context->len + 4;
cd30f38cac77a83 David Howells 2020-09-24   62  	bsize = krb5_shash_size(shash) +
cd30f38cac77a83 David Howells 2020-09-24   63  		krb5_digest_size(shash) +
cd30f38cac77a83 David Howells 2020-09-24   64  		crypto_roundup(data.len);
cd30f38cac77a83 David Howells 2020-09-24   65  	buffer = kzalloc(bsize, GFP_NOFS);
cd30f38cac77a83 David Howells 2020-09-24   66  	if (!buffer)
cd30f38cac77a83 David Howells 2020-09-24   67  		goto error_shash;
cd30f38cac77a83 David Howells 2020-09-24   68  
cd30f38cac77a83 David Howells 2020-09-24   69  	desc = buffer;
cd30f38cac77a83 David Howells 2020-09-24  @70  	desc->tfm = shash;
cd30f38cac77a83 David Howells 2020-09-24   71  	ret = crypto_shash_init(desc);
cd30f38cac77a83 David Howells 2020-09-24   72  	if (ret < 0)
cd30f38cac77a83 David Howells 2020-09-24   73  		goto error;
cd30f38cac77a83 David Howells 2020-09-24   74  
cd30f38cac77a83 David Howells 2020-09-24   75  	p = data.data = buffer +
cd30f38cac77a83 David Howells 2020-09-24   76  		krb5_shash_size(shash) +
cd30f38cac77a83 David Howells 2020-09-24   77  		krb5_digest_size(shash);
cd30f38cac77a83 David Howells 2020-09-24   78  	*(__be32 *)p = htonl(0x00000001);
cd30f38cac77a83 David Howells 2020-09-24   79  	p += 4;
cd30f38cac77a83 David Howells 2020-09-24   80  	memcpy(p, label->data, label->len);
cd30f38cac77a83 David Howells 2020-09-24   81  	p += label->len;
cd30f38cac77a83 David Howells 2020-09-24   82  	*p++ = 0;
cd30f38cac77a83 David Howells 2020-09-24   83  	memcpy(p, context->data, context->len);
cd30f38cac77a83 David Howells 2020-09-24   84  	p += context->len;
cd30f38cac77a83 David Howells 2020-09-24   85  	tmp = htonl(k);
cd30f38cac77a83 David Howells 2020-09-24   86  	memcpy(p, &tmp, 4);
cd30f38cac77a83 David Howells 2020-09-24   87  	p += 4;
cd30f38cac77a83 David Howells 2020-09-24   88  
cd30f38cac77a83 David Howells 2020-09-24   89  	ret = -EINVAL;
cd30f38cac77a83 David Howells 2020-09-24   90  	if (WARN_ON(p - (u8 *)data.data != data.len))
cd30f38cac77a83 David Howells 2020-09-24   91  		goto error;
cd30f38cac77a83 David Howells 2020-09-24   92  
cd30f38cac77a83 David Howells 2020-09-24   93  	K1.len = crypto_shash_digestsize(shash);
cd30f38cac77a83 David Howells 2020-09-24   94  	K1.data = buffer +
cd30f38cac77a83 David Howells 2020-09-24   95  		krb5_shash_size(shash);
cd30f38cac77a83 David Howells 2020-09-24   96  
cd30f38cac77a83 David Howells 2020-09-24   97  	ret = crypto_shash_finup(desc, data.data, data.len, K1.data);
cd30f38cac77a83 David Howells 2020-09-24   98  	if (ret < 0)
cd30f38cac77a83 David Howells 2020-09-24   99  		goto error;
cd30f38cac77a83 David Howells 2020-09-24  100  
cd30f38cac77a83 David Howells 2020-09-24  101  	memcpy(result->data, K1.data, result->len);
cd30f38cac77a83 David Howells 2020-09-24  102  
cd30f38cac77a83 David Howells 2020-09-24  103  error:
cd30f38cac77a83 David Howells 2020-09-24  104  	kfree_sensitive(buffer);
cd30f38cac77a83 David Howells 2020-09-24  105  error_shash:
cd30f38cac77a83 David Howells 2020-09-24  106  	crypto_free_shash(shash);
cd30f38cac77a83 David Howells 2020-09-24  107  	return ret;
cd30f38cac77a83 David Howells 2020-09-24  108  }
cd30f38cac77a83 David Howells 2020-09-24  109  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 35911 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-13 19:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13 19:55 [dhowells-fs:crypto-krb5 26/35] crypto/krb5/rfc8009_aes2.c:70 rfc8009_calc_KDF_HMAC_SHA2() warn: is 'buffer' large enough for 'struct 0 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.