All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: "Javi Merino" <javi.merino@cloud.com>,
	xen-devel@lists.xenproject.org, jbeulich@suse.com,
	"Anthony PERARD" <anthony.perard@vates.tech>,
	"Juergen Gross" <jgross@suse.com>,
	"Edwin Török" <edwin.torok@cloud.com>
Subject: Re: [XEN PATCH v2 1/3] libxl: Fix nul-termination of the return value of libxl_xen_console_read_line()
Date: Mon, 2 Sep 2024 09:50:28 +0200	[thread overview]
Message-ID: <ZtVuRHJbx_syQgdN@macbook.local> (raw)
In-Reply-To: <dc7d8179-b2c9-4ec8-99e5-5a901b751832@citrix.com>

On Fri, Aug 30, 2024 at 08:22:29PM +0100, Andrew Cooper wrote:
> On 29/08/2024 4:53 pm, Roger Pau Monné wrote:
> > On Fri, Aug 23, 2024 at 06:05:03PM +0100, Javi Merino wrote:
> >> When built with ASAN, "xl dmesg" crashes in the "printf("%s", line)"
> >> call in main_dmesg().  ASAN reports a heap buffer overflow: an
> >> off-by-one access to cr->buffer.
> >>
> >> The readconsole sysctl copies up to count characters into the buffer,
> >> but it does not add a null character at the end.  Despite the
> >> documentation of libxl_xen_console_read_line(), line_r is not
> >> nul-terminated if 16384 characters were copied to the buffer.
> >>
> >> Fix this by asking xc_readconsolering() to fill the buffer up to size
> >> - 1.  As the number of characters in the buffer is only needed in
> >> libxl_xen_console_read_line(), make it a local variable there instead
> >> of part of the libxl__xen_console_reader struct.
> > Instead of playing games with the buffer size in order to add an extra
> > NUL character, we could possibly use libxl_write_exactly(ctx,
> > STDOUT_FILENO,...) in main_dmesg(), using cr->count as the buffer
> > length?
> 
> Sadly no.
> 
> struct libxl__xen_console_reader (which has the count field) is a libxl
> private (opaque) type which `xl` can't access.

I was fooled by the libxl_xen_console_reader typedef.

> Otherwise this would be a oneline fix already...

Hm, maybe the easiest way is to introduce a new function that returns
the buffer and the number of characters?
(libxl_xen_console_dump_buffer() or similar?)

Thanks, Roger.


  reply	other threads:[~2024-09-02  7:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-23 17:05 [XEN PATCH v2 0/3] libxl: Fixes for libxl_xenconsole_readline() Javi Merino
2024-08-23 17:05 ` [XEN PATCH v2 1/3] libxl: Fix nul-termination of the return value of libxl_xen_console_read_line() Javi Merino
2024-08-27 15:20   ` Anthony PERARD
2024-09-02 14:55     ` Javi Merino
2024-08-29 15:53   ` Roger Pau Monné
2024-08-30 19:22     ` Andrew Cooper
2024-09-02  7:50       ` Roger Pau Monné [this message]
2024-09-02 15:03         ` Javi Merino
2024-08-23 17:05 ` [XEN PATCH v2 2/3] libxl: Remove unnecessary buffer zeroing and zalloc() Javi Merino
2024-08-27 15:21   ` Anthony PERARD
2024-08-23 17:05 ` [XEN PATCH v2 3/3] libxl: Update the documentation of libxl_xen_console_read_line() Javi Merino
2024-08-23 17:31   ` Andrew Cooper
2024-09-02 16:16     ` Javi Merino
2024-08-27 15:26   ` Anthony PERARD
2024-09-02 16:19     ` Javi Merino
2024-09-02 10:14   ` Alejandro Vallejo
2024-09-02 15:08     ` Javi Merino

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=ZtVuRHJbx_syQgdN@macbook.local \
    --to=roger.pau@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=edwin.torok@cloud.com \
    --cc=javi.merino@cloud.com \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=xen-devel@lists.xenproject.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.