Fix (rare) undetected truncation of 64 bit int results to 32 bits

resolves: RHEL-45466
This commit is contained in:
Richard W.M. Jones 2024-06-28 10:10:57 +01:00
parent d9b4d60317
commit a86c5a4fb4
5 changed files with 383 additions and 1 deletions

View File

@ -0,0 +1,198 @@
From 69f567363a098654354e0be94adbf9c5f847a8e9 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 25 Apr 2024 12:56:48 +0100
Subject: [PATCH] test-data/binaries: Remove +x attribute
These binaries are not meant to be run, they are purely data files
used for testing. Remove the +x attribute to prevent accidentally
running them.
However to avoid breaking the phony guests, we need to chmod +x the
files when we upload them into those guests.
(cherry picked from commit 574a87f889c7b48b231fcabf0d45b88bd48b53f8)
---
test-data/binaries/bin-aarch64-dynamic | Bin
test-data/binaries/bin-armv7-dynamic | Bin
test-data/binaries/bin-i586-dynamic | Bin
test-data/binaries/bin-ia64-dynamic | Bin
test-data/binaries/bin-mipsel-dynamic | Bin
test-data/binaries/bin-ppc64-dynamic | Bin
test-data/binaries/bin-ppc64le-dynamic | Bin
test-data/binaries/bin-riscv64-dynamic | Bin
test-data/binaries/bin-s390x-dynamic | Bin
test-data/binaries/bin-sparc-dynamic | Bin
test-data/binaries/bin-win32.exe | Bin
test-data/binaries/bin-win64.exe | Bin
test-data/binaries/bin-x86_64-dynamic | Bin
test-data/binaries/lib-aarch64.so | Bin
test-data/binaries/lib-armv7.so | Bin
test-data/binaries/lib-i586.so | Bin
test-data/binaries/lib-ia64.so | Bin
test-data/binaries/lib-mipsel.so | Bin
test-data/binaries/lib-ppc64.so | Bin
test-data/binaries/lib-ppc64le.so | Bin
test-data/binaries/lib-riscv64.so | Bin
test-data/binaries/lib-s390x.so | Bin
test-data/binaries/lib-sparc.so | Bin
test-data/binaries/lib-win32.dll | Bin
test-data/binaries/lib-win64.dll | Bin
test-data/binaries/lib-x86_64.so | Bin
test-data/phony-guests/make-archlinux-img.sh | 1 +
test-data/phony-guests/make-debian-img.sh | 1 +
test-data/phony-guests/make-fedora-img.pl | 1 +
test-data/phony-guests/make-ubuntu-img.sh | 1 +
30 files changed, 4 insertions(+)
mode change 100755 => 100644 test-data/binaries/bin-aarch64-dynamic
mode change 100755 => 100644 test-data/binaries/bin-armv7-dynamic
mode change 100755 => 100644 test-data/binaries/bin-i586-dynamic
mode change 100755 => 100644 test-data/binaries/bin-ia64-dynamic
mode change 100755 => 100644 test-data/binaries/bin-mipsel-dynamic
mode change 100755 => 100644 test-data/binaries/bin-ppc64-dynamic
mode change 100755 => 100644 test-data/binaries/bin-ppc64le-dynamic
mode change 100755 => 100644 test-data/binaries/bin-riscv64-dynamic
mode change 100755 => 100644 test-data/binaries/bin-s390x-dynamic
mode change 100755 => 100644 test-data/binaries/bin-sparc-dynamic
mode change 100755 => 100644 test-data/binaries/bin-win32.exe
mode change 100755 => 100644 test-data/binaries/bin-win64.exe
mode change 100755 => 100644 test-data/binaries/bin-x86_64-dynamic
mode change 100755 => 100644 test-data/binaries/lib-aarch64.so
mode change 100755 => 100644 test-data/binaries/lib-armv7.so
mode change 100755 => 100644 test-data/binaries/lib-i586.so
mode change 100755 => 100644 test-data/binaries/lib-ia64.so
mode change 100755 => 100644 test-data/binaries/lib-mipsel.so
mode change 100755 => 100644 test-data/binaries/lib-ppc64.so
mode change 100755 => 100644 test-data/binaries/lib-ppc64le.so
mode change 100755 => 100644 test-data/binaries/lib-riscv64.so
mode change 100755 => 100644 test-data/binaries/lib-s390x.so
mode change 100755 => 100644 test-data/binaries/lib-sparc.so
mode change 100755 => 100644 test-data/binaries/lib-win32.dll
mode change 100755 => 100644 test-data/binaries/lib-win64.dll
mode change 100755 => 100644 test-data/binaries/lib-x86_64.so
diff --git a/test-data/binaries/bin-aarch64-dynamic b/test-data/binaries/bin-aarch64-dynamic
old mode 100755
new mode 100644
diff --git a/test-data/binaries/bin-armv7-dynamic b/test-data/binaries/bin-armv7-dynamic
old mode 100755
new mode 100644
diff --git a/test-data/binaries/bin-i586-dynamic b/test-data/binaries/bin-i586-dynamic
old mode 100755
new mode 100644
diff --git a/test-data/binaries/bin-ia64-dynamic b/test-data/binaries/bin-ia64-dynamic
old mode 100755
new mode 100644
diff --git a/test-data/binaries/bin-mipsel-dynamic b/test-data/binaries/bin-mipsel-dynamic
old mode 100755
new mode 100644
diff --git a/test-data/binaries/bin-ppc64-dynamic b/test-data/binaries/bin-ppc64-dynamic
old mode 100755
new mode 100644
diff --git a/test-data/binaries/bin-ppc64le-dynamic b/test-data/binaries/bin-ppc64le-dynamic
old mode 100755
new mode 100644
diff --git a/test-data/binaries/bin-riscv64-dynamic b/test-data/binaries/bin-riscv64-dynamic
old mode 100755
new mode 100644
diff --git a/test-data/binaries/bin-s390x-dynamic b/test-data/binaries/bin-s390x-dynamic
old mode 100755
new mode 100644
diff --git a/test-data/binaries/bin-sparc-dynamic b/test-data/binaries/bin-sparc-dynamic
old mode 100755
new mode 100644
diff --git a/test-data/binaries/bin-win32.exe b/test-data/binaries/bin-win32.exe
old mode 100755
new mode 100644
diff --git a/test-data/binaries/bin-win64.exe b/test-data/binaries/bin-win64.exe
old mode 100755
new mode 100644
diff --git a/test-data/binaries/bin-x86_64-dynamic b/test-data/binaries/bin-x86_64-dynamic
old mode 100755
new mode 100644
diff --git a/test-data/binaries/lib-aarch64.so b/test-data/binaries/lib-aarch64.so
old mode 100755
new mode 100644
diff --git a/test-data/binaries/lib-armv7.so b/test-data/binaries/lib-armv7.so
old mode 100755
new mode 100644
diff --git a/test-data/binaries/lib-i586.so b/test-data/binaries/lib-i586.so
old mode 100755
new mode 100644
diff --git a/test-data/binaries/lib-ia64.so b/test-data/binaries/lib-ia64.so
old mode 100755
new mode 100644
diff --git a/test-data/binaries/lib-mipsel.so b/test-data/binaries/lib-mipsel.so
old mode 100755
new mode 100644
diff --git a/test-data/binaries/lib-ppc64.so b/test-data/binaries/lib-ppc64.so
old mode 100755
new mode 100644
diff --git a/test-data/binaries/lib-ppc64le.so b/test-data/binaries/lib-ppc64le.so
old mode 100755
new mode 100644
diff --git a/test-data/binaries/lib-riscv64.so b/test-data/binaries/lib-riscv64.so
old mode 100755
new mode 100644
diff --git a/test-data/binaries/lib-s390x.so b/test-data/binaries/lib-s390x.so
old mode 100755
new mode 100644
diff --git a/test-data/binaries/lib-sparc.so b/test-data/binaries/lib-sparc.so
old mode 100755
new mode 100644
diff --git a/test-data/binaries/lib-win32.dll b/test-data/binaries/lib-win32.dll
old mode 100755
new mode 100644
diff --git a/test-data/binaries/lib-win64.dll b/test-data/binaries/lib-win64.dll
old mode 100755
new mode 100644
diff --git a/test-data/binaries/lib-x86_64.so b/test-data/binaries/lib-x86_64.so
old mode 100755
new mode 100644
diff --git a/test-data/phony-guests/make-archlinux-img.sh b/test-data/phony-guests/make-archlinux-img.sh
index 066df09d..e0e3d3de 100755
--- a/test-data/phony-guests/make-archlinux-img.sh
+++ b/test-data/phony-guests/make-archlinux-img.sh
@@ -50,6 +50,7 @@ write /etc/hostname "archlinux.test"
upload $SRCDIR/archlinux-package /var/lib/pacman/local/test-package-1:0.1-1/desc
upload $SRCDIR/../binaries/bin-x86_64-dynamic /bin/ls
+chmod 0755 /bin/ls
mkdir /boot/grub
touch /boot/grub/grub.conf
diff --git a/test-data/phony-guests/make-debian-img.sh b/test-data/phony-guests/make-debian-img.sh
index 637bd4bc..27c68e6e 100755
--- a/test-data/phony-guests/make-debian-img.sh
+++ b/test-data/phony-guests/make-debian-img.sh
@@ -85,6 +85,7 @@ write /etc/hostname "debian.invalid"
upload $SRCDIR/debian-packages /var/lib/dpkg/status
upload $SRCDIR/../binaries/bin-x86_64-dynamic /bin/ls
+chmod 0755 /bin/ls
upload $SRCDIR/debian-syslog /var/log/syslog
diff --git a/test-data/phony-guests/make-fedora-img.pl b/test-data/phony-guests/make-fedora-img.pl
index 6362e225..b7dc902e 100755
--- a/test-data/phony-guests/make-fedora-img.pl
+++ b/test-data/phony-guests/make-fedora-img.pl
@@ -331,6 +331,7 @@ $g->write ('/usr/lib/rpm/macros', <<EOF);
EOF
$g->upload ($ENV{SRCDIR}.'/../binaries/bin-x86_64-dynamic', '/bin/ls');
+$g->chmod (0755, '/bin/ls');
$g->tar_in ($ENV{SRCDIR}.'/fedora-journal.tar.xz', '/var/log/journal', compress => "xz");
diff --git a/test-data/phony-guests/make-ubuntu-img.sh b/test-data/phony-guests/make-ubuntu-img.sh
index a3aa6105..5e7a3a96 100755
--- a/test-data/phony-guests/make-ubuntu-img.sh
+++ b/test-data/phony-guests/make-ubuntu-img.sh
@@ -76,6 +76,7 @@ write /etc/hostname "ubuntu.invalid"
upload $SRCDIR/debian-packages /var/lib/dpkg/status
upload $SRCDIR/../binaries/bin-x86_64-dynamic /bin/ls
+chmod 0755 /bin/ls
mkdir /boot/grub
touch /boot/grub/grub.conf

View File

@ -0,0 +1,20 @@
From c1bae8cb76bd14b0bc02983e7e25be09ebc0a19d Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 25 Apr 2024 13:15:08 +0100
Subject: [PATCH] gobject: tests: Don't erase error messages
(cherry picked from commit e0ffe31e96d23b4ffce27fa6c3b1590e3641a910)
---
gobject/run-tests-retvalues | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gobject/run-tests-retvalues b/gobject/run-tests-retvalues
index 272b92e4..d594b464 100755
--- a/gobject/run-tests-retvalues
+++ b/gobject/run-tests-retvalues
@@ -22,4 +22,4 @@ $TEST_FUNCTIONS
skip_if_skipped
skip_unless_environment_variable_set GJS
-$GJS $srcdir/bindtests-retvalues.js 2>/dev/null
+$GJS $srcdir/bindtests-retvalues.js

View File

@ -0,0 +1,125 @@
From 27645254de11a50778161e1d864998323e28bb9e Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 10 May 2024 13:45:59 +0100
Subject: [PATCH] daemon/parted: Assume sfdisk --part-type exists
This "new" parameter was added in 2014:
commit 8eab3194ce1737a167812d5e84d83b0dfc253fac
Author: Karel Zak <kzak@redhat.com>
Date: Mon Sep 15 12:37:52 2014 +0200
sfdisk: add --parttype
The patch also makes --{id,change-id,print-id} deprecated in favour
of --parttype. The original --id is too generic option name and the
--print-id and --change-id are unnecessary and inconsistent with
another sfdisk options (e.g. we don't have --change-bootable)
Also remove an extraneous / incorrect comment about parted. As
history has played out, sfdisk proves to be the better tool and parted
is a PITA.
(cherry picked from commit 857615d6d258d5bb3badf4caebd4bc8e69f1a33a)
---
daemon/parted.c | 32 +++-----------------------------
daemon/parted.ml | 22 +---------------------
2 files changed, 4 insertions(+), 50 deletions(-)
diff --git a/daemon/parted.c b/daemon/parted.c
index 6d33e5a6..d0f2ce03 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -424,30 +424,6 @@ do_part_get_bootable (const char *device, int partnum)
return strstr (boot, "boot") != NULL;
}
-/* Test if sfdisk is recent enough to have --part-type, to be used instead
- * of --print-id and --change-id.
- */
-static int
-test_sfdisk_has_part_type (void)
-{
- static int tested = -1;
-
- if (tested != -1)
- return tested;
-
- int r;
- CLEANUP_FREE char *out = NULL, *err = NULL;
-
- r = command (&out, &err, "sfdisk", "--help", NULL);
- if (r == -1) {
- reply_with_error ("%s: %s", "sfdisk --help", err);
- return -1;
- }
-
- tested = strstr (out, "--part-type") != NULL;
- return tested;
-}
-
int
do_part_set_mbr_id (const char *device, int partnum, int idbyte)
{
@@ -456,8 +432,6 @@ do_part_set_mbr_id (const char *device, int partnum, int idbyte)
return -1;
}
- const char *param = test_sfdisk_has_part_type () ? "--part-type" : "--change-id";
-
char partnum_str[16];
snprintf (partnum_str, sizeof partnum_str, "%d", partnum);
@@ -470,10 +444,10 @@ do_part_set_mbr_id (const char *device, int partnum, int idbyte)
udev_settle ();
- r = command (NULL, &err, "sfdisk",
- param, device, partnum_str, idbyte_str, NULL);
+ r = command (NULL, &err, "sfdisk", "--part-type",
+ device, partnum_str, idbyte_str, NULL);
if (r == -1) {
- reply_with_error ("sfdisk %s: %s", param, err);
+ reply_with_error ("sfdisk --part-type: %s", err);
return -1;
}
diff --git a/daemon/parted.ml b/daemon/parted.ml
index e0ca7a60..c9e55890 100644
--- a/daemon/parted.ml
+++ b/daemon/parted.ml
@@ -25,33 +25,13 @@ open Utils
include Structs
-(* Test if [sfdisk] is recent enough to have [--part-type], to be used
- * instead of [--print-id] and [--change-id].
- *)
-let test_sfdisk_has_part_type = lazy (
- let out = command "sfdisk" ["--help"] in
- String.find out "--part-type" >= 0
-)
-
-(* Currently we use sfdisk for getting and setting the ID byte. In
- * future, extend parted to provide this functionality. As a result
- * of using sfdisk, this won't work for non-MBR-style partitions, but
- * that limitation is noted in the documentation and we can extend it
- * later without breaking the ABI.
- *)
let part_get_mbr_id device partnum =
if partnum <= 0 then
failwith "partition number must be >= 1";
- let param =
- if Lazy.force test_sfdisk_has_part_type then
- "--part-type"
- else
- "--print-id" in
-
udev_settle ();
let out =
- command "sfdisk" [param; device; string_of_int partnum] in
+ command "sfdisk" ["--part-type"; device; string_of_int partnum] in
udev_settle ();
(* It's printed in hex, possibly with a leading space. *)

View File

@ -0,0 +1,31 @@
From 7a6d56d653e7bd41e2e0f6b7ab56a0a2b874572e Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 28 Jun 2024 09:39:59 +0100
Subject: [PATCH] generator/daemon: Don't truncate 64 bit results from OCaml
functions
Commit d5b6f1df5f ("daemon: Allow parts of the daemon and APIs to be
written in OCaml.", 2017) contained a bug where in any OCaml function
that returns int64_t, the result was truncated to an int. This
particularly affected part_get_gpt_attributes as that returns large 64
bit numbers, but probably affects other functions too, undetected.
Fixes: commit d5b6f1df5ff2d387a5dfc89b8316c0dff67ce2c9
(cherry picked from commit 882ef4d93a2f8b150a66fa89f87ef1c4dd42de2f)
---
generator/daemon.ml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/generator/daemon.ml b/generator/daemon.ml
index a2c06f14..5dba2eee 100644
--- a/generator/daemon.ml
+++ b/generator/daemon.ml
@@ -835,7 +835,7 @@ let generate_daemon_caml_stubs () =
| RInt _ ->
pr " CAMLreturnT (int, Int_val (retv));\n"
| RInt64 _ ->
- pr " CAMLreturnT (int, Int64_val (retv));\n"
+ pr " CAMLreturnT (int64_t, Int64_val (retv));\n"
| RBool _ ->
pr " CAMLreturnT (int, Bool_val (retv));\n"
| RConstString _ -> assert false

View File

@ -45,7 +45,7 @@ Summary: Access and modify virtual machine disk images
Name: libguestfs
Epoch: 1
Version: 1.50.1
Release: 10%{?dist}
Release: 11%{?dist}
License: LGPLv2+
# Build only for architectures that have a kernel
@ -136,6 +136,10 @@ Patch0042: 0042-po-docs-Rename-guestfs-release-notes-historical-to-g.patch
Patch0043: 0043-po-docs-Run-po4a-translate-and-sed-commands-separate.patch
Patch0044: 0044-Update-common-submodule.patch
Patch0045: 0045-po-docs-Make-sure-guestmount.1-depends-on-includes.patch
Patch0046: 0046-test-data-binaries-Remove-x-attribute.patch
Patch0047: 0047-gobject-tests-Don-t-erase-error-messages.patch
Patch0048: 0048-daemon-parted-Assume-sfdisk-part-type-exists.patch
Patch0049: 0049-generator-daemon-Don-t-truncate-64-bit-results-from-.patch
%if 0%{patches_touch_autotools}
BuildRequires: autoconf, automake, libtool, gettext-devel
@ -1148,6 +1152,10 @@ rm ocaml/html/.gitignore
%changelog
* Fri Jun 28 2024 Richard W.M. Jones <rjones@redhat.com> - 1:1.50.1-11
- Fix (rare) undetected truncation of 64 bit int results to 32 bits
resolves: RHEL-45466
* Thu Jun 20 2024 Richard W.M. Jones <rjones@redhat.com> - 1:1.50.1-10
- Remove bundled ocaml-augeas
resolves: RHEL-32142