From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
kvm@vger.kernel.org, qemu-arm@nongnu.org,
"Richard Henderson" <rth@twiddle.net>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: [PATCH v2 5/7] hw/arm/boot: Abort if set_kernel_args() fails
Date: Mon, 18 May 2020 17:53:06 +0200 [thread overview]
Message-ID: <20200518155308.15851-6-f4bug@amsat.org> (raw)
In-Reply-To: <20200518155308.15851-1-f4bug@amsat.org>
If a address_space_write() fails while calling
set_kernel_args(), the guest kernel will boot
using crap data. Avoid that by aborting if this
ever occurs.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/arm/boot.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index fef4072db1..7cc271034c 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -291,7 +291,8 @@ static inline bool have_dtb(const struct arm_boot_info *info)
#define WRITE_WORD(p, value) do { \
address_space_stl_notdirty(as, p, value, \
- MEMTXATTRS_UNSPECIFIED, NULL); \
+ MEMTXATTRS_UNSPECIFIED, &result); \
+ assert(result == MEMTX_OK); \
p += 4; \
} while (0)
@@ -300,6 +301,7 @@ static void set_kernel_args(const struct arm_boot_info *info, AddressSpace *as)
int initrd_size = info->initrd_size;
hwaddr base = info->loader_start;
hwaddr p;
+ MemTxResult result;
p = base + KERNEL_ARGS_ADDR;
/* ATAG_CORE */
@@ -326,8 +328,9 @@ static void set_kernel_args(const struct arm_boot_info *info, AddressSpace *as)
int cmdline_size;
cmdline_size = strlen(info->kernel_cmdline);
- address_space_write(as, p + 8, MEMTXATTRS_UNSPECIFIED,
- info->kernel_cmdline, cmdline_size + 1);
+ result = address_space_write(as, p + 8, MEMTXATTRS_UNSPECIFIED,
+ info->kernel_cmdline, cmdline_size + 1);
+ assert(result == MEMTX_OK);
cmdline_size = (cmdline_size >> 2) + 1;
WRITE_WORD(p, cmdline_size + 2);
WRITE_WORD(p, 0x54410009);
@@ -341,8 +344,9 @@ static void set_kernel_args(const struct arm_boot_info *info, AddressSpace *as)
atag_board_len = (info->atag_board(info, atag_board_buf) + 3) & ~3;
WRITE_WORD(p, (atag_board_len + 8) >> 2);
WRITE_WORD(p, 0x414f4d50);
- address_space_write(as, p, MEMTXATTRS_UNSPECIFIED,
- atag_board_buf, atag_board_len);
+ result = address_space_write(as, p, MEMTXATTRS_UNSPECIFIED,
+ atag_board_buf, atag_board_len);
+ assert(result == MEMTX_OK);
p += atag_board_len;
}
/* ATAG_END */
@@ -357,6 +361,7 @@ static void set_kernel_args_old(const struct arm_boot_info *info,
const char *s;
int initrd_size = info->initrd_size;
hwaddr base = info->loader_start;
+ MemTxResult result;
/* see linux/include/asm-arm/setup.h */
p = base + KERNEL_ARGS_ADDR;
@@ -419,7 +424,9 @@ static void set_kernel_args_old(const struct arm_boot_info *info,
}
s = info->kernel_cmdline;
if (s) {
- address_space_write(as, p, MEMTXATTRS_UNSPECIFIED, s, strlen(s) + 1);
+ result = address_space_write(as, p, MEMTXATTRS_UNSPECIFIED,
+ s, strlen(s) + 1);
+ assert(result == MEMTX_OK);
} else {
WRITE_WORD(p, 0);
}
--
2.21.3
next prev parent reply other threads:[~2020-05-18 15:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-18 15:53 [PATCH v2 0/7] exec/memory: Enforce checking MemTxResult values Philippe Mathieu-Daudé
2020-05-18 15:53 ` [PATCH v2 1/7] exec: Let address_space_read/write_cached() propagate MemTxResult Philippe Mathieu-Daudé
2020-05-18 16:13 ` Peter Maydell
2020-05-18 15:53 ` [PATCH v2 2/7] exec: Propagate cpu_memory_rw_debug() error Philippe Mathieu-Daudé
2020-05-18 15:53 ` [PATCH v2 3/7] disas: Let disas::read_memory() handler return EIO on error Philippe Mathieu-Daudé
2020-05-18 15:53 ` [PATCH v2 4/7] hw/elf_ops: Do not ignore write failures when loading ELF Philippe Mathieu-Daudé
2020-05-19 7:58 ` Stefano Garzarella
2020-05-18 15:53 ` Philippe Mathieu-Daudé [this message]
2020-05-18 16:08 ` [PATCH v2 5/7] hw/arm/boot: Abort if set_kernel_args() fails Peter Maydell
2020-05-18 15:53 ` [RFC PATCH v2 6/7] accel/kvm: Let KVM_EXIT_MMIO return error Philippe Mathieu-Daudé
2020-05-18 16:01 ` Peter Maydell
2020-05-18 16:06 ` Philippe Mathieu-Daudé
2020-05-21 15:39 ` Paolo Bonzini
2020-05-21 15:45 ` Peter Maydell
2020-05-18 15:53 ` [RFC PATCH v2 7/7] hw/core/loader: Assert loading ROM regions succeeds at reset Philippe Mathieu-Daudé
2020-05-18 16:12 ` Peter Maydell
2020-05-18 16:25 ` Philippe Mathieu-Daudé
2020-05-21 15:40 ` [PATCH v2 0/7] exec/memory: Enforce checking MemTxResult values Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200518155308.15851-6-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).