From patchwork Tue Sep 14 06:22:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruchika Gupta X-Patchwork-Id: 510916 Delivered-To: patches@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1254794jao; Mon, 13 Sep 2021 23:22:30 -0700 (PDT) X-Received: by 2002:a17:90b:3b8b:: with SMTP id pc11mr233609pjb.153.1631600550450; Mon, 13 Sep 2021 23:22:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631600550; cv=none; d=google.com; s=arc-20160816; b=EeSR+uxNeJb9yHw/OAmjRnU//DkMZ69r3o9UKPdXH93771rOGvwpyKdeSuCYkWzdDb 0sPmeFXbslB86YghF9DR63VHnyRl3rHSkCK9OPIJD5+qJwr4NcXYdZe/X2emvxGGR3fm rqVKiZ4HanO4Oi7Te/ag1dHkPFJPTBrOBnoNApW7ECM0fuQq4rEaLwENUCR5SMa2QLm+ +uSYHav+kfu8d+ZY4tHLMthVSp4+YbKf1s/SBkztmnPLCBUps+yR+Z+0PgLw3gRlpn9R lqVLlvQbKe52Uas4TRP8AUqoiGddmv6TZMUr/pR3CJEAnjufV0hS7Fbq/UlZaLOKJP/J cD2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=Ut2ILv/S6tIB5jpAztbKbSHCBdbODrInZKknMfSBPa4=; b=O1T0HnhMdxuHBUXxoHPUmZP68BI2EtK5LDS2wfvybnDl26VejGJ6MjarslKPD98LBp iqbdmnaGlKKxrOKafb0lBwBSW2ZCU7eKwdr5P6pm1c6VlegBbT8eWsdXTbaQPgwWCwKL /hh1fvTQd4mB98i74mqPVPdPFumjyQX6NCb+j3x6IPK1HWowMy3SXavOkQEPpLfNOzjK xx1kCVu+vKyxqL6RCbHNynJI7hbth9XzHmOzaYgF3mA9/+oVaVSv63D6nrElwHZhk0Z2 wQUBx2tjVGAAkNkxV0aFfLD5UsvQVBdz4+gYmczbyAaai5YVJ1DuAAxBqXKIZBDyPqUq Kfjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lqpUgW2a; spf=pass (google.com: domain of ruchika.gupta@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ruchika.gupta@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 21sor98104pjh.19.2021.09.13.23.22.30 for (Google Transport Security); Mon, 13 Sep 2021 23:22:30 -0700 (PDT) Received-SPF: pass (google.com: domain of ruchika.gupta@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lqpUgW2a; spf=pass (google.com: domain of ruchika.gupta@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ruchika.gupta@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ut2ILv/S6tIB5jpAztbKbSHCBdbODrInZKknMfSBPa4=; b=lqpUgW2aMPe+ETjSwwV1I6kJMYVCehqkhtpsIXPNj0GV9beeJuoY2AgcrTpqDHsDVo /FVZ6ZruwPIihy7yAxzoH8uy+0rNKP64XuFOtJiESbz9Rsq0B30m/3BdkfwLmc4qexxv wOdt6PMHbkO42q2/91K3Q6ivyjeJUusK6rq7uZl6TmHeEZ5feTasVjSJeBJnL71JpLUn 06RclGGNOhJCozw4/Ohd+5eTNrBfm+NS+tRN3xgMOJgRjlAwkdEu+uKxoPe0EdutlvHc OtD5OSuoLXT4I9ukfKVgJgibM2mAjSNsVfN/DqccAH+ifJlJKU9m4tPHBP7cjCHqEEsA dkfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ut2ILv/S6tIB5jpAztbKbSHCBdbODrInZKknMfSBPa4=; b=E06eogCku3aKOfD6ylp8/QcdnNLyPuSHDvBNbudZhfx7TJYguT1H+lWMY+LtAEuD1M eZZmkDH9RRLAtxjQdjInCHU7Tdh/79O0OSVMiO7mlNI/ifKXRQNh10nAPn8XPyemvUtK ux3xsAkpCDoCcFa5MBObzkjJgVBppzeE0axniSVObQj+MNGh4E9nTzIHrWppIc15kqck 4QC0EuMHuAkuM9Zq+ubEXOjTWz3lmOb+BaydGEoAflZAqpmLiOH5cgZ4HlxiQnmI9xkJ yl+rCXVnw14Byjv65tIrmDv3qrOHOd1dmvfNZ8A7Qp3ZCkVZIAeZks8bz8MqNkFZrJxg BXbQ== X-Gm-Message-State: AOAM531P7hDnTcFZ9FP1bqIzrTIuGtCtkQ0G1zQ2L33vVHF+uAFkeS3E m88UODF1N/gCqBa+sNOmqofRrT1u9rKITS7ybf0= X-Google-Smtp-Source: ABdhPJwmrRu6XQNwOacapo1q6kUGJFeZRX3ew24/ra3B+5K1KyqRjqiis27tILw0vqYZeGFhlriifg== X-Received: by 2002:a17:90a:7aca:: with SMTP id b10mr288716pjl.2.1631600549969; Mon, 13 Sep 2021 23:22:29 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([106.215.93.139]) by smtp.gmail.com with ESMTPSA id y26sm8874020pfe.69.2021.09.13.23.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Sep 2021 23:22:29 -0700 (PDT) From: Ruchika Gupta To: ruchika.gupta@linaro.org Cc: patches@linaro.org Subject: [PATCH] efi_loader: Fix spec ID event creation Date: Tue, 14 Sep 2021 11:52:22 +0530 Message-Id: <20210914062222.885321-1-ruchika.gupta@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 numberOfAlgorithms field in spec ID event should be dependent on the number of active algorithms supported by the TPM device, not all the algorithms. Signed-off-by: Ruchika Gupta --- include/efi_tcg2.h | 7 +------ lib/efi_loader/efi_tcg2.c | 39 ++++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 23 deletions(-) -- 2.25.1 diff --git a/include/efi_tcg2.h b/include/efi_tcg2.h index c99384fb00..6c9f448a26 100644 --- a/include/efi_tcg2.h +++ b/include/efi_tcg2.h @@ -165,8 +165,6 @@ struct tcg_efi_spec_id_event_algorithm_size { * @digest_sizes: array of number_of_algorithms pairs * 1st member defines the algorithm id * 2nd member defines the algorithm size - * @vendor_info_size: size in bytes for vendor specific info - * @vendor_info: vendor specific info */ struct tcg_efi_spec_id_event { u8 signature[16]; @@ -176,10 +174,7 @@ struct tcg_efi_spec_id_event { u8 spec_errata; u8 uintn_size; u32 number_of_algorithms; - struct tcg_efi_spec_id_event_algorithm_size digest_sizes[TPM2_NUM_PCR_BANKS]; - u8 vendor_info_size; - /* U-Boot does not provide any vendor info */ - u8 vendor_info[]; + struct tcg_efi_spec_id_event_algorithm_size digest_sizes[]; } __packed; /** diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index b268a02976..749c3e6143 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -575,9 +575,10 @@ static efi_status_t tcg2_create_digest(const u8 *input, u32 length, EFI_PRINT("Unsupported algorithm %x\n", hash_alg); return EFI_INVALID_PARAMETER; } + digest_list->digests[digest_list->count].hash_alg = hash_alg; + memcpy(&digest_list->digests[digest_list->count].digest, final, + (u32)alg_to_len(hash_alg)); digest_list->count++; - digest_list->digests[i].hash_alg = hash_alg; - memcpy(&digest_list->digests[i].digest, final, (u32)alg_to_len(hash_alg)); } return EFI_SUCCESS; @@ -798,8 +799,9 @@ static efi_status_t tcg2_hash_pe_image(void *efi, u64 efi_size, EFI_PRINT("Unsupported algorithm %x\n", hash_alg); return EFI_INVALID_PARAMETER; } - digest_list->digests[i].hash_alg = hash_alg; - memcpy(&digest_list->digests[i].digest, hash, (u32)alg_to_len(hash_alg)); + digest_list->digests[digest_list->count].hash_alg = hash_alg; + memcpy(&digest_list->digests[digest_list->count].digest, hash, + (u32)alg_to_len(hash_alg)); digest_list->count++; } @@ -1123,7 +1125,7 @@ static efi_status_t create_specid_event(struct udevice *dev, void *buffer, struct tcg_efi_spec_id_event *spec_event; size_t spec_event_size; efi_status_t ret = EFI_DEVICE_ERROR; - u32 active = 0, supported = 0; + u32 active = 0, supported = 0, pcr_count = 0, alg_count = 0; int err; size_t i; @@ -1145,25 +1147,29 @@ static efi_status_t create_specid_event(struct udevice *dev, void *buffer, TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_ERRATA_TPM2; spec_event->uintn_size = sizeof(efi_uintn_t) / sizeof(u32); - err = tpm2_get_pcr_info(dev, &supported, &active, - &spec_event->number_of_algorithms); + err = tpm2_get_pcr_info(dev, &supported, &active, &pcr_count); + if (err) goto out; - if (spec_event->number_of_algorithms > MAX_HASH_COUNT || - spec_event->number_of_algorithms < 1) - goto out; - for (i = 0; i < spec_event->number_of_algorithms; i++) { + for (i = 0; i < pcr_count; i++) { u16 hash_alg = hash_algo_list[i].hash_alg; u16 hash_len = hash_algo_list[i].hash_len; - if (active && alg_to_mask(hash_alg)) { + if (active & alg_to_mask(hash_alg)) { put_unaligned_le16(hash_alg, - &spec_event->digest_sizes[i].algorithm_id); + &spec_event->digest_sizes[alg_count].algorithm_id); put_unaligned_le16(hash_len, - &spec_event->digest_sizes[i].digest_size); + &spec_event->digest_sizes[alg_count].digest_size); + alg_count++; } } + + spec_event->number_of_algorithms = alg_count; + if (spec_event->number_of_algorithms > MAX_HASH_COUNT || + spec_event->number_of_algorithms < 1) + goto out; + /* * the size of the spec event and placement of vendor_info_size * depends on supported algoriths @@ -1172,9 +1178,8 @@ static efi_status_t create_specid_event(struct udevice *dev, void *buffer, offsetof(struct tcg_efi_spec_id_event, digest_sizes) + spec_event->number_of_algorithms * sizeof(spec_event->digest_sizes[0]); /* no vendor info for us */ - memset(buffer + spec_event_size, 0, - sizeof(spec_event->vendor_info_size)); - spec_event_size += sizeof(spec_event->vendor_info_size); + memset(buffer + spec_event_size, 0, 1); + spec_event_size += 1; *event_size = spec_event_size; return EFI_SUCCESS;