From owner-svn-src-stable@freebsd.org Wed May 22 23:19:22 2019 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4564B1590C43; Wed, 22 May 2019 23:19:22 +0000 (UTC) (envelope-from sjg@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AA43E6FF6D; Wed, 22 May 2019 23:19:21 +0000 (UTC) (envelope-from sjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8168224603; Wed, 22 May 2019 23:19:21 +0000 (UTC) (envelope-from sjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x4MNJLSI057227; Wed, 22 May 2019 23:19:21 GMT (envelope-from sjg@FreeBSD.org) Received: (from sjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x4MNJKBG057223; Wed, 22 May 2019 23:19:20 GMT (envelope-from sjg@FreeBSD.org) Message-Id: <201905222319.x4MNJKBG057223@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sjg set sender to sjg@FreeBSD.org using -f From: "Simon J. Gerraty" Date: Wed, 22 May 2019 23:19:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r348129 - in stable/12/lib/libsecureboot: . h tests X-SVN-Group: stable-12 X-SVN-Commit-Author: sjg X-SVN-Commit-Paths: in stable/12/lib/libsecureboot: . h tests X-SVN-Commit-Revision: 348129 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: AA43E6FF6D X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.95)[-0.953,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 May 2019 23:19:22 -0000 Author: sjg Date: Wed May 22 23:19:20 2019 New Revision: 348129 URL: https://svnweb.freebsd.org/changeset/base/348129 Log: libsecureboot: allow control of when pseudo pcr is updated During boot we only want to measure things which *must* be verified - this should provide more deterministic ordering. MFC r347981 Reviewed by: stevek Sponsored by: Juniper Networks Differential Revision: https://reviews.freebsd.org/D20297 Modified: stable/12/lib/libsecureboot/h/libsecureboot.h stable/12/lib/libsecureboot/tests/tvo.c stable/12/lib/libsecureboot/vepcr.c stable/12/lib/libsecureboot/verify_file.c Modified: stable/12/lib/libsecureboot/h/libsecureboot.h ============================================================================== --- stable/12/lib/libsecureboot/h/libsecureboot.h Wed May 22 23:11:16 2019 (r348128) +++ stable/12/lib/libsecureboot/h/libsecureboot.h Wed May 22 23:19:20 2019 (r348129) @@ -81,6 +81,8 @@ unsigned char *verify_asc(const char *, int); /* OpenP void ve_pcr_init(void); void ve_pcr_update(unsigned char *, size_t); ssize_t ve_pcr_get(unsigned char *, size_t); +int ve_pcr_updating_get(void); +void ve_pcr_updating_set(int); /* flags for verify_{asc,sig,signed} */ #define VEF_VERBOSE 1 Modified: stable/12/lib/libsecureboot/tests/tvo.c ============================================================================== --- stable/12/lib/libsecureboot/tests/tvo.c Wed May 22 23:11:16 2019 (r348128) +++ stable/12/lib/libsecureboot/tests/tvo.c Wed May 22 23:19:20 2019 (r348129) @@ -74,6 +74,9 @@ main(int argc, char *argv[]) } } +#ifdef VE_PCR_SUPPORT + ve_pcr_updating_set(1); +#endif ve_self_tests(); for ( ; optind < argc; optind++) { @@ -176,6 +179,10 @@ main(int argc, char *argv[]) } } } +#ifdef VE_PCR_SUPPORT + verify_pcr_export(); + printf("pcr=%s\n", getenv("loader.ve.pcr")); +#endif return (0); } Modified: stable/12/lib/libsecureboot/vepcr.c ============================================================================== --- stable/12/lib/libsecureboot/vepcr.c Wed May 22 23:11:16 2019 (r348128) +++ stable/12/lib/libsecureboot/vepcr.c Wed May 22 23:19:20 2019 (r348129) @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); static const br_hash_class *pcr_md = NULL; static br_hash_compat_context pcr_ctx; static size_t pcr_hlen = 0; +static int pcr_updating; /** * @brief initialize pcr context @@ -53,18 +54,37 @@ static size_t pcr_hlen = 0; void ve_pcr_init(void) { + pcr_updating = 0; pcr_hlen = br_sha256_SIZE; pcr_md = &br_sha256_vtable; pcr_md->init(&pcr_ctx.vtable); } /** + * @brief get pcr_updating state + */ +int +ve_pcr_updating_get(void) +{ + return (pcr_updating); +} + +/** + * @brief set pcr_updating state + */ +void +ve_pcr_updating_set(int updating) +{ + pcr_updating = updating; +} + +/** * @brief update pcr context */ void ve_pcr_update(unsigned char *data, size_t dlen) { - if (pcr_md) + if (pcr_updating != 0 && pcr_md != NULL) pcr_md->update(&pcr_ctx.vtable, data, dlen); } Modified: stable/12/lib/libsecureboot/verify_file.c ============================================================================== --- stable/12/lib/libsecureboot/verify_file.c Wed May 22 23:11:16 2019 (r348128) +++ stable/12/lib/libsecureboot/verify_file.c Wed May 22 23:19:20 2019 (r348129) @@ -340,6 +340,14 @@ verify_file(int fd, const char *filename, off_t off, i if (rc != VE_FINGERPRINT_WRONG && loaded_manifests) { if (severity <= VE_GUESS) severity = severity_guess(filename); +#ifdef VE_PCR_SUPPORT + /* + * Only update pcr with things that must verify + * these tend to be processed in a more deterministic + * order, which makes our pseudo pcr more useful. + */ + ve_pcr_updating_set((severity == VE_MUST)); +#endif if ((rc = verify_fd(fd, filename, off, &st)) >= 0) { if (verbose || severity > VE_WANT) { #if defined(VE_DEBUG_LEVEL) && VE_DEBUG_LEVEL > 0