Linux-Integrity Archive on lore.kernel.org
 help / Atom feed
From: Nathan Chancellor <natechancellor@gmail.com>
To: ndesaulniers@google.com
Cc: jejb@linux.vnet.ibm.com, dhowells@redhat.com,
	ebiggers@google.com, Mimi Zohar <zohar@linux.vnet.ibm.com>,
	James Morris <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	linux-integrity@vger.kernel.org, keyrings@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KEYS: trusted: fix -Wvarags warning
Date: Thu, 11 Oct 2018 18:50:22 -0700
Message-ID: <20181012015022.GA7508@flashbox> (raw)
In-Reply-To: <20181011203126.15338-1-ndesaulniers@google.com>

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 <jejb@linux.vnet.ibm.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>  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.

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
> 

  reply index

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09 22:11 undefined behavior (-Wvarargs) in security/keys/trusted.c#TSS_authhmac() Nick Desaulniers
2018-10-11 16:02 ` Arnd Bergmann
2018-10-11 16:10   ` James Bottomley
2018-10-11 20:31     ` [PATCH] KEYS: trusted: fix -Wvarags warning ndesaulniers
2018-10-12  1:50       ` Nathan Chancellor [this message]
2018-10-12 16:55         ` Nick Desaulniers
2018-10-12 17:03           ` Nathan Chancellor
2018-10-12 12:29       ` Denis Kenzior
2018-10-12 15:05         ` James Bottomley
2018-10-12 15:13           ` Denis Kenzior
2018-10-12 15:22             ` James Bottomley
2018-10-12 15:44               ` Denis Kenzior
2018-10-12 15:46                 ` James Bottomley
2018-10-12 15:53                   ` Denis Kenzior
2018-10-12 16:01                     ` James Bottomley
2018-10-12 17:14                       ` Nick Desaulniers
2018-10-12 15:25             ` James Bottomley
2018-10-12 17:05             ` Nick Desaulniers
2018-10-12 17:17               ` Nick Desaulniers
2018-10-12 17:27               ` Denis Kenzior
2018-10-12 18:39                 ` Nick Desaulniers
2018-10-12 17:02         ` Nick Desaulniers
2018-10-12 17:15           ` Denis Kenzior
2018-10-15  9:26       ` David Laight
2018-10-15  9:26         ` David Laight
2018-10-15 21:53         ` Nick Desaulniers
2018-10-16  8:13           ` David Laight
2018-10-16  8:13             ` David Laight
2018-10-22 23:43             ` [PATCH v2] " ndesaulniers
2018-10-23  0:00               ` Nathan Chancellor
2018-10-24  8:36               ` Jarkko Sakkinen
2018-10-29 17:54                 ` Nick Desaulniers
2019-02-11 18:36                   ` Nick Desaulniers
2019-02-12 23:12                     ` Jarkko Sakkinen
2019-02-14 10:52                       ` Jarkko Sakkinen

Reply instructions:

You may reply publically 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=20181012015022.GA7508@flashbox \
    --to=natechancellor@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=ebiggers@google.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=jmorris@namei.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=serge@hallyn.com \
    --cc=zohar@linux.vnet.ibm.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

Linux-Integrity Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-integrity/0 linux-integrity/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-integrity linux-integrity/ https://lore.kernel.org/linux-integrity \
		linux-integrity@vger.kernel.org linux-integrity@archiver.kernel.org
	public-inbox-index linux-integrity


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-integrity


AGPL code for this site: git clone https://public-inbox.org/ public-inbox