All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: kbuild@lists.01.org
Subject: [dhowells-fs:rxrpc-rxgk 35/39] net/rxrpc/rxgk_rfc8009.c:80 rfc8009_calc_KDF_HMAC_SHA2() warn: is 'buffer' large enough for 'struct 0
Date: Sat, 03 Oct 2020 16:54:00 +0800	[thread overview]
Message-ID: <202010031657.zglInOWh-lkp@intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 8014 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 rxrpc-rxgk
head:   8059c4a3daa29a955b7c045c846d037360c33e78
commit: 21f4cdac957f8d60968986513f236a27f50c8bc1 [35/39] rxrpc: rxgk: Implement the AES enctypes from rfc8009
:::::: branch date: 20 hours ago
:::::: commit date: 20 hours ago
config: ia64-randconfig-m031-20201003 (attached as .config)
compiler: ia64-linux-gcc (GCC) 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:
net/rxrpc/rxgk_rfc8009.c:80 rfc8009_calc_KDF_HMAC_SHA2() warn: is 'buffer' large enough for 'struct shash_desc'? 0

vim +80 net/rxrpc/rxgk_rfc8009.c

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

---
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: 27766 bytes --]

                 reply	other threads:[~2020-10-03  8:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202010031657.zglInOWh-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=kbuild@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.