From patchwork Tue Jun 22 02:59:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 1495428 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=2404:9400:2:0:216:3eff:fee1:b9f1; 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=aPazyleN; dkim-atps=neutral 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G8B2v000yz9sXN for ; Tue, 22 Jun 2021 13:00:06 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4G8B2t2wLmz304R for ; Tue, 22 Jun 2021 13:00:06 +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=aPazyleN; 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::1029; helo=mail-pj1-x1029.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=aPazyleN; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) (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 4G8B2m14pbz2yQm for ; Tue, 22 Jun 2021 12:59:57 +1000 (AEST) Received: by mail-pj1-x1029.google.com with SMTP id 22-20020a17090a0c16b0290164a5354ad0so873756pjs.2 for ; Mon, 21 Jun 2021 19:59:56 -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=H5PoORkmuPaCbNliTHJBbO5Jr66C+J38Y/fZPHY+YiU=; b=aPazyleN3HiqQtNCJ1Kq0yXRitbK4UM8OY6r64cPTrr2ALgl3cuj/qP++sBTJ5PNk8 AO9B590Jca8p7MS/FCly8dOV8KOyFYU1n5R6ocaUmjh0gXoHM7qHWAzeQq7umNTHN6ag Ncgw4MaoG4w+7XiGptCqxhE08sZZ3aH2hIxzs= 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=H5PoORkmuPaCbNliTHJBbO5Jr66C+J38Y/fZPHY+YiU=; b=bmBgbj9mnYSLjUG2mw3Jp4fASy/mj7fyyLfHjC1xUiiCpxsk067oRrmQrKQ8kMiX0F E1dVfBxEcVMjODpCZEpgBOwzbEkbzjsW05rwfWYvtgylgvvc1mxqBuy+v4Xl8VFgHZa8 sz1875g/zjSd2nT2QJAI90guofVDWaCTzv9a67nb7ZMCYcKXzEB9Z1mvFwCDCWfg4AJ1 xxsD8TcseqKUMpwTreZaNvldrg+aeTm+Hl/rm3Vb1dgHN55jccSJL4TDX9E7+7V8QC06 4ewRTIyhcUSBkQKYFzPJpLxlGJCQmIsAAGI0Xq5XLOXLhnREO6A9iLopiiX00d4qx1hN wjAQ== X-Gm-Message-State: AOAM5324Zjuwy79AccKqqbeGQ7RivRekQNURtzQdXGL7kaKvatAyTquB IFWjCghBV/NPg7Y8xkObydNO7i1gJRofkg== X-Google-Smtp-Source: ABdhPJwWizoMC9LlDXT6yfQYwDaytsWbcRcrprHCU3fizBK1yjoWd71t/lF5F1OuoWikawh8o1qHog== X-Received: by 2002:a17:90b:78e:: with SMTP id l14mr1377239pjz.110.1624330794822; Mon, 21 Jun 2021 19:59:54 -0700 (PDT) Received: from localhost ([203.206.29.204]) by smtp.gmail.com with ESMTPSA id w123sm9660177pff.186.2021.06.21.19.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 19:59:54 -0700 (PDT) From: Daniel Axtens To: skiboot@lists.ozlabs.org Date: Tue, 22 Jun 2021 12:59:50 +1000 Message-Id: <20210622025950.54276-1-dja@axtens.net> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [Skiboot] [PATCH] 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: , Cc: nick.child@ibm.com, nayna@linux.ibm.com 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 There's one annotation that I'm not super happy about - the annotation of efi_time->timezone. Happy for other ideas on that one. Signed-off-by: Daniel Axtens --- 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..17df2b7bc536 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; + s16 ENDIAN_TYPE 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.