From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: Peter Jones <pjones@redhat.com>
Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
Roberto Sassu <roberto.sassu@huawei.com>,
Matthew Garrett <mjg59@google.com>,
Bartosz Szczepanek <bsz@semihalf.com>,
Lyude Paul <lyude@redhat.com>,
linux-efi <linux-efi@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] efi+tpm: Don't access event->count when it isn't mapped.
Date: Sat, 31 Aug 2019 19:11:27 +0300 [thread overview]
Message-ID: <CAKv+Gu-JQMaFdfSAVzqskC143roHvw2OrMvuUMikYHoReNiDoA@mail.gmail.com> (raw)
In-Reply-To: <20190826153028.32639-1-pjones@redhat.com>
On Mon, 26 Aug 2019 at 18:30, Peter Jones <pjones@redhat.com> wrote:
>
> Some machines generate a lot of event log entries. When we're
> iterating over them, the code removes the old mapping and adds a
> new one, so once we cross the page boundary we're unmapping the page
> with the count on it. Hilarity ensues.
>
> This patch keeps the info from the header in local variables so we don't
> need to access that page again or keep track of if it's mapped.
>
> Signed-off-by: Peter Jones <pjones@redhat.com>
> Tested-by: Lyude Paul <lyude@redhat.com>
> ---
> include/linux/tpm_eventlog.h | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/tpm_eventlog.h b/include/linux/tpm_eventlog.h
> index 63238c84dc0..549dab0b56b 100644
> --- a/include/linux/tpm_eventlog.h
> +++ b/include/linux/tpm_eventlog.h
> @@ -170,6 +170,7 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
> u16 halg;
> int i;
> int j;
> + u32 count, event_type;
>
> marker = event;
> marker_start = marker;
> @@ -190,16 +191,22 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
> }
>
> event = (struct tcg_pcr_event2_head *)mapping;
> + /*
> + * the loop below will unmap these fields if the log is larger than
> + * one page, so save them here for reference.
> + */
> + count = event->count;
> + event_type = event->event_type;
>
These assignments should be using READ_ONCE(), since otherwise, the
compiler may reload these quantities from memory anyway.
With that fixed,
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> efispecid = (struct tcg_efi_specid_event_head *)event_header->event;
>
> /* Check if event is malformed. */
> - if (event->count > efispecid->num_algs) {
> + if (count > efispecid->num_algs) {
> size = 0;
> goto out;
> }
>
> - for (i = 0; i < event->count; i++) {
> + for (i = 0; i < count; i++) {
> halg_size = sizeof(event->digests[i].alg_id);
>
> /* Map the digest's algorithm identifier */
> @@ -256,8 +263,9 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
> + event_field->event_size;
> size = marker - marker_start;
>
> - if ((event->event_type == 0) && (event_field->event_size == 0))
> + if (event_type == 0 && event_field->event_size == 0)
> size = 0;
> +
> out:
> if (do_mapping)
> TPM_MEMUNMAP(mapping, mapping_size);
> --
> 2.23.0.rc2
>
prev parent reply other threads:[~2019-08-31 16:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-26 15:30 [PATCH 1/2] efi+tpm: Don't access event->count when it isn't mapped Peter Jones
2019-08-26 15:30 ` [PATCH 2/2] efi+tpm: don't traverse an event log with no events Peter Jones
2019-08-26 16:30 ` Jarkko Sakkinen
2019-08-26 17:45 ` Matthew Garrett
2019-08-31 16:46 ` Ard Biesheuvel
2019-08-26 16:28 ` [PATCH 1/2] efi+tpm: Don't access event->count when it isn't mapped Jarkko Sakkinen
2019-08-26 17:44 ` Matthew Garrett
2019-08-27 11:03 ` Jarkko Sakkinen
2019-08-27 13:41 ` Jarkko Sakkinen
2019-08-27 16:00 ` Matthew Garrett
2019-08-27 22:11 ` Peter Jones
2019-08-29 13:21 ` Jarkko Sakkinen
2019-08-31 16:11 ` Ard Biesheuvel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAKv+Gu-JQMaFdfSAVzqskC143roHvw2OrMvuUMikYHoReNiDoA@mail.gmail.com \
--to=ard.biesheuvel@linaro.org \
--cc=bsz@semihalf.com \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lyude@redhat.com \
--cc=mjg59@google.com \
--cc=pjones@redhat.com \
--cc=roberto.sassu@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).