Commit Graph

11650 Commits

Author SHA1 Message Date
Richard W.M. Jones
a8c4c4fc23 valgrind: Add suppression for dlopen in glibc 2.35
See: f6409b4137
2022-03-01 11:07:54 +00:00
Richard W.M. Jones
e74656a134 valgrind: Modify suppressions for extra stack frame
When running the OCaml bytecode tests, small but apparently
unimportant differences in the stack frames caused the existing
suppressions not to match.  Adding an extra "..." will ignore these
differences allowing the tests to pass.

Valgrind output before this commit (note "UnknownInlinedFun" frame):

==1733400== 79 (48 direct, 31 indirect) bytes in 1 blocks are definitely lost in loss record 320 of 518
==1733400==    at 0x484A464: calloc (vg_replace_malloc.c:1328)
==1733400==    by 0x59685D0: g_malloc0 (gmem.c:136)
==1733400==    by 0x531BB59: virClassNew (virobject.c:191)
==1733400==    by 0x553A3BF: UnknownInlinedFun (datatypes.c:110)
==1733400==    by 0x553A3BF: virDataTypesOnce (datatypes.c:121)
==1733400==    by 0x49EA0C8: __pthread_once_slow (pthread_once.c:116)
==1733400==    by 0x53312E9: virOnce (virthread.c:44)
==1733400==    by 0x553A74A: UnknownInlinedFun (datatypes.c:121)
==1733400==    by 0x553A74A: virGetConnect (datatypes.c:133)
==1733400==    by 0x54FA94F: virConnectOpenInternal (libvirt.c:895)
==1733400==    by 0x54FB883: virConnectOpenAuth (libvirt.c:1277)
==1733400==    by 0x50E842A: guestfs_int_open_libvirt_connection.constprop.0 (libvirt-auth.c:224)
==1733400==    by 0x50C6120: launch_libvirt.lto_priv.0 (launch-libvirt.c:390)
==1733400==    by 0x5040E30: UnknownInlinedFun (launch.c:114)
==1733400==    by 0x5040E30: guestfs_launch (actions-3.c:513)
==1733400==
==1733400== 256 bytes in 1 blocks are definitely lost in loss record 481 of 518
==1733400==    at 0x484586F: malloc (vg_replace_malloc.c:381)
==1733400==    by 0x137A0E: UnknownInlinedFun (memory.c:824)
==1733400==    by 0x137A0E: caml_executable_name (unix.c:367)
==1733400==    by 0x14C224: UnknownInlinedFun (startup_byt.c:502)
==1733400==    by 0x14C224: caml_main (startup_byt.c:457)
==1733400==    by 0x11CEE1: main (main.c:41)
2022-03-01 10:50:09 +00:00
Laszlo Ersek
b6ef56187f TODO: remove "Better support for encrypted devices"
LUKS support used to work best if the LUKS device resided on a partition,
and contained a Physical Volume for an LVM Volume Group. This scheme, also
called LVM-on-LUKS, is commonly created by installers of various Linux
distributions. (See RHBZ#1451665.)

Libguestfs now also supports the scheme wherein the LUKS device resides on
an LVM Logical Volume, and contains a filesystem. This is called
LUKS-on-LVM, it is the inverse of the above scheme, and is created by
installers of other Linux distributions. (See RHBZ#1658126.)

Both schemes are now decrypted by libguestfs-based utilities when
inspection is enabled (such as in "guestfish -i", virt-inspector,
virt-v2v), through the inspect_mount() function in utilities written in C,
and through the "inspect_decrypt" function in ones written in OCaml.

We don't seem to need an API like "list-luks-devices", as
"list-dm-devices" returns decrypted (i.e., opened) LUKS devices too; for
example, in the LUKS-on-LVM case:

> ><fs> list-dm-devices
> /dev/mapper/luks-0d619854-ccd5-43b1-8883-991fec5ef713
> /dev/mapper/luks-4e9e7a6f-a68c-42fd-92b4-8f4f2579a389

Thus, the subject TODO section is now out of date, and it's unclear what
remains "to do" there; let's just remove the section.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1658126
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20220223162120.16729-4-lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
2022-02-28 13:12:25 +01:00
Laszlo Ersek
3221133140 tests: add LUKS-on-LVM test
Create a new (fake) Fedora disk image with two partitions. /dev/sda1 is
the boot partition as usual, /dev/sda2 is used as an LVM PV. The VG has
four LVs, Root and LV1 through LV3.

Each LV holds a LUKS device (with a different key). Each decrypted LUKS
device holds an ext2 filesystem, with "/dev/mapper/Root-luks" holding the
root filesystem.

Each filesystem has a dedicated label (ROOT, LV1, LV2, LV3).

In the test case, run guestfish in inspector mode, twice.

In the first invocation, provide the LUKS passphrases by LV name. Also
specific to the first invocation, fetch the LUKS UUIDs by LV name.

In the second invocation, provide the LUKS passphrases by UUID.

In both invocations, after decryption, check the filesystem labels, the
/dev/mapper/* names generated for the decrypted LUKS block devices, and
the existence of "/etc/fedora-release" on the root filesystem.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1658126
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20220223162120.16729-3-lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
2022-02-28 13:12:21 +01:00
Laszlo Ersek
39a5bb6fda tests: rename "luks" to "lvm-on-luks"
Clarify that our current usage of "luks" stands for "lvm-on-luks" (IOW,
that the decrypted LUKS devices are Physical Volumes for LVM).

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1658126
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20220223162120.16729-2-lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
2022-02-28 13:11:56 +01:00
Laszlo Ersek
ed7e3462a2 Update common submodule
$ git shortlog 41126802097f..2d8c0f8d40b5

Laszlo Ersek (2):
      options: extract & refactor decryption of mountables (partitions)
      options: decrypt LUKS-on-LV devices

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
2022-02-28 13:08:43 +01:00
Laszlo Ersek
b92c026ddb md-create: specify that the "chunk" parameter should be absent for RAID1
Recently, mdadm has started (correctly) rejecting the "chunk" parameter
for RAID1; see e.g. <https://bugzilla.redhat.com/show_bug.cgi?id=1987170>.
Update the documentation accordingly, and in the mdadm test case, move the
"chunk:65536" parameter from a RAID1 creation command to a RAID5 one.

Suggested-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20220217142944.8213-1-lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
2022-02-17 16:06:14 +01:00
Laszlo Ersek
19cc3dbcc4 Update common submodule
$ git shortlog 5b5fac3e0b10..41126802097f

Laszlo Ersek (3):
      Demote "Std_utils.wrap" to an internal function in Tools_utils
      Tools_utils.wrap: only wrap text for TTYs
      add common ("standard") option --wrap

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
2022-02-15 09:55:48 +01:00
Richard W.M. Jones
0553f90462 Update common submodule 2022-01-17 16:24:44 +00:00
Richard W.M. Jones
f019cc01b0 lib: Better handling for problems creating the socket path
GCC 12 gives a warning about our previous attempt to check the length
of the socket path.  In the ensuing discussion it was pointed out that
it is easier to get snprintf to do the hard work.  snprintf will
return an int >= UNIX_PATH_MAX if the path is too long, or < 0 if
there are other errors such as locale/encoding problems.  So we should
just check for those two cases instead.

https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/NPKWMTSJ2A2ABNJJEH6WTZIAEFTX6CQY/

Thanks: Martin Sebor and Laszlo Ersek
2022-01-17 15:50:36 +00:00
Richard W.M. Jones
d1e7e1a323 Version 1.47.2. v1.47.2 2021-12-24 10:08:03 +00:00
Laszlo Ersek
5858c2cf6c launch-libvirt: add virtio-net via the standard <interface> element
Starting with version 3.8.0, libvirt allows us to specify the network
address and network mask (as prefix) for SLIRP directly via the
<interface> element in the domain XML:
<https://libvirt.org/formatdomain.html#userspace-slirp-stack>. This means
we don't need the <qemu:commandline> hack for virtio-net on such versions.

Restrict the hack in construct_libvirt_xml_qemu_cmdline() to
libvirt<3.8.0, and generate the proper <interface> element in
construct_libvirt_xml_devices() on libvirt>=3.8.0.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2034160
Suggested-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20211223103701.12702-4-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Tested-by: Richard W.M. Jones <rjones@redhat.com>
2021-12-23 13:22:38 +01:00
Laszlo Ersek
216de164e0 lib: extract NETWORK_ADDRESS and NETWORK_PREFIX as macros
The 169.254.0.0/16 network specification (for the appliance) is currently
duplicated between the direct backend and the libvirt backend. In a
subsequent patch, we're going to need the network specification in yet
another spot; extract it now to the NETWORK_ADDRESS and NETWORK_PREFIX
macros (simply as strings).

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2034160
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20211223103701.12702-3-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Tested-by: Richard W.M. Jones <rjones@redhat.com>
2021-12-23 13:22:35 +01:00
Laszlo Ersek
5ce5ef6a97 launch-libvirt: place our virtio-net-pci device in slot 0x1e
The <qemu:commandline> trick we use for adding our virtio-net-pci device
in the libvirt backend can conflict with libvirtd's and QEMU's PCI address
assignment. Try to mitigate that by placing our device in slot 0x1e on the
root bus. In practice this could only conflict with a "dmi-to-pci-bridge"
device model, which libvirtd itself places in slot 0x1e. However, given
the XMLs we generate, and modern QEMU versions, libvirtd has no reason to
auto-add "dmi-to-pci-bridge". Refer to
<https://libvirt.org/formatdomain.html#controllers>.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2034160
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20211223103701.12702-2-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Tested-by: Richard W.M. Jones <rjones@redhat.com>
2021-12-23 13:22:14 +01:00
Richard W.M. Jones
4af6d68e2d fish: Avoid valgrind test from creating fish/.cache
Work around for https://bugzilla.redhat.com/show_bug.cgi?id=2031135
2021-12-10 16:18:03 +00:00
Richard W.M. Jones
c6b25262ee valgrind: Update suppressions list
For OCaml 4.13, libvirt 7.7.
2021-12-10 14:53:43 +00:00
Richard W.M. Jones
1941593585 Disable OCaml warning 6 completely
Warning 6 "labels-omitted" is not useful.  It's fine to omit labels on
positional arguments.

Example:

  File "perl_edit.ml", line 30, characters 2-13:
  30 |   c_edit_file (verbose ()) g (Guestfs.c_pointer g) file expr
         ^^^^^^^^^^^
  Warning 6 [labels-omitted]: label verbose was omitted in the application of this function.

The function is specified as:

  external c_edit_file : verbose:bool -> Guestfs.t -> int64 -> string -> string -> unit

The complaint is that the verbose: label has been omitted from the
first argument when the function is called, but IMO this is a
stylistic thing, not a bug.

(cherry picked from
guestfs-tools commit 577f7aee4b1c720f4c4826115b49a0c3870b149e)
2021-12-10 10:30:17 +00:00
Richard W.M. Jones
0d05a229f3 customize: Suppress OCaml warning
In OCaml 4.13:

File "perl_edit.ml", line 30, characters 2-13:
30 |   c_edit_file (verbose ()) g (Guestfs.c_pointer g) file expr
       ^^^^^^^^^^^
Error (warning 6 [labels-omitted]): label verbose was omitted in the application of this function.

(cherry picked from
guestfs-tools commit a4930f5fad82e5358d565b8cf3610970e9646259)
2021-12-10 10:30:11 +00:00
Richard W.M. Jones
b64e9bffc1 generator: Replace more "noalloc" with [@@noalloc]
In some places in the generator we were still generating "noalloc".
It was hidden from the previous regexp I used to replace these because
of string escaping.

Updates: commit a69cde79ca
2021-12-10 09:58:12 +00:00
Richard W.M. Jones
1e60550c2a Update common submodule
Picks up this commit:

    mlstdutils/std_utils.mli: Remove export of deprecated String.copy

    Since OCaml strings are at long last immutable, the String.copy
    function is deprecated.  Stop exporting it from our Std_utils.String.
    Any places we use it are wrong and should be fixed.
2021-12-10 09:55:51 +00:00
Neil Hanlon
631962c0e8 Add detection support for Rocky Linux (CentOS/RHEL-like)
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2030709
Thanks: label@rockylinux.org

---

RWMJ notes: I fixed the original patch so it compiled.  This patch
sets osinfo to "rocky8", which doesn't exist in the osinfo db yet.
Arguably we might want to set this to "centos8", but we can see what
libosinfo decides to do.  Here is partial virt-inspector output on a
Rocky Linux disk image:

$ ./run virt-inspector -a disk.img
<?xml version="1.0"?>
<operatingsystems>
  <operatingsystem>
    <root>/dev/rl/root</root>
    <name>linux</name>
    <arch>x86_64</arch>
    <distro>rocky</distro>
    <product_name>Rocky Linux 8.5 (Green Obsidian)</product_name>
    <major_version>8</major_version>
    <minor_version>5</minor_version>
    <package_format>rpm</package_format>
    <package_management>dnf</package_management>
    <hostname>localhost.localdomain</hostname>
    <osinfo>rocky8</osinfo>
    <mountpoints>
      <mountpoint dev="/dev/rl/root">/</mountpoint>
      <mountpoint dev="/dev/sda1">/boot</mountpoint>
    </mountpoints>
    <filesystems>
      <filesystem dev="/dev/rl/root">
        <type>xfs</type>
        <uuid>fed8331f-9f25-40cd-883e-090cd640559d</uuid>
      </filesystem>
      <filesystem dev="/dev/rl/swap">
        <type>swap</type>
        <uuid>6da2c121-ea7d-49ce-98a3-14a37fceaadd</uuid>
      </filesystem>
      <filesystem dev="/dev/sda1">
        <type>xfs</type>
        <uuid>4efafe61-2d20-4d93-8055-537e09bfd033</uuid>
      </filesystem>
    </filesystems>
2021-12-10 09:09:47 +00:00
Richard W.M. Jones
d6773c102d Version 1.47.1. v1.47.1 2021-12-09 17:26:05 +00:00
Richard W.M. Jones
90eb3a4184 lib, lua: Fix usage of strerror_r
$ ./run guestfish -vx add-drive foo "readonly:true"
  libguestfs: trace: set_pgroup true
  libguestfs: trace: set_pgroup = 0
  libguestfs: trace: add_drive "foo" "readonly:true"
  libguestfs: error: foo:
  libguestfs: trace: add_drive = -1 (error)
  libguestfs: trace: close
  libguestfs: closing guestfs handle 0x55c0bacf12a0 (state 0)

Fix the usage of strerror_r by using the new wrapper defined in
libguestfs-common.  A similar fix is made in the Lua bindings.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2030396
Reported-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Tested-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2021-12-09 13:46:28 +00:00
Laszlo Ersek
d829f9ff9a daemon/listfs: don't call "sgdisk -i" on bogus MBR partition table entry
The "is_partition_can_hold_filesystem" function calls
"Parted.part_get_gpt_type" on the partition if:
- the partition table type is GPT,
- or the partition table type is MBR, and the partition is primary or
  logical.

The one entry in the fake MBR partition table described in the previous
patch passes the second branch of this check, therefore
"Parted.part_get_gpt_type" is reached, and it invokes "sgdisk -i 1" on the
disk.

Surprisingly (not), while "sgdisk -i" copes fine with valid MBR partition
tables, it chokes on the fake one. The output does not contain the
"Partition GUID code" line, and so "sgdisk_info_extract_field" throws an
exception.

Prevent calling "Parted.part_get_gpt_type" on a bogus MBR partition table,
similarly to the "extended entry in MBR partition table" case; the
difference is that the bogus primary entry, unlike a valid extended entry,
*can* hold a filesystem.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1931821
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
Message-Id: <20211125094954.9713-6-lersek@redhat.com>
2021-11-26 10:17:54 +01:00
Laszlo Ersek
edfebee404 daemon/parted: work around part table type misreporting by "parted"
"parted" incorrectly reports "loop" rather than "msdos" for the partition
table type, when the (fake) partition table comes from the "--mbr" option
of "mkfs.fat" (in dosfstools-4.2+), and the FAT variant in question is
FAT16 or FAT32. (See RHBZ#2026224.) Work this around by
- parsing the partition table ourselves, and
- overriding "loop" with "msdos" when appropriate.

Note that when the FAT variant is FAT12, "parted" fails to parse the fake
MBR partition table completely (see RHBZ#2026220), which we cannot work
around. However, FAT12 should be a rare corner case in libguestfs usage --
"mkfs.fat" auto-chooses FAT12 only below 9MB disk size, and even "-F 12"
can only be forced up to and including 255MB disk size.

Add the helper function "has_bogus_mbr" to the Utils module; we'll use it
elsewhere too.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1931821
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
Message-Id: <20211125094954.9713-5-lersek@redhat.com>
[lersek@redhat.com: drop "fun" keyword, and use partial application, in
 the definition of "sec0at" [Rich]]
2021-11-26 10:17:05 +01:00
Laszlo Ersek
c33c2a1d13 daemon/parted: simplify print_partition_table() prototype
Since commit 994ca1f8eb ("daemon: Reimplement 'part_get_mbr_part_type'
API in OCaml.", 2018-05-02), we've not had any calls to
print_partition_table() that would pass a "false" argument for the
"add_m_option" parameter.

Remove the parameter, and inside part_get_mbr_part_type(), remove the dead
branch.

Relatedly, update the comment on the
"print_partition_table_machine_readable" OCaml function, originally from
commit 32e661f421 ("daemon: Reimplement ‘part_list’ API in OCaml.",
2017-07-27). Because print_partition_table() now passes "-m" to "parted"
unconditionally, and there are no use cases left that would *forbid* "-m",
"print_partition_table_machine_readable" is almost equivalent to
print_partition_table() -- modulo the enforcement of the "BYT;" header.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
Message-Id: <20211125094954.9713-4-lersek@redhat.com>
2021-11-26 10:16:06 +01:00
Laszlo Ersek
e3671362af daemon/9p: fix wrong pathname in error message
The directory that readdir() and closedir() work on is BUS_PATH
("/sys/bus/virtio/drivers/9pnet_virtio"), not "/sys/block". Fix the error
messages that are sent when readdir() or closedir() fails.

(The invalid "sys/block" pathname could be a leftover from when the
directory reading logic was (perhaps) copied from "daemon/sync.c".)

Fixes: 5f10c33503
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
Message-Id: <20211125094954.9713-3-lersek@redhat.com>
2021-11-26 10:16:05 +01:00
Laszlo Ersek
0ab9305055 daemon/mkfs: disable creation of fake MBR partition table with "mkfs.fat"
Search the usage output of "mkfs.fat" for "--mbr[="; cache the result for
further invocations. If the option is supported, pass "--mbr=n" to
"mkfs.fat". This will prevent the creation of a bogus partition table
whose first (and only) entry describes a partition that contains the
partition table.

(Such a bogus partition table breaks "parted", which is a tool used by
libguestfs extensively, both internally and in public libguestfs APIs.)

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1931821
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
Message-Id: <20211125094954.9713-2-lersek@redhat.com>
2021-11-26 10:16:05 +01:00
Richard W.M. Jones
e7f72ab146 xfs: Document lazy-counters setting cannot be changed in XFS version 5
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2024022
2021-11-22 15:11:20 +00:00
Richard W.M. Jones
9fda9110e6 Update common submodule
Removes old compat Bytes module.

Fixes: commit b536c61a6d
Thanks: Laszlo Ersek
2021-11-12 14:02:04 +00:00
Richard W.M. Jones
4fe8df48a7 tests/gdisk/test-expand-gpt.pl: Don't race with other tests
Another test was removing all disk_*.img files, which removed the file
used by this test.  This was ultimately caused by us using parallel
tests.

Put the disk image files back into the tests/gdisk/ subdirectory to
avoid this race.

Fixes: commit 6d32773e81
2021-11-09 11:49:06 +00:00
Richard W.M. Jones
30a3c72d51 tests/gdisk/test-expand-gpt.pl: Don't hide error message from qemu-img resize
In a test I ran qemu-img resize failed.  However because we redirected
stderr to /dev/null the error message was hidden.
2021-11-09 11:37:54 +00:00
Richard W.M. Jones
5da2b9f130 tests/gdisk/test-expand-gpt.pl: Fix some warnings
"my" variable $output masks earlier declaration in same scope at ./gdisk/test-expand-gpt.pl line 73.
"my" variable $end_sectors masks earlier declaration in same scope at ./gdisk/test-expand-gpt.pl line 78.
2021-11-09 11:36:50 +00:00
Richard W.M. Jones
60e9232f4e Move minimum OCaml version to 4.04.
Synchronize with common module which also requires 4.04.

Small adjustment to use of List.sort_uniq because the signature
changed slightly.
2021-11-09 10:21:30 +00:00
Richard W.M. Jones
a69cde79ca daemon: Replace "noalloc" with [@@noalloc] 2021-11-09 10:20:37 +00:00
Richard W.M. Jones
b536c61a6d m4: Remove test for OCaml Bytes module 2021-11-09 10:07:00 +00:00
Richard W.M. Jones
760d11ecfa rust: Use distclean to clean cache rather than make clean
Actually cargo caches downloaded libraries.  The previous change
caused cargo to download and rebuild these after make clean which is
overly aggressive.  Use make distclean instead.

Updates: commit 1834f19d20
2021-10-21 14:36:41 +01:00
Richard W.M. Jones
1834f19d20 rust: Wire up make clean so it runs cargo clean
Before this commit, after make clean:

$ du -sh rust
641M	rust

After:

776K	rust
2021-10-20 17:55:19 +01:00
Laszlo Ersek
305b02e7e7 daemon: inspection: Add support for Kylin (RHBZ#1995391).
Similar-to: cd08039d24
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20211013163023.21786-1-lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
2021-10-14 19:49:56 +02:00
Laszlo Ersek
f34bd6b12f build, docs: spell out minimum version (4.0.0) for the (optional) Yara lib
Commit e597fc5317 ("daemon/yara: fix undefined behavior due to Yara 4.0
API changes", 2021-10-12) prevents the daemon from using such a Yara
version that precedes 4.0.0.

If only yara < 4 is found, treat the library as absent, rather than
attempting and failing to compile the yara module of the daemon. Note the
version requirement in the documentation too.

Suggested-by: Eric Blake <eblake@redhat.com>
Suggested-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20211013133611.21599-4-lersek@redhat.com>
Acked-by: Eric Blake <eblake@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
2021-10-14 19:45:07 +02:00
Laszlo Ersek
4daec34a01 build: eliminate the AC_CHECK_LIB / AC_CHECK_HEADER tests for Yara
Eliminate the AC_CHECK_LIB / AC_CHECK_HEADER tests for Yara, for the
following reasons:

- Upstream Yara has provided a pkg-config file since 2015, so the
  (now-fixed) pkg-config check should always find it, without the
  AC_CHECK_LIB / AC_CHECK_HEADER fallback branch.

- In a subsequent patch, we'll want to test for the incompatible Yara API
  changes described at
  <https://github.com/VirusTotal/yara/wiki/Backward-incompatible-changes-in-YARA-4.0-API>.

  That's easy to do with pkg-config, but impossible with AC_CHECK_*,
  without a custom test. Namely, both AC_CHECK_DECLS and AC_CHECK_TYPES
  appear unable to check the parameter list of a function pointer typedef
  (namely YR_CALLBACK_FUNC and YR_COMPILER_CALLBACK_FUNC). And writing a
  dedicated test for this is overkill.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20211013133611.21599-3-lersek@redhat.com>
Acked-by: Eric Blake <eblake@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
2021-10-14 19:45:03 +02:00
Laszlo Ersek
54187b7f98 build: fix the pkg-config identifier of the (optional) Yara library
The upstream Yara project has always provided its "libyara/yara.pc.in"
file with "Name: yara" -- ever since its introduction in commit
334bd1a671ca ("Add support for pkg-config", 2015-01-08).

In spite of this, when the (optional) Yara dependency was added to
libguestfs in commit 2e24129da3 ("appliance: add yara dependency",
2017-05-02), PKG_CHECK_MODULES was invoked with [libyara] as
list-of-modules.

(That was clearly a bug. I'm unsure what Debian calls their Yara
pkg-config module, but calling it anything else than "yara" would be a
distribution bug: upstream projects provide pkg-config files specifically
so that dependent projects can find their dependencies *regardless of
distribution*.)

As a consequence, on Fedora today, the PKG_CHECK_MODULES macro always
fails, and only the AC_CHECK_LIB / AC_CHECK_HEADER branch finds Yara.

In a subsequent patch, we'll want to add a version requirement to the
PKG_CHECK_MODULES macro invocation, so at first, fix the pkg-config
identifier of Yara.

Fixes: 2e24129da3
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20211013133611.21599-2-lersek@redhat.com>
Acked-by: Eric Blake <eblake@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
2021-10-14 19:44:31 +02:00
Laszlo Ersek
e597fc5317 daemon/yara: fix undefined behavior due to Yara 4.0 API changes
Currently, the Yara test case ("yara/test-yara-scan.sh") fails, with the
following obscure error message:

> ><fs> yara-scan /text.txt
> libguestfs: error: deserialise_yara_detection_list:

Namely, the Yara rule match list serialization / de-serialization, between
the daemon and the library, is broken. It is caused by the following
incompatible pointer passing (i.e., undefined behavior), in function
do_internal_yara_scan(), file "daemon/yara.c":

>   r = yr_rules_scan_fd (rules, fd, 0, yara_rules_callback, (void *) path, 0);
                                        ^^^^^^^^^^^^^^^^^^^

The prototype of yara_rules_callback() is:

> static int
> yara_rules_callback (int code, void *message, void *data)

however, in Yara commit 2b121b166d25 ("Track string matches using
YR_SCAN_CONTEXT.", 2020-02-27), which was included in the upstream v4.0.0
release, the rules callback prototype was changed as follows:

> diff --git a/libyara/include/yara/types.h b/libyara/include/yara/types.h
> index cad095cd70c2..f415033c4aa6 100644
> --- a/libyara/include/yara/types.h
> +++ b/libyara/include/yara/types.h
> @@ -661,6 +644,7 @@ struct YR_MEMORY_BLOCK_ITERATOR
>
>
>  typedef int (*YR_CALLBACK_FUNC)(
> +    YR_SCAN_CONTEXT* context,
>      int message,
>      void* message_data,
>      void* user_data);

Therefore, the yara_rules_callback() function is entered with a mismatched
parameter list in the daemon, and so it passes garbage to
send_detection_info(), for serializing the match list.

This incompatible change was in fact documented by the Yara project:

  https://github.com/VirusTotal/yara/wiki/Backward-incompatible-changes-in-YARA-4.0-API#scanning-callback

Gcc too warns about the incompatible pointer type, under
"-Wincompatible-pointer-types". However, libguestfs is built without
"-Werror" by default, so the warning is easy to miss, and the bug only
manifests at runtime.

(The same problem exists for yr_compiler_set_callback() /
compile_error_callback():

  https://github.com/VirusTotal/yara/wiki/Backward-incompatible-changes-in-YARA-4.0-API#compiler-callback

except that this instance of the problem is not triggered by the test
case, as the rule list always compiles.)

Rather than simply fixing the parameter lists, consider the following
approach.

If Yara's YR_CALLBACK_FUNC and YR_COMPILER_CALLBACK_FUNC typedefs were not
for *pointer* types but actual *function* prototypes, then we could use
them directly in the declarations of our callback functions. Then any
future changes in the param lists would force a "conflicting types"
*compilation error* (not a warning). Illustration:

  /* this is *not* a pointer type */
  typedef int HELLO_FUNC (void);

  /* function declarations */
  static HELLO_FUNC my_hello_good;
  static HELLO_FUNC my_hello_bad;

  /* function definition, with explicit parameter list */
  static int my_hello_good (void) { return 1; }

  /* function definition with wrong param list -> compilation error */
  static int my_hello_bad (int i) { return i; }

Unfortunately, given that the Yara-provided typedefs are already pointers,
we can't do this, in standard C anyway. Type derivation only allows for
array, structure, union, function, and pointer type derivation; it does
not allow "undoing" previous derivations.

However, using gcc's "typeof" keyword, the idea is possible. Given
YR_CALLBACK_FUNC, the expression

  (YR_CALLBACK_FUNC)NULL

is a well-defined null pointer, and the function designator expression

  *(YR_CALLBACK_FUNC)NULL

has the desired function type.

Of course, evaluating this expression would be undefined behavior, but in
the GCC extension expression

  typeof (*(YR_CALLBACK_FUNC)NULL)

the operand of the "typeof" operator is never evaluated, as it does not
have a variably modified type. We can therefore use this "typeof" in the
same role as HELLO_FUNC had in the above example.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20211011223627.20856-4-lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
[lersek@redhat.com: clean up whitespace in "YR_RULE *rule"]
2021-10-12 16:48:04 +02:00
Laszlo Ersek
98ed0243e7 lib/proto: suppress "may be used uninitialized" in send_file_complete()
gcc emits the following warning:

> proto.c: In function ‘send_file_complete’:
> proto.c:437:10: error: ‘buf’ may be used uninitialized
> [-Werror=maybe-uninitialized]
>   437 |   return send_file_chunk (g, 0, buf, 0);
>       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In theory, passing the 1-byte array "buf", with indeterminate contents, to
xdr_bytes() ultimately, could be fine -- assuming xdr_bytes() never reads
the contents of the buffer, due to the buffer size being zero. However,
the xdr_bytes() manual does not seem to guarantee this (it also does not
explicitly permit passing a NULL buffer alongside size=0, which would be
even simpler for the caller).

In order to shut up the compiler, just zero-initialize the buffer --
that's simpler than adding diagnostics pragmas. The "maybe-uninitialized"
warning is otherwise very useful, so keep it globally enabled (per
WARN_CFLAGS / WERROR_CFLAGS).

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20211011223627.20856-3-lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
2021-10-12 16:48:01 +02:00
Laszlo Ersek
7915938b8e build: fix typo in "--enable-werror" help string
While <https://libguestfs.org/guestfs-building.1.html> correctly documents
the "--enable-werror" option, the "./configure" help text itself doesn't.
Replace "--enable-error" with "--enable-werror" now.

Fixes: 0f54df53d2
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20211011223627.20856-2-lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
2021-10-12 16:47:37 +02:00
Richard W.M. Jones
63c9cd933a m4/guestfs-ocaml.m4: Fix deprecated warning format
In OCaml 4.13:

Alert ocaml_deprecated_cli: Setting a warning with a sequence of lowercase or uppercase letters,
like 'CDEFLMPSUVYZX', is deprecated.
Use the equivalent signed form: +C+D+E+F+L+M+P+S+U+V+Y+Z+X+52-3.

(cherry picked from
guestfs-tools commit fa4f59e1d99c08d7e0bae2a7cb54f254a6506d67)
2021-10-05 21:08:07 +01:00
Laszlo Ersek
3f6f2fb8f6 daemon/inspect_fs_unix: recognize modern Pardus GNU/Linux releases
Recent Pardus releases seem to have abandoned the original
"/etc/pardus-release" file, which the current Pardus detection, from
commit 233530d354 ("inspect: Add detection of Pardus.", 2010-10-29), is
based upon.

Instead, Pardus apparently adopted the "/etc/os-release" specification
<https://www.freedesktop.org/software/systemd/man/os-release.html>, with
"ID=pardus". Extend the "distro_of_os_release_id" function accordingly.
Keep the original method for recognizing earlier releases.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1993842
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20211001125338.8956-1-lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
2021-10-01 15:34:25 +02:00
Laszlo Ersek
e2f8db27d0 Go bindings: fix "C array of strings" -- char** -- allocation
The current "arg_string_list" and "free_string_list" implementations go
back to commit b6f01f3260 ("Add Go (language) bindings.", 2013-07-03).
There are two problems with them:

- "free_string_list" doesn't actually free anything,

- at the *first* such g.Internal_test() call site that passes an
  Ostringlist member inside the Optargs argument, namely:

> g.Internal_test ("abc",
>                  string_addr ("def"),
>                  []string{},
>                  false,
>                  0,
>                  0,
>                  "123",
>                  "456",
>                  []byte{'a', 'b', 'c', '\000', 'a', 'b', 'c'},
>                  &guestfs.OptargsInternal_test{Ostringlist_is_set: true,
>                                                Ostringlist: []string{}
>                                               }
>                 )

  the "golang/run-bindtests" case crashes:

> panic: runtime error: cgo argument has Go pointer to Go pointer
>
> goroutine 1 [running]:
> libguestfs.org/guestfs.(*Guestfs).Internal_test.func7(0xc000018180,
> 0xadfb60, 0xadfb80, 0xc000010048, 0x0, 0x0, 0x0, 0xae3e10, 0xae3e30,
> 0xade3a0, ...)
>         golang/src/libguestfs.org/guestfs/guestfs.go:6729 +0xa9
> libguestfs.org/guestfs.(*Guestfs).Internal_test(0xc000018180, 0x4ee3a5,
> 0x3, 0xc000061be8, 0xc000061af8, 0x0, 0x0, 0xc000061a00, 0x0, 0x0, ...)
>         golang/src/libguestfs.org/guestfs/guestfs.go:6729 +0x3c9
> main.main()
>         golang/bindtests/bindtests.go:77 +0x151e
> exit status 2
> FAIL run-bindtests (exit status: 1)

In Daniel P. Berrangé's words [1],

> You're allowed to pass a Go pointer to C via CGo, but the memory that
> points to is not allowed to contained further Go pointers. So the struct
> fields must strictly use a C pointer.

One pattern to solve the problem has been shown on stackoverflow [2].
Thus, rewrite the "arg_string_list" and "free_string_list" functions
almost entirely in C, following that example.

While this approach is not the most idiomatic Go, as a solution exists
without C helper functions [3], it should still be acceptable, at least as
an incremental improvement, for letting "golang/run-bindtests" pass.

[1] https://listman.redhat.com/archives/libguestfs/2021-September/msg00118.html
[2] https://stackoverflow.com/questions/35924545/golang-cgo-panic-runtime-error-cgo-argument-has-go-pointer-to-go-pointer
[3] https://listman.redhat.com/archives/libguestfs/2021-September/msg00106.html

Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: "Richard W.M. Jones" <rjones@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20210921192939.32468-1-lersek@redhat.com>
Tested-by: "Richard W.M. Jones" <rjones@redhat.com>
Acked-by: "Richard W.M. Jones" <rjones@redhat.com>
2021-09-27 09:57:34 +02:00
Richard W.M. Jones
5c68392175 Version 1.46.0. v1.46.0 2021-09-23 14:52:46 +01:00
Richard W.M. Jones
5b432781e2 build: Remove BUGS file
Recent changes to Red Hat Bugzilla broke our ability to generate this
file.  In any case it's not very useful since a simple Bugzilla query
can be used instead:

https://bugzilla.redhat.com/buglist.cgi?component=libguestfs

Remove the file.  The generator used this file to ensure it was being
run from the correct directory and to take a lock.  Use RELEASES file
instead.

See also: https://github.com/python-bugzilla/python-bugzilla/issues/149
2021-09-23 14:52:46 +01:00