From 3110c594afb8839ba81b528f316b6d6dce757e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Tue, 22 May 2018 17:34:47 +0200 Subject: [PATCH 1/3] gnu: parted: Use weak (non-blocking) randomness for FAT serial numbers. Partly fixes . * gnu/packages/patches/parted-non-blocking-random.patch: New file. * gnu/packages/disk.scm (parted)[source]: Use it. * gnu/local.mk (dist_patch_DATA): Add it. --- gnu/local.mk | 1 + gnu/packages/disk.scm | 3 +- .../patches/parted-non-blocking-random.patch | 39 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 gnu/packages/patches/parted-non-blocking-random.patch diff --git a/gnu/local.mk b/gnu/local.mk index 20975306b..4222050b5 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -975,6 +975,7 @@ dist_patch_DATA = \ %D%/packages/patches/p7zip-CVE-2017-17969.patch \ %D%/packages/patches/p7zip-remove-unused-code.patch \ %D%/packages/patches/password-store-gnupg-compat.patch \ + %D%/packages/patches/parted-non-blocking-random.patch \ %D%/packages/patches/patchelf-page-size.patch \ %D%/packages/patches/patchelf-rework-for-arm.patch \ %D%/packages/patches/patchutils-xfail-gendiff-tests.patch \ diff --git a/gnu/packages/disk.scm b/gnu/packages/disk.scm index d7bf72683..476b26acb 100644 --- a/gnu/packages/disk.scm +++ b/gnu/packages/disk.scm @@ -65,7 +65,8 @@ version ".tar.xz")) (sha256 (base32 - "1r3qpg3bhz37mgvp9chsaa3k0csby3vayfvz8ggsqz194af5i2w5")))) + "1r3qpg3bhz37mgvp9chsaa3k0csby3vayfvz8ggsqz194af5i2w5")) + (patches (search-patches "parted-non-blocking-random.patch")))) (build-system gnu-build-system) (arguments `(#:phases diff --git a/gnu/packages/patches/parted-non-blocking-random.patch b/gnu/packages/patches/parted-non-blocking-random.patch new file mode 100644 index 000000000..e30d9f413 --- /dev/null +++ b/gnu/packages/patches/parted-non-blocking-random.patch @@ -0,0 +1,39 @@ +Explicitly use a non-blocking random primitive. This is used primarily +to compute FAT "serial numbers" in libparted/fs/r/fat/fat.c:fat_create, +for which GRND_NONBLOCK is probably good enough. + +Assume the running kernel does support 'getrandom', which is the case on +GuixSD. See . + +--- a/libparted/labels/misc.h ++++ b/libparted/labels/misc.h +@@ -17,7 +17,8 @@ + along with this program. If not, see . */ + + #include +-#include ++#include ++#include + + /* hack: use the ext2 uuid library to generate a reasonably random (hopefully + * with /dev/random) number. Unfortunately, we can only use 4 bytes of it. +@@ -28,11 +29,17 @@ static inline uint32_t + generate_random_uint32 (void) + { + union { +- uuid_t uuid; ++ char uuid[4]; + uint32_t i; + } uu32; ++ ssize_t ret; + +- uuid_generate (uu32.uuid); ++ do ++ ret = getrandom (uu32.uuid, sizeof uu32, GRND_NONBLOCK); ++ while (ret == EAGAIN); ++ ++ if (ret < sizeof uu32) ++ abort (); + + return uu32.i > 0 ? uu32.i : 0xffffffff; + } -- 2.17.0