Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e55fdbd7 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
* git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus:
  virtio: remove virtio-pci root device
  LGUEST_GUEST: fix unmet direct dependencies (VIRTUALIZATION && VIRTIO)
  lguest: compile fixes
  lguest: Use this_cpu_ops
  lguest: document --rng in example Launcher
  lguest: example launcher to use guard pages, drop PROT_EXEC, fix limit logic
  lguest: --username and --chroot options
parents c522682d 8b3bb3ec
Loading
Loading
Loading
Loading
+65 −8
Original line number Original line Diff line number Diff line
@@ -39,6 +39,9 @@
#include <limits.h>
#include <limits.h>
#include <stddef.h>
#include <stddef.h>
#include <signal.h>
#include <signal.h>
#include <pwd.h>
#include <grp.h>

#include <linux/virtio_config.h>
#include <linux/virtio_config.h>
#include <linux/virtio_net.h>
#include <linux/virtio_net.h>
#include <linux/virtio_blk.h>
#include <linux/virtio_blk.h>
@@ -298,20 +301,27 @@ static void *map_zeroed_pages(unsigned int num)


	/*
	/*
	 * We use a private mapping (ie. if we write to the page, it will be
	 * We use a private mapping (ie. if we write to the page, it will be
	 * copied).
	 * copied). We allocate an extra two pages PROT_NONE to act as guard
	 * pages against read/write attempts that exceed allocated space.
	 */
	 */
	addr = mmap(NULL, getpagesize() * num,
	addr = mmap(NULL, getpagesize() * (num+2),
		    PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, fd, 0);
		    PROT_NONE, MAP_PRIVATE, fd, 0);

	if (addr == MAP_FAILED)
	if (addr == MAP_FAILED)
		err(1, "Mmapping %u pages of /dev/zero", num);
		err(1, "Mmapping %u pages of /dev/zero", num);


	if (mprotect(addr + getpagesize(), getpagesize() * num,
		     PROT_READ|PROT_WRITE) == -1)
		err(1, "mprotect rw %u pages failed", num);

	/*
	/*
	 * One neat mmap feature is that you can close the fd, and it
	 * One neat mmap feature is that you can close the fd, and it
	 * stays mapped.
	 * stays mapped.
	 */
	 */
	close(fd);
	close(fd);


	return addr;
	/* Return address after PROT_NONE page */
	return addr + getpagesize();
}
}


/* Get some more pages for a device. */
/* Get some more pages for a device. */
@@ -343,7 +353,7 @@ static void map_at(int fd, void *addr, unsigned long offset, unsigned long len)
	 * done to it.  This allows us to share untouched memory between
	 * done to it.  This allows us to share untouched memory between
	 * Guests.
	 * Guests.
	 */
	 */
	if (mmap(addr, len, PROT_READ|PROT_WRITE|PROT_EXEC,
	if (mmap(addr, len, PROT_READ|PROT_WRITE,
		 MAP_FIXED|MAP_PRIVATE, fd, offset) != MAP_FAILED)
		 MAP_FIXED|MAP_PRIVATE, fd, offset) != MAP_FAILED)
		return;
		return;


@@ -573,10 +583,10 @@ static void *_check_pointer(unsigned long addr, unsigned int size,
			    unsigned int line)
			    unsigned int line)
{
{
	/*
	/*
	 * We have to separately check addr and addr+size, because size could
	 * Check if the requested address and size exceeds the allocated memory,
	 * be huge and addr + size might wrap around.
	 * or addr + size wraps around.
	 */
	 */
	if (addr >= guest_limit || addr + size >= guest_limit)
	if ((addr + size) > guest_limit || (addr + size) < addr)
		errx(1, "%s:%i: Invalid address %#lx", __FILE__, line, addr);
		errx(1, "%s:%i: Invalid address %#lx", __FILE__, line, addr);
	/*
	/*
	 * We return a pointer for the caller's convenience, now we know it's
	 * We return a pointer for the caller's convenience, now we know it's
@@ -1872,6 +1882,8 @@ static struct option opts[] = {
	{ "block", 1, NULL, 'b' },
	{ "block", 1, NULL, 'b' },
	{ "rng", 0, NULL, 'r' },
	{ "rng", 0, NULL, 'r' },
	{ "initrd", 1, NULL, 'i' },
	{ "initrd", 1, NULL, 'i' },
	{ "username", 1, NULL, 'u' },
	{ "chroot", 1, NULL, 'c' },
	{ NULL },
	{ NULL },
};
};
static void usage(void)
static void usage(void)
@@ -1894,6 +1906,12 @@ int main(int argc, char *argv[])
	/* If they specify an initrd file to load. */
	/* If they specify an initrd file to load. */
	const char *initrd_name = NULL;
	const char *initrd_name = NULL;


	/* Password structure for initgroups/setres[gu]id */
	struct passwd *user_details = NULL;

	/* Directory to chroot to */
	char *chroot_path = NULL;

	/* Save the args: we "reboot" by execing ourselves again. */
	/* Save the args: we "reboot" by execing ourselves again. */
	main_args = argv;
	main_args = argv;


@@ -1950,6 +1968,14 @@ int main(int argc, char *argv[])
		case 'i':
		case 'i':
			initrd_name = optarg;
			initrd_name = optarg;
			break;
			break;
		case 'u':
			user_details = getpwnam(optarg);
			if (!user_details)
				err(1, "getpwnam failed, incorrect username?");
			break;
		case 'c':
			chroot_path = optarg;
			break;
		default:
		default:
			warnx("Unknown argument %s", argv[optind]);
			warnx("Unknown argument %s", argv[optind]);
			usage();
			usage();
@@ -2021,6 +2047,37 @@ int main(int argc, char *argv[])
	/* If we exit via err(), this kills all the threads, restores tty. */
	/* If we exit via err(), this kills all the threads, restores tty. */
	atexit(cleanup_devices);
	atexit(cleanup_devices);


	/* If requested, chroot to a directory */
	if (chroot_path) {
		if (chroot(chroot_path) != 0)
			err(1, "chroot(\"%s\") failed", chroot_path);

		if (chdir("/") != 0)
			err(1, "chdir(\"/\") failed");

		verbose("chroot done\n");
	}

	/* If requested, drop privileges */
	if (user_details) {
		uid_t u;
		gid_t g;

		u = user_details->pw_uid;
		g = user_details->pw_gid;

		if (initgroups(user_details->pw_name, g) != 0)
			err(1, "initgroups failed");

		if (setresgid(g, g, g) != 0)
			err(1, "setresgid failed");

		if (setresuid(u, u, u) != 0)
			err(1, "setresuid failed");

		verbose("Dropping privileges completed\n");
	}

	/* Finally, run the Guest.  This doesn't return. */
	/* Finally, run the Guest.  This doesn't return. */
	run_guest();
	run_guest();
}
}
+5 −0
Original line number Original line Diff line number Diff line
@@ -117,6 +117,11 @@ Running Lguest:
    
    
  for general information on how to get bridging to work.
  for general information on how to get bridging to work.


- Random number generation. Using the --rng option will provide a
  /dev/hwrng in the guest that will read from the host's /dev/random.
  Use this option in conjunction with rng-tools (see ../hw_random.txt)
  to provide entropy to the guest kernel's /dev/random.

There is a helpful mailing list at http://ozlabs.org/mailman/listinfo/lguest
There is a helpful mailing list at http://ozlabs.org/mailman/listinfo/lguest


Good luck!
Good luck!
+1 −0
Original line number Original line Diff line number Diff line
@@ -2,6 +2,7 @@ config LGUEST_GUEST
	bool "Lguest guest support"
	bool "Lguest guest support"
	select PARAVIRT
	select PARAVIRT
	depends on X86_32
	depends on X86_32
	select VIRTUALIZATION
	select VIRTIO
	select VIRTIO
	select VIRTIO_RING
	select VIRTIO_RING
	select VIRTIO_CONSOLE
	select VIRTIO_CONSOLE
+1 −1
Original line number Original line Diff line number Diff line
@@ -824,7 +824,7 @@ static void __init lguest_init_IRQ(void)


	for (i = FIRST_EXTERNAL_VECTOR; i < NR_VECTORS; i++) {
	for (i = FIRST_EXTERNAL_VECTOR; i < NR_VECTORS; i++) {
		/* Some systems map "vectors" to interrupts weirdly.  Not us! */
		/* Some systems map "vectors" to interrupts weirdly.  Not us! */
		__get_cpu_var(vector_irq)[i] = i - FIRST_EXTERNAL_VECTOR;
		__this_cpu_write(vector_irq[i], i - FIRST_EXTERNAL_VECTOR);
		if (i != SYSCALL_VECTOR)
		if (i != SYSCALL_VECTOR)
			set_intr_gate(i, interrupt[i - FIRST_EXTERNAL_VECTOR]);
			set_intr_gate(i, interrupt[i - FIRST_EXTERNAL_VECTOR]);
	}
	}
+1 −1
Original line number Original line Diff line number Diff line
@@ -1137,7 +1137,7 @@ void free_guest_pagetable(struct lguest *lg)
 */
 */
void map_switcher_in_guest(struct lg_cpu *cpu, struct lguest_pages *pages)
void map_switcher_in_guest(struct lg_cpu *cpu, struct lguest_pages *pages)
{
{
	pte_t *switcher_pte_page = __get_cpu_var(switcher_pte_pages);
	pte_t *switcher_pte_page = __this_cpu_read(switcher_pte_pages);
	pte_t regs_pte;
	pte_t regs_pte;


#ifdef CONFIG_X86_PAE
#ifdef CONFIG_X86_PAE
Loading