From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D8C6156967 for ; Mon, 29 Jan 2024 16:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706547485; cv=none; b=uog8d7z9tzPqpBQHUVxDu/HmqG4ncIge2VfU473Z5IKsOEkAmv1omTPt3uQ67Ujsz3QLakPTNXPCjeezpEsbdzDL/Ro7YjnQRaBHdjfn1auGgiMFpjyzt9qOGOMzd4U/cuUZqHcAXatUnfnJtlCzmyVkMAy73H0++CnOylI/m1o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706547485; c=relaxed/simple; bh=H7yE0TLn19iCiWHo/FkB1Rzc6lLBWxGxr0DrrmYLh3M=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=cY8lLoWuU6+LuH9tTSzMv213t8xdw2BvkZdgmAdKB1j8HUJ+N1VobeDjU3OFZuAeTjhSkUECNHbZ8g3nAi9UuYFbEEL0C7QGxXw1jc7p0u8gufCmsWH3mjCDbxmI+NDmbQOiARRIsjLRNLTwP7qskMDCjcb+P8QTKIaZCfwopNI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KyY5ql3K; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KyY5ql3K" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-55eda7c5bffso12527a12.1 for ; Mon, 29 Jan 2024 08:58:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706547481; x=1707152281; darn=lists.linux.dev; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=P/syXXY1Bnocb0Cr84guiLCcezGMcnPfVVnMLYh6D2Q=; b=KyY5ql3KFjqr88qbDgz2JWiY8uzTt8sgwKNAIxX+4Dsy42s89idTx2j3BDwzZSwQTB XPSl/MmcoJqWsH+Yip9Cvn1PeroIcSaaHlp8uk15K2mJDUsffikrbXL3jd5tQufTCJyH uWQWLA4OjVNDY25QCnAVQxzV2KLoeSBf6Iasuv9d529KhWZQSTqTdmmmRhM34bnCHXMF aku/0o6Qf7A3e8gP8HajAkaf94yOWqXA6XiNWgodaMnQaf5N+EXQ/ZPUOf5VjqZr46O4 DfchXN1gerDfdk5bdo9hMEymt3/Om+QKaId968nL8Xnib4RxZGlGAenMVrcWFi6ScShT zLgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706547481; x=1707152281; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P/syXXY1Bnocb0Cr84guiLCcezGMcnPfVVnMLYh6D2Q=; b=eMxkpG8FtNy4euRJcNZMOhWWrsT4gUaaTqaHKvo2pKL0qNG527qcdShcmO0xvt2YlF tif+WTxQQDsvmlAquM/WscggQEG3J3/j96r6wIGiBgy54vQ/AcmxmehzqifN4MthRTWa eRf9NqGSuJ4mND8DS/xKUBWB5dpB6Jy0IYVGlC3dDvToFx1pY6fGvITa0RIg7U0D+wAQ 5pHaH/ZuO/M/t/Zp8umyH9e39YtHw/d6bYPb7oQJ6yd3GrVSYv1nSAtiRacpMcipPXeK O4TBH8nqUaW3pY+bsxI5EUcgXbakITJkG6wA/2u7LF2uGv2cHCd10gMV+VC+RqhbkHot dL4g== X-Gm-Message-State: AOJu0YxD9qhXVuNrJk35iDsaXvK2e9t/yJpUhh+6Y6jFQ3cF80iZN2Av LSyK8KI2YzUKbApG+EdmZRxC5Oj5DodNjUDs6n0LxdwzBFthPRRUuYIAsDnYokyhkW8eTVUMXZ1 xrbQEo6rR6psFYPL1tBxyt7c5rtXPIpqhnNlD X-Google-Smtp-Source: AGHT+IFwTYFTgvHTNZp2/70im1mOgO6bOgpZmgF7iH0m3dzPzmHnHcy1zYSsfZIjKRWt8jUXXH2+uz7tsRTLyh1ayNQ= X-Received: by 2002:a05:6402:3115:b0:55f:1351:ee28 with SMTP id dc21-20020a056402311500b0055f1351ee28mr147467edb.6.1706547481247; Mon, 29 Jan 2024 08:58:01 -0800 (PST) Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240128212532.2754325-1-sameo@rivosinc.com> <20240128212532.2754325-2-sameo@rivosinc.com> In-Reply-To: <20240128212532.2754325-2-sameo@rivosinc.com> From: Dionna Amalie Glaze Date: Mon, 29 Jan 2024 08:57:49 -0800 Message-ID: Subject: Re: [RFC PATCH v2 1/4] tsm: Runtime measurement register support To: Samuel Ortiz Cc: Dan Williams , Kuppuswamy Sathyanarayanan , Qinkun Bao , "Yao, Jiewen" , "Xing, Cedric" , biao.lu@intel.com, linux-coco@lists.linux.dev, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable The rtmr backend doesn't specify the digest size it expects to user space, so rtmr_extend could be zero-fill, or provide a truncated update, or be strict and return an error. Should the expected digest size for writes not also be a RO attribute? On Sun, Jan 28, 2024 at 1:27=E2=80=AFPM Samuel Ortiz w= rote: > > Some confidential computing architecture (Intel TDX, ARM-CCA, RISC-V > CoVE) provide the TVM (confidential computing guest) with a set of > runtime measurement registers (RTMR). TVMs can extend those registers > with their measurements at runtime, i.e. after the TVM initial > measurements are finalized and the TVM actually runs. > > RTMRs are separated from the initial measurement registers set, and TSMs > typically includes RTMR values into a distinct section of their signed > attestion reports. > > We add support for extending and reading a TSM runtime measurement > registers by extending the TSM ops structure with resp. an rtmr_extend() > and an rtmr_read() function pointers. TSM providers/backends will > implement those ops if they are capable of exposing RTMRs to their > TVMs. This capability is now described by a tsm_capabilites structure, > passed by the TSM provider to the TSM framework at registration time. > > TVMs can configure, extend and read RTMRs from the configfs-tsm interface= . > > Signed-off-by: Samuel Ortiz > --- > drivers/virt/coco/tsm.c | 80 +++++++++++++++++++++++++++++++++++++++++ > include/linux/tsm.h | 39 +++++++++++++++++++- > 2 files changed, 118 insertions(+), 1 deletion(-) > > diff --git a/drivers/virt/coco/tsm.c b/drivers/virt/coco/tsm.c > index d1c2db83a8ca..1a8c3c096120 100644 > --- a/drivers/virt/coco/tsm.c > +++ b/drivers/virt/coco/tsm.c > @@ -11,6 +11,7 @@ > #include > #include > #include > +#include > > static struct tsm_provider { > const struct tsm_ops *ops; > @@ -50,6 +51,85 @@ enum tsm_data_select { > TSM_CERTS, > }; > > +/** > + * DOC: Trusted Security Module (TSM) Runtime Measurement Register (RTMR= ) Interface > + * > + * The TSM RTMR interface is a common ABI for allowing TVMs to extend > + * and read measurement registers at runtime, i.e. after the TVM initial > + * measurement is finalized. TSMs that support such capability will typi= cally > + * include all runtime measurement registers values into their signed > + * attestation report, providing the TVM post-boot measurements to e.g. = remote > + * attestation services. > + * > + * A TVM uses the TSM RTMR configfs ABI to create all runtime measuremen= t > + * registers (RTMR) that it needs. Each created RTMR must be configured = first > + * before being readable and extensible. TVM configures an RTMR by setti= ng its > + * index and optionally by mapping it to one or more TCG PCR indexes. > + * > + * A TSM backend statically declares the number of RTMRs it supports and= which > + * hash algorithm must be used when extending them. This declaration is = done > + * through the tsm_capabilities structure, at TSM registration time (see > + * tsm_register()). > + */ > + > +/** > + * struct tsm_rtmr_state - tracks the state of a TSM RTMR. > + * @index: The RTMR hardware index. > + * @alg: The hash algorithm used for this RTMR. > + * @digest: The RTMR cached digest value. > + * @cached_digest: Is the RTMR cached digest valid or not. > + * @cfg: The configfs item for this RTMR. > + */ > +struct tsm_rtmr_state { > + u32 index; > + enum hash_algo alg; > + u8 digest[TSM_DIGEST_MAX]; > + bool cached_digest; > + struct config_item cfg; > +}; > + > +static bool is_rtmr_configured(struct tsm_rtmr_state *rtmr_state) > +{ > + return rtmr_state->index !=3D U32_MAX; > +} > + > +/** > + * struct tsm_rtmrs_state - tracks the state of all RTMRs for a TSM. > + * @rtmrs: The array of all created RTMRs. > + * @tcg_map: A mapping between TCG PCR and RTMRs, indexed by PCR indexes= . > + * Entry `i` on this map points to an RTMR that covers TCG PCR[i] for th= e TSM > + * hash algorithm. > + * @group: The configfs group for a TSM RTMRs. > + */ > +static struct tsm_rtmrs_state { > + struct tsm_rtmr_state **rtmrs; > + const struct tsm_rtmr_state *tcg_map[TPM2_PLATFORM_PCR]; > + struct config_group *group; > +} *tsm_rtmrs; > + > +static int tsm_rtmr_read(struct tsm_provider *tsm, u32 idx, > + u8 *digest, size_t digest_size) > +{ > + if (tsm->ops && tsm->ops->rtmr_read) > + return tsm->ops->rtmr_read(idx, digest, digest_size); > + > + return -ENXIO; > +} > + > +static int tsm_rtmr_extend(struct tsm_provider *tsm, u32 idx, > + const u8 *digest, size_t digest_size) > +{ > + if (tsm->ops && tsm->ops->rtmr_extend) > + return tsm->ops->rtmr_extend(idx, digest, digest_size); > + > + return -ENXIO; > +} > + > +static struct tsm_rtmr_state *to_tsm_rtmr_state(struct config_item *cfg) > +{ > + return container_of(cfg, struct tsm_rtmr_state, cfg); > +} > + > static struct tsm_report *to_tsm_report(struct config_item *cfg) > { > struct tsm_report_state *state =3D > diff --git a/include/linux/tsm.h b/include/linux/tsm.h > index de8324a2223c..a546983c24fc 100644 > --- a/include/linux/tsm.h > +++ b/include/linux/tsm.h > @@ -2,11 +2,13 @@ > #ifndef __TSM_H > #define __TSM_H > > +#include > #include > #include > > #define TSM_INBLOB_MAX 64 > #define TSM_OUTBLOB_MAX SZ_32K > +#define TSM_DIGEST_MAX SHA512_DIGEST_SIZE > > /* > * Privilege level is a nested permission concept to allow confidential > @@ -42,12 +44,44 @@ struct tsm_report { > u8 *auxblob; > }; > > +#define TSM_MAX_RTMR 32 > + > +/** > + * struct tsm_rtmr_desc - Describes a TSM Runtime Measurement Register (= RTMR). > + * @hash_alg: The hash algorithm used to extend this runtime measurement > + * register. > + * @tcg_pcr_mask: A bit mask of all TCG PCRs mapped to this RTMR. > + */ > +struct tsm_rtmr_desc { > + enum hash_algo hash_alg; > + unsigned long tcg_pcr_mask; > +}; > + > +/** > + * struct tsm_capabilities - Describes a TSM capabilities. > + * @num_rtmrs: The number of Runtime Measurement Registers (RTMR) availa= ble from > + * a TSM. > + * @rtmr_hash_alg: The hash algorithm used to extend a runtime measureme= nt > + * register. > + */ > +struct tsm_capabilities { > + size_t num_rtmrs; > + const struct tsm_rtmr_desc *rtmrs; > +}; > + > /** > * struct tsm_ops - attributes and operations for tsm instances > * @name: tsm id reflected in /sys/kernel/config/tsm/report/$report/prov= ider > * @privlevel_floor: convey base privlevel for nested scenarios > + * @capabilities: Describe the TSM capabilities, e.g. the number of avai= lable > + * runtime measurement registers (see `struct tsm_capabil= ities`). > * @report_new: Populate @report with the report blob and auxblob > - * (optional), return 0 on successful population, or -errno otherwise > + * (optional), return 0 on successful population, or -errno > + * otherwise > + * @rtmr_extend: Extend an RTMR with the provided digest. > + * Return 0 on successful extension, or -errno otherwise. > + * @rtmr_read: Reads the value of an RTMR. > + * Return the number of bytes read or -errno for errors. > * > * Implementation specific ops, only one is expected to be registered at > * a time i.e. only one of "sev-guest", "tdx-guest", etc. > @@ -55,7 +89,10 @@ struct tsm_report { > struct tsm_ops { > const char *name; > const unsigned int privlevel_floor; > + const struct tsm_capabilities capabilities; > int (*report_new)(struct tsm_report *report, void *data); > + int (*rtmr_extend)(u32 idx, const u8 *digest, size_t digest_size)= ; > + ssize_t (*rtmr_read)(u32 idx, u8 *digest, size_t digest_size); > }; > > extern const struct config_item_type tsm_report_default_type; > -- > 2.42.0 > --=20 -Dionna Glaze, PhD (she/her)