From patchwork Mon Oct 22 23:43:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 10652629 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5FD7F13BF for ; Mon, 22 Oct 2018 23:44:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D184B29089 for ; Mon, 22 Oct 2018 23:44:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C501B29094; Mon, 22 Oct 2018 23:44:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C23E29089 for ; Mon, 22 Oct 2018 23:44:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726426AbeJWIE6 (ORCPT ); Tue, 23 Oct 2018 04:04:58 -0400 Received: from mail-ot1-f73.google.com ([209.85.210.73]:39081 "EHLO mail-ot1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726082AbeJWIE6 (ORCPT ); Tue, 23 Oct 2018 04:04:58 -0400 Received: by mail-ot1-f73.google.com with SMTP id 36so13535491oth.6 for ; Mon, 22 Oct 2018 16:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=AVaE6qqCM7P1pf2cFcPqWk4W3pnXUdpSoKA8uQ0SjZ4=; b=mBzyYu1HdbYE9z8r5x4PGuQhDtMqe4IrmxEbiZGjR45uneCPsqf07yKK18YzpzXCCT EsRM0VAhjtUeutUbpYgWJVrShoR+yyt2zU552O3ks7MPiojNA/P5YMXQTvREcGgf8NUi KfPv5KbgFoTdnPVQks3lRzxuovXxtyu8hYxB4Yz22M9lQ7dZ6k7S7aAPMhzXvQ9DX9sw F5AzTn0gRPOGytm2GlCs24SVbH6u3E3sDCQw1avqon1jeulFHKWhXACLX9eCz37pTvbb +W0lnRoywsqrDBzHmZnPQ0zsqLcdnXLNJhQvkylb6qgtvr+2Jw2hPKlgIKN9cmU9dKwP ah7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=AVaE6qqCM7P1pf2cFcPqWk4W3pnXUdpSoKA8uQ0SjZ4=; b=iLdpCbAeGEEmgwS+SPp8pQdw0eQAUtjQScZBTV0nWqNIjYsfWaTpLfhdoLWWnEdWGd KP/qqRZmws9MNWqX9ptw5CRWU7jmVbMdguk7ZhoU+iXIv/04DZpG7ja3TApoSVmjeMwl HF3w91hjVfQXAcRStXysrtNYbggQCT1jBSxOqQrdYM7lxAGaPOdPsARhtK3VgLWGPqE9 pecaxeRfLAXq0i1PVlHedjXSf/dwc0YRJq6D5e6fuYXJehpJoDVjEV+z9ynpvOE0h2xl kQKW4il8TGAuh4ut5K1sON21aAZi3VPjbdvhCTb85E9DyNGFL2SF81ZzfkuT+2RYBxOg g00Q== X-Gm-Message-State: ABuFfogLc93OCowAvzP4H43aTgGsU0RSyH1EEzZt4b+U5DtFymQBaiG1 0mlMGM3eWqQTyvPFAkQ15jcZjFKRr6erPu43yrc= X-Google-Smtp-Source: ACcGV62tz4jpL504gq8yGC58f+ICh5t7A1p5mMqKqhrqA/y65g9HBDMq5/8RNd+EHBgG74quCce1vqIdtPoXX8VTHP4= X-Received: by 2002:a9d:2351:: with SMTP id k17mr38895235otd.34.1540251855357; Mon, 22 Oct 2018 16:44:15 -0700 (PDT) Date: Mon, 22 Oct 2018 16:43:57 -0700 In-Reply-To: <0147a993d4a94426afa469a8dcc4e5d7@AcuMS.aculab.com> Message-Id: <20181022234357.82217-1-ndesaulniers@google.com> Mime-Version: 1.0 References: <0147a993d4a94426afa469a8dcc4e5d7@AcuMS.aculab.com> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog Subject: [PATCH v2] [PATCH] KEYS: trusted: fix -Wvarags warning From: ndesaulniers@google.com To: dhowells@redhat.com, jejb@linux.vnet.ibm.com Cc: natechancellor@gmail.com, David.Laight@aculab.com, denkenz@gmail.com, Nick Desaulniers , 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 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Jarkko Sakkinen --- 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;