Bundle GMP to privatize memory functions
Related: #2097327 Signed-off-by: Daiki Ueno <dueno@redhat.com>
This commit is contained in:
parent
999f3b003c
commit
4f04a0acf4
1
.gitignore
vendored
1
.gitignore
vendored
@ -19,3 +19,4 @@ nettle-1.15.tar.gz
|
||||
/nettle-3.7.2-hobbled.tar.xz
|
||||
/nettle-3.7.3-hobbled.tar.xz
|
||||
/nettle-3.8-hobbled.tar.xz
|
||||
/gmp-6.2.1.tar.xz
|
||||
|
3515
gmp-6.2.1-intel-cet.patch
Normal file
3515
gmp-6.2.1-intel-cet.patch
Normal file
File diff suppressed because it is too large
Load Diff
53
gmp-6.2.1-zeroize-allocator.patch
Normal file
53
gmp-6.2.1-zeroize-allocator.patch
Normal file
@ -0,0 +1,53 @@
|
||||
diff -r e3123b88d012 memory.c
|
||||
--- a/memory.c Tue Aug 16 22:02:45 2022 +0200
|
||||
+++ b/memory.c Fri Aug 19 06:25:37 2022 +0900
|
||||
@@ -29,7 +29,8 @@
|
||||
see https://www.gnu.org/licenses/. */
|
||||
|
||||
#include <stdio.h>
|
||||
-#include <stdlib.h> /* for malloc, realloc, free */
|
||||
+#include <stdlib.h> /* for malloc, free */
|
||||
+#include <string.h> /* for memcpy, explicit_bzero */
|
||||
|
||||
#include "gmp-impl.h"
|
||||
|
||||
@@ -98,11 +99,28 @@
|
||||
new_size += 2 * GMP_LIMB_BYTES;
|
||||
#endif
|
||||
|
||||
- ret = realloc (oldptr, new_size);
|
||||
- if (ret == 0)
|
||||
+ if (new_size == 0)
|
||||
+ {
|
||||
+ explicit_bzero (oldptr, old_size);
|
||||
+ free (oldptr);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ else if (old_size == new_size)
|
||||
+ return oldptr;
|
||||
+ else
|
||||
{
|
||||
- fprintf (stderr, "GNU MP: Cannot reallocate memory (old_size=%lu new_size=%lu)\n", (long) old_size, (long) new_size);
|
||||
- abort ();
|
||||
+ /* We can't simply call realloc, as it may allocate memory from
|
||||
+ a different arena. */
|
||||
+ ret = malloc (new_size);
|
||||
+ if (ret == NULL)
|
||||
+ {
|
||||
+ fprintf (stderr, "GNU MP: Cannot reallocate memory (old_size=%lu new_size=%lu)\n", (long) old_size, (long) new_size);
|
||||
+ explicit_bzero(oldptr, old_size);
|
||||
+ abort();
|
||||
+ }
|
||||
+ memcpy (ret, oldptr, MIN(old_size, new_size));
|
||||
+ explicit_bzero (oldptr, old_size);
|
||||
+ free (oldptr);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
@@ -141,5 +159,6 @@
|
||||
blk_ptr = p - 1;
|
||||
}
|
||||
#endif
|
||||
+ explicit_bzero (blk_ptr, blk_size);
|
||||
free (blk_ptr);
|
||||
}
|
43
nettle.spec
43
nettle.spec
@ -15,7 +15,7 @@
|
||||
|
||||
Name: nettle
|
||||
Version: 3.8
|
||||
Release: 1%{?dist}
|
||||
Release: 2%{?dist}
|
||||
Summary: A low-level cryptographic library
|
||||
|
||||
License: LGPLv3+ or GPLv2+
|
||||
@ -28,9 +28,17 @@ Source2: nettle-3.5-remove-ecc-testsuite.patch
|
||||
%endif
|
||||
Patch0: nettle-3.4-annocheck.patch
|
||||
|
||||
Source100: gmp-6.2.1.tar.xz
|
||||
# Taken from the main gmp package
|
||||
Source101: gmp-6.2.1-intel-cet.patch
|
||||
Source102: gmp-6.2.1-zeroize-allocator.patch
|
||||
|
||||
BuildRequires: make
|
||||
BuildRequires: gcc
|
||||
BuildRequires: gmp-devel, m4
|
||||
%if !%{with fips}
|
||||
BuildRequires: gmp-devel
|
||||
%endif
|
||||
BuildRequires: m4
|
||||
BuildRequires: libtool, automake, autoconf, gettext-devel
|
||||
%if %{with fips}
|
||||
BuildRequires: fipscheck
|
||||
@ -58,6 +66,18 @@ applications with nettle.
|
||||
%prep
|
||||
%autosetup -Tb 0 -p1
|
||||
|
||||
%if %{with fips}
|
||||
mkdir -p bundled_gmp
|
||||
pushd bundled_gmp
|
||||
tar --strip-components=1 -xf %{SOURCE100}
|
||||
patch -p1 < %{SOURCE101}
|
||||
patch -p1 < %{SOURCE102}
|
||||
popd
|
||||
|
||||
# Prevent -lgmp appearing in the compiler command line in dependent components
|
||||
sed -i '/^Libs.private:/d' hogweed.pc.in
|
||||
%endif
|
||||
|
||||
%if 0%{?bootstrap}
|
||||
mkdir -p bootstrap_ver
|
||||
pushd bootstrap_ver
|
||||
@ -77,8 +97,22 @@ sed 's/ecc-secp192r1.c//g' -i Makefile.in
|
||||
sed 's/ecc-secp224r1.c//g' -i Makefile.in
|
||||
|
||||
%build
|
||||
%if %{with fips}
|
||||
pushd bundled_gmp
|
||||
autoreconf -ifv
|
||||
%configure --enable-shared --enable-fat
|
||||
%configure --disable-cxx --disable-shared --enable-fat --with-pic
|
||||
%make_build
|
||||
popd
|
||||
%endif
|
||||
|
||||
autoreconf -ifv
|
||||
|
||||
%configure --enable-shared --enable-fat \
|
||||
%if %{with fips}
|
||||
--with-include-path=$PWD/bundled_gmp --with-lib-path=$PWD/bundled_gmp/.libs \
|
||||
%endif
|
||||
%{nil}
|
||||
|
||||
%make_build
|
||||
|
||||
%if 0%{?bootstrap}
|
||||
@ -170,6 +204,9 @@ make check
|
||||
|
||||
|
||||
%changelog
|
||||
* Thu Aug 18 2022 Daiki Ueno <dueno@redhat.com> - 3.8-2
|
||||
- Bundle GMP to privatize memory functions
|
||||
|
||||
* Tue Jun 28 2022 Daiki Ueno <dueno@redhat.com> - 3.8-1
|
||||
- Update to nettle 3.8 (#1992457)
|
||||
|
||||
|
1
sources
1
sources
@ -1 +1,2 @@
|
||||
SHA512 (nettle-3.8-hobbled.tar.xz) = a0c24568401212895b69eff046dbc0450fc14f1759ec3b4b62771a3d77192056b9a43c3ee386aeae1fe2d12ce58efc183849af5f9088e4ea7dab278f52572b2f
|
||||
SHA512 (gmp-6.2.1.tar.xz) = c99be0950a1d05a0297d65641dd35b75b74466f7bf03c9e8a99895a3b2f9a0856cd17887738fa51cf7499781b65c049769271cbcb77d057d2e9f1ec52e07dd84
|
||||
|
Loading…
Reference in New Issue
Block a user