All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Mario Fleischmann <mario.fleischmann@lauterbach.com>
Cc: qemu-devel@nongnu.org, alex.bennee@linaro.org, philmd@linaro.org,
	armbru@redhat.com, christian.boenig@lauterbach.com
Subject: Re: [PATCH v2 08/20] mcd: Implement server connection API
Date: Thu, 15 May 2025 10:58:21 +0100	[thread overview]
Message-ID: <aCW6vZivY9-Yt8-H@redhat.com> (raw)
In-Reply-To: <20250430052741.21145-9-mario.fleischmann@lauterbach.com>

On Wed, Apr 30, 2025 at 07:27:29AM +0200, Mario Fleischmann wrote:
> This commit implements the necessary operations required to establish
> a connection with the MCD server:
> 
> * query information about the server
> * connect to "
> * disconnect from "
> 
> Signed-off-by: Mario Fleischmann <mario.fleischmann@lauterbach.com>
> ---
>  mcd/mcd_qapi.c         |  13 +++
>  mcd/mcd_qapi.h         |   2 +
>  mcd/mcd_server.c       | 110 +++++++++++++++++++++-
>  mcd/mcd_stub.c         |  98 ++++++++++++++++++++
>  qapi/mcd.json          | 205 +++++++++++++++++++++++++++++++++++++++++
>  tests/qtest/mcd-test.c |  96 +++++++++++++++++++
>  tests/qtest/mcd-util.c |  60 ++++++++++++
>  tests/qtest/mcd-util.h |   9 ++
>  8 files changed, 588 insertions(+), 5 deletions(-)
> 
> diff --git a/mcd/mcd_qapi.c b/mcd/mcd_qapi.c
> index 9a99866..d2a2926 100644
> --- a/mcd/mcd_qapi.c
> +++ b/mcd/mcd_qapi.c


> +MCDQryServersResult *qmp_mcd_qry_servers(const char *host, bool running,
> +                                         uint32_t start_index,
> +                                         uint32_t num_servers, Error **errp)
> +{
> +    MCDServerInfoList **tailp;
> +    MCDServerInfo *info;
> +    mcd_server_info_st *server_info = NULL;
> +    bool query_num_only = num_servers == 0;
> +    MCDQryServersResult *result = g_malloc0(sizeof(*result));
> +
> +    if (!query_num_only) {
> +        server_info = g_malloc0(num_servers * sizeof(*server_info));

This multiplication is (theoretically) subject to overflow. To eliminate
this risk, this should use

    g_new0(mcd_server_info_st, num_servers)

which will validate overflow & abort if hit.

There are many more instances of this code pattern in the series

$ git diff -r master | grep g_malloc | grep ' \* '
+        .tx = g_malloc(txlist->num_tx * sizeof(mcd_tx_st)),
+        server_info = g_malloc0(num_servers * sizeof(*server_info));
+        system_con_info = g_malloc0(num_systems * sizeof(*system_con_info));
+        device_con_info = g_malloc0(num_devices * sizeof(*device_con_info));
+        core_con_info = g_malloc0(num_cores * sizeof(*core_con_info));
+        memspaces = g_malloc0(num_mem_spaces * sizeof(*memspaces));
+        reg_groups = g_malloc0(num_reg_groups * sizeof(*reg_groups));
+        regs = g_malloc0(num_regs * sizeof(*regs));
+        ctrig_info = g_malloc0(num_ctrigs * sizeof(*ctrig_info));
+        trig_ids = g_malloc0(num_trigs * sizeof(*trig_ids));


QEMU is a bit inconsistent, but we have a slight bias in favour
of using g_new0, even for single struct allocations.

IMHO being in the habit of always using g_new0 instead of g_malloc
makes it less likely for people to inadvertantly introduce the
multiplication overflow code pattern with g_malloc.


With 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:[~2025-05-15  9:59 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-30  5:27 [PATCH v2 00/20] Add Multi-Core Debug (MCD) API support Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 01/20] mcd: Introduce Multi-Core Debug (MCD) API Mario Fleischmann
2025-04-30  8:19   ` Daniel P. Berrangé
2025-04-30 12:47     ` Mario Fleischmann
2025-04-30 12:55       ` Daniel P. Berrangé
2025-04-30 15:22         ` Mario Fleischmann
2025-04-30 16:00           ` Daniel P. Berrangé
2025-04-30  5:27 ` [PATCH v2 02/20] meson: Add --enable-mcd option Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 03/20] mcd: Introduce MCD server Mario Fleischmann
2025-05-15  9:46   ` Daniel P. Berrangé
2025-04-30  5:27 ` [PATCH v2 04/20] qapi: Introduce MCD schema Mario Fleischmann
2025-05-08 11:07   ` Markus Armbruster
2025-05-20  7:10     ` Markus Armbruster
2025-04-30  5:27 ` [PATCH v2 05/20] mcd: Introduce MCD server stub Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 06/20] qtest: Introduce MCD test suite Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 07/20] mcd: Implement target initialization API Mario Fleischmann
2025-05-08 12:03   ` Markus Armbruster
2025-05-14 13:59     ` Mario Fleischmann
2025-05-15  9:33       ` Markus Armbruster
2025-05-15 13:02   ` Markus Armbruster
2025-05-19 16:52     ` Mario Fleischmann
2025-05-20  7:13       ` Markus Armbruster
2025-04-30  5:27 ` [PATCH v2 08/20] mcd: Implement server connection API Mario Fleischmann
2025-05-15  9:58   ` Daniel P. Berrangé [this message]
2025-05-19 16:54     ` Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 09/20] mcd: Implement target system query Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 10/20] mcd: Implement core connection control Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 11/20] mcd: Implement memory space query Mario Fleischmann
2025-05-19  9:41   ` Manos Pitsidianakis
2025-05-19 18:24     ` Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 12/20] gdbstub: Expose GDBRegisterState Mario Fleischmann
2025-05-19  8:41   ` Manos Pitsidianakis
2025-05-19 18:26     ` Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 13/20] mcd: Implement register query Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 14/20] mcd: Implement runstate control Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 15/20] mcd test: Implement core state query Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 16/20] gdbstub: Expose gdb_write_register Mario Fleischmann
2025-05-19  8:38   ` Manos Pitsidianakis
2025-04-30  5:27 ` [PATCH v2 17/20] mcd: Implement register/memory access Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 18/20] mcd: Implement single stepping Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 19/20] mcd: Implement trigger control Mario Fleischmann
2025-04-30  5:27 ` [PATCH v2 20/20] mcd: Implement reset control Mario Fleischmann
2025-05-08 11:37 ` [PATCH v2 00/20] Add Multi-Core Debug (MCD) API support Markus Armbruster
2025-05-14 14:05   ` Mario Fleischmann
2025-05-20  7:35 ` Markus Armbruster
2025-05-20 14:16   ` Mario Fleischmann
2025-07-24  5:28 ` Markus Armbruster

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=aCW6vZivY9-Yt8-H@redhat.com \
    --to=berrange@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=christian.boenig@lauterbach.com \
    --cc=mario.fleischmann@lauterbach.com \
    --cc=philmd@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.