Skip to content

[Medium] Patch shim-unsigned-x64 for CVE-2024-9143 #13946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3.0-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion SPECS/shim-unsigned-aarch64/shim-unsigned-aarch64.spec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Name: shim-unsigned-aarch64
Provides: shim-unsigned-%{efiarch}

Version: 15.8
Release: 5%{?dist}
Release: 6%{?dist}
Summary: First-stage UEFI bootloader
ExclusiveArch: aarch64
License: BSD
Expand Down Expand Up @@ -160,6 +160,9 @@ HASH=$(cat %{buildroot}%{shimdir}/shim%{efiarch}.hash | cut -d ' ' -f 1)
%files debugsource -f build-%{efiarch}/debugsource.list

%changelog
* Mon Jun 02 2025 Sreeniavsulu Malavathula <v-smalavathu@microsoft.com> - 15-8.6
- Bump to match shim release

* Thu Nov 28 2024 Chris Co <chrco@microsoft.com> - 15.8-5
- Bump to match shim release

Expand Down
77 changes: 77 additions & 0 deletions SPECS/shim-unsigned-x64/CVE-2024-9143.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
From a69837a1f5b4f192a14cb9fd6e2e67014d9713bc Mon Sep 17 00:00:00 2001
From: Sreenivasulu Malavathula <v-smalavathu@microsoft.com>
Date: Mon, 2 Jun 2025 18:17:27 -0500
Subject: [PATCH] Address CVE-2024-9143
Upstream Patch Reference: https://github.com/openssl/openssl/commit/bc7e04d7c8d509fb78fc0e285aa948fb0da04700

---
Cryptlib/OpenSSL/crypto/bn/bn_gf2m.c | 31 +++++++++++++++++++++-------
1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/Cryptlib/OpenSSL/crypto/bn/bn_gf2m.c b/Cryptlib/OpenSSL/crypto/bn/bn_gf2m.c
index 2c61da1..7917365 100644
--- a/Cryptlib/OpenSSL/crypto/bn/bn_gf2m.c
+++ b/Cryptlib/OpenSSL/crypto/bn/bn_gf2m.c
@@ -95,6 +95,10 @@
#include "cryptlib.h"
#include "bn_lcl.h"

+# ifndef OPENSSL_ECC_MAX_FIELD_BITS
+# define OPENSSL_ECC_MAX_FIELD_BITS 661
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+# endif
+
#ifndef OPENSSL_NO_EC2M

/*
@@ -1243,16 +1247,26 @@ int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
/*
* Convert the bit-string representation of a polynomial ( \sum_{i=0}^n a_i *
* x^i) into an array of integers corresponding to the bits with non-zero
- * coefficient. Array is terminated with -1. Up to max elements of the array
- * will be filled. Return value is total number of array elements that would
- * be filled if array was large enough.
+ * coefficient. The array is intended to be suitable for use with
+ * `BN_GF2m_mod_arr()`, and so the constant term of the polynomial must not be
+ * zero. This translates to a requirement that the input BIGNUM `a` is odd.
+ *
+ * Given sufficient room, the array is terminated with -1. Up to max elements
+ * of the array will be filled.
+ *
+ * The return value is total number of array elements that would be filled if
+ * array was large enough, including the terminating `-1`. It is `0` when `a`
+ * is not odd or the constant term is zero contrary to requirement.
+ *
+ * The return value is also `0` when the leading exponent exceeds
+ * `OPENSSL_ECC_MAX_FIELD_BITS`, this guards against CPU exhaustion attacks,
*/
int BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max)
{
int i, j, k = 0;
BN_ULONG mask;

- if (BN_is_zero(a))
+ if (!BN_is_odd(a))
return 0;

for (i = a->top - 1; i >= 0; i--) {
@@ -1270,12 +1284,13 @@ int BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max)
}
}

- if (k < max) {
+ if (k > 0 && p[0] > OPENSSL_ECC_MAX_FIELD_BITS)
+ return 0;
+
+ if (k < max)
p[k] = -1;
- k++;
- }

- return k;
+ return k + 1;
}

/*
--
2.45.2

6 changes: 5 additions & 1 deletion SPECS/shim-unsigned-x64/shim-unsigned-x64.spec
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

Name: shim-unsigned-%{efiarch}
Version: 15.8
Release: 5%{?dist}
Release: 6%{?dist}
Summary: First-stage UEFI bootloader
ExclusiveArch: x86_64
License: BSD
Expand All @@ -52,6 +52,7 @@ Source3: sbat.azurelinux.csv
Source4: shim.patches

Source100: shim-find-debuginfo.sh
Patch0: CVE-2024-9143.patch

%include %{SOURCE4}

Expand Down Expand Up @@ -221,6 +222,9 @@ HASH=$(cat %{buildroot}%{shimdir}/shim%{efiarch}.hash | cut -d ' ' -f 1)
%files debugsource -f build-%{efiarch}/debugsource.list

%changelog
* Mon Jun 02 2025 Sreeniavsulu Malavathula <v-smalavathu@microsoft.com> - 15.8-6
- Patch CVE-2024-9143

* Thu Nov 28 2024 Chris Co <chrco@microsoft.com> - 15.8-5
- Bump to match shim release

Expand Down
5 changes: 4 additions & 1 deletion SPECS/shim/shim.spec
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
Summary: First stage UEFI bootloader
Name: shim
Version: 15.8
Release: 5%{?dist}
Release: 6%{?dist}
License: BSD
Vendor: Microsoft Corporation
Distribution: Azure Linux
Expand Down Expand Up @@ -187,6 +187,9 @@ fi
/boot/efi/EFI/%{efidir}/*

%changelog
* Mon Jun 02 2025 Sreeniavsulu Malavathula <v-smalavathu@microsoft.com> - 15-8.6
- Bump to match shim release

* Thu Nov 28 2024 Chris Co <chrco@microsoft.com> - 15.8-5
- Add Provides for shim-unsigned

Expand Down
Loading