From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Anthony PERARD <anthony@xenproject.org>
Cc: qemu-devel@nongnu.org,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Paul Durrant" <paul@xen.org>,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH 1/2] xen/console: fix error handling in xen_console_device_create()
Date: Thu, 9 Jan 2025 17:06:54 +0100 [thread overview]
Message-ID: <Z3_0HpmfpSM3Xw5Q@macbook.local> (raw)
In-Reply-To: <Z3-hWRLyMldV4ZZD@l14>
On Thu, Jan 09, 2025 at 11:13:45AM +0100, Anthony PERARD wrote:
> On Tue, Jan 07, 2025 at 10:31:39AM +0100, Roger Pau Monne wrote:
> > The usage of error_prepend() in some of the error contexts of
> > xen_console_device_create() is incorrect, as `errp` hasn't been initialized.
> > This leads to the following segmentation fault on error paths resulting from
> > xenstore reads:
> >
> > Program terminated with signal SIGSEGV, Segmentation fault.
> > Address not mapped to object.
> > fmt=0x15c4dfeade42 "failed to read console device type: ", ap=0x15cd0165ab50)
> > at ../qemu-xen-dir-remote/util/error.c:142
> > 142 g_string_append(newmsg, (*errp)->msg);
> > [...]
> > (gdb) bt
> > (errp=0x15cd0165ae10, fmt=0x15c4dfeade42 "failed to read console device type: ", ap=0x15cd0165ab50) at ../qemu-xen-dir-remote/util/error.c:142
> > (errp=0x15cd0165ae10, fmt=0x15c4dfeade42 "failed to read console device type: ")
> > at ../qemu-xen-dir-remote/util/error.c:152
> > (backend=0x43944de00660, opts=0x43944c929000, errp=0x15cd0165ae10)
> > at ../qemu-xen-dir-remote/hw/char/xen_console.c:555
> >
> > Replace usages of error_prepend() with error_setg() where appropriate.
> >
> > Fixes: 9b7737469080 ('hw/xen: update Xen console to XenDevice model')
> > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> > ---
> > hw/char/xen_console.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c
> > index ef0c2912efa1..af706c7ef440 100644
> > --- a/hw/char/xen_console.c
> > +++ b/hw/char/xen_console.c
> > @@ -551,7 +551,7 @@ static void xen_console_device_create(XenBackendInstance *backend,
> > }
> >
> > if (xs_node_scanf(xsh, XBT_NULL, fe, "type", errp, "%ms", &type) != 1) {
> > - error_prepend(errp, "failed to read console device type: ");
> > + error_setg(errp, "failed to read console device type: ");
>
> According to error_setg() doc, *errp must be NULL but xs_node_scanf may
> set it. Looking at the implementation, error_setg() seems to simply
> discard this new error message if *errp is already set.
>
> Currently, when there's an I/O error, we get something like:
> failed to read console device type: failed to read from /xenstore/path: doesn't exist
> and when the format scan failed:
> SEGV
>
> With this patch, when there's an I/O error, I think we get something
> like:
> failed to read from /xenstore/path: doesn't exist
> and when the format scan failed:
> failed to read console device type:
>
>
> So I think we'll want to distiguish between IO error from
> xs_node_scanf() and format error, first one returns EOF (like vsscanf)
> and second one returns a value >= 0 but we expect exactly 1.
The call to xs_node_scanf() will go away in the next patch replaced by
qemu_xen_xs_read(), at which point errp will never be initialized.
I can change the order of the patches if that makes it easier.
>
> > goto fail;
> > }
> >
> > @@ -582,7 +582,7 @@ static void xen_console_device_create(XenBackendInstance *backend,
> > } else if (number) {
> > cd = serial_hd(number);
> > if (!cd) {
> > - error_prepend(errp, "console: No serial device #%ld found: ",
> > + error_setg(errp, "console: No serial device #%ld found: ",
> > number);
>
> This change looks correct, ableit we could remove ": " from the end of
> the string since they shouldn't be anything after it.
Thanks, Roger.
next prev parent reply other threads:[~2025-01-09 16:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-07 9:31 [PATCH 0/2] xen: error handling and FreeBSD compatibility fixes Roger Pau Monne
2025-01-07 9:31 ` [PATCH 1/2] xen/console: fix error handling in xen_console_device_create() Roger Pau Monne
2025-01-09 10:13 ` Anthony PERARD
2025-01-09 16:06 ` Roger Pau Monné [this message]
2025-01-07 9:31 ` [PATCH 2/2] xen: do not use '%ms' scanf specifier Roger Pau Monne
2025-01-09 10:59 ` Anthony PERARD
2025-01-09 11:25 ` David Woodhouse
2025-01-09 16:55 ` Roger Pau Monné
2025-01-10 8:08 ` David Woodhouse
2025-01-10 8:16 ` Philippe Mathieu-Daudé
2025-01-10 8:21 ` David Woodhouse
2025-01-09 16:15 ` Roger Pau Monné
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=Z3_0HpmfpSM3Xw5Q@macbook.local \
--to=roger.pau@citrix.com \
--cc=anthony@xenproject.org \
--cc=edgar.iglesias@gmail.com \
--cc=marcandre.lureau@redhat.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sstabellini@kernel.org \
--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.