[PATCH] init: Don't allocate modules on the stack (RHBZ#1339691).
by Richard W.M. Jones
If the modules are unstripped and/or especially large, then the stack
can overflow.
---
init/init.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/init/init.c b/init/init.c
index 106be02..733d66e 100644
--- a/init/init.c
+++ b/init/init.c
@@ -314,7 +314,11 @@ insmod (const char *filename)
exit (EXIT_FAILURE);
}
size = st.st_size;
- char buf[size];
+ char *buf = malloc (size);
+ if (buf == NULL) {
+ fprintf (stderr, "insmod: malloc (%s, %zu bytes): %m\n", filename, size);
+ exit (EXIT_FAILURE);
+ }
size_t offset = 0;
do {
ssize_t rc = read (fd, buf + offset, size - offset);
@@ -332,6 +336,8 @@ insmod (const char *filename)
* of a missing device.
*/
}
+
+ free (buf);
}
/* Mount /proc unless it's mounted already. */
--
2.7.4
8 years, 7 months
[PATCH] rescue: add --autosysroot option RHBZ#1183493
by Maros Zatko
--autosysroot option uses suggestions to user on how to mount filesystems
and change root suggested by --suggest option in virt-rescue.
Commands are passed on kernel command line in format
guestfs_command=command;. Command ends with a semicolon and there can be
multiple commands specified. These are executed just before bash starts.
On successfull run user is presented directly with bash in chroot
environment.
RFE: RHBZ#1183493
Depends on commit: utils: make guestfs_int_count_strings return 0 on NULL input
Maros Zatko (1):
rescue: add --autosysroot option RHBZ#1183493
appliance/init | 6 +++
rescue/rescue.c | 160 ++++++++++++++++++++++++++++++++++++++++++++------------
2 files changed, 134 insertions(+), 32 deletions(-)
--
2.5.5
8 years, 7 months
[PATCH 1/3] inspect: recognize the Void Linux distribution
by Pino Toscano
Since Void Linux provides only an /etc/os-release with no VERSION_ID
field, then special-case it to avoid that the os-release parsing ignore
it.
This provides basic distro identification, and icon.
---
generator/actions.ml | 4 ++++
inspector/virt-inspector.rng | 1 +
src/guestfs-internal.h | 1 +
src/inspect-fs-unix.c | 14 ++++++++++++--
src/inspect-fs.c | 2 ++
src/inspect-icon.c | 13 +++++++++++++
src/inspect.c | 1 +
7 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/generator/actions.ml b/generator/actions.ml
index b17808e..25d3c0d 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -1183,6 +1183,10 @@ Ubuntu.
The distro could not be determined.
+=item \"voidlinux\"
+
+Void Linux.
+
=item \"windows\"
Windows does not have distributions. This string is
diff --git a/inspector/virt-inspector.rng b/inspector/virt-inspector.rng
index c861c80..c4c423c 100644
--- a/inspector/virt-inspector.rng
+++ b/inspector/virt-inspector.rng
@@ -108,6 +108,7 @@
<value>suse-based</value>
<value>ttylinux</value>
<value>ubuntu</value>
+ <value>voidlinux</value>
<value>windows</value>
<!-- "unknown" is intentionally left out -->
</choice>
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 0340687..8a36ab7 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -569,6 +569,7 @@ enum inspect_os_distro {
OS_DISTRO_ALTLINUX,
OS_DISTRO_FRUGALWARE,
OS_DISTRO_PLD_LINUX,
+ OS_DISTRO_VOID_LINUX,
};
enum inspect_os_package_format {
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 0e64e33..4d41086 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -216,6 +216,8 @@ parse_os_release (guestfs_h *g, struct inspect_fs *fs, const char *filename)
distro = OS_DISTRO_SLES;
else if (VALUE_IS ("ubuntu"))
distro = OS_DISTRO_UBUNTU;
+ else if (VALUE_IS ("void"))
+ distro = OS_DISTRO_VOID_LINUX;
} else if (STRPREFIX (line, "PRETTY_NAME=")) {
free (product_name);
product_name = safe_strndup (g, value, value_len);
@@ -229,10 +231,18 @@ parse_os_release (guestfs_h *g, struct inspect_fs *fs, const char *filename)
}
/* If we haven't got all the fields, exit right away. */
- if (distro == OS_DISTRO_UNKNOWN || product_name == NULL ||
- version.v_major == -1 || version.v_minor == -1)
+ if (distro == OS_DISTRO_UNKNOWN || product_name == NULL)
return 0;
+ if (version.v_major == -1 || version.v_minor == -1) {
+ /* Void Linux has no VERSION_ID (yet), but since it's a rolling
+ * distro and has no other version/release-like file. */
+ if (distro == OS_DISTRO_VOID_LINUX)
+ version_init_null (&version);
+ else
+ return 0;
+ }
+
/* Apparently, os-release in Debian and CentOS does not provide the full
* version number in VERSION_ID, but just the "major" part of it.
* Hence, if version.v_minor is 0, act as there was no information in
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index ca96667..c718773 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -499,6 +499,7 @@ guestfs_int_check_package_format (guestfs_h *g, struct inspect_fs *fs)
case OS_DISTRO_OPENBSD:
case OS_DISTRO_FRUGALWARE:
case OS_DISTRO_PLD_LINUX:
+ case OS_DISTRO_VOID_LINUX:
case OS_DISTRO_UNKNOWN:
fs->package_format = OS_PACKAGE_FORMAT_UNKNOWN;
break;
@@ -583,6 +584,7 @@ guestfs_int_check_package_management (guestfs_h *g, struct inspect_fs *fs)
case OS_DISTRO_OPENBSD:
case OS_DISTRO_FRUGALWARE:
case OS_DISTRO_PLD_LINUX:
+ case OS_DISTRO_VOID_LINUX:
case OS_DISTRO_UNKNOWN:
fs->package_management = OS_PACKAGE_MANAGEMENT_UNKNOWN;
break;
diff --git a/src/inspect-icon.c b/src/inspect-icon.c
index 2f084b7..e8edee0 100644
--- a/src/inspect-icon.c
+++ b/src/inspect-icon.c
@@ -61,6 +61,7 @@ static char *icon_opensuse (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
#if CAN_DO_CIRROS
static char *icon_cirros (guestfs_h *g, struct inspect_fs *fs, size_t *size_r);
#endif
+static char *icon_voidlinux (guestfs_h *g, struct inspect_fs *fs, size_t *size_r);
#if CAN_DO_WINDOWS
static char *icon_windows (guestfs_h *g, struct inspect_fs *fs, size_t *size_r);
#endif
@@ -158,6 +159,10 @@ guestfs_impl_inspect_get_icon (guestfs_h *g, const char *root, size_t *size_r,
#endif
break;
+ case OS_DISTRO_VOID_LINUX:
+ r = icon_voidlinux (g, fs, &size);
+ break;
+
/* These are just to keep gcc warnings happy. */
case OS_DISTRO_ARCHLINUX:
case OS_DISTRO_BUILDROOT:
@@ -420,6 +425,14 @@ icon_cirros (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
#endif /* CAN_DO_CIRROS */
+#define VOIDLINUX_ICON "/usr/share/void-artwork/void-logo.png"
+
+static char *
+icon_voidlinux (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
+{
+ return get_png (g, fs, VOIDLINUX_ICON, size_r, 20480);
+}
+
#if CAN_DO_WINDOWS
/* Windows, as usual, has to be much more complicated and stupid than
diff --git a/src/inspect.c b/src/inspect.c
index bd32d8f..29b4f85 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -291,6 +291,7 @@ guestfs_impl_inspect_get_distro (guestfs_h *g, const char *root)
case OS_DISTRO_TTYLINUX: ret = safe_strdup (g, "ttylinux"); break;
case OS_DISTRO_WINDOWS: ret = safe_strdup (g, "windows"); break;
case OS_DISTRO_UBUNTU: ret = safe_strdup (g, "ubuntu"); break;
+ case OS_DISTRO_VOID_LINUX: ret = safe_strdup (g, "voidlinux"); break;
case OS_DISTRO_UNKNOWN: ret = safe_strdup (g, "unknown"); break;
}
--
2.5.5
8 years, 7 months
[PATCH] utils: make guestfs_int_count_strings return 0 on NULL input
by Maros Zatko
This miniature patch makes function guestfs_int_count_strings accept NULL input
and return 0 signalling that it is empty list. It makes it more usefull with
NULL initialized variables and a tiny bit more robust.
Maros Zatko (1):
utils: make guestfs_int_count_strings return 0 on NULL input
src/utils.c | 3 +++
1 file changed, 3 insertions(+)
--
2.5.5
8 years, 7 months
[PATCH v3 0/3] SUSE VMDP support
by Cédric Bosdonnat
Hi there,
Here is v3 of the remaining patches. Diff to v2:
* Removed the patch related to QXL
* Fixed the firstboot script with Roman's comments
* Fixed ova with subfolders test
* Handle MF-relative path in ova files
* Fixed now unneeded match case as per Richard's comment
Cédric Bosdonnat (3):
customize: fix windows firstboot script
v2v: add support for SUSE VMDP drivers
v2v: handle subfolders in ova files
customize/firstboot.ml | 10 +--
v2v/Makefile.am | 1 +
v2v/convert_windows.ml | 77 +++++++++++++-----
v2v/input_ova.ml | 6 +-
v2v/test-v2v-i-ova-subfolders.expected | 18 +++++
v2v/test-v2v-i-ova-subfolders.ovf | 138 +++++++++++++++++++++++++++++++++
v2v/test-v2v-i-ova-subfolders.sh | 65 ++++++++++++++++
v2v/windows_virtio.ml | 35 ++++++---
8 files changed, 312 insertions(+), 38 deletions(-)
create mode 100644 v2v/test-v2v-i-ova-subfolders.expected
create mode 100644 v2v/test-v2v-i-ova-subfolders.ovf
create mode 100755 v2v/test-v2v-i-ova-subfolders.sh
--
2.6.6
8 years, 7 months
[PATCH 1/5] mllib: make external_command echo the command executed
by Pino Toscano
Add an optional parameter to disable this behaviour, so the Curl module
in v2v won't print user-sensible data (like passwords).
---
builder/checksums.ml | 1 -
builder/downloader.ml | 1 -
builder/sigchecker.ml | 1 -
mllib/common_utils.ml | 4 +++-
mllib/common_utils.mli | 7 +++++--
v2v/curl.ml | 2 +-
6 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/builder/checksums.ml b/builder/checksums.ml
index 95103e9..c8cdc98 100644
--- a/builder/checksums.ml
+++ b/builder/checksums.ml
@@ -43,7 +43,6 @@ let verify_checksum csum filename =
in
let cmd = sprintf "%s %s" prog (quote filename) in
- debug "%s" cmd;
let lines = external_command cmd in
match lines with
| [] ->
diff --git a/builder/downloader.ml b/builder/downloader.ml
index e31748d..7dc0a29 100644
--- a/builder/downloader.ml
+++ b/builder/downloader.ml
@@ -99,7 +99,6 @@ and download_to t ?(progress_bar = false) ~proxy uri filename =
t.curl
(if verbose () then "" else " -s -S")
(quote uri) in
- debug "%s" cmd;
let lines = external_command cmd in
if List.length lines < 1 then
error (f_"unexpected output from curl command, enable debug and look at previous messages");
diff --git a/builder/sigchecker.ml b/builder/sigchecker.ml
index 2b77193..39a2766 100644
--- a/builder/sigchecker.ml
+++ b/builder/sigchecker.ml
@@ -69,7 +69,6 @@ let import_keyfile ~gpg ~gpghome ?(trust = true) keyfile =
* fingerprint of the subkeys. *)
let cmd = sprintf "%s --homedir %s --with-colons --with-fingerprint --with-fingerprint --list-keys %s"
gpg gpghome !fingerprint in
- debug "%s" cmd;
let lines = external_command cmd in
let current = ref None in
let subkeys = ref [] in
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index 0ffa92c..32071f4 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -649,7 +649,9 @@ let compare_lvm2_uuids uuid1 uuid2 =
loop 0 0
(* Run an external command, slurp up the output as a list of lines. *)
-let external_command cmd =
+let external_command ?(echo_cmd = true) cmd =
+ if echo_cmd then
+ debug "%s" cmd;
let chan = Unix.open_process_in cmd in
let lines = ref [] in
(try while true do lines := input_line chan :: !lines done
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index 666e023..a216e21 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -239,8 +239,11 @@ val compare_version : string -> string -> int
val compare_lvm2_uuids : string -> string -> int
(** Compare two LVM2 UUIDs, ignoring '-' characters. *)
-val external_command : string -> string list
-(** Run an external command, slurp up the output as a list of lines. *)
+val external_command : ?echo_cmd:bool -> string -> string list
+(** Run an external command, slurp up the output as a list of lines.
+
+ [echo_cmd] specifies whether output the full command on verbose
+ mode, and it's on by default. *)
val uuidgen : unit -> string
(** Run uuidgen to return a random UUID. *)
diff --git a/v2v/curl.ml b/v2v/curl.ml
index 046cba2..f0af160 100644
--- a/v2v/curl.ml
+++ b/v2v/curl.ml
@@ -48,7 +48,7 @@ let run curl_args =
close_out chan;
let cmd = sprintf "curl -q --config %s" (Filename.quote config_file) in
- let lines = external_command cmd in
+ let lines = external_command ~echo_cmd:false cmd in
Unix.unlink config_file;
lines
--
2.5.5
8 years, 7 months
[PATCH] umask: Use /proc/<PID>/status to read umask in Linux >= 4.7.
by Richard W.M. Jones
Since Linux 4.7, the process umask is available in /proc/<pid>/status.
See:
https://github.com/torvalds/linux/commit/3e42979e65dace1f9268dd5440e5ab09...
Use this value if available, else fall back to the existing codepath
for Linux <= 4.6 and other Unix.
---
src/umask.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 78 insertions(+), 8 deletions(-)
diff --git a/src/umask.c b/src/umask.c
index b8748e8..3f32337 100644
--- a/src/umask.c
+++ b/src/umask.c
@@ -18,12 +18,22 @@
/**
* Return current umask in a thread-safe way.
+ *
+ * glibc documents, but does not actually implement, a "getumask(3)"
+ * call.
+ *
+ * We use C<Umask> from F</proc/I<PID>/status> for Linux E<ge> 4.7.
+ * For older Linux and other Unix, this file implements an expensive
+ * but thread-safe way to get the current process's umask.
+ *
+ * Thanks to: Josh Stone, Jiri Jaburek, Eric Blake.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
@@ -35,21 +45,81 @@
#include "guestfs.h"
#include "guestfs-internal.h"
+static int get_umask_from_proc (guestfs_h *g);
+static int get_umask_from_fork (guestfs_h *g);
+
/**
- * glibc documents, but does not actually implement, a L<getumask(3)>
- * call.
- *
- * This function implements an expensive, but thread-safe way to get
- * the current process's umask.
- *
* Returns the current process's umask. On failure, returns C<-1> and
* sets the error in the guestfs handle.
- *
- * Thanks to: Josh Stone, Jiri Jaburek, Eric Blake.
*/
int
guestfs_int_getumask (guestfs_h *g)
{
+ int mask;
+
+ mask = get_umask_from_proc (g);
+ if (mask == -1)
+ return -1;
+ if (mask >= 0)
+ return mask;
+
+ return get_umask_from_fork (g);
+}
+
+/**
+ * For Linux E<ge> 4.7 get the umask from F</proc/I<PID>/status>.
+ *
+ * On failure this returns C<-1>. However if we could not open the
+ * F</proc> file or find the C<Umask> entry in it, return C<-2> which
+ * causes the fallback path to run.
+ */
+static int
+get_umask_from_proc (guestfs_h *g)
+{
+ FILE *fp;
+ CLEANUP_FREE char *path = NULL, *line = NULL;
+ size_t allocsize;
+ ssize_t len;
+ unsigned int mask;
+ bool found = false;
+
+ path = safe_asprintf (g, "/proc/%d/status", getpid ());
+ fp = fopen (path, "r");
+ if (fp == NULL) {
+ if (errno == ENOENT || errno == ENOTDIR)
+ return -2; /* fallback */
+ perrorf (g, "open: %s", path);
+ return -1;
+ }
+
+ while ((len = getline (&line, &allocsize, fp)) != -1) {
+ if (len > 0 && line[len-1] == '\n')
+ line[--len] = '\0';
+
+ /* Looking for: "Umask: 0022" */
+ if (sscanf (line, "Umask: %o", &mask) == 1) {
+ found = true;
+ break;
+ }
+ }
+
+ if (fclose (fp) == -1) {
+ perrorf (g, "close: %s", path);
+ return -1;
+ }
+
+ if (!found)
+ return -2; /* fallback */
+
+ return (int) mask;
+}
+
+/**
+ * Fallback method of getting the umask using fork.
+ */
+static int
+get_umask_from_fork (guestfs_h *g)
+{
pid_t pid;
int fd[2], r;
int mask;
--
2.7.4
8 years, 7 months