From patchwork Wed Jun 23 09:41:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 1496008 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.a=rsa-sha256 header.s=google header.b=Xuww/Pgd; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G8ywY3rqKz9sWc for ; Wed, 23 Jun 2021 19:42:21 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4G8ywY6zynz3bvm for ; Wed, 23 Jun 2021 19:42:21 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.a=rsa-sha256 header.s=google header.b=Xuww/Pgd; 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=axtens.net (client-ip=2607:f8b0:4864:20::532; helo=mail-pg1-x532.google.com; envelope-from=dja@axtens.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.a=rsa-sha256 header.s=google header.b=Xuww/Pgd; dkim-atps=neutral Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) (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 4G8ywJ1Ws7z30Fs for ; Wed, 23 Jun 2021 19:42:07 +1000 (AEST) Received: by mail-pg1-x532.google.com with SMTP id v7so1308990pgl.2 for ; Wed, 23 Jun 2021 02:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=emsXJCYWlqWvD6xHElIRds3SizxzmC52GMdC6fnzFvI=; b=Xuww/PgdoFLn/7XSg5k8aGg2yxaTYtp/iP8qG0e3Q+lW+TGefOW5AR1GW952GYrAAV c79ZCnJTJ16Ne1jbMRKVgpaldMKZ+fidijvWSg3w10sqAqeBabVCPoCZ3B9dn6V+cFXm tFV5aF9aP0slqJt+3HsW1oBo7XmPBqFHXpcPo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=emsXJCYWlqWvD6xHElIRds3SizxzmC52GMdC6fnzFvI=; b=eFQtIfUWl9FDFhqIrIA3YGYNbw9MhRxqg1z3EpRdlOf/ps+uDEXi29K7OG/BogOJ/Q l/v9XfAhQBjErW2iCqUUooBeB2U81EUi0WPIeFjM60TK4zgzDc5UC3n6gorUBCadOnCW xWxnO4PqT4BwoMZagzpoQIqFBEQ/T5mDslzzEogUa8i+rHXBmNfev2VvKsBwtqxYQWK7 l+MNOUgwuaQIQ/U+HnLwLUJ+2itnp1PZGMurnnZH2OOCrhqTIWvn4y+XmdSM3BD+MAf3 0FWxXARYWXYpg9f39d45Ut+X3mfgD2VKR238QJ5iTkiHzz8Ze8z3BIkyXbnDfeO2u8oK C7/A== X-Gm-Message-State: AOAM532v5R6alNTGVjXVYme/IOY6JNCpsMOSItex4UI+xFezHnqebga8 6XT/OAxwl5H37vpnbw7e7NjaxRsXfMkGog== X-Google-Smtp-Source: ABdhPJwHh8ngk8jjUOr/uaKAZYNfIiM7eVz/pQmG8mD1UjzJsbzS1QO5aoO1ywuz3Y4qjJzCSZUu9w== X-Received: by 2002:a65:4689:: with SMTP id h9mr3090397pgr.347.1624441323323; Wed, 23 Jun 2021 02:42:03 -0700 (PDT) Received: from localhost ([203.206.29.204]) by smtp.gmail.com with ESMTPSA id i27sm787034pgl.78.2021.06.23.02.42.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 02:42:02 -0700 (PDT) From: Daniel Axtens To: skiboot@lists.ozlabs.org Date: Wed, 23 Jun 2021 19:41:54 +1000 Message-Id: <20210623094154.421169-1-dja@axtens.net> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [Skiboot] [PATCH v2] secvar/backend: use endian-aware types in edk2.h 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" Recently we had an issue where we did the following: uint16_t year = le32_to_cpu(timestamp->year); This is wrong and will break on BE. However, we didn't catch this with sparse because there was a whole slew of warnings. The reason for the slew of warnings is that we didn't annotate the types that store little-endian specific data in edk2.h. Provide the appropriate annotations. We now get a single sparse warning for the file, which correctly identifies the issue: edk2-compat-process.c:374:46: warning: incorrect type in argument 1 (different base types) edk2-compat-process.c:374:46: expected restricted leint32_t [usertype] le_val edk2-compat-process.c:374:46: got restricted leint16_t const [usertype] year We do lose the signedness of efi_time->timezone, but that's probably OK: we never use the timezone anyway and the comment above the data structure makes the signedness pretty clear. Signed-off-by: Daniel Axtens --- This doesn't fix any actual bug, it just makes it easier for us to pick up endian issues in future. --- libstb/secvar/backend/edk2.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libstb/secvar/backend/edk2.h b/libstb/secvar/backend/edk2.h index ef6d7c79e7ff..d76251482ac2 100644 --- a/libstb/secvar/backend/edk2.h +++ b/libstb/secvar/backend/edk2.h @@ -125,15 +125,15 @@ static const uuid_t EFI_CERT_RSA2048_GUID = {{ 0xe8, 0x66, 0x57, 0x3c, 0x9c, 0x2 * TimeZone: -1440 to 1440 or 2047 */ struct efi_time { - u16 year; + le16 year; u8 month; u8 day; u8 hour; u8 minute; u8 second; u8 pad1; - u32 nanosecond; - s16 timezone; + le32 nanosecond; + le16 timezone; u8 daylight; u8 pad2; }; @@ -163,15 +163,15 @@ typedef struct __packed { /// /// Total size of the signature list, including this header. /// - uint32_t SignatureListSize; + leint32_t SignatureListSize; /// /// Size of the signature header which precedes the array of signatures. /// - uint32_t SignatureHeaderSize; + leint32_t SignatureHeaderSize; /// /// Size of each signature. /// - uint32_t SignatureSize; + leint32_t SignatureSize; /// /// Header before the array of signatures. The format of this header is specified /// by the SignatureType. @@ -191,18 +191,18 @@ struct win_certificate { * The length of the entire certificate, including the length of the * header, in bytes. */ - u32 dw_length; + le32 dw_length; /* * The revision level of the WIN_CERTIFICATE structure. The current * revision level is 0x0200. */ - u16 w_revision; + le16 w_revision; /* * The certificate type. See WIN_CERT_TYPE_xxx for the UEFI certificate * types. The UEFI specification reserves the range of certificate type * values from 0x0EF0 to 0x0EFF. */ - u16 w_certificate_type; + le16 w_certificate_type; /* * The following is the actual certificate. The format of * the certificate depends on wCertificateType.