Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp2822749ima; Mon, 22 Oct 2018 17:05:05 -0700 (PDT) X-Google-Smtp-Source: ACcGV61qWw1aIBYc1pwPgd0Wt/zHqWAUXdwQ75M/beomwcZZPaA1oA00nwwvSNvy9CbhzeDMfWWv X-Received: by 2002:a63:d0e:: with SMTP id c14-v6mr44248406pgl.281.1540253104986; Mon, 22 Oct 2018 17:05:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540253104; cv=none; d=google.com; s=arc-20160816; b=R+4kdj2Rf8JwHvRPI6ifJA9IhDF2vg1/Thamq/onW/VjFpXsu+1inag/o8pbMwZWIU 3NA3oNeCAdK64yZ4sbNnY4BYilaQm3DPyqQ6cx/ql/Wj+TH9XGcdmSHR4/s9olu5aJTj yKOBPjuAT9IMjI1u//NtDSK/KgjjAduyc3pfeNu/Qh8ABKygLkqJG940ypYzeCqzhrXB TGdKRJwO9RupSBEQjAgIlt3rM3faL7SO9pBcl+89/j00EYcbeHfmkWDGnpYsX6hqm+lw 1Myslu+XP/dpUk2zBnvqW+TbPXKw+tV9e6u/wZ8j0QwYLrOl1VDVygzqK2R7m0FPRKpa h6EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=EMozjLO2AkOaduQqwXZYBsZUrZ1QZa9lUM/qe262pPc=; b=wpCfcLsCsDELe/1BMfzfH2kon4VKLCMJCDeQ2MTvkGgBX/mxPHh3LMUac4vJiRjz/E 6PGlQTWlpy3d9t1A45LjbW9Kld0veo0Go0O8mO9Qpq/pBpgKxbCe9RUbkRHoLMZdcppI UChzvcM5EE3m0/4QAyzzHaJDOhKn0U0XtyLRAkmmlHvdgaTMUFJEICb6Bua4vycoOXl2 7/0RgquNKjLOJCNCpT+F0RaYhmh2WR6NYAJ5Jt+8ldUVnALaItZkgaqQRmnPzHGd0pHY iBTQdWmiZ21Uw9p8yzIZ3wtZHpUbsX1hF9yUbd8sj2NodnMq0Wy+JNQ258LDTEtrio2k i9KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nWwU7inQ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c41-v6si17356238plj.305.2018.10.22.17.04.46; Mon, 22 Oct 2018 17:05:04 -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=@gmail.com header.s=20161025 header.b=nWwU7inQ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726574AbeJWIVn (ORCPT + 99 others); Tue, 23 Oct 2018 04:21:43 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55612 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725799AbeJWIVn (ORCPT ); Tue, 23 Oct 2018 04:21:43 -0400 Received: by mail-wm1-f68.google.com with SMTP id x6-v6so644733wmc.5; Mon, 22 Oct 2018 17:00:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=EMozjLO2AkOaduQqwXZYBsZUrZ1QZa9lUM/qe262pPc=; b=nWwU7inQfPiJmcM8Fr+mCGTSXIPKbYXB9z9BKS/jAWRH8Bzz5A6ofcgud8YrkVwpWp eHR5MqVZaPaQmlpw+nvj2UuRzqkOnjE2iOgcuqpy8SrgUonvQRxlgn3hU/skVmyjqsmu agkxtCmvaDaJu40phb0iEV5E6ggIAjatGHHfWGnii1Kicg/JjUyQqgaGtUsGd1Z+w3r6 WvAHdqPA7HW4bUEtx3MnbG0ZU+DBwinoA1XzmCIs4+Au3cZ3FxulbvFM09qn1c+0/0hJ Zw8KNtZrJt/T/qW6VQQ88RQQWWZNb8RPClIgqQwq5S0gFsu9O7mwEGDs9FP27L6TMzEY uKGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=EMozjLO2AkOaduQqwXZYBsZUrZ1QZa9lUM/qe262pPc=; b=eRKuCGv0xQ4n6xdJBCxjsvk/i1lS0ru7tOzAQzberdawO1ED6qSrWc3zLX4CfaMwCr 57sVTDTCkgzj5zxS9o8uC1L9s62s2B0cEuU/gqdlzhjzoS+2jhWQ4Xtta+Z9j0Aa40XQ CzuX2r5ctZpaMPW4Fnwmyfsia6FobUd1F42bCxQ3e2KyedG9YvcNPp/jp1gydxQ+BrXu sdv9+XUV2a9lKZb7oQy3rOvvbv/gwSxVEXMm+VIKlPRVtRK8gaLdHx2okZ0A+bemhGH/ DQnky1JNtFtmaVxRj3REhiCr1T+ijQmI6X0oyyYD00FoHvHKy/JbGW75sUcYlRTQYz07 MOHw== X-Gm-Message-State: AGRZ1gLwiGWAdYuU1y7Ovmux/xlBqVMfqPcJAGX7PL2b7/HzhlNm0Ixi WAHN+mbMjhvHzzoJiRN7eKw= X-Received: by 2002:a1c:85d0:: with SMTP id h199-v6mr17714382wmd.127.1540252855135; Mon, 22 Oct 2018 17:00:55 -0700 (PDT) Received: from flashbox ([2a01:4f8:10b:24a5::2]) by smtp.gmail.com with ESMTPSA id x12-v6sm2482547wmd.32.2018.10.22.17.00.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Oct 2018 17:00:54 -0700 (PDT) Date: Mon, 22 Oct 2018 17:00:51 -0700 From: Nathan Chancellor To: ndesaulniers@google.com Cc: dhowells@redhat.com, jejb@linux.vnet.ibm.com, David.Laight@aculab.com, denkenz@gmail.com, Jarkko Sakkinen , Mimi Zohar , James Morris , "Serge E. Hallyn" , keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Subject: Re: [PATCH v2] [PATCH] KEYS: trusted: fix -Wvarags warning Message-ID: <20181023000051.GA17367@flashbox> References: <0147a993d4a94426afa469a8dcc4e5d7@AcuMS.aculab.com> <20181022234357.82217-1-ndesaulniers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181022234357.82217-1-ndesaulniers@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 22, 2018 at 04:43:57PM -0700, ndesaulniers@google.com wrote: > Fixes the warning reported by Clang: > 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 > Link: https://www.eskimo.com/~scs/cclass/int/sx11c.html > Suggested-by: David Laight > Suggested-by: Denis Kenzior > Suggested-by: James Bottomley > Suggested-by: Nathan Chancellor > Signed-off-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor > --- > v1 -> v2: > * Don't reorder args, just use default function promotion type > of unsigned int. > * Add !! boolean cast as per Denis in > https://lkml.org/lkml/2018/10/12/838. > * Tested with gcc-8 and clang-8. > > include/keys/trusted.h | 2 +- > security/keys/trusted.c | 4 ++-- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/keys/trusted.h b/include/keys/trusted.h > index adbcb6817826..0071298b9b28 100644 > --- a/include/keys/trusted.h > +++ b/include/keys/trusted.h > @@ -38,7 +38,7 @@ enum { > > 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 int h3, ...); > int TSS_checkhmac1(unsigned char *buffer, > const uint32_t command, > const unsigned char *ononce, > diff --git a/security/keys/trusted.c b/security/keys/trusted.c > index ff6789365a12..335ce6d1cf6b 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, > */ > 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 int h3, ...) > { > unsigned char paramdigest[SHA1_DIGEST_SIZE]; > struct sdesc *sdesc; > @@ -139,7 +139,7 @@ int TSS_authhmac(unsigned char *digest, const unsigned char *key, > return PTR_ERR(sdesc); > } > > - c = h3; > + c = !!h3; > ret = crypto_shash_init(&sdesc->shash); > if (ret < 0) > goto out; > -- > 2.19.1.568.g152ad8e336-goog > Thank you for the fix! Nathan