From nobody Thu Oct 07 01:41:22 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 1307412D0ADB; Thu, 7 Oct 2021 01:41:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HPvDg00Wpz4dgR; Thu, 7 Oct 2021 01:41:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D49652D53; Thu, 7 Oct 2021 01:41:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1971fMOH021791; Thu, 7 Oct 2021 01:41:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1971fMKu021790; Thu, 7 Oct 2021 01:41:22 GMT (envelope-from git) Date: Thu, 7 Oct 2021 01:41:22 GMT Message-Id: <202110070141.1971fMKu021790@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: 224a95f12427 - main - libfido2: Address CHERI compatibility List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 224a95f124270275ddd7ab9f8f87dd47bad7c282 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=224a95f124270275ddd7ab9f8f87dd47bad7c282 commit 224a95f124270275ddd7ab9f8f87dd47bad7c282 Author: Jessica Clarke AuthorDate: 2021-10-02 15:51:38 +0000 Commit: Ed Maste CommitDate: 2021-10-07 01:40:26 +0000 libfido2: Address CHERI compatibility Cherry-picked from libfido2 upstream f20a735c0a6f: iso7816: Avoid storing pointers in a packed structure On CHERI, and thus Arm's experimental Morello prototype architecture, pointers are represented as capabilities, which are unforgeable bounded pointers, providing always-on fine-grained spatial memory safety. The unforgeability is enforced through the use of tagged memory, with one validity tag bit per capability-sized-and-aligned word in memory. This means that storing a pointer to an unaligned location, which is not guaranteed to work per the C standard, either traps or results in the capability losing its tag (and thus never being dereferenceable again), depending on how exactly the store is done (specifically, whether a capability store or memcpy is used). However, iso7816 itself does not need to be packed, and doing so likely causes inefficiencies on existing architectures. The iso7816_header_t member is packed, and the flexible payload array is a uint8_t (which by definition has no padding bits and is exactly 8 bits in size and, since CHAR_BITS must be at least 8, its existence implies that it has the same representation as unsigned char, and that it has size and alignment 1) so there will never be any padding inserted between header and payload (but payload may overlap with padding at the end of the struct due to how flexible arrays work, which means we need to be careful about our calculations). Co-authored-by: pedro martelletto --- contrib/libfido2/src/iso7816.c | 4 ++-- contrib/libfido2/src/iso7816.h | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/contrib/libfido2/src/iso7816.c b/contrib/libfido2/src/iso7816.c index a11aae3e99d1..a4902277c6d8 100644 --- a/contrib/libfido2/src/iso7816.c +++ b/contrib/libfido2/src/iso7816.c @@ -59,6 +59,6 @@ iso7816_ptr(const iso7816_apdu_t *apdu) size_t iso7816_len(const iso7816_apdu_t *apdu) { - return apdu->alloc_len - sizeof(apdu->alloc_len) - - sizeof(apdu->payload_len) - sizeof(apdu->payload_ptr); + return apdu->alloc_len - offsetof(iso7816_apdu_t, header) - + (sizeof(iso7816_apdu_t) - offsetof(iso7816_apdu_t, payload)); } diff --git a/contrib/libfido2/src/iso7816.h b/contrib/libfido2/src/iso7816.h index 5f5363a63a56..9bfad1fbab9d 100644 --- a/contrib/libfido2/src/iso7816.h +++ b/contrib/libfido2/src/iso7816.h @@ -27,14 +27,13 @@ struct iso7816_header { uint8_t lc3; }) -PACKED_TYPE(iso7816_apdu_t, -struct iso7816_apdu { +typedef struct iso7816_apdu { size_t alloc_len; uint16_t payload_len; uint8_t *payload_ptr; iso7816_header_t header; uint8_t payload[]; -}) +} iso7816_apdu_t; const unsigned char *iso7816_ptr(const iso7816_apdu_t *); int iso7816_add(iso7816_apdu_t *, const void *, size_t);