Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp995811imm; Fri, 12 Oct 2018 09:58:37 -0700 (PDT) X-Google-Smtp-Source: ACcGV60TN3CgjQR4X6Yf5eODmLPo8h7HLcZ+yjC7a6My1/DTNxCP4dLswZxdewF+xpjhGrA+3a+z X-Received: by 2002:a62:3541:: with SMTP id c62-v6mr6870927pfa.45.1539363517518; Fri, 12 Oct 2018 09:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539363517; cv=none; d=google.com; s=arc-20160816; b=KXdf2QyHOaMxYDpTgDeziDl+QY2i5Xjvs9sqUCPnO+r42BbzKWKEaT/7acil4nxeCS 9VEKCLt55vFHId8Hw1vmeYmYfivo/7R0aDbcLLesegvf6+mgwRaHwremEfE3AjvJ6yLu oyoU4hztatM3YipZJu6ZINWX8523I96sNvgbmMHd7wOsAgg23vihJeulMlTTp+AZObJ9 p6/nDqtc7Y1GYOheGAUzrgxKYJUKR23js73b2RX6n/R4HFnd8Z2mv+2SrpC+/+9twtxv j0uGFBzw7AT9ZRLBFQL9rhU+VlsiBLdR/lSjgr2iDF7Iw3iONUHlpz4H8DcA/3aZ7T+w K/Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=CZqIrbWJKC3RtxsrK/0HJ6SbrXDpmv9rKA5oHxqvaDM=; b=kiNXut33O5ZD2dSnRG/3NKFsJYrGirGbCXX8GRKmqpXKpzhWocthOX6wSTrQvL31cJ 5/NeVxlfqQBhWGPrw5UqP+CDrbEkUZRBOf6HZfTh8x6u2Ugm85Swl+GuDCRoRk7P7oa9 rQLsJ2F14Uc56hPztxNKf9X8mxlY2fhlHMng76hoWysJedQgtR6cSm1l3wbImETFe/GB fN2SIA/TlvdLOybMU0IWLRv0ZMnkyTQH4YUpI2RvF5mjeQwfGtGwSTPFeSlruzSz+SlR yf6gbxWUkG5md5l4fAQ9ojkxolmq+YrttONAFu+FLs0RLzkZTLn/N6BrPQMGmZrmzYiI ikAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qKK30L2L; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j7-v6si1806349pfk.203.2018.10.12.09.58.22; Fri, 12 Oct 2018 09:58:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qKK30L2L; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727469AbeJMA3b (ORCPT + 99 others); Fri, 12 Oct 2018 20:29:31 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:38267 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727401AbeJMA3b (ORCPT ); Fri, 12 Oct 2018 20:29:31 -0400 Received: by mail-pf1-f196.google.com with SMTP id f29-v6so6495981pff.5 for ; Fri, 12 Oct 2018 09:56:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=CZqIrbWJKC3RtxsrK/0HJ6SbrXDpmv9rKA5oHxqvaDM=; b=qKK30L2LBG4SDZ6XEZ+XI27BlpgfDXqoPco+Yi5ChT1oZvwX8eLals57RjewUNWnxg MhxkG5L7CxoOLCxRaUfCwnUPjKaZL40Pf93QJSyq6qv1YYKGTcCEQ1LxUpgLrxt36kRu frCKRp26q2lLz9WZKjvxVGqfAesu52vJ5kT0O9Ese2EXPuDk2tE8QJ4UAFx/nD5VIdzA 5Mx04px6J48IqnT3eXHMF+2ozxSagGOen5byeUO+x5DdhJu3AgyJCoDS6seysb7r8kd5 QQ56kNLvzGUo/rFpQDBd9Oqk9LnlBIV+2RhtnqI8rYMbAF1jwuRuRuZ0YiOnLwVBe82i e9ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CZqIrbWJKC3RtxsrK/0HJ6SbrXDpmv9rKA5oHxqvaDM=; b=UylXlLt5K9jl3MrmsmJ/vyTwAfPeMe5P06Hr6cCBqCIVye9QUVnPNMmNovJr7E+uan jux+MCxocxlQUIDLAntJM8Hj8P6qMD2FIIfEU1v8RBBCf+haikYdwrdi8KTHnNUrDA1Q bPHC57wNx7pgO7Baj/0Ox30iiyNDd7yNHiRLvT8p7K322fjjiA4t512MLxlPdZvqammq mkCNnydwLRaW21IsZyla9We9hy1W7E2HaN7C/HlEj1QLVPcflzormbujG2fq/ja3veR0 DkhEFMf+SG+vxoL5B41H2AbPd3T/YkfCqzw0K8NSly4TM7os1QRY4f/UBZUBmY7Ad48z 1AyQ== X-Gm-Message-State: ABuFfojVQ6PcFFrAMLWvFn+rpRmYrf7BuOuT1L31PZNl5NUI4BONjeLa TDiZG/TgxuP+26zJ50D5UCEa2WOlkkm5U5sGEM6g+w== X-Received: by 2002:a63:df06:: with SMTP id u6-v6mr6248735pgg.202.1539363367091; Fri, 12 Oct 2018 09:56:07 -0700 (PDT) MIME-Version: 1.0 References: <1539274203.2623.56.camel@linux.vnet.ibm.com> <20181011203126.15338-1-ndesaulniers@google.com> <20181012015022.GA7508@flashbox> In-Reply-To: <20181012015022.GA7508@flashbox> From: Nick Desaulniers Date: Fri, 12 Oct 2018 09:55:55 -0700 Message-ID: Subject: Re: [PATCH] KEYS: trusted: fix -Wvarags warning To: Nathan Chancellor Cc: "James E.J. Bottomley" , dhowells@redhat.com, Eric Biggers , zohar@linux.vnet.ibm.com, jmorris@namei.org, serge@hallyn.com, linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 11, 2018 at 6:50 PM Nathan Chancellor wrote: > > On Thu, Oct 11, 2018 at 01:31:26PM -0700, ndesaulniers@google.com wrote: > > by swapping h2 and h3. > > > > security/keys/trusted.c:146:17: warning: passing an object that > > undergoes default > > argument promotion to 'va_start' has undefined behavior [-Wvarargs] > > va_start(argp, h3); > > ^ > > security/keys/trusted.c:126:37: note: parameter of type 'unsigned > > char' is declared here > > unsigned char *h2, unsigned char h3, ...) > > ^ > > > > Specifically, it seems that both the C90 (4.8.1.1) and C11 (7.16.1.4) > > standards explicitly call this out as undefined behavior: > > > > The parameter parmN is the identifier of the rightmost parameter in > > the variable parameter list in the function definition (the one just > > before the ...). If the parameter parmN is declared with ... or with a > > type that is not compatible with the type that results after > > application of the default argument promotions, the behavior is > > undefined. > > > > Link: https://github.com/ClangBuiltLinux/linux/issues/41 > > Suggested-by: James Bottomley > > Signed-off-by: Nick Desaulniers > > --- > > security/keys/trusted.c | 14 +++++++------- > > 1 file changed, 7 insertions(+), 7 deletions(-) > > > > diff --git a/security/keys/trusted.c b/security/keys/trusted.c > > index b69d3b1777c2..d425b2b839af 100644 > > --- a/security/keys/trusted.c > > +++ b/security/keys/trusted.c > > @@ -123,7 +123,7 @@ static int TSS_rawhmac(unsigned char *digest, const unsigned char *key, > > */ > > static int TSS_authhmac(unsigned char *digest, const unsigned char *key, > > unsigned int keylen, unsigned char *h1, > > - unsigned char *h2, unsigned char h3, ...) > > + unsigned char h2, unsigned char *h3, ...) > > Prototype needs to be updated in include/keys/trusted.h and it looks > like this function is used in crypto/asymmetric_keys/asym_tpm.c so these > same changes should be made there. Thanks for the review. Which tree are you looking at? These files don't exist in torvalds/linux, but maybe -next or the crypto tree have expanded the number of call sites of this function? > > Otherwise, looks good to me! Thanks for sending the patch. > > Nathan > > > { > > unsigned char paramdigest[SHA1_DIGEST_SIZE]; > > struct sdesc *sdesc; > > @@ -139,7 +139,7 @@ static int TSS_authhmac(unsigned char *digest, const unsigned char *key, > > return PTR_ERR(sdesc); > > } > > > > - c = h3; > > + c = h2; > > ret = crypto_shash_init(&sdesc->shash); > > if (ret < 0) > > goto out; > > @@ -163,7 +163,7 @@ static int TSS_authhmac(unsigned char *digest, const unsigned char *key, > > if (!ret) > > ret = TSS_rawhmac(digest, key, keylen, SHA1_DIGEST_SIZE, > > paramdigest, TPM_NONCE_SIZE, h1, > > - TPM_NONCE_SIZE, h2, 1, &c, 0, 0); > > + TPM_NONCE_SIZE, h3, 1, &c, 0, 0); > > out: > > kzfree(sdesc); > > return ret; > > @@ -508,7 +508,7 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype, > > if (pcrinfosize == 0) { > > /* no pcr info specified */ > > ret = TSS_authhmac(td->pubauth, sess.secret, SHA1_DIGEST_SIZE, > > - sess.enonce, td->nonceodd, cont, > > + sess.enonce, cont, td->nonceodd, > > sizeof(uint32_t), &ordinal, SHA1_DIGEST_SIZE, > > td->encauth, sizeof(uint32_t), &pcrsize, > > sizeof(uint32_t), &datsize, datalen, data, 0, > > @@ -516,7 +516,7 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype, > > } else { > > /* pcr info specified */ > > ret = TSS_authhmac(td->pubauth, sess.secret, SHA1_DIGEST_SIZE, > > - sess.enonce, td->nonceodd, cont, > > + sess.enonce, cont, td->nonceodd, > > sizeof(uint32_t), &ordinal, SHA1_DIGEST_SIZE, > > td->encauth, sizeof(uint32_t), &pcrsize, > > pcrinfosize, pcrinfo, sizeof(uint32_t), > > @@ -608,12 +608,12 @@ static int tpm_unseal(struct tpm_buf *tb, > > return ret; > > } > > ret = TSS_authhmac(authdata1, keyauth, TPM_NONCE_SIZE, > > - enonce1, nonceodd, cont, sizeof(uint32_t), > > + enonce1, cont, nonceodd, sizeof(uint32_t), > > &ordinal, bloblen, blob, 0, 0); > > if (ret < 0) > > return ret; > > ret = TSS_authhmac(authdata2, blobauth, TPM_NONCE_SIZE, > > - enonce2, nonceodd, cont, sizeof(uint32_t), > > + enonce2, cont, nonceodd, sizeof(uint32_t), > > &ordinal, bloblen, blob, 0, 0); > > if (ret < 0) > > return ret; > > -- > > 2.19.0.605.g01d371f741-goog > > -- Thanks, ~Nick Desaulniers