Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1348858ybp; Thu, 17 Oct 2019 11:25:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxp5vQdQmv98zdsiTeevnCZshszbq27HZm3T9MVlp1kPXSfWv5gQtpdipUPPkouUyMNoccw X-Received: by 2002:a17:906:c2c1:: with SMTP id ch1mr4619259ejb.321.1571336734342; Thu, 17 Oct 2019 11:25:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571336734; cv=none; d=google.com; s=arc-20160816; b=bgxSAp7xICbf3JMtu0AJq/K6NsZeEaG5zFztIP+Gv1EEikBs7y8CZ+0JYwuNgIVe5m CRBdjhwpB5iFQ6gDvI5W8Fo0RgpyfHXluk0avkfHabSpW9ojFD4fICXU9exADPfmRFQp +JEYoc0I9pFUWrc4ogLUL3jL6Iu6WzOUPN/jzE9Vt+zDOhWf9hesWQPGm/u5bJKetPKy IxXjkvhtqO7l40+JdjqHnNTQqrOS06YiMUfCs1jnjOniJJCvLu53aNFC0gA39ccHK5kf QCe2EUNsrRnn/3t4WurNm6JoVcmx7UUA2CcBhbHDZBWEcF6nJ/TNwg0bp/ZdbvAuvRud OzjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=klBjvFp2hajX86vQ+wAyY1lis6dj5m3ANLYP6/6Q60k=; b=kZbpPgqSlnKtegfmQgP+dXSxn5f123rsd2zpQYpyLbbQlaNS9giPF7988FTHnz7Lfh iC2FnOhZrlB5hGq+ppKQsF1/pAmfb5xqktt/oYGuo+PhqG9DCXXp6i2p/mFeKQjp+r+1 bYFWW0fxD5x4WMUI2MpJDVx1568QXsBPYjNkdDOd2Iu1n+nESBL68PRsDLBRiGBPjsNr TU6tcgfBFRpkqFiOW+pVLc/Z43ZZYQjX8l+iHoJ97cPYyFEI0ElG680KD9D2THkRHwgK 1J2q/cqJN3BV46O8ubuquMcAPxyx5/uG8UIOXyjmX20Uh0XEDEwsfeZ9AFlq5J9QwU/L xUrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RYulFlea; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g15si2066874edm.349.2019.10.17.11.25.11; Thu, 17 Oct 2019 11:25:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RYulFlea; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404481AbfJPWEn (ORCPT + 99 others); Wed, 16 Oct 2019 18:04:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:53108 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438354AbfJPV7A (ORCPT ); Wed, 16 Oct 2019 17:59:00 -0400 Received: from localhost (unknown [192.55.54.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 979B2218DE; Wed, 16 Oct 2019 21:58:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571263139; bh=zDAyQj87Ix+mlCwGZuPzUCOe+91kc9aoAPI8vKo9zP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RYulFleah8emP24FFJPI2rc7LrYUVllvon1X7iISzg5qgb/wZDrd2ukTgiLzclxQS 6aEY5aVQ5VNDSG6AFz2hwRlza1mp3btWRDZNu/B+zX3ooo7AVDeY4lGIK1QKNxr5Oy 8izx7lw3dcmHPRS7VyBGsgrgAGyltNlHv/nJX9Ak= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lyude Paul , Peter Jones , Jarkko Sakkinen , Ard Biesheuvel , Matthew Garrett , Ben Dooks , Dave Young , Jerry Snitselaar , Linus Torvalds , Lukas Wunner , Octavian Purdila , Peter Zijlstra , Scott Talbert , Thomas Gleixner , linux-efi@vger.kernel.org, linux-integrity@vger.kernel.org, Ingo Molnar Subject: [PATCH 5.3 063/112] efi/tpm: Dont access event->count when it isnt mapped Date: Wed, 16 Oct 2019 14:50:55 -0700 Message-Id: <20191016214901.201583264@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214844.038848564@linuxfoundation.org> References: <20191016214844.038848564@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Jones commit 047d50aee341d940350897c85799e56ae57c3849 upstream. 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. Tested-by: Lyude Paul Signed-off-by: Peter Jones Signed-off-by: Jarkko Sakkinen Signed-off-by: Ard Biesheuvel Reviewed-by: Jarkko Sakkinen Acked-by: Matthew Garrett Acked-by: Ard Biesheuvel Cc: Ben Dooks Cc: Dave Young Cc: Jerry Snitselaar Cc: Linus Torvalds Cc: Lukas Wunner Cc: Octavian Purdila Cc: Peter Zijlstra Cc: Scott Talbert Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Cc: linux-integrity@vger.kernel.org Cc: stable@vger.kernel.org Fixes: 44038bc514a2 ("tpm: Abstract crypto agile event size calculations") Link: https://lkml.kernel.org/r/20191002165904.8819-4-ard.biesheuvel@linaro.org [ Minor edits. ] Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- include/linux/tpm_eventlog.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/include/linux/tpm_eventlog.h +++ b/include/linux/tpm_eventlog.h @@ -170,6 +170,7 @@ static inline int __calc_tpm2_event_size 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 } 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 = READ_ONCE(event->count); + event_type = READ_ONCE(event->event_type); 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 + 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);