From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Christophe de Dinechin <dinechin@redhat.com>
Subject: [PULL 01/61] scsi/qemu-pr-helper: Fix out-of-bounds access to trnptid_list[]
Date: Mon, 16 Mar 2020 22:26:28 +0100 [thread overview]
Message-ID: <1584394048-44994-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1584394048-44994-1-git-send-email-pbonzini@redhat.com>
From: Christophe de Dinechin <dinechin@redhat.com>
Compile error reported by gcc 10.0.1:
scsi/qemu-pr-helper.c: In function ‘multipath_pr_out’:
scsi/qemu-pr-helper.c:523:32: error: array subscript <unknown> is outside array bounds of ‘struct transportid *[0]’ [-Werror=array-bounds]
523 | paramp.trnptid_list[paramp.num_transportid++] = id;
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from scsi/qemu-pr-helper.c:36:
/usr/include/mpath_persist.h:168:22: note: while referencing ‘trnptid_list’
168 | struct transportid *trnptid_list[];
| ^~~~~~~~~~~~
scsi/qemu-pr-helper.c:424:35: note: defined here ‘paramp’
424 | struct prout_param_descriptor paramp;
| ^~~~~~
This highlights an actual implementation issue in function multipath_pr_out.
The variable paramp is declared with type `struct prout_param_descriptor`,
which is a struct terminated by an empty array in mpath_persist.h:
struct transportid *trnptid_list[];
That empty array was filled with code that looked like that:
trnptid_list[paramp.descr.num_transportid++] = id;
This is an actual out-of-bounds access.
The fix is to malloc `paramp`.
Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
scsi/qemu-pr-helper.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
index 0659cee..181ed4a 100644
--- a/scsi/qemu-pr-helper.c
+++ b/scsi/qemu-pr-helper.c
@@ -421,10 +421,13 @@ static int multipath_pr_out(int fd, const uint8_t *cdb, uint8_t *sense,
int rq_servact = cdb[1];
int rq_scope = cdb[2] >> 4;
int rq_type = cdb[2] & 0xf;
- struct prout_param_descriptor paramp;
+ g_autofree struct prout_param_descriptor *paramp = NULL;
char transportids[PR_HELPER_DATA_SIZE];
int r;
+ paramp = g_malloc0(sizeof(struct prout_param_descriptor)
+ + sizeof(struct transportid *) * MPATH_MX_TIDS);
+
if (sz < PR_OUT_FIXED_PARAM_SIZE) {
/* Illegal request, Parameter list length error. This isn't fatal;
* we have read the data, send an error without closing the socket.
@@ -454,10 +457,9 @@ static int multipath_pr_out(int fd, const uint8_t *cdb, uint8_t *sense,
* used by libmpathpersist (which, of course, will immediately
* do the opposite).
*/
- memset(¶mp, 0, sizeof(paramp));
- memcpy(¶mp.key, ¶m[0], 8);
- memcpy(¶mp.sa_key, ¶m[8], 8);
- paramp.sa_flags = param[20];
+ memcpy(¶mp->key, ¶m[0], 8);
+ memcpy(¶mp->sa_key, ¶m[8], 8);
+ paramp->sa_flags = param[20];
if (sz > PR_OUT_FIXED_PARAM_SIZE) {
size_t transportid_len;
int i, j;
@@ -520,12 +522,13 @@ static int multipath_pr_out(int fd, const uint8_t *cdb, uint8_t *sense,
return CHECK_CONDITION;
}
- paramp.trnptid_list[paramp.num_transportid++] = id;
+ assert(paramp->num_transportid < MPATH_MX_TIDS);
+ paramp->trnptid_list[paramp->num_transportid++] = id;
}
}
r = mpath_persistent_reserve_out(fd, rq_servact, rq_scope, rq_type,
- ¶mp, noisy, verbose);
+ paramp, noisy, verbose);
return mpath_reconstruct_sense(fd, r, sense);
}
#endif
--
1.8.3.1
next prev parent reply other threads:[~2020-03-16 21:29 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-16 21:26 [PULL 00/61] Misc patches for soft freeze Paolo Bonzini
2020-03-16 21:26 ` Paolo Bonzini [this message]
2020-03-16 21:26 ` [PULL 02/61] optionrom/pvh: scan entire RSDP Area Paolo Bonzini
2020-03-16 21:26 ` [PULL 03/61] misc: Replace zero-length arrays with flexible array member (automatic) Paolo Bonzini
2020-03-16 21:26 ` [PULL 04/61] misc: Replace zero-length arrays with flexible array member (manual) Paolo Bonzini
2020-03-16 21:26 ` [PULL 05/61] configure: add configure option avx512f_opt Paolo Bonzini
2020-03-16 21:26 ` [PULL 06/61] util: add util function buffer_zero_avx512() Paolo Bonzini
2020-03-16 22:02 ` Paolo Bonzini
2020-03-16 21:26 ` [PULL 07/61] WHPX: TSC get and set should be dependent on VM state Paolo Bonzini
2020-03-16 21:26 ` [PULL 08/61] WHPX: Use QEMU values for trapped CPUID Paolo Bonzini
2020-03-16 21:26 ` [PULL 09/61] MAINTAINERS: Add entry for Guest X86 HAXM CPUs Paolo Bonzini
2020-03-17 7:46 ` Colin Xu
2020-03-17 8:26 ` Paolo Bonzini
2020-03-17 8:55 ` Colin Xu
2020-03-17 10:27 ` Paolo Bonzini
2020-03-18 0:23 ` Colin Xu
2020-03-16 21:26 ` [PULL 10/61] hw/i386/intel_iommu: Fix out-of-bounds access on guest IRT Paolo Bonzini
2020-03-16 21:26 ` [PULL 11/61] oslib-posix: initialize mutex and condition variable Paolo Bonzini
2020-03-16 21:26 ` [PULL 12/61] build-sys: do not make qemu-ga link with pixman Paolo Bonzini
2020-03-16 21:26 ` [PULL 13/61] modules: load modules from versioned /var/run dir Paolo Bonzini
2020-03-16 21:26 ` [PULL 14/61] configure: Fix building with SASL on Windows Paolo Bonzini
2020-03-16 21:26 ` [PULL 15/61] tests/docker: Install SASL library to extend code coverage on amd64 Paolo Bonzini
2020-03-16 21:26 ` [PULL 16/61] memory: Fix start offset for bitmap log_clear hook Paolo Bonzini
2020-03-16 21:26 ` [PULL 17/61] qom/object: enable setter for uint types Paolo Bonzini
2020-03-16 21:26 ` [PULL 18/61] ich9: fix getter type for sci_int property Paolo Bonzini
2020-03-16 21:26 ` [PULL 19/61] ich9: Simplify ich9_lpc_initfn Paolo Bonzini
2020-03-16 21:26 ` [PULL 20/61] qom/object: Use common get/set uint helpers Paolo Bonzini
2020-03-16 21:26 ` [PULL 21/61] i386: Fix GCC warning with snprintf when HAX is enabled Paolo Bonzini
2020-03-16 21:26 ` [PULL 22/61] WHPX: Use proper synchronization primitives while processing Paolo Bonzini
2020-03-16 21:26 ` [PULL 23/61] Makefile: Align 'help' target output Paolo Bonzini
2020-03-16 21:26 ` [PULL 24/61] Makefile: Let the 'help' target list the tools targets Paolo Bonzini
2020-03-16 21:26 ` [PULL 25/61] hw/audio/fmopl: Move ENV_CURVE to .heap to save 32KiB of .bss Paolo Bonzini
2020-03-16 21:26 ` [PULL 26/61] hw/audio/intel-hda: Use memory region alias to reduce .rodata by 4.34MB Paolo Bonzini
2020-03-16 21:26 ` [PULL 27/61] hw/usb/quirks: Use smaller types to reduce .rodata by 10KiB Paolo Bonzini
2020-03-16 21:26 ` [PULL 28/61] ui/curses: Make control_characters[] array const Paolo Bonzini
2020-03-16 21:26 ` [PULL 29/61] ui/curses: Move arrays to .heap to save 74KiB of .bss Paolo Bonzini
2020-03-16 21:26 ` [PULL 30/61] qemu-cpu-models.rst: Document -noTSX, mds-no, taa-no, and tsx-ctrl Paolo Bonzini
2020-03-16 21:26 ` [PULL 31/61] softmmu/vl.c: Handle '-cpu help' and '-device help' before 'no default machine' Paolo Bonzini
2020-03-16 21:26 ` [PULL 32/61] Use -isystem for linux-headers dir Paolo Bonzini
2020-03-16 21:27 ` [PULL 33/61] exec/rom_reset: Free rom data during inmigrate skip Paolo Bonzini
2020-03-16 21:27 ` [PULL 34/61] cpus: avoid pause_all_vcpus getting stuck due to race Paolo Bonzini
2020-03-16 21:27 ` [PULL 35/61] lockable: add lock guards Paolo Bonzini
2020-03-16 21:27 ` [PULL 36/61] lockable: add QemuRecMutex support Paolo Bonzini
2020-03-16 21:27 ` [PULL 37/61] memory: Correctly return alias region type Paolo Bonzini
2020-03-16 21:27 ` [PULL 38/61] memory: Simplify memory_region_init_rom_nomigrate() to ease review Paolo Bonzini
2020-03-16 21:27 ` [PULL 39/61] scripts/cocci: Rename memory-region-{init-ram -> housekeeping} Paolo Bonzini
2020-03-16 21:27 ` [PULL 40/61] scripts/cocci: Patch to replace memory_region_init_{ram, readonly -> rom} Paolo Bonzini
2020-03-16 21:27 ` [PULL 41/61] hw/arm: Use memory_region_init_rom() with read-only regions Paolo Bonzini
2020-03-16 21:27 ` [PULL 42/61] hw/display: " Paolo Bonzini
2020-03-16 21:27 ` [PULL 43/61] hw/m68k: " Paolo Bonzini
2020-03-16 21:27 ` [PULL 44/61] hw/net: " Paolo Bonzini
2020-03-16 21:27 ` [PULL 45/61] hw/pci-host: " Paolo Bonzini
2020-03-16 21:27 ` [PULL 46/61] hw/ppc: " Paolo Bonzini
2020-03-16 21:27 ` [PULL 47/61] hw/riscv: " Paolo Bonzini
2020-03-16 21:27 ` [PULL 48/61] hw/sh4: " Paolo Bonzini
2020-03-16 21:27 ` [PULL 49/61] hw/sparc: " Paolo Bonzini
2020-03-16 21:27 ` [PULL 50/61] scripts/cocci: Patch to detect potential use of memory_region_init_rom Paolo Bonzini
2020-03-16 21:27 ` [PULL 51/61] scripts/cocci: Patch to remove unnecessary memory_region_set_readonly() Paolo Bonzini
2020-03-16 21:27 ` [PULL 52/61] scripts/cocci: Patch to let devices own their MemoryRegions Paolo Bonzini
2020-03-16 21:27 ` [PULL 53/61] hw/core: Let devices own the MemoryRegion they create Paolo Bonzini
2020-03-16 21:27 ` [PULL 54/61] hw/display: " Paolo Bonzini
2020-03-16 21:27 ` [PULL 55/61] hw/dma: " Paolo Bonzini
2020-03-16 21:27 ` [PULL 56/61] hw/riscv: " Paolo Bonzini
2020-03-16 21:27 ` [PULL 57/61] hw/char: " Paolo Bonzini
2020-03-16 21:27 ` [PULL 58/61] hw/arm/stm32: Use memory_region_init_rom() with read-only regions Paolo Bonzini
2020-03-16 21:27 ` [PULL 59/61] hw/ppc/ppc405: " Paolo Bonzini
2020-03-16 21:27 ` [PULL 60/61] hw/arm: Remove unnecessary memory_region_set_readonly() on ROM alias Paolo Bonzini
2020-03-16 21:27 ` [PULL 61/61] hw/arm: Let devices own the MemoryRegion they create Paolo Bonzini
2020-03-16 23:58 ` [PULL 00/61] Misc patches for soft freeze no-reply
2020-03-17 0:27 ` no-reply
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=1584394048-44994-2-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=dinechin@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).