All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PULL 15/30] opts: don't silently truncate long option values
Date: Mon, 14 May 2018 17:23:37 +0100	[thread overview]
Message-ID: <20180514162337.GE23010@redhat.com> (raw)
In-Reply-To: <CAFEAcA9=byErqiGKfeSmgrd7Uyu31LDZubLv+Ov-Z3c+86a5QA@mail.gmail.com>

On Mon, May 14, 2018 at 05:19:04PM +0100, Peter Maydell wrote:
> On 8 May 2018 at 23:14, Paolo Bonzini <pbonzini@redhat.com> wrote:
> > From: Daniel P. Berrangé <berrange@redhat.com>
> >
> > The existing QemuOpts parsing code uses a fixed size 1024 byte buffer
> > for storing the option values. If a value exceeded this size it was
> > silently truncated and no error reported to the user. Long option values
> > is not a common scenario, but it is conceivable that they will happen.
> > eg if the user has a very deeply nested filesystem it would be possible
> > to come up with a disk path that was > 1024 bytes. Most of the time if
> > such data was silently truncated, the user would get an error about
> > opening a non-existant disk. If they're unlucky though, QEMU might use a
> > completely different disk image from another VM, which could be
> > considered a security issue. Another example program was in using the
> > -smbios command line arg with very large data blobs. In this case the
> > silent truncation will be providing semantically incorrect data to the
> > guest OS for SMBIOS tables.
> >
> > If the operating system didn't limit the user's argv when spawning QEMU,
> > the code should honour whatever length arguments were given without
> > imposing its own length restrictions. This patch thus changes the code
> > to use a heap allocated buffer for storing the values during parsing,
> > lifting the arbitrary length restriction.
> 
> Hi; Coverity doesn't like this change (CID1391003):
> 
> > --- a/util/qemu-option.c
> > +++ b/util/qemu-option.c
> > @@ -70,25 +70,37 @@ static const char *get_opt_name(const char *p, char **option, char delim)
> >   * delimiter is fixed to be comma which starts a new option. To specify an
> >   * option value that contains commas, double each comma.
> >   */
> > -const char *get_opt_value(char *buf, int buf_size, const char *p)
> > +const char *get_opt_value(const char *p, char **value)
> >  {
> > -    char *q;
> > +    size_t capacity = 0, length;
> > +    const char *offset;
> > +
> > +    *value = NULL;
> 
> Here we write to *value, so value must be non-NULL, and
> within the loop the only place we write to value it
> can't become NULL either (g_renew can't fail)...

Oh, real bug ! This should have been

   if (value) {
      *value = NULL;
   }

because multiboot.c passes in NULL for this parameter.

Unless we decide to rewrite multiboot.c to avoid that instead,
since all other callers pass non-NULL.

> 
> > +    while (1) {
> > +        offset = strchr(p, ',');
> > +        if (!offset) {
> > +            offset = p + strlen(p);
> > +        }
> >
> > -    q = buf;
> > -    while (*p != '\0') {
> > -        if (*p == ',') {
> > -            if (*(p + 1) != ',')
> > -                break;
> > -            p++;
> > +        length = offset - p;
> > +        if (*offset != '\0' && *(offset + 1) == ',') {
> > +            length++;
> > +        }
> > +        if (value) {
> 
> ...so this check for whether value is NULL can never be true.
> 
> > +            *value = g_renew(char, *value, capacity + length + 1);
> > +            strncpy(*value + capacity, p, length);
> > +            (*value)[capacity + length] = '\0';
> > +        }
> > +        capacity += length;
> > +        if (*offset == '\0' ||
> > +            *(offset + 1) != ',') {
> > +            break;
> >          }
> > -        if (q && (q - buf) < buf_size - 1)
> > -            *q++ = *p;
> > -        p++;
> > +
> > +        p += (offset - p) + 2;
> >      }
> > -    if (q)
> > -        *q = '\0';
> >
> > -    return p;
> > +    return offset;
> >  }
> >
> 
> thanks
> -- PMM
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

  reply	other threads:[~2018-05-14 16:23 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-08 22:14 [Qemu-devel] [PULL 00/30] Misc patches for 2018-05-09 Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 01/30] configure: recognize more rpmbuild macros Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 02/30] cpus: Fix event order on resume of stopped guest Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 03/30] cpus: tcg: fix never exiting loop on unplug Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 04/30] checkpatch.pl: add common glib defines to typelist Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 05/30] qom: allow object_get_canonical_path_component without parent Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 06/30] memdev: remove "id" property Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 07/30] exec: move memory access declarations to a common header, inline *_phys functions Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 08/30] exec: small changes to flatview_do_translate Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 09/30] exec: extract address_space_translate_iommu, fix page_mask corner case Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 10/30] exec: reintroduce MemoryRegion caching Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 11/30] qemu-thread: always keep the posix wrapper layer Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 12/30] update-linux-headers: drop hyperv.h Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 13/30] accel: use g_strsplit for parsing accelerator names Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 14/30] opts: don't silently truncate long parameter keys Paolo Bonzini
2018-05-09  5:46   ` Thomas Huth
2018-05-08 22:14 ` [Qemu-devel] [PULL 15/30] opts: don't silently truncate long option values Paolo Bonzini
2018-05-14 16:19   ` Peter Maydell
2018-05-14 16:23     ` Daniel P. Berrangé [this message]
2018-05-08 22:14 ` [Qemu-devel] [PULL 16/30] target/i386: sev: fix memory leaks Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 17/30] qemu-options: Mark -virtioconsole as deprecated Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 18/30] qemu-options: Remove remainders of the -tdf option Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 19/30] qemu-options: Bail out on unsupported options instead of silently ignoring them Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 20/30] qemu-options: Remove deprecated -no-kvm-pit-reinjection Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 21/30] qemu-options: Remove deprecated -no-kvm-irqchip Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 22/30] qemu-doc: provide details of supported build platforms Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 23/30] glib: bump min required glib library version to 2.42 Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 24/30] i386/kvm: add support for Hyper-V reenlightenment MSRs Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 25/30] configure: Really use local libfdt if the system one is too old Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 26/30] configure: Display if libfdt is from system or git Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 27/30] shippable: Remove Debian 8 libfdt kludge Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 28/30] build: Silence dtc directory creation Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 29/30] pc-dimm: fix error messages if no slots were defined Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 30/30] rename included C files to foo.inc.c, remove osdep.h Paolo Bonzini
2018-05-11 12:19 ` [Qemu-devel] [PULL 00/30] Misc patches for 2018-05-09 Peter Maydell
2018-05-11 12:33   ` Paolo Bonzini
2018-05-11 12:39     ` Peter Maydell
2018-05-11 12:42   ` Daniel P. Berrangé
2018-05-11 12:50     ` Peter Maydell
2018-05-11 12:54       ` Daniel P. Berrangé

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=20180514162337.GE23010@redhat.com \
    --to=berrange@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.