From patchwork Sun Jul 7 23:48:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Chikunov X-Patchwork-Id: 11034475 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 7EFF8112C for ; Sun, 7 Jul 2019 23:49:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E92627FAE for ; Sun, 7 Jul 2019 23:49:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62B7628173; Sun, 7 Jul 2019 23:49: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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 0450127FAE for ; Sun, 7 Jul 2019 23:49:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727692AbfGGXtV (ORCPT ); Sun, 7 Jul 2019 19:49:21 -0400 Received: from vmicros1.altlinux.org ([194.107.17.57]:43292 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727590AbfGGXtV (ORCPT ); Sun, 7 Jul 2019 19:49:21 -0400 Received: from imap.altlinux.org (imap.altlinux.org [194.107.17.38]) by vmicros1.altlinux.org (Postfix) with ESMTP id AE52D72CC6C; Mon, 8 Jul 2019 02:49:18 +0300 (MSK) Received: from beacon.altlinux.org (unknown [185.6.174.98]) by imap.altlinux.org (Postfix) with ESMTPSA id 938664A4AF6; Mon, 8 Jul 2019 02:49:18 +0300 (MSK) From: Vitaly Chikunov To: Mimi Zohar , Dmitry Kasatkin , linux-integrity@vger.kernel.org Subject: [PATCH v1 5/5] ima-evm-utils: Fix clang warning about possible unaligned pointer for hdr->keyid Date: Mon, 8 Jul 2019 02:48:37 +0300 Message-Id: <20190707234837.4866-6-vt@altlinux.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190707234837.4866-1-vt@altlinux.org> References: <20190707234837.4866-1-vt@altlinux.org> MIME-Version: 1.0 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 Struct signature_v2_hdr is packed so clang complains that taking address of packed member may result in an unaligned pointer value: libimaevm.c:481:21: warning: taking address of packed member 'keyid' of class or structure 'signature_v2_hdr' may result in an unaligned pointer value [-Waddress-of-packed-member] __be32_to_cpup(&hdr->keyid)); ^~~~~~~~~~ libimaevm.c:905:17: warning: taking address of packed member 'keyid' of class or structure 'signature_v2_hdr' may result in an unaligned pointer value [-Waddress-of-packed-member] calc_keyid_v2(&hdr->keyid, name, pkey); ^~~~~~~~~~ Signed-off-by: Vitaly Chikunov --- src/libimaevm.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libimaevm.c b/src/libimaevm.c index b556276..f8ab812 100644 --- a/src/libimaevm.c +++ b/src/libimaevm.c @@ -475,10 +475,12 @@ int verify_hash_v2(const char *file, const unsigned char *hash, int size, } if (public_keys) { - pkey = find_keyid(hdr->keyid); + uint32_t keyid = hdr->keyid; + + pkey = find_keyid(keyid); if (!pkey) { log_err("%s: unknown keyid: %x\n", file, - __be32_to_cpup(&hdr->keyid)); + __be32_to_cpup(&keyid)); return -1; } } else { @@ -869,6 +871,7 @@ int sign_hash_v2(const char *algo, const unsigned char *hash, int size, const ch const EVP_MD *md; size_t sigsize; const char *st; + uint32_t keyid; if (!hash) { log_err("sign_hash_v2: hash is null\n"); @@ -902,7 +905,8 @@ int sign_hash_v2(const char *algo, const unsigned char *hash, int size, const ch hdr->hash_algo = get_hash_algo(algo); - calc_keyid_v2(&hdr->keyid, name, pkey); + calc_keyid_v2(&keyid, name, pkey); + hdr->keyid = keyid; st = "EVP_PKEY_CTX_new"; if (!(ctx = EVP_PKEY_CTX_new(pkey, NULL)))