From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BC8CC433ED for ; Wed, 14 Apr 2021 08:05:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CB3CA613BB for ; Wed, 14 Apr 2021 08:05:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CB3CA613BB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4E7C86B0070; Wed, 14 Apr 2021 04:05:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BEE96B0071; Wed, 14 Apr 2021 04:05:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3606F6B0078; Wed, 14 Apr 2021 04:05:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id 1D6FD6B0070 for ; Wed, 14 Apr 2021 04:05:18 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id CB3E982499B9 for ; Wed, 14 Apr 2021 08:05:17 +0000 (UTC) X-FDA: 78030237474.20.D80C010 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by imf17.hostedemail.com (Postfix) with ESMTP id 8008240002DD for ; Wed, 14 Apr 2021 08:05:14 +0000 (UTC) IronPort-SDR: /b80ZTRYq6Ib/Xd1dW6Hlsik7aIAB8matG+zXguaBal/hKAReKHOA7NjOfRPzOa5CsqBHHY/Xa 2yklpT+aXlLw== X-IronPort-AV: E=McAfee;i="6200,9189,9953"; a="258557265" X-IronPort-AV: E=Sophos;i="5.82,221,1613462400"; d="scan'208";a="258557265" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2021 01:05:14 -0700 IronPort-SDR: g2I6Bc4nMJsezEHCNWsl3lz+8abSsZE3AYwS3VD5GbFIs99b1s63IBub+v2Xm5Vw1W5iokq1RR kCtrt6SYzEiA== X-IronPort-AV: E=Sophos;i="5.82,221,1613462400"; d="scan'208";a="424615617" Received: from shao2-debian.sh.intel.com (HELO localhost) ([10.239.13.11]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2021 01:05:13 -0700 Date: Wed, 14 Apr 2021 16:04:16 +0800 From: kernel test robot To: James Bottomley Cc: kbuild-all@lists.01.org, Linux Memory Management List , Jarkko Sakkinen Subject: [linux-next:master 10444/12404] security/keys/trusted-keys/trusted_tpm2.c:38:25: warning: Either the condition '!scratch' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck] Message-ID: <20210414080416.GG1780177@shao2-debian> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 8008240002DD X-Stat-Signature: 8enwwo3tof6hcoes9dqhwhnr4fi6wnwa Received-SPF: none (intel.com>: No applicable sender policy available) receiver=imf17; identity=mailfrom; envelope-from=""; helo=mga07.intel.com; client-ip=134.134.136.100 X-HE-DKIM-Result: none/none X-HE-Tag: 1618387514-903483 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master head: dcf1b51d6b2ac5da234ae6883ed0e9422c339588 commit: 14676f1eb79660b6ee262644fa788a5c42ac19e4 [10444/12404] security: keys: trusted: use ASN.1 TPM2 key format for the blobs compiler: hppa64-linux-gcc (GCC) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot cppcheck possible warnings: (new ones prefixed by >>, may not real problems) >> security/keys/trusted-keys/trusted_tpm2.c:38:25: warning: Either the condition '!scratch' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck] u8 *end_work = scratch + SCRATCH_SIZE; ^ security/keys/trusted-keys/trusted_tpm2.c:50:6: note: Assuming that condition '!scratch' is not redundant if (!scratch) ^ security/keys/trusted-keys/trusted_tpm2.c:38:25: note: Null pointer addition u8 *end_work = scratch + SCRATCH_SIZE; ^ vim +38 security/keys/trusted-keys/trusted_tpm2.c 14676f1eb79660 James Bottomley 2021-01-27 30 14676f1eb79660 James Bottomley 2021-01-27 31 static int tpm2_key_encode(struct trusted_key_payload *payload, 14676f1eb79660 James Bottomley 2021-01-27 32 struct trusted_key_options *options, 14676f1eb79660 James Bottomley 2021-01-27 33 u8 *src, u32 len) 14676f1eb79660 James Bottomley 2021-01-27 34 { 14676f1eb79660 James Bottomley 2021-01-27 35 const int SCRATCH_SIZE = PAGE_SIZE; 14676f1eb79660 James Bottomley 2021-01-27 36 u8 *scratch = kmalloc(SCRATCH_SIZE, GFP_KERNEL); 14676f1eb79660 James Bottomley 2021-01-27 37 u8 *work = scratch, *work1; 14676f1eb79660 James Bottomley 2021-01-27 @38 u8 *end_work = scratch + SCRATCH_SIZE; 14676f1eb79660 James Bottomley 2021-01-27 39 u8 *priv, *pub; 14676f1eb79660 James Bottomley 2021-01-27 40 u16 priv_len, pub_len; 14676f1eb79660 James Bottomley 2021-01-27 41 14676f1eb79660 James Bottomley 2021-01-27 42 priv_len = get_unaligned_be16(src) + 2; 14676f1eb79660 James Bottomley 2021-01-27 43 priv = src; 14676f1eb79660 James Bottomley 2021-01-27 44 14676f1eb79660 James Bottomley 2021-01-27 45 src += priv_len; 14676f1eb79660 James Bottomley 2021-01-27 46 14676f1eb79660 James Bottomley 2021-01-27 47 pub_len = get_unaligned_be16(src) + 2; 14676f1eb79660 James Bottomley 2021-01-27 48 pub = src; 14676f1eb79660 James Bottomley 2021-01-27 49 14676f1eb79660 James Bottomley 2021-01-27 50 if (!scratch) 14676f1eb79660 James Bottomley 2021-01-27 51 return -ENOMEM; 14676f1eb79660 James Bottomley 2021-01-27 52 14676f1eb79660 James Bottomley 2021-01-27 53 work = asn1_encode_oid(work, end_work, tpm2key_oid, 14676f1eb79660 James Bottomley 2021-01-27 54 asn1_oid_len(tpm2key_oid)); 14676f1eb79660 James Bottomley 2021-01-27 55 14676f1eb79660 James Bottomley 2021-01-27 56 if (options->blobauth_len == 0) { 14676f1eb79660 James Bottomley 2021-01-27 57 unsigned char bool[3], *w = bool; 14676f1eb79660 James Bottomley 2021-01-27 58 /* tag 0 is emptyAuth */ 14676f1eb79660 James Bottomley 2021-01-27 59 w = asn1_encode_boolean(w, w + sizeof(bool), true); 14676f1eb79660 James Bottomley 2021-01-27 60 if (WARN(IS_ERR(w), "BUG: Boolean failed to encode")) 14676f1eb79660 James Bottomley 2021-01-27 61 return PTR_ERR(w); 14676f1eb79660 James Bottomley 2021-01-27 62 work = asn1_encode_tag(work, end_work, 0, bool, w - bool); 14676f1eb79660 James Bottomley 2021-01-27 63 } 14676f1eb79660 James Bottomley 2021-01-27 64 14676f1eb79660 James Bottomley 2021-01-27 65 /* 14676f1eb79660 James Bottomley 2021-01-27 66 * Assume both octet strings will encode to a 2 byte definite length 14676f1eb79660 James Bottomley 2021-01-27 67 * 14676f1eb79660 James Bottomley 2021-01-27 68 * Note: For a well behaved TPM, this warning should never 14676f1eb79660 James Bottomley 2021-01-27 69 * trigger, so if it does there's something nefarious going on 14676f1eb79660 James Bottomley 2021-01-27 70 */ 14676f1eb79660 James Bottomley 2021-01-27 71 if (WARN(work - scratch + pub_len + priv_len + 14 > SCRATCH_SIZE, 14676f1eb79660 James Bottomley 2021-01-27 72 "BUG: scratch buffer is too small")) 14676f1eb79660 James Bottomley 2021-01-27 73 return -EINVAL; 14676f1eb79660 James Bottomley 2021-01-27 74 14676f1eb79660 James Bottomley 2021-01-27 75 work = asn1_encode_integer(work, end_work, options->keyhandle); 14676f1eb79660 James Bottomley 2021-01-27 76 work = asn1_encode_octet_string(work, end_work, pub, pub_len); 14676f1eb79660 James Bottomley 2021-01-27 77 work = asn1_encode_octet_string(work, end_work, priv, priv_len); 14676f1eb79660 James Bottomley 2021-01-27 78 14676f1eb79660 James Bottomley 2021-01-27 79 work1 = payload->blob; 14676f1eb79660 James Bottomley 2021-01-27 80 work1 = asn1_encode_sequence(work1, work1 + sizeof(payload->blob), 14676f1eb79660 James Bottomley 2021-01-27 81 scratch, work - scratch); 14676f1eb79660 James Bottomley 2021-01-27 82 if (WARN(IS_ERR(work1), "BUG: ASN.1 encoder failed")) 14676f1eb79660 James Bottomley 2021-01-27 83 return PTR_ERR(work1); 14676f1eb79660 James Bottomley 2021-01-27 84 14676f1eb79660 James Bottomley 2021-01-27 85 return work1 - payload->blob; 14676f1eb79660 James Bottomley 2021-01-27 86 } 14676f1eb79660 James Bottomley 2021-01-27 87 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org