From nobody Fri Nov 29 21:36:04 2024 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (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 AFA24156F42 for ; Fri, 13 Sep 2024 23:20:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726269645; cv=none; b=kJzGbbI6inkYMtiGYeL1DORGR+fKCStuDU2xHV3h8IetP1K/2+DUoy+fJZ2JLEKxBgyXgQi5J7oQ+aW2AFEekHvb2oL6Bj/hti/HSwMRdNVTS2BrBiqFvbkzxSi+j5iIYGnKuCAgTWkyytpIv9jzGqI6eFmZrZ7jI9KPPmkFiaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726269645; c=relaxed/simple; bh=uC7TJ50a7SgbOtivAxR2KdbHsbIyQdSdr5oMF9F4ufo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PWWRuxOYKu477rNsauaYr7xxk8zTbssD9BYeayB7v2pPYSya4uhAqekyNu+h8ZCaZMUC63Ikc4hWXK4Rla92MXWBo8u4cvMU/+BZo1SIHzYqpjVPh5RQodx+bNRBV8Qxq+DLeS2yU0XfhSZ+2+JS2kPXnsxonWcwkchz59OT9oE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=GZvzxVyY; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="GZvzxVyY" Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-45812fdcd0aso33505501cf.0 for ; Fri, 13 Sep 2024 16:20:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1726269642; x=1726874442; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R1Rs9Vcw1DZn6LrVte9jSPxFRjikUDDX06xvoSnqYrw=; b=GZvzxVyYJXhxL5uhKbC4ps8nFJjYktP+SieYEpMXdAGofqEfy2y7pPRlXWnbu7lFbJ xZ7QRWQNe/RMeYES2A9XjgNUWmkjv7KiBFLp0qtXxEnfIcRNAV3jek5iSxIYLxdfK7YK hn40XYogjjCMch9KFraj/wJwYvwszGT9vFOSV8rZaGDrvo/1yzX3pdFJq7SwhntR5Xzh MmLGJshLfNi8vMfQcn+n3bL6wkI4i9WlHNrGyq59y843OPXdhXWlAMUr43L8spiwh6cI LI6ltVCT0uvBGXswcTU4KEcRUZPz5ZEN06iQeZXSgYoGrRPWmEAiXswsSKbBiG1Y2Hi/ F+SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726269642; x=1726874442; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R1Rs9Vcw1DZn6LrVte9jSPxFRjikUDDX06xvoSnqYrw=; b=suMANMY+PhA0FWl6opC0iUxdhZp1Bvti0BAXBR1k6v5YooPRQyjSCJ1vLgi5vKr5ay FY/B3zU7alY4ibH2la90hXzuNba77M9+4tPxnLO4m828NRu48iwyTZQkp3nuX25R3pmA IG7B5zBZOxfk3XQA4XVW/vnSwMYCSDU9EyXSl7434+uWaDyDReor44w2aQi3bIefCWCU m09t8N6+biVj9DNLRrgVOsboo4F2rjx0D2RVp0BHpTr9F6m+y9OiFFmvRKy9g+8IWbMb vSlZtrE9Pb48S6Ljb5EMqqx/VQh70k+qme8tiLTv7q/N7PXT7RvJAWKXyObA+TbxZfwe Lxlg== X-Gm-Message-State: AOJu0YxW9iaFfVxArV1cVD6aeJJ9KkN6X2UIchdfYNcTXB/PlNs+XkWz Y0IcUOFeBbq/d2d7jHS/uDE2zvvgDczelIhBLF3/rz1AgptuwtnA6uBsxjrhIG0= X-Google-Smtp-Source: AGHT+IFp0i6BEsm6qcRfgkhhKwCvAWwpyUz8Me8bMXheogGSHuS5iPPX0ul01QpecBqdsilzODu7fQ== X-Received: by 2002:a05:622a:418c:b0:44f:f271:af63 with SMTP id d75a77b69052e-4583c7adbcamr268220821cf.21.1726269642488; Fri, 13 Sep 2024 16:20:42 -0700 (PDT) Received: from PC2K9PVX.TheFacebook.com (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-459aac7fb7bsm1245801cf.21.2024.09.13.16.20.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 16:20:42 -0700 (PDT) From: Gregory Price To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, ardb@kernel.org, leitao@debian.org, usamaarif642@gmail.com, sathyanarayanan.kuppuswamy@linux.intel.com, ilias.apalodimas@linaro.org Subject: [PATCH v2 1/4] tpm: fix signed/unsigned bug when checking event logs Date: Fri, 13 Sep 2024 19:19:51 -0400 Message-ID: <20240913231954.20081-2-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240913231954.20081-1-gourry@gourry.net> References: <20240913231954.20081-1-gourry@gourry.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A prior bugfix that fixes a signed/unsigned error causes another signed unsigned error. A situation where log_tbl->size is invalid can cause the size passed to memblock_reserve to become negative. log_size from the main event log is an unsigned int, and the code reduces to the following u64 value =3D (int)unsigned_value; This results in sign extension, and the value sent to memblock_reserve becomes effectively negative. Fixes: be59d57f9806 ("efi/tpm: Fix sanity check of unsigned tbl_size being = less than zero") Signed-off-by: Gregory Price Reviewed-by: Ilias Apalodimas --- drivers/firmware/efi/tpm.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c index e8d69bd548f3..9c3613e6af15 100644 --- a/drivers/firmware/efi/tpm.c +++ b/drivers/firmware/efi/tpm.c @@ -40,7 +40,8 @@ int __init efi_tpm_eventlog_init(void) { struct linux_efi_tpm_eventlog *log_tbl; struct efi_tcg2_final_events_table *final_tbl; - int tbl_size; + unsigned int tbl_size; + int final_tbl_size; int ret =3D 0; =20 if (efi.tpm_log =3D=3D EFI_INVALID_TABLE_ADDR) { @@ -80,26 +81,26 @@ int __init efi_tpm_eventlog_init(void) goto out; } =20 - tbl_size =3D 0; + final_tbl_size =3D 0; if (final_tbl->nr_events !=3D 0) { void *events =3D (void *)efi.tpm_final_log + sizeof(final_tbl->version) + sizeof(final_tbl->nr_events); =20 - tbl_size =3D tpm2_calc_event_log_size(events, - final_tbl->nr_events, - log_tbl->log); + final_tbl_size =3D tpm2_calc_event_log_size(events, + final_tbl->nr_events, + log_tbl->log); } =20 - if (tbl_size < 0) { + if (final_tbl_size < 0) { pr_err(FW_BUG "Failed to parse event in TPM Final Events Log\n"); ret =3D -EINVAL; goto out_calc; } =20 memblock_reserve(efi.tpm_final_log, - tbl_size + sizeof(*final_tbl)); - efi_tpm_final_log_size =3D tbl_size; + final_tbl_size + sizeof(*final_tbl)); + efi_tpm_final_log_size =3D final_tbl_size; =20 out_calc: early_memunmap(final_tbl, sizeof(*final_tbl)); --=20 2.43.0 From nobody Fri Nov 29 21:36:04 2024 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (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 003B2183CCC for ; Fri, 13 Sep 2024 23:20:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726269646; cv=none; b=ZkwgVQSyHLH7CbdY/vnzfpp0f+/4vbXVlqx/PscPt/s/Z1Wet/ThzS++xVigDGyylY10qi7h005ISuycJPZ/nN3cBn7om65YlKkFO2O1rtiIKTPcZkcOBmPUrBEwULimZe8xIIxKNWMq2ynVO6uIcjX1EhM2+wAJ/ZkctrZCF3w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726269646; c=relaxed/simple; bh=wpENg5K7Akr//dxuFB0ettmRrYVh6xPRVyKwVZ5+LdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uLWM6b4KH0HV5qQMqZE0d+VATq8wdz0s3z8miWqnadqNkK5qIxC1ZGGcXwh4US/lzGzl1EzwwD64JRNh7NRV/TJO7feH+lf1HBw9oQn9HkA/4Tafxb2wZglom5xw7uAYEEBdtZdIq7t95KHyZGAWXmu07eFqQ3lW/mxnjHxgRT0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=orcj1T0v; arc=none smtp.client-ip=209.85.160.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="orcj1T0v" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-45832b2784bso21699001cf.3 for ; Fri, 13 Sep 2024 16:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1726269644; x=1726874444; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mK/BpjWFhfY+uS5/8x0nkKgbHvfXWYi9NIxTZR2LU/o=; b=orcj1T0vmMbUesoQIcl2Od9wP3R3KjRLueA0eSxs9CO4ysG8kYwDMQ68XUc5rv9uKq HoAFaJGoYH1ZxhVJ7dJ3heo4doLDIwn+Cjklxemasaa+rEH/ReO5+llq8EOX66yDYMiE Rx6VUtnqGvn84MJBRhXxelBdgaFOJ5kRFfiYuALPQDzVNIRCBJ2XeJ+unn2NzSb+9jRW ndbEO/A0pFYVyVUUVvDcCCkTjiYKxjLMVolX5N397NgakHQB1PlkDHxoQPaZd6tevix1 hO6+gH79RNPpB/rJqS8du0WQFDufJgWapzqJehPVEkeY2j18KcUWP9mw12NgRZ7sbT1h UfYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726269644; x=1726874444; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mK/BpjWFhfY+uS5/8x0nkKgbHvfXWYi9NIxTZR2LU/o=; b=QzMtWl8lIOnORGgcCaDb5MJmnTRS4AiB87kG5x9PEKbiY9MVN+P1TA0VOdt2sjkIcG J4uNonx2OaRWII3aK4OUI3QX2xPMW/Ywpjc9uBSHYKcqLwdKqaPFcm3Gv+aRMo5e5KWU DEpqQtJhPS7GnGOT3Ncq5T9+9/ph/eBPG8XPg8aWIebOUk4bRFi6SO3zd7cXx6SP8uSr eRhx5P0LSeDnsry7qdXJYfLivP549V/VLwMOYK2nkSVxePl/413F6ovTErc2tgEZRCjm xU776cgj9XbMOuv/ZxGl6C0qc3ge24kWGcytTMKmg8L5gnzFfPEJrSAk1+CxiZ4GWX6C 8EQg== X-Gm-Message-State: AOJu0YxatuIaofh+wyflt12oATf+bcqPSAEF0bSQZ5A9jCS6AkykV8Kt eAktgoFRZgNChLbMmueYG0+PVNguvicRr6+2s+Lw8W5YKt8H90GNNQTUnFOKKmg= X-Google-Smtp-Source: AGHT+IHU5jGSje/03tzXLhSjKsNALxLWzuMQn7LkdG77pbKLrDkPmNHZPN14O+1c5KiHQTAmeDwWnQ== X-Received: by 2002:ac8:5fc2:0:b0:456:802c:a67f with SMTP id d75a77b69052e-458602a9264mr127611441cf.3.1726269643753; Fri, 13 Sep 2024 16:20:43 -0700 (PDT) Received: from PC2K9PVX.TheFacebook.com (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-459aac7fb7bsm1245801cf.21.2024.09.13.16.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 16:20:43 -0700 (PDT) From: Gregory Price To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, ardb@kernel.org, leitao@debian.org, usamaarif642@gmail.com, sathyanarayanan.kuppuswamy@linux.intel.com, ilias.apalodimas@linaro.org Subject: [PATCH v2 2/4] tpm: do not ignore memblock_reserve return value Date: Fri, 13 Sep 2024 19:19:52 -0400 Message-ID: <20240913231954.20081-3-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240913231954.20081-1-gourry@gourry.net> References: <20240913231954.20081-1-gourry@gourry.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" tpm code currently ignores a relevant failure case silently. Add an error to make this failure non-silent. Signed-off-by: Gregory Price --- drivers/firmware/efi/tpm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c index 9c3613e6af15..b0cc2cc11d7e 100644 --- a/drivers/firmware/efi/tpm.c +++ b/drivers/firmware/efi/tpm.c @@ -61,7 +61,12 @@ int __init efi_tpm_eventlog_init(void) } =20 tbl_size =3D sizeof(*log_tbl) + log_tbl->size; - memblock_reserve(efi.tpm_log, tbl_size); + if (memblock_reserve(efi.tpm_log, tbl_size)) { + pr_err("TPM Event Log memblock reserve fails (0x%lx, 0x%x)\n", + efi.tpm_log, tbl_size); + ret =3D -ENOMEM; + goto out; + } =20 if (efi.tpm_final_log =3D=3D EFI_INVALID_TABLE_ADDR) { pr_info("TPM Final Events table not present\n"); --=20 2.43.0 From nobody Fri Nov 29 21:36:04 2024 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (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 2DB7C185B47 for ; Fri, 13 Sep 2024 23:20:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726269648; cv=none; b=qOyhXeC5ynFhcGrmkP5M+eWXK0cLFrsCYK62SGb0NNGdOqIHtFPJ12obsYUPPPCAQGc35oY8QBvWpWge0StGhOfH4AsIj1h+JP4CYz3wd0gd1G6Q+g0SjaPyDfaWNBI+jV1YyjEsVCz65IOjnmD6mhrkJKKbPW/vomzU1QzOvrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726269648; c=relaxed/simple; bh=67vrryU9UsTS+odD3Hr++7bs/r/n/mJM7bxXmT5GFXI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yfil/HKA70NWKQF6N84lDxG7VPSZdzotgwwF4s5topE1TrvWmDX56gQ7GQ8jPTizSyaoy56Hym7DlttYMemwAlslfPLt/kCcFPGA5nTpmxmH469k0LB+KKMTD1riGFYNtN4uyAVOyzE2ETPocQPFvevzM+q1xvAnHqGXdvMAlWc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=ppu8EzRu; arc=none smtp.client-ip=209.85.160.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="ppu8EzRu" Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-4583083d05eso20013731cf.3 for ; Fri, 13 Sep 2024 16:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1726269645; x=1726874445; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5qmyPO2gV2TdLvoy/ahfQtBr82+inMJIdQs23EMKWKs=; b=ppu8EzRuBCtot/9pVwqKfojTcHOa6UFnKCl25Klu0ZXuHLPcDnDDqZdirctt1HdGv9 zmoIXrzZlzmuv+hZ8NvAt0MlXVWKVk2nYUU9BcOZUyxv79bii28Ep43XUQ6RPTG6pyZX d2IiHRpx0+NWiqgB8OBwGDeY5k8slc2o3J+aPFScCQVkk29RdQbuATnhX5+O7wlHvdko Zd8MvixTD32fFaVU8EwAgprUZLg3UIe3Au8HEApq4MM08Vtt4UC57k79eeTLS5qQP5YU LqtzoG0NGxPsmrhT9JzNEk4jsQnZ8Yz3GqZdYy82g//g2QlYVJizyn9levz+l430MXkM aIvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726269645; x=1726874445; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5qmyPO2gV2TdLvoy/ahfQtBr82+inMJIdQs23EMKWKs=; b=hOhGXoInhJgD5vbjZgvDWlf4CjPoBhfCraoKXQDeRnbyob5AEoTQPIVfGStSbsf3Jr /Z4RmiJQtCavVDFZq2nYBd298V2oMPzV+CQClCfzdekrs6g6WFLUybC7CvCYSymm+qBO czK0UGVLA5v9MGyZ/S1MA8QJPkmf4We0HuVhPWNsF3MzCFGfiZuxvoQWl+Krm3KkRrz2 bNFtrdfqHHhdHu/BLCYg9vFBPNWfTxMapgMuN2M6Fg38/DVZvu2rWMcXIGE4sBKTwE3S z5du60sU3VXnkJGJbZotwdo6YFjdsg3JD/90QtV5m7CdTPP1v91GqAT051heInYHLhrh RK0A== X-Gm-Message-State: AOJu0YzAFmunBVbXTH5m6OJ2Y/bnVCA0K+abhWj2Uf4saWPjfWx6kHDA +SBX7Jdx5cviMaRYVQRPl3XWf4KqC9Z5APEP2/oSaYEmGWcj1p3f/pNAhuRNdAP4twKYG8tARqw l X-Google-Smtp-Source: AGHT+IEv2T5u2KP3uo5VZTlultKi7QNfE9nP2N/YxwrZuzhrSep3tbOlZyBFH3cqwRpFuYqPrBzOSg== X-Received: by 2002:a05:622a:1892:b0:458:4c0d:bbd0 with SMTP id d75a77b69052e-4586032a0bamr103252871cf.30.1726269645075; Fri, 13 Sep 2024 16:20:45 -0700 (PDT) Received: from PC2K9PVX.TheFacebook.com (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-459aac7fb7bsm1245801cf.21.2024.09.13.16.20.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 16:20:44 -0700 (PDT) From: Gregory Price To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, ardb@kernel.org, leitao@debian.org, usamaarif642@gmail.com, sathyanarayanan.kuppuswamy@linux.intel.com, ilias.apalodimas@linaro.org Subject: [PATCH v2 3/4] tpm: fix unsigned/signed mismatch errors related to __calc_tpm2_event_size Date: Fri, 13 Sep 2024 19:19:53 -0400 Message-ID: <20240913231954.20081-4-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240913231954.20081-1-gourry@gourry.net> References: <20240913231954.20081-1-gourry@gourry.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __calc_tpm2_event_size returns 0 or a positive length, but return values are often interpreted as ints. Convert everything over to u32 to avoid signed/unsigned logic errors. Signed-off-by: Gregory Price --- drivers/firmware/efi/libstub/tpm.c | 6 +++--- drivers/firmware/efi/tpm.c | 2 +- include/linux/tpm_eventlog.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libs= tub/tpm.c index df3182f2e63a..f194e43f00ad 100644 --- a/drivers/firmware/efi/libstub/tpm.c +++ b/drivers/firmware/efi/libstub/tpm.c @@ -57,7 +57,7 @@ static void efi_retrieve_tcg2_eventlog(int version, efi_p= hysical_addr_t log_loca struct linux_efi_tpm_eventlog *log_tbl =3D NULL; unsigned long first_entry_addr, last_entry_addr; size_t log_size, last_entry_size; - int final_events_size =3D 0; + u32 final_events_size =3D 0; =20 first_entry_addr =3D (unsigned long) log_location; =20 @@ -110,9 +110,9 @@ static void efi_retrieve_tcg2_eventlog(int version, efi= _physical_addr_t log_loca */ if (final_events_table && final_events_table->nr_events) { struct tcg_pcr_event2_head *header; - int offset; + u32 offset; void *data; - int event_size; + u32 event_size; int i =3D final_events_table->nr_events; =20 data =3D (void *)final_events_table; diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c index b0cc2cc11d7e..cdd431027065 100644 --- a/drivers/firmware/efi/tpm.c +++ b/drivers/firmware/efi/tpm.c @@ -19,7 +19,7 @@ EXPORT_SYMBOL(efi_tpm_final_log_size); static int __init tpm2_calc_event_log_size(void *data, int count, void *si= ze_info) { struct tcg_pcr_event2_head *header; - int event_size, size =3D 0; + u32 event_size, size =3D 0; =20 while (count > 0) { header =3D data + size; diff --git a/include/linux/tpm_eventlog.h b/include/linux/tpm_eventlog.h index 7d68a5cc5881..891368e82558 100644 --- a/include/linux/tpm_eventlog.h +++ b/include/linux/tpm_eventlog.h @@ -157,7 +157,7 @@ struct tcg_algorithm_info { * Return: size of the event on success, 0 on failure */ =20 -static __always_inline int __calc_tpm2_event_size(struct tcg_pcr_event2_he= ad *event, +static __always_inline u32 __calc_tpm2_event_size(struct tcg_pcr_event2_he= ad *event, struct tcg_pcr_event *event_header, bool do_mapping) { --=20 2.43.0 From nobody Fri Nov 29 21:36:04 2024 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (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 45DD3BA2D for ; Fri, 13 Sep 2024 23:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726269648; cv=none; b=lkKbkaDICfPLY31dglC3+mYb0emQJ9EShMUqRNbqqH7BBrnWdPHIccIot/hfbqwWIkf7MdayYJApRWbRW7tAIE9IgdkARE7xUMO1lYtM/1fMu3ZJzAFW72Wsg8DM3N3JAUpT+CjW87OQyQ/KPVdG1fCL92hvfvDQOpMt3a9hGxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726269648; c=relaxed/simple; bh=Crzg9hmq5LPADdASQA4zRbh7dPjZ1xqI+Kmgq3o6Oc0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jwoNBpUEHZ32x741qhIRYVgyNk+P+aVGYfJIAWCjyiylw1WxAVUTrsf0VC9S/EjGwHhqCehHpEDOkaBtk0pOIQSxl3AMq34EgGS81JjeVWKjidEFnJM5ttx0mPz9EsvEYO4op5VJtSNOSr71qO7xjQU9ATX/5TUMjVQ7KL0KGgM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=n8sNxF0e; arc=none smtp.client-ip=209.85.160.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="n8sNxF0e" Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-457e153cbdcso24035371cf.2 for ; Fri, 13 Sep 2024 16:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1726269646; x=1726874446; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VKowLLj1rEpuegkSJn+z8DbnyDQaIfPDvu9JHxdaX6I=; b=n8sNxF0eb8GprolGb4AdpdjfLnIqtI0ZYFhCotbgTKlhclcQlrkXmDhtIvNuzFkfAc i/dxGjS1hvgarNCOshEwqo7iImi238GXeUJn2/jZMOXY+lGdn17JTUBZc6pY7W4xiEmC bcF1PC02kxBkqGHGlYdUJMYz2U+Fk29QMfpKUWzN4OcaWoin/2lkZMSYBxAdLdXGLdwB TtO7McmO+lS1T2NH4rPbG+eg+xoDXvc5XmvKXKtfSGNEcVD3QuUU9P9N6k3QrTnC/q4y thxRds+TPwvUrxggef9bF+ja6qyDmY4HCXiKh8J0FPVse5baPgimOV4Q7VIrmr/k4qRV xMxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726269646; x=1726874446; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VKowLLj1rEpuegkSJn+z8DbnyDQaIfPDvu9JHxdaX6I=; b=ROiUaIsQJnnmnktaTmDUoHWVZjQPRzHX6ifpZ1+/h5Lh87UNCzM32XVozxd9ru4Dhu bRz3dAMKZd6c0m18THW/xT2fZDiqF8t1c1NAquGV7nNd6VyaHPbx0x58hGScR+TTWDDM sBuiUYRjnliSdzwkAQKfJmYAQmRbJnY/8aLoI1/jlEt7pknF5sPi1IiOV3HtJO9+WSF/ DmsOh7kvQ1bNgY6qiKL8rgFT9U/PLMabqbrNMjeUP7fG5MYt4exdcPoCzMUvmFCWp7Np kMuCLP/p34KbJzYinSdzyircbMdk2/MzBBNd7rZicu34k7zt7SsksMxK0Q+Cb2JNi57W PEYg== X-Gm-Message-State: AOJu0YynfNjzGlwFklf19x724QkEWy5uGHf7F0dGdQ9awPFPKgaHsv8s F1zrHKPBYKXAbIcWO+bD/UXdyX2y0/TrAgAHC8FuQi91dW6WZHKkKjIZamgyeAM= X-Google-Smtp-Source: AGHT+IF5NIHVlHuaEE4y3ptAaRlLmvMbZI36tTwSTYRpK7t/TOQFWvaJeuPFPNFrOnexOkgerUG54A== X-Received: by 2002:a05:622a:28e:b0:458:3766:964c with SMTP id d75a77b69052e-4586032d392mr123607251cf.30.1726269646221; Fri, 13 Sep 2024 16:20:46 -0700 (PDT) Received: from PC2K9PVX.TheFacebook.com (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-459aac7fb7bsm1245801cf.21.2024.09.13.16.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 16:20:45 -0700 (PDT) From: Gregory Price To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, ardb@kernel.org, leitao@debian.org, usamaarif642@gmail.com, sathyanarayanan.kuppuswamy@linux.intel.com, ilias.apalodimas@linaro.org Subject: [PATCH v2 4/4] libstub,tpm: do not ignore failure case when reading final event log Date: Fri, 13 Sep 2024 19:19:54 -0400 Message-ID: <20240913231954.20081-5-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240913231954.20081-1-gourry@gourry.net> References: <20240913231954.20081-1-gourry@gourry.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Current code fails to check for an error case when reading events from final event log to calculate offsets. Check the error case, and break early because all subsequent calls will also fail. Signed-off-by: Gregory Price --- drivers/firmware/efi/libstub/tpm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libs= tub/tpm.c index f194e43f00ad..8e04aaf428d0 100644 --- a/drivers/firmware/efi/libstub/tpm.c +++ b/drivers/firmware/efi/libstub/tpm.c @@ -124,6 +124,9 @@ static void efi_retrieve_tcg2_eventlog(int version, efi= _physical_addr_t log_loca event_size =3D __calc_tpm2_event_size(header, (void *)(long)log_location, false); + /* If calc fails this is a malformed log */ + if (!event_size) + break; final_events_size +=3D event_size; i--; } --=20 2.43.0