public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: Jianglei Nie <niejianglei2021@163.com>
Cc: kbuild-all@lists.01.org, linux-kernel@vger.kernel.org,
	0day robot <lkp@intel.com>
Subject: security/keys/trusted-keys/trusted_tpm2.c:42:9: warning: ISO C90 forbids mixed declarations and code
Date: Mon, 25 Jul 2022 03:13:13 +0800	[thread overview]
Message-ID: <202207250357.XCaCDvpe-lkp@intel.com> (raw)

tree:   https://github.com/intel-lab-lkp/linux/commits/UPDATE-20220722-162642/Jianglei-Nie/KEYS-trusted-Fix-memory-leak-in-tpm2_key_encode/20220608-211954
head:   7112e578934830db95743922ab0d46d2f4b7dff4
commit: 7112e578934830db95743922ab0d46d2f4b7dff4 KEYS: trusted: Fix memory leak in tpm2_key_encode()
date:   2 days ago
config: alpha-randconfig-r026-20220721 (https://download.01.org/0day-ci/archive/20220725/202207250357.XCaCDvpe-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/7112e578934830db95743922ab0d46d2f4b7dff4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review UPDATE-20220722-162642/Jianglei-Nie/KEYS-trusted-Fix-memory-leak-in-tpm2_key_encode/20220608-211954
        git checkout 7112e578934830db95743922ab0d46d2f4b7dff4
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=alpha SHELL=/bin/bash security/keys/trusted-keys/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   security/keys/trusted-keys/trusted_tpm2.c: In function 'tpm2_key_encode':
>> security/keys/trusted-keys/trusted_tpm2.c:42:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
      42 |         u8 *work = scratch, *work1;
         |         ^~


vim +42 security/keys/trusted-keys/trusted_tpm2.c

f2219745250f38 James Bottomley 2021-01-27   30  
f2219745250f38 James Bottomley 2021-01-27   31  static int tpm2_key_encode(struct trusted_key_payload *payload,
f2219745250f38 James Bottomley 2021-01-27   32  			   struct trusted_key_options *options,
f2219745250f38 James Bottomley 2021-01-27   33  			   u8 *src, u32 len)
f2219745250f38 James Bottomley 2021-01-27   34  {
7112e578934830 Jianglei Nie    2022-07-22   35  	int ret;
f2219745250f38 James Bottomley 2021-01-27   36  	const int SCRATCH_SIZE = PAGE_SIZE;
7112e578934830 Jianglei Nie    2022-07-22   37  	u8 *scratch;
7112e578934830 Jianglei Nie    2022-07-22   38  
7112e578934830 Jianglei Nie    2022-07-22   39  	scratch = kmalloc(SCRATCH_SIZE, GFP_KERNEL);
7112e578934830 Jianglei Nie    2022-07-22   40  	if (!scratch)
7112e578934830 Jianglei Nie    2022-07-22   41  		return -ENOMEM;
f2219745250f38 James Bottomley 2021-01-27  @42  	u8 *work = scratch, *work1;
f2219745250f38 James Bottomley 2021-01-27   43  	u8 *end_work = scratch + SCRATCH_SIZE;
f2219745250f38 James Bottomley 2021-01-27   44  	u8 *priv, *pub;
f2219745250f38 James Bottomley 2021-01-27   45  	u16 priv_len, pub_len;
f2219745250f38 James Bottomley 2021-01-27   46  
f2219745250f38 James Bottomley 2021-01-27   47  	priv_len = get_unaligned_be16(src) + 2;
f2219745250f38 James Bottomley 2021-01-27   48  	priv = src;
f2219745250f38 James Bottomley 2021-01-27   49  
f2219745250f38 James Bottomley 2021-01-27   50  	src += priv_len;
f2219745250f38 James Bottomley 2021-01-27   51  
f2219745250f38 James Bottomley 2021-01-27   52  	pub_len = get_unaligned_be16(src) + 2;
f2219745250f38 James Bottomley 2021-01-27   53  	pub = src;
f2219745250f38 James Bottomley 2021-01-27   54  
f2219745250f38 James Bottomley 2021-01-27   55  	work = asn1_encode_oid(work, end_work, tpm2key_oid,
f2219745250f38 James Bottomley 2021-01-27   56  			       asn1_oid_len(tpm2key_oid));
f2219745250f38 James Bottomley 2021-01-27   57  
f2219745250f38 James Bottomley 2021-01-27   58  	if (options->blobauth_len == 0) {
f2219745250f38 James Bottomley 2021-01-27   59  		unsigned char bool[3], *w = bool;
f2219745250f38 James Bottomley 2021-01-27   60  		/* tag 0 is emptyAuth */
f2219745250f38 James Bottomley 2021-01-27   61  		w = asn1_encode_boolean(w, w + sizeof(bool), true);
7112e578934830 Jianglei Nie    2022-07-22   62  		if (WARN(IS_ERR(w), "BUG: Boolean failed to encode")) {
7112e578934830 Jianglei Nie    2022-07-22   63  			ret = PTR_ERR(w);
7112e578934830 Jianglei Nie    2022-07-22   64  			goto err;
7112e578934830 Jianglei Nie    2022-07-22   65  		}
f2219745250f38 James Bottomley 2021-01-27   66  		work = asn1_encode_tag(work, end_work, 0, bool, w - bool);
f2219745250f38 James Bottomley 2021-01-27   67  	}
f2219745250f38 James Bottomley 2021-01-27   68  
f2219745250f38 James Bottomley 2021-01-27   69  	/*
f2219745250f38 James Bottomley 2021-01-27   70  	 * Assume both octet strings will encode to a 2 byte definite length
f2219745250f38 James Bottomley 2021-01-27   71  	 *
f2219745250f38 James Bottomley 2021-01-27   72  	 * Note: For a well behaved TPM, this warning should never
f2219745250f38 James Bottomley 2021-01-27   73  	 * trigger, so if it does there's something nefarious going on
f2219745250f38 James Bottomley 2021-01-27   74  	 */
f2219745250f38 James Bottomley 2021-01-27   75  	if (WARN(work - scratch + pub_len + priv_len + 14 > SCRATCH_SIZE,
7112e578934830 Jianglei Nie    2022-07-22   76  		 "BUG: scratch buffer is too small")) {
7112e578934830 Jianglei Nie    2022-07-22   77  		ret = -EINVAL;
7112e578934830 Jianglei Nie    2022-07-22   78  		goto err;
7112e578934830 Jianglei Nie    2022-07-22   79  	}
f2219745250f38 James Bottomley 2021-01-27   80  
f2219745250f38 James Bottomley 2021-01-27   81  	work = asn1_encode_integer(work, end_work, options->keyhandle);
f2219745250f38 James Bottomley 2021-01-27   82  	work = asn1_encode_octet_string(work, end_work, pub, pub_len);
f2219745250f38 James Bottomley 2021-01-27   83  	work = asn1_encode_octet_string(work, end_work, priv, priv_len);
f2219745250f38 James Bottomley 2021-01-27   84  
f2219745250f38 James Bottomley 2021-01-27   85  	work1 = payload->blob;
f2219745250f38 James Bottomley 2021-01-27   86  	work1 = asn1_encode_sequence(work1, work1 + sizeof(payload->blob),
f2219745250f38 James Bottomley 2021-01-27   87  				     scratch, work - scratch);
7112e578934830 Jianglei Nie    2022-07-22   88  	if (WARN(IS_ERR(work1), "BUG: ASN.1 encoder failed")) {
7112e578934830 Jianglei Nie    2022-07-22   89  		ret = PTR_ERR(work1);
7112e578934830 Jianglei Nie    2022-07-22   90  		goto err;
7112e578934830 Jianglei Nie    2022-07-22   91  	}
f2219745250f38 James Bottomley 2021-01-27   92  
7112e578934830 Jianglei Nie    2022-07-22   93  	kfree(scratch);
f2219745250f38 James Bottomley 2021-01-27   94  	return work1 - payload->blob;
7112e578934830 Jianglei Nie    2022-07-22   95  
7112e578934830 Jianglei Nie    2022-07-22   96  err:
7112e578934830 Jianglei Nie    2022-07-22   97  	kfree(scratch);
7112e578934830 Jianglei Nie    2022-07-22   98  	return ret;
f2219745250f38 James Bottomley 2021-01-27   99  }
f2219745250f38 James Bottomley 2021-01-27  100  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

             reply	other threads:[~2022-07-24 19:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-24 19:13 kernel test robot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-07-24 19:13 security/keys/trusted-keys/trusted_tpm2.c:42:9: warning: ISO C90 forbids mixed declarations and code kernel test robot

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=202207250357.XCaCDvpe-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=kbuild-all@lists.01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=niejianglei2021@163.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox