diff options
44 files changed, 248 insertions, 180 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index 145be0f45f..b05e751376 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1178,8 +1178,8 @@ M: Stefan Hajnoczi <stefanha@redhat.com> M: Fam Zheng <famz@redhat.com> L: qemu-block@nongnu.org S: Supported -F: async.c -F: aio-*.c +F: util/async.c +F: util/aio-*.c F: block/io.c F: migration/block* F: include/block/aio.h @@ -1308,8 +1308,8 @@ Main loop M: Paolo Bonzini <pbonzini@redhat.com> S: Maintained F: cpus.c -F: main-loop.c -F: qemu-timer.c +F: util/main-loop.c +F: util/qemu-timer.c F: vl.c Human Monitor (HMP) @@ -1488,6 +1488,7 @@ S: Maintained F: crypto/ F: include/crypto/ F: tests/test-crypto-* +F: qemu.sasl Coroutines M: Stefan Hajnoczi <stefanha@redhat.com> @@ -1578,6 +1579,7 @@ F: default-configs/*-bsd-user.mak Linux user M: Riku Voipio <riku.voipio@iki.fi> +R: Laurent Vivier <laurent@vivier.eu> S: Maintained F: linux-user/ F: default-configs/*-linux-user.mak diff --git a/block/crypto.c b/block/crypto.c index 6828180840..10e5ddccaa 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -56,10 +56,10 @@ static int block_crypto_probe_generic(QCryptoBlockFormat format, static ssize_t block_crypto_read_func(QCryptoBlock *block, - void *opaque, size_t offset, uint8_t *buf, size_t buflen, + void *opaque, Error **errp) { BlockDriverState *bs = opaque; @@ -83,10 +83,10 @@ struct BlockCryptoCreateData { static ssize_t block_crypto_write_func(QCryptoBlock *block, - void *opaque, size_t offset, const uint8_t *buf, size_t buflen, + void *opaque, Error **errp) { struct BlockCryptoCreateData *data = opaque; @@ -102,8 +102,8 @@ static ssize_t block_crypto_write_func(QCryptoBlock *block, static ssize_t block_crypto_init_func(QCryptoBlock *block, - void *opaque, size_t headerlen, + void *opaque, Error **errp) { struct BlockCryptoCreateData *data = opaque; diff --git a/block/replication.c b/block/replication.c index d300c15475..3885f04c31 100644 --- a/block/replication.c +++ b/block/replication.c @@ -22,9 +22,17 @@ #include "qapi/error.h" #include "replication.h" +typedef enum { + BLOCK_REPLICATION_NONE, /* block replication is not started */ + BLOCK_REPLICATION_RUNNING, /* block replication is running */ + BLOCK_REPLICATION_FAILOVER, /* failover is running in background */ + BLOCK_REPLICATION_FAILOVER_FAILED, /* failover failed */ + BLOCK_REPLICATION_DONE, /* block replication is done */ +} ReplicationStage; + typedef struct BDRVReplicationState { ReplicationMode mode; - int replication_state; + ReplicationStage stage; BdrvChild *active_disk; BdrvChild *hidden_disk; BdrvChild *secondary_disk; @@ -36,14 +44,6 @@ typedef struct BDRVReplicationState { int error; } BDRVReplicationState; -enum { - BLOCK_REPLICATION_NONE, /* block replication is not started */ - BLOCK_REPLICATION_RUNNING, /* block replication is running */ - BLOCK_REPLICATION_FAILOVER, /* failover is running in background */ - BLOCK_REPLICATION_FAILOVER_FAILED, /* failover failed */ - BLOCK_REPLICATION_DONE, /* block replication is done */ -}; - static void replication_start(ReplicationState *rs, ReplicationMode mode, Error **errp); static void replication_do_checkpoint(ReplicationState *rs, Error **errp); @@ -141,10 +141,10 @@ static void replication_close(BlockDriverState *bs) { BDRVReplicationState *s = bs->opaque; - if (s->replication_state == BLOCK_REPLICATION_RUNNING) { + if (s->stage == BLOCK_REPLICATION_RUNNING) { replication_stop(s->rs, false, NULL); } - if (s->replication_state == BLOCK_REPLICATION_FAILOVER) { + if (s->stage == BLOCK_REPLICATION_FAILOVER) { block_job_cancel_sync(s->active_disk->bs->job); } @@ -174,7 +174,7 @@ static int64_t replication_getlength(BlockDriverState *bs) static int replication_get_io_status(BDRVReplicationState *s) { - switch (s->replication_state) { + switch (s->stage) { case BLOCK_REPLICATION_NONE: return -EIO; case BLOCK_REPLICATION_RUNNING: @@ -403,7 +403,7 @@ static void backup_job_completed(void *opaque, int ret) BlockDriverState *bs = opaque; BDRVReplicationState *s = bs->opaque; - if (s->replication_state != BLOCK_REPLICATION_FAILOVER) { + if (s->stage != BLOCK_REPLICATION_FAILOVER) { /* The backup job is cancelled unexpectedly */ s->error = -EIO; } @@ -445,7 +445,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, aio_context_acquire(aio_context); s = bs->opaque; - if (s->replication_state != BLOCK_REPLICATION_NONE) { + if (s->stage != BLOCK_REPLICATION_NONE) { error_setg(errp, "Block replication is running or done"); aio_context_release(aio_context); return; @@ -545,7 +545,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, abort(); } - s->replication_state = BLOCK_REPLICATION_RUNNING; + s->stage = BLOCK_REPLICATION_RUNNING; if (s->mode == REPLICATION_MODE_SECONDARY) { secondary_do_checkpoint(s, errp); @@ -581,7 +581,7 @@ static void replication_get_error(ReplicationState *rs, Error **errp) aio_context_acquire(aio_context); s = bs->opaque; - if (s->replication_state != BLOCK_REPLICATION_RUNNING) { + if (s->stage != BLOCK_REPLICATION_RUNNING) { error_setg(errp, "Block replication is not running"); aio_context_release(aio_context); return; @@ -601,7 +601,7 @@ static void replication_done(void *opaque, int ret) BDRVReplicationState *s = bs->opaque; if (ret == 0) { - s->replication_state = BLOCK_REPLICATION_DONE; + s->stage = BLOCK_REPLICATION_DONE; /* refresh top bs's filename */ bdrv_refresh_filename(bs); @@ -610,7 +610,7 @@ static void replication_done(void *opaque, int ret) s->hidden_disk = NULL; s->error = 0; } else { - s->replication_state = BLOCK_REPLICATION_FAILOVER_FAILED; + s->stage = BLOCK_REPLICATION_FAILOVER_FAILED; s->error = -EIO; } } @@ -625,7 +625,7 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp) aio_context_acquire(aio_context); s = bs->opaque; - if (s->replication_state != BLOCK_REPLICATION_RUNNING) { + if (s->stage != BLOCK_REPLICATION_RUNNING) { error_setg(errp, "Block replication is not running"); aio_context_release(aio_context); return; @@ -633,7 +633,7 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp) switch (s->mode) { case REPLICATION_MODE_PRIMARY: - s->replication_state = BLOCK_REPLICATION_DONE; + s->stage = BLOCK_REPLICATION_DONE; s->error = 0; break; case REPLICATION_MODE_SECONDARY: @@ -648,12 +648,12 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp) if (!failover) { secondary_do_checkpoint(s, errp); - s->replication_state = BLOCK_REPLICATION_DONE; + s->stage = BLOCK_REPLICATION_DONE; aio_context_release(aio_context); return; } - s->replication_state = BLOCK_REPLICATION_FAILOVER; + s->stage = BLOCK_REPLICATION_FAILOVER; commit_active_start(NULL, s->active_disk->bs, s->secondary_disk->bs, BLOCK_JOB_INTERNAL, 0, BLOCKDEV_ON_ERROR_REPORT, NULL, replication_done, bs, true, errp); diff --git a/bsd-user/main.c b/bsd-user/main.c index 714a692e6f..04f95ddd54 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -744,10 +744,7 @@ int main(int argc, char **argv) qemu_init_cpu_list(); module_call_init(MODULE_INIT_QOM); - if ((envlist = envlist_create()) == NULL) { - (void) fprintf(stderr, "Unable to allocate envlist\n"); - exit(1); - } + envlist = envlist_create(); /* add current environment into the list */ for (wrk = environ; *wrk != NULL; wrk++) { @@ -785,10 +782,7 @@ int main(int argc, char **argv) usage(); } else if (!strcmp(r, "ignore-environment")) { envlist_free(envlist); - if ((envlist = envlist_create()) == NULL) { - (void) fprintf(stderr, "Unable to allocate envlist\n"); - exit(1); - } + envlist = envlist_create(); } else if (!strcmp(r, "U")) { r = argv[optind++]; if (envlist_unsetenv(envlist, r) != 0) @@ -956,10 +950,10 @@ int main(int argc, char **argv) } for (wrk = target_environ; *wrk; wrk++) { - free(*wrk); + g_free(*wrk); } - free(target_environ); + g_free(target_environ); if (qemu_loglevel_mask(CPU_LOG_PAGE)) { qemu_log("guest_base 0x%lx\n", guest_base); diff --git a/crypto/block-luks.c b/crypto/block-luks.c index d5a31bbaeb..2b97d89a69 100644 --- a/crypto/block-luks.c +++ b/crypto/block-luks.c @@ -473,9 +473,9 @@ qcrypto_block_luks_load_key(QCryptoBlock *block, * then encrypted. */ rv = readfunc(block, - opaque, slot->key_offset * QCRYPTO_BLOCK_LUKS_SECTOR_SIZE, splitkey, splitkeylen, + opaque, errp); if (rv < 0) { goto cleanup; @@ -676,9 +676,10 @@ qcrypto_block_luks_open(QCryptoBlock *block, /* Read the entire LUKS header, minus the key material from * the underlying device */ - rv = readfunc(block, opaque, 0, + rv = readfunc(block, 0, (uint8_t *)&luks->header, sizeof(luks->header), + opaque, errp); if (rv < 0) { ret = rv; @@ -1245,7 +1246,7 @@ qcrypto_block_luks_create(QCryptoBlock *block, QCRYPTO_BLOCK_LUKS_SECTOR_SIZE; /* Reserve header space to match payload offset */ - initfunc(block, opaque, block->payload_offset, &local_err); + initfunc(block, block->payload_offset, opaque, &local_err); if (local_err) { error_propagate(errp, local_err); goto error; @@ -1267,9 +1268,10 @@ qcrypto_block_luks_create(QCryptoBlock *block, /* Write out the partition header and key slot headers */ - writefunc(block, opaque, 0, + writefunc(block, 0, (const uint8_t *)&luks->header, sizeof(luks->header), + opaque, &local_err); /* Delay checking local_err until we've byte-swapped */ @@ -1295,10 +1297,11 @@ qcrypto_block_luks_create(QCryptoBlock *block, /* Write out the master key material, starting at the * sector immediately following the partition header. */ - if (writefunc(block, opaque, + if (writefunc(block, luks->header.key_slots[0].key_offset * QCRYPTO_BLOCK_LUKS_SECTOR_SIZE, splitkey, splitkeylen, + opaque, errp) != splitkeylen) { goto error; } diff --git a/crypto/init.c b/crypto/init.c index f65207e57d..f131c42306 100644 --- a/crypto/init.c +++ b/crypto/init.c @@ -32,6 +32,8 @@ #include <gcrypt.h> #endif +#include "crypto/random.h" + /* #define DEBUG_GNUTLS */ /* @@ -146,5 +148,9 @@ int qcrypto_init(Error **errp) gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); #endif + if (qcrypto_random_init(errp) < 0) { + return -1; + } + return 0; } diff --git a/crypto/random-gcrypt.c b/crypto/random-gcrypt.c index 0de9a096df..9f1c9ee60e 100644 --- a/crypto/random-gcrypt.c +++ b/crypto/random-gcrypt.c @@ -31,3 +31,5 @@ int qcrypto_random_bytes(uint8_t *buf, gcry_randomize(buf, buflen, GCRY_STRONG_RANDOM); return 0; } + +int qcrypto_random_init(Error **errp G_GNUC_UNUSED) { return 0; } diff --git a/crypto/random-gnutls.c b/crypto/random-gnutls.c index 04b45a8f8f..5350003a0b 100644 --- a/crypto/random-gnutls.c +++ b/crypto/random-gnutls.c @@ -41,3 +41,6 @@ int qcrypto_random_bytes(uint8_t *buf, return 0; } + + +int qcrypto_random_init(Error **errp G_GNUC_UNUSED) { return 0; } diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 82b755afad..0eddb915b7 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -22,14 +22,16 @@ #include "crypto/random.h" -int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, - size_t buflen G_GNUC_UNUSED, - Error **errp) -{ - int fd; - int ret = -1; - int got; +#ifdef _WIN32 +#include <Wincrypt.h> +static HCRYPTPROV hCryptProv; +#else +static int fd; /* a file handle to either /dev/urandom or /dev/random */ +#endif +int qcrypto_random_init(Error **errp) +{ +#ifndef _WIN32 /* TBD perhaps also add support for BSD getentropy / Linux * getrandom syscalls directly */ fd = open("/dev/urandom", O_RDONLY); @@ -41,6 +43,25 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, error_setg(errp, "No /dev/urandom or /dev/random found"); return -1; } +#else + if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, + CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) { + error_setg_win32(errp, GetLastError(), + "Unable to create cryptographic provider"); + return -1; + } +#endif + + return 0; +} + +int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, + size_t buflen G_GNUC_UNUSED, + Error **errp) +{ +#ifndef _WIN32 + int ret = -1; + int got; while (buflen > 0) { got = read(fd, buf, buflen); @@ -59,6 +80,14 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, ret = 0; cleanup: - close(fd); return ret; +#else + if (!CryptGenRandom(hCryptProv, buflen, buf)) { + error_setg_win32(errp, GetLastError(), + "Unable to read random bytes"); + return -1; + } + + return 0; +#endif } diff --git a/device_tree.c b/device_tree.c index 6e06320830..a24ddff02b 100644 --- a/device_tree.c +++ b/device_tree.c @@ -148,6 +148,7 @@ static void read_fstree(void *fdt, const char *dirname) d = opendir(dirname); if (!d) { error_setg(&error_fatal, "%s cannot open %s", __func__, dirname); + return; } while ((de = readdir(d)) != NULL) { diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 98c16a7a9a..604d37dfc8 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -42,9 +42,7 @@ static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq, static void virtio_blk_free_request(VirtIOBlockReq *req) { - if (req) { - g_free(req); - } + g_free(req); } static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status) diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c index 58f1f02902..46012673c3 100644 --- a/hw/core/generic-loader.c +++ b/hw/core/generic-loader.c @@ -137,20 +137,21 @@ static void generic_loader_realize(DeviceState *dev, Error **errp) #endif if (s->file) { + AddressSpace *as = s->cpu ? s->cpu->as : NULL; + if (!s->force_raw) { size = load_elf_as(s->file, NULL, NULL, &entry, NULL, NULL, - big_endian, 0, 0, 0, s->cpu->as); + big_endian, 0, 0, 0, as); if (size < 0) { size = load_uimage_as(s->file, &entry, NULL, NULL, NULL, NULL, - s->cpu->as); + as); } } if (size < 0 || s->force_raw) { /* Default to the maximum size being the machine's ram size */ - size = load_image_targphys_as(s->file, s->addr, ram_size, - s->cpu->as); + size = load_image_targphys_as(s->file, s->addr, ram_size, as); } else { s->addr = entry; } diff --git a/hw/display/jazz_led.c b/hw/display/jazz_led.c index b72fdb1717..3c97d56434 100644 --- a/hw/display/jazz_led.c +++ b/hw/display/jazz_led.c @@ -227,13 +227,13 @@ static void jazz_led_invalidate_display(void *opaque) static void jazz_led_text_update(void *opaque, console_ch_t *chardata) { LedState *s = opaque; - char buf[2]; + char buf[3]; dpy_text_cursor(s->con, -1, -1); qemu_console_resize(s->con, 2, 1); /* TODO: draw the segments */ - snprintf(buf, 2, "%02hhx\n", s->segments); + snprintf(buf, 3, "%02hhx", s->segments); console_write_ch(chardata++, ATTR2CHTYPE(buf[0], QEMU_COLOR_BLUE, QEMU_COLOR_BLACK, 1)); console_write_ch(chardata++, ATTR2CHTYPE(buf[1], QEMU_COLOR_BLUE, diff --git a/hw/microblaze/boot.c b/hw/microblaze/boot.c index 1834d22a61..457a08a2fe 100644 --- a/hw/microblaze/boot.c +++ b/hw/microblaze/boot.c @@ -189,7 +189,7 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base, ram_size - initrd_offset); } if (initrd_size < 0) { - error_report("qemu: could not load initrd '%s'", + error_report("could not load initrd '%s'", initrd_filename); exit(EXIT_FAILURE); } diff --git a/hw/nios2/boot.c b/hw/nios2/boot.c index e0a9aff2f4..2b31f5b844 100644 --- a/hw/nios2/boot.c +++ b/hw/nios2/boot.c @@ -197,7 +197,7 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base, ram_size - initrd_offset); } if (initrd_size < 0) { - error_report("qemu: could not load initrd '%s'", + error_report("could not load initrd '%s'", initrd_filename); exit(EXIT_FAILURE); } diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index d4bcdb027f..6a498565c7 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -610,7 +610,7 @@ static void ppc_powernv_init(MachineState *machine) /* Create the processor chips */ chip_typename = g_strdup_printf(TYPE_PNV_CHIP "-%s", machine->cpu_model); if (!object_class_by_name(chip_typename)) { - error_report("qemu: invalid CPU model '%s' for %s machine", + error_report("invalid CPU model '%s' for %s machine", machine->cpu_model, MACHINE_GET_CLASS(machine)->name); exit(1); } diff --git a/hw/ppc/ppc_booke.c b/hw/ppc/ppc_booke.c index 60baffaf1d..23bcf1b138 100644 --- a/hw/ppc/ppc_booke.c +++ b/hw/ppc/ppc_booke.c @@ -282,7 +282,6 @@ void store_booke_tcr(CPUPPCState *env, target_ulong val) ppc_tb_t *tb_env = env->tb_env; booke_timer_t *booke_timer = tb_env->opaque; - tb_env = env->tb_env; env->spr[SPR_BOOKE_TCR] = val; kvmppc_set_tcr(cpu); diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index b4f6dd58dd..83d6023894 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -505,10 +505,10 @@ static void sclp_realize(DeviceState *dev, Error **errp) ret = s390_set_memory_limit(machine->maxram_size, &hw_limit); if (ret == -E2BIG) { - error_setg(&err, "qemu: host supports a maximum of %" PRIu64 " GB", + error_setg(&err, "host supports a maximum of %" PRIu64 " GB", hw_limit >> 30); } else if (ret) { - error_setg(&err, "qemu: setting the guest size failed"); + error_setg(&err, "setting the guest size failed"); } out: diff --git a/hw/tricore/tricore_testboard.c b/hw/tricore/tricore_testboard.c index 19dd587207..8910bf0f27 100644 --- a/hw/tricore/tricore_testboard.c +++ b/hw/tricore/tricore_testboard.c @@ -50,7 +50,7 @@ static void tricore_load_kernel(CPUTriCoreState *env) NULL, 0, EM_TRICORE, 1, 0); if (kernel_size <= 0) { - error_report("qemu: no kernel file '%s'", + error_report("no kernel file '%s'", tricoretb_binfo.kernel_filename); exit(1); } diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c index 757b8b3f5a..49cb1829b5 100644 --- a/hw/usb/dev-smartcard-reader.c +++ b/hw/usb/dev-smartcard-reader.c @@ -813,7 +813,10 @@ static void ccid_write_data_block(USBCCIDState *s, uint8_t slot, uint8_t seq, if (p->b.bError) { DPRINTF(s, D_VERBOSE, "error %d\n", p->b.bError); } - memcpy(p->abData, data, len); + if (len) { + g_assert_nonnull(data); + memcpy(p->abData, data, len); + } ccid_reset_error_status(s); usb_wakeup(s->bulk, 0); } diff --git a/include/crypto/block.h b/include/crypto/block.h index 4a053a3ffa..013a435f1b 100644 --- a/include/crypto/block.h +++ b/include/crypto/block.h @@ -30,22 +30,22 @@ typedef struct QCryptoBlock QCryptoBlock; * and QCryptoBlockOpenOptions in qapi/crypto.json */ typedef ssize_t (*QCryptoBlockReadFunc)(QCryptoBlock *block, - void *opaque, size_t offset, uint8_t *buf, size_t buflen, + void *opaque, Error **errp); typedef ssize_t (*QCryptoBlockInitFunc)(QCryptoBlock *block, - void *opaque, size_t headerlen, + void *opaque, Error **errp); typedef ssize_t (*QCryptoBlockWriteFunc)(QCryptoBlock *block, - void *opaque, size_t offset, const uint8_t *buf, size_t buflen, + void *opaque, Error **errp); /** diff --git a/include/crypto/random.h b/include/crypto/random.h index a101353202..a07229ce96 100644 --- a/include/crypto/random.h +++ b/include/crypto/random.h @@ -40,5 +40,14 @@ int qcrypto_random_bytes(uint8_t *buf, size_t buflen, Error **errp); +/** + * qcrypto_random_init: + * @errp: pointer to a NULL-initialized error object + * + * Initializes the handles used by qcrypto_random_bytes + * + * Returns 0 on success, -1 on error + */ +int qcrypto_random_init(Error **errp); #endif /* QCRYPTO_RANDOM_H */ diff --git a/include/io/channel-file.h b/include/io/channel-file.h index d2462c2ed7..79245f1183 100644 --- a/include/io/channel-file.h +++ b/include/io/channel-file.h @@ -71,7 +71,7 @@ qio_channel_file_new_fd(int fd); /** * qio_channel_file_new_path: - * @fd: the file descriptor + * @path: the file path * @flags: the open flags (O_RDONLY|O_WRONLY|O_RDWR, etc) * @mode: the file creation mode if O_WRONLY is set in @flags * @errp: pointer to initialized error object diff --git a/include/io/channel.h b/include/io/channel.h index 5d48906998..db9bb022a1 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -315,7 +315,7 @@ ssize_t qio_channel_read(QIOChannel *ioc, Error **errp); /** - * qio_channel_writev: + * qio_channel_write: * @ioc: the channel object * @buf: the memory regions to send data from * @buflen: the length of @buf diff --git a/linux-user/main.c b/linux-user/main.c index 79d621b872..ad03c9e8b2 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -4229,10 +4229,7 @@ int main(int argc, char **argv, char **envp) qemu_init_cpu_list(); module_call_init(MODULE_INIT_QOM); - if ((envlist = envlist_create()) == NULL) { - (void) fprintf(stderr, "Unable to allocate envlist\n"); - exit(EXIT_FAILURE); - } + envlist = envlist_create(); /* add current environment into the list */ for (wrk = environ; *wrk != NULL; wrk++) { @@ -4429,10 +4426,10 @@ int main(int argc, char **argv, char **envp) } for (wrk = target_environ; *wrk; wrk++) { - free(*wrk); + g_free(*wrk); } - free(target_environ); + g_free(target_environ); if (qemu_loglevel_mask(CPU_LOG_PAGE)) { qemu_log("guest_base 0x%lx\n", guest_base); @@ -174,7 +174,7 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp) } if (node->has_mem && node->has_memdev) { - error_setg(errp, "qemu: cannot specify both mem= and memdev="); + error_setg(errp, "cannot specify both mem= and memdev="); return; } @@ -182,7 +182,7 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp) have_memdevs = node->has_memdev; } if (node->has_memdev != have_memdevs) { - error_setg(errp, "qemu: memdev option must be specified for either " + error_setg(errp, "memdev option must be specified for either " "all or no nodes"); return; } diff --git a/qemu-doc.texi b/qemu-doc.texi index 794ab4a080..3dd9eac4f3 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -1732,37 +1732,45 @@ SASL service config /etc/sasl2/qemu.conf. If running QEMU as an unprivileged user, an environment variable SASL_CONF_PATH can be used to make it search alternate locations for the service config. -The default configuration might contain +If the TLS option is enabled for VNC, then it will provide session encryption, +otherwise the SASL mechanism will have to provide encryption. In the latter +case the list of possible plugins that can be used is drastically reduced. In +fact only the GSSAPI SASL mechanism provides an acceptable level of security +by modern standards. Previous versions of QEMU referred to the DIGEST-MD5 +mechanism, however, it has multiple serious flaws described in detail in +RFC 6331 and thus should never be used any more. The SCRAM-SHA-1 mechanism +provides a simple username/password auth facility similar to DIGEST-MD5, but +does not support session encryption, so can only be used in combination with +TLS. + +When not using TLS the recommended configuration is @example -mech_list: digest-md5 -sasldb_path: /etc/qemu/passwd.db +mech_list: gssapi +keytab: /etc/qemu/krb5.tab @end example -This says to use the 'Digest MD5' mechanism, which is similar to the HTTP -Digest-MD5 mechanism. The list of valid usernames & passwords is maintained -in the /etc/qemu/passwd.db file, and can be updated using the saslpasswd2 -command. While this mechanism is easy to configure and use, it is not -considered secure by modern standards, so only suitable for developers / -ad-hoc testing. +This says to use the 'GSSAPI' mechanism with the Kerberos v5 protocol, with +the server principal stored in /etc/qemu/krb5.tab. For this to work the +administrator of your KDC must generate a Kerberos principal for the server, +with a name of 'qemu/somehost.example.com@@EXAMPLE.COM' replacing +'somehost.example.com' with the fully qualified host name of the machine +running QEMU, and 'EXAMPLE.COM' with the Kerberos Realm. -A more serious deployment might use Kerberos, which is done with the 'gssapi' -mechanism +When using TLS, if username+password authentication is desired, then a +reasonable configuration is @example -mech_list: gssapi -keytab: /etc/qemu/krb5.tab +mech_list: scram-sha-1 +sasldb_path: /etc/qemu/passwd.db @end example -For this to work the administrator of your KDC must generate a Kerberos -principal for the server, with a name of 'qemu/somehost.example.com@@EXAMPLE.COM' -replacing 'somehost.example.com' with the fully qualified host name of the -machine running QEMU, and 'EXAMPLE.COM' with the Kerberos Realm. +The saslpasswd2 program can be used to populate the passwd.db file with +accounts. -Other configurations will be left as an exercise for the reader. It should -be noted that only Digest-MD5 and GSSAPI provides a SSF layer for data -encryption. For all other mechanisms, VNC should always be configured to -use TLS and x509 certificates to protect security credentials from snooping. +Other SASL configurations will be left as an exercise for the reader. Note that +all mechanisms except GSSAPI, should be combined with use of TLS to ensure a +secure data channel. @node gdb_usage @section GDB usage @@ -1878,8 +1886,8 @@ resolution modes which the Cirrus Logic BIOS does not support (i.e. >= Windows 9x does not correctly use the CPU HLT instruction. The result is that it takes host CPU cycles even when idle. You can install the utility from -@url{http://www.user.cityline.ru/~maxamn/amnhltm.zip} to solve this -problem. Note that no such tool is needed for NT, 2000 or XP. +@url{http://web.archive.org/web/20060212132151/http://www.user.cityline.ru/~maxamn/amnhltm.zip} +to solve this problem. Note that no such tool is needed for NT, 2000 or XP. @subsubsection Windows 2000 disk full problem @@ -1927,9 +1935,9 @@ vvfat block device ("-hdb fat:directory_which_holds_the_SP"). @subsubsection CPU usage reduction DOS does not correctly use the CPU HLT instruction. The result is that -it takes host CPU cycles even when idle. You can install the utility -from @url{http://www.vmware.com/software/dosidle210.zip} to solve this -problem. +it takes host CPU cycles even when idle. You can install the utility from +@url{http://web.archive.org/web/20051222085335/http://www.vmware.com/software/dosidle210.zip} +to solve this problem. @node QEMU System emulator for non PC targets @chapter QEMU System emulator for non PC targets diff --git a/qemu-options.hx b/qemu-options.hx index 70c0ded12e..f806af9f2d 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -604,7 +604,7 @@ Special files such as iSCSI devices can be specified using protocol specific URLs. See the section for "Device URL Syntax" for more information. @item if=@var{interface} This option defines on which type on interface the drive is connected. -Available types are: ide, scsi, sd, mtd, floppy, pflash, virtio. +Available types are: ide, scsi, sd, mtd, floppy, pflash, virtio, none. @item bus=@var{bus},unit=@var{unit} These options define where is connected the drive by defining the bus number and the unit id. @@ -876,7 +876,7 @@ ETEXI DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs, "-virtfs local,path=path,mount_tag=tag,security_model=[mapped-xattr|mapped-file|passthrough|none]\n" - " [,writeout=immediate][,readonly][,socket=socket|sock_fd=sock_fd]\n", + " [,id=id][,writeout=immediate][,readonly][,socket=socket|sock_fd=sock_fd]\n", QEMU_ARCH_ALL) STEXI @@ -1,36 +1,44 @@ -# If you want to use the non-TLS socket, then you *must* include -# the GSSAPI or DIGEST-MD5 mechanisms, because they are the only -# ones that can offer session encryption as well as authentication. +# If you want to use VNC remotely without TLS, then you *must* +# pick a mechanism which provides session encryption as well +# as authentication. # -# If you're only using TLS, then you can turn on any mechanisms +# If you are only using TLS, then you can turn on any mechanisms # you like for authentication, because TLS provides the encryption # -# Default to a simple username+password mechanism -# NB digest-md5 is no longer considered secure by current standards -mech_list: digest-md5 +# If you are only using UNIX sockets then encryption is not +# required at all. +# +# NB, previously DIGEST-MD5 was set as the default mechanism for +# QEMU VNC. Per RFC 6331 this is vulnerable to many serious security +# flaws as should no longer be used. Thus GSSAPI is now the default. +# +# To use GSSAPI requires that a QEMU service principal is +# added to the Kerberos server for each host running QEMU. +# This principal needs to be exported to the keytab file listed below +mech_list: gssapi -# Before you can use GSSAPI, you need a service principle on the -# KDC server for libvirt, and that to be exported to the keytab -# file listed below -#mech_list: gssapi +# If using TLS with VNC, or a UNIX socket only, it is possible to +# enable plugins which don't provide session encryption. The +# 'scram-sha-1' plugin allows plain username/password authentication +# to be performed # -# You can also list many mechanisms at once, then the user can choose -# by adding '?auth=sasl.gssapi' to their libvirt URI, eg -# qemu+tcp://hostname/system?auth=sasl.gssapi -#mech_list: digest-md5 gssapi +#mech_list: scram-sha-1 + +# You can also list many mechanisms at once, and the VNC server will +# negotiate which to use by considering the list enabled on the VNC +# client. +#mech_list: scram-sha-1 gssapi # Some older builds of MIT kerberos on Linux ignore this option & # instead need KRB5_KTNAME env var. # For modern Linux, and other OS, this should be sufficient # -# There is no default value here, uncomment if you need this -#keytab: /etc/qemu/krb5.tab +# This file needs to be populated with the service principal that +# was created on the Kerberos v5 server. If switching to a non-gssapi +# mechanism this can be commented out. +keytab: /etc/qemu/krb5.tab -# If using digest-md5 for username/passwds, then this is the file +# If using scram-sha-1 for username/passwds, then this is the file # containing the passwds. Use 'saslpasswd2 -a qemu [username]' # to add entries, and 'sasldblistusers2 -f [sasldb_path]' to browse it -sasldb_path: /etc/qemu/passwd.db - - -auxprop_plugin: sasldb - +#sasldb_path: /etc/qemu/passwd.db diff --git a/qga/commands-posix.c b/qga/commands-posix.c index ba06be4c86..284ecc6d7e 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2125,9 +2125,11 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk, * we think this VM does not support online/offline memory block, * any other solution? */ - if (!dp && errno == ENOENT) { - result->response = - GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED; + if (!dp) { + if (errno == ENOENT) { + result->response = + GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED; + } goto out1; } closedir(dp); diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 73cee81b79..45027b9281 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl # (c) 2001, Dave Jones. (the file handling bit) # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit) # (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite) @@ -6,6 +6,7 @@ # Licensed under the terms of the GNU GPL License version 2 use strict; +use warnings; my $P = $0; $P =~ s@.*/@@g; diff --git a/scripts/clean-header-guards.pl b/scripts/clean-header-guards.pl index 54ab99ae29..5e67f1998c 100755 --- a/scripts/clean-header-guards.pl +++ b/scripts/clean-header-guards.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl # # Clean up include guards in headers # @@ -28,6 +28,7 @@ # "cc -E -DGUARD_H -c -P -", and fed the test program on stdin. use strict; +use warnings; use Getopt::Std; # Stuff we don't want to clean because we import it into our tree: diff --git a/scripts/cleanup-trace-events.pl b/scripts/cleanup-trace-events.pl index 7e808efb6a..e93abc00da 100755 --- a/scripts/cleanup-trace-events.pl +++ b/scripts/cleanup-trace-events.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Copyright (C) 2013 Red Hat, Inc. # # Authors: diff --git a/scripts/disas-objdump.pl b/scripts/disas-objdump.pl index 8f7e8182a1..bec905f04b 100755 --- a/scripts/disas-objdump.pl +++ b/scripts/disas-objdump.pl @@ -1,4 +1,6 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl + +use warnings; use File::Temp qw/ tempfile /; use Getopt::Long; diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl index 96e66a80a0..711a9a6bd0 100755 --- a/scripts/get_maintainer.pl +++ b/scripts/get_maintainer.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl # (c) 2007, Joe Perches <joe@perches.com> # created from checkpatch.pl # @@ -11,6 +11,7 @@ # Licensed under the terms of the GNU GPL License version 2 use strict; +use warnings; my $P = $0; my $V = '0.26'; diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh index 0f1aa63872..8afc3eb5bb 100755 --- a/scripts/qemu-binfmt-conf.sh +++ b/scripts/qemu-binfmt-conf.sh @@ -284,12 +284,12 @@ while true ; do shift # check given cpu is in the supported CPU list for cpu in ${qemu_target_list} ; do - if [ "$cpu" == "$1" ] ; then + if [ "$cpu" = "$1" ] ; then break fi done - if [ "$cpu" == "$1" ] ; then + if [ "$cpu" = "$1" ] ; then qemu_target_list="$1" else echo "ERROR: unknown CPU \"$1\"" 1>&2 diff --git a/scripts/shaderinclude.pl b/scripts/shaderinclude.pl index 81b5146332..cd3bb40b12 100644 --- a/scripts/shaderinclude.pl +++ b/scripts/shaderinclude.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; use warnings; diff --git a/scripts/switch-timer-api b/scripts/switch-timer-api index b0e230b9f1..41736d11dd 100755 --- a/scripts/switch-timer-api +++ b/scripts/switch-timer-api @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; use warnings; diff --git a/scripts/texi2pod.pl b/scripts/texi2pod.pl index 6e8fec41a1..39ce584a32 100755 --- a/scripts/texi2pod.pl +++ b/scripts/texi2pod.pl @@ -1,4 +1,4 @@ -#! /usr/bin/perl -w +#! /usr/bin/env perl # Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc. @@ -22,6 +22,8 @@ # markup to Perl POD format. It's intended to be used to extract # something suitable for a manpage from a Texinfo document. +use warnings; + $output = 0; $skipping = 0; %sects = (); diff --git a/tests/.gitignore b/tests/.gitignore index a966740c2c..40c2e3e757 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -11,6 +11,8 @@ check-qom-proplist qht-bench rcutorture test-aio +test-aio-multithread +test-arm-mptimer test-base64 test-bitops test-bitcnt @@ -24,6 +26,7 @@ test-crypto-afsplit test-crypto-block test-crypto-cipher test-crypto-hash +test-crypto-hmac test-crypto-ivgen test-crypto-pbkdf test-crypto-secret @@ -37,6 +40,7 @@ test-crypto-tlssession-server/ test-crypto-xts test-cutils test-hbitmap +test-hmp test-int128 test-iov test-io-channel-buffer diff --git a/tests/postcopy-test.c b/tests/postcopy-test.c index de35a18903..e86f87656a 100644 --- a/tests/postcopy-test.c +++ b/tests/postcopy-test.c @@ -41,7 +41,7 @@ static bool ufd_version_check(void) struct uffdio_api api_struct; uint64_t ioctl_mask; - int ufd = ufd = syscall(__NR_userfaultfd, O_CLOEXEC); + int ufd = syscall(__NR_userfaultfd, O_CLOEXEC); if (ufd == -1) { g_test_message("Skipping test: userfaultfd not available"); diff --git a/tests/test-crypto-block.c b/tests/test-crypto-block.c index 85e6603d59..95c4bd5da3 100644 --- a/tests/test-crypto-block.c +++ b/tests/test-crypto-block.c @@ -187,10 +187,10 @@ static struct QCryptoBlockTestData { static ssize_t test_block_read_func(QCryptoBlock *block, - void *opaque, size_t offset, uint8_t *buf, size_t buflen, + void *opaque, Error **errp) { Buffer *header = opaque; @@ -204,8 +204,8 @@ static ssize_t test_block_read_func(QCryptoBlock *block, static ssize_t test_block_init_func(QCryptoBlock *block, - void *opaque, size_t headerlen, + void *opaque, Error **errp) { Buffer *header = opaque; @@ -219,10 +219,10 @@ static ssize_t test_block_init_func(QCryptoBlock *block, static ssize_t test_block_write_func(QCryptoBlock *block, - void *opaque, size_t offset, const uint8_t *buf, size_t buflen, + void *opaque, Error **errp) { Buffer *header = opaque; diff --git a/util/envlist.c b/util/envlist.c index e86857e70a..1eeb7fca87 100644 --- a/util/envlist.c +++ b/util/envlist.c @@ -17,16 +17,14 @@ static int envlist_parse(envlist_t *envlist, const char *env, int (*)(envlist_t *, const char *)); /* - * Allocates new envlist and returns pointer to that or - * NULL in case of error. + * Allocates new envlist and returns pointer to it. */ envlist_t * envlist_create(void) { envlist_t *envlist; - if ((envlist = malloc(sizeof (*envlist))) == NULL) - return (NULL); + envlist = g_malloc(sizeof(*envlist)); QLIST_INIT(&envlist->el_entries); envlist->el_count = 0; @@ -48,10 +46,10 @@ envlist_free(envlist_t *envlist) entry = envlist->el_entries.lh_first; QLIST_REMOVE(entry, ev_link); - free((char *)entry->ev_var); - free(entry); + g_free((char *)entry->ev_var); + g_free(entry); } - free(envlist); + g_free(envlist); } /* @@ -101,8 +99,7 @@ envlist_parse(envlist_t *envlist, const char *env, if ((envlist == NULL) || (env == NULL)) return (EINVAL); - if ((tmpenv = strdup(env)) == NULL) - return (errno); + tmpenv = g_strdup(env); envsave = tmpenv; do { @@ -117,7 +114,7 @@ envlist_parse(envlist_t *envlist, const char *env, tmpenv = envvar + 1; } while (envvar != NULL); - free(envsave); + g_free(envsave); return ret; } @@ -155,18 +152,14 @@ envlist_setenv(envlist_t *envlist, const char *env) if (entry != NULL) { QLIST_REMOVE(entry, ev_link); - free((char *)entry->ev_var); - free(entry); + g_free((char *)entry->ev_var); + g_free(entry); } else { envlist->el_count++; } - if ((entry = malloc(sizeof (*entry))) == NULL) - return (errno); - if ((entry->ev_var = strdup(env)) == NULL) { - free(entry); - return (errno); - } + entry = g_malloc(sizeof(*entry)); + entry->ev_var = g_strdup(env); QLIST_INSERT_HEAD(&envlist->el_entries, entry, ev_link); return (0); @@ -201,8 +194,8 @@ envlist_unsetenv(envlist_t *envlist, const char *env) } if (entry != NULL) { QLIST_REMOVE(entry, ev_link); - free((char *)entry->ev_var); - free(entry); + g_free((char *)entry->ev_var); + g_free(entry); envlist->el_count--; } @@ -212,12 +205,12 @@ envlist_unsetenv(envlist_t *envlist, const char *env) /* * Returns given envlist as array of strings (in same form that * global variable environ is). Caller must free returned memory - * by calling free(3) for each element and for the array. Returned - * array and given envlist are not related (no common references). + * by calling g_free for each element and the array. + * Returned array and given envlist are not related (no common + * references). * * If caller provides count pointer, number of items in array is - * stored there. In case of error, NULL is returned and no memory - * is allocated. + * stored there. */ char ** envlist_to_environ(const envlist_t *envlist, size_t *count) @@ -225,13 +218,11 @@ envlist_to_environ(const envlist_t *envlist, size_t *count) struct envlist_entry *entry; char **env, **penv; - penv = env = malloc((envlist->el_count + 1) * sizeof (char *)); - if (env == NULL) - return (NULL); + penv = env = g_malloc((envlist->el_count + 1) * sizeof(char *)); for (entry = envlist->el_entries.lh_first; entry != NULL; entry = entry->ev_link.le_next) { - *(penv++) = strdup(entry->ev_var); + *(penv++) = g_strdup(entry->ev_var); } *penv = NULL; /* NULL terminate the list */ @@ -3524,10 +3524,11 @@ int main(int argc, char **argv, char **envp) exit(1); } fsdev = qemu_opts_create(qemu_find_opts("fsdev"), + qemu_opts_id(opts) ?: qemu_opt_get(opts, "mount_tag"), 1, NULL); if (!fsdev) { - error_report("duplicate fsdev id: %s", + error_report("duplicate or invalid fsdev id: %s", qemu_opt_get(opts, "mount_tag")); exit(1); } @@ -3565,7 +3566,7 @@ int main(int argc, char **argv, char **envp) &error_abort); qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort); qemu_opt_set(device, "fsdev", - qemu_opt_get(opts, "mount_tag"), &error_abort); + qemu_opts_id(fsdev), &error_abort); qemu_opt_set(device, "mount_tag", qemu_opt_get(opts, "mount_tag"), &error_abort); break; |