From patchwork Fri Apr 8 15:31:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1614964 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=oC6w4QqV; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KZj0v0lnHz9sFq for ; Sat, 9 Apr 2022 01:32:15 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KZj0t6WFZz3bfr for ; Sat, 9 Apr 2022 01:32:14 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=oC6w4QqV; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1030; helo=mail-pj1-x1030.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=oC6w4QqV; dkim-atps=neutral Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KZj0W5Nczz2xrS for ; Sat, 9 Apr 2022 01:31:55 +1000 (AEST) Received: by mail-pj1-x1030.google.com with SMTP id e8-20020a17090a118800b001cb13402ea2so5534936pja.0 for ; Fri, 08 Apr 2022 08:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1lVgq1twGRW6JsLrjcaaximQ7HJkdTq1Aq524j6KbsA=; b=oC6w4QqVEhnDK0HZnoxnSrYAZRv/ovi0SJ3Yxq6xzb2+5S6nL/w0OTveQrEZ44Y/S/ 5XznfO2UpsJJi8WSkkA0EZEqP1rW5yqkdPobua56sy1I1S/ka5kMvVjGADZy6hLrSkdP Jt9Rxxbb13U9sNu7AA6RHpTmZ/u+wI9UMwTrA99mDvRXOT+7bxk6BMmQAxPtk06RKq6c eOjEbMHxpC0pTYZzGNPpL3DK5gPMgIWxUDtjGBrXb+mkLkYDzjJB8onJ6SpucYPetqj3 it96Iw2yGron0UKvDxHkm9fWk8gvc/E/EFORmvTuJ2HTg946Vlhvxe4ImEPimie+IfP6 7KQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1lVgq1twGRW6JsLrjcaaximQ7HJkdTq1Aq524j6KbsA=; b=CAqLy+PPiYXHgeAjBqbDVbYdWUsXY0zg+dLaFKftQN4KNqB0FxUQZq+kViql4EB/OA 74D5r2QlDrA2D4Sc4qbQGm9afnO4EShJ3aMj97yWSUcgjRFPIBBmu6tTJhe9vW5lD8lB avswETZj7G4gj6yAwjE00U87xUodHDmjJDJM+noe/JsJazd3vJ7hQURLJFAe4jYqPmpL jjLp0AgIpkI1MTvtC4UqbiR49RnE3H+CZj9L3BrCpOWChTBTf29SRZ7R8QuNEkid00xJ H7Gt/4ufjw5gjt5+LXYTWs0kk3Y3rLhIppaosEtEvBm0xybL/gfHMwkCRX/gwSXEAzl2 6keA== X-Gm-Message-State: AOAM530A9Wrdg/oHyNb67mM4/ujPP2itnAuPEikaT4FpZUvQk8r+amXz DU/C43hOE92Aix9I940+wLdvesv5MD0= X-Google-Smtp-Source: ABdhPJztABO7bhqSG1HQN8vnI5Q8HayNWN8LckCW6OwYLJRk48RzXpsS6TMOOPe9nV/kn9WLiSXooA== X-Received: by 2002:a17:90b:4f8d:b0:1c6:408b:6b0d with SMTP id qe13-20020a17090b4f8d00b001c6408b6b0dmr22113326pjb.90.1649431913529; Fri, 08 Apr 2022 08:31:53 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (220-235-208-104.tpgi.com.au. [220.235.208.104]) by smtp.gmail.com with ESMTPSA id y26-20020a056a00181a00b004fe3a6f02cesm14175172pfa.85.2022.04.08.08.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Apr 2022 08:31:53 -0700 (PDT) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sat, 9 Apr 2022 01:31:36 +1000 Message-Id: <20220408153137.996621-4-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220408153137.996621-1-npiggin@gmail.com> References: <20220408153137.996621-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH 3/4] libstb: endian annotations X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Add endian annotations to silence sparse endian warnings in libstb. Signed-off-by: Nicholas Piggin --- libstb/secvar/storage/secboot_tpm.c | 8 ++++---- libstb/tss2/ibmtpm20tss/utils/tssauth20.c | 4 ++-- libstb/tss2/ibmtpm20tss/utils/tssdevskiboot.c | 4 ++-- libstb/tss2/ibmtpm20tss/utils/tssutils.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libstb/secvar/storage/secboot_tpm.c b/libstb/secvar/storage/secboot_tpm.c index ff8ea9e0a..1dce0c711 100644 --- a/libstb/secvar/storage/secboot_tpm.c +++ b/libstb/secvar/storage/secboot_tpm.c @@ -160,9 +160,9 @@ static char *secboot_serialize_secvar(char *target, const struct secvar *var, co + var->key_len + var->data_size) > end) return NULL; - *((uint64_t*) target) = cpu_to_be64(var->key_len); + *((beint64_t*) target) = cpu_to_be64(var->key_len); target += sizeof(var->key_len); - *((uint64_t*) target) = cpu_to_be64(var->data_size); + *((beint64_t*) target) = cpu_to_be64(var->data_size); target += sizeof(var->data_size); memcpy(target, var->key, var->key_len); target += var->key_len; @@ -289,9 +289,9 @@ static int secboot_deserialize_secvar(struct secvar **var, char **src, const cha assert(var); /* Load in the two header values */ - key_len = be64_to_cpu(*((uint64_t *) *src)); + key_len = be64_to_cpu(*((beint64_t *) *src)); *src += sizeof(uint64_t); - data_size = be64_to_cpu(*((uint64_t *) *src)); + data_size = be64_to_cpu(*((beint64_t *) *src)); *src += sizeof(uint64_t); /* Check if we've reached the last var to deserialize */ diff --git a/libstb/tss2/ibmtpm20tss/utils/tssauth20.c b/libstb/tss2/ibmtpm20tss/utils/tssauth20.c index 8489e86d5..a3dafb9d4 100644 --- a/libstb/tss2/ibmtpm20tss/utils/tssauth20.c +++ b/libstb/tss2/ibmtpm20tss/utils/tssauth20.c @@ -1295,7 +1295,7 @@ TPM_RC TSS_GetCommandDecryptParam(TSS_AUTH_CONTEXT *tssAuthContext, } /* extract contents of the first TPM2B */ if (rc == 0) { - *decryptParamSize = ntohs(*(uint16_t *)cpBuffer); + *decryptParamSize = ntohs(*(beint16_t *)cpBuffer); *decryptParamBuffer = cpBuffer + sizeof(uint16_t); } /* sanity range check */ @@ -1491,7 +1491,7 @@ TPM_RC TSS_GetResponseEncryptParam(TSS_AUTH_CONTEXT *tssAuthContext, } /* extract contents of the first TPM2B */ if (rc == 0) { - *encryptParamSize = ntohs(*(uint16_t *)rpBuffer); + *encryptParamSize = ntohs(*(beint16_t *)rpBuffer); *encryptParamBuffer = rpBuffer + sizeof(uint16_t); } /* sanity range check */ diff --git a/libstb/tss2/ibmtpm20tss/utils/tssdevskiboot.c b/libstb/tss2/ibmtpm20tss/utils/tssdevskiboot.c index 24d437985..e4b1b1072 100644 --- a/libstb/tss2/ibmtpm20tss/utils/tssdevskiboot.c +++ b/libstb/tss2/ibmtpm20tss/utils/tssdevskiboot.c @@ -166,7 +166,7 @@ TPM_RC TSS_Dev_Transmit(TSS_CONTEXT *tssContext, * it here. */ if (rc == 0) { - responseSize = ntohl(*(uint32_t *)(responseBuffer + sizeof(TPM_ST))); + responseSize = ntohl(*(beint32_t *)(responseBuffer + sizeof(TPM_ST))); if (responseSize != *length) { if (tssVerbose) printf("TSS_Skiboot_Transmit: Bytes read (%u) and Buffer responseSize field (%lu) don't match\n", @@ -180,7 +180,7 @@ TPM_RC TSS_Dev_Transmit(TSS_CONTEXT *tssContext, * and deliver it to the upper layers */ if (rc == 0) - rc = ntohl(*(uint32_t *)(responseBuffer + sizeof(TPM_ST) + sizeof(uint32_t))); + rc = ntohl(*(beint32_t *)(responseBuffer + sizeof(TPM_ST) + sizeof(uint32_t))); if (tssVverbose) printf("TSS_Skiboot_Transmit: Response Code: %08x", rc); diff --git a/libstb/tss2/ibmtpm20tss/utils/tssutils.c b/libstb/tss2/ibmtpm20tss/utils/tssutils.c index 29124c36e..90c4f568d 100644 --- a/libstb/tss2/ibmtpm20tss/utils/tssutils.c +++ b/libstb/tss2/ibmtpm20tss/utils/tssutils.c @@ -253,7 +253,7 @@ TPM_RC TSS_TPM2B_CreateUint32(TPM2B *target, uint32_t source, uint16_t targetSiz } } if (rc == 0) { - uint32_t sourceNbo = htonl(source); + beint32_t sourceNbo = htonl(source); memmove(target->buffer, (uint8_t *)&sourceNbo, sizeof(uint32_t)); target->size = sizeof(uint32_t); }