Skip to content

Commit

Permalink
bpf: use correct loop bound for conf->cpus traversal in cpuinfo map c…
Browse files Browse the repository at this point in the history
…reation

We were using the wrong bound, causing a buffer overrun on machines with
online CPUs that do not have sequential CPU IDs.

(Add an assertion to verify that there are never more online CPUs
than possible CPUs.)

Orabug: 36356681
Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
nickalcock authored and kvanhees committed Mar 5, 2024
1 parent d4ff5b1 commit 6afe34c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions libdtrace/dt_bpf.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
Expand Down Expand Up @@ -613,10 +613,13 @@ gmap_create_cpuinfo(dtrace_hdl_t *dtp)
int i, rc;
uint32_t key = 0;
dtrace_conf_t *conf = &dtp->dt_conf;
size_t ncpus = conf->max_cpuid + 1;
size_t ncpus = conf->num_online_cpus;
dt_bpf_cpuinfo_t *data;
cpuinfo_t *ci;

/*
* num_possible_cpus <= num_online_cpus: see dt_conf_init.
*/
data = dt_calloc(dtp, dtp->dt_conf.num_possible_cpus,
sizeof(dt_bpf_cpuinfo_t));
if (data == NULL)
Expand Down
4 changes: 3 additions & 1 deletion libdtrace/dt_conf.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
Expand Down Expand Up @@ -98,6 +98,8 @@ dt_conf_init(dtrace_hdl_t *dtp)
if (conf->num_online_cpus == 0 || conf->cpus == NULL)
return;

assert(conf->num_possible_cpus >= conf->num_online_cpus);

conf->max_cpuid = conf->cpus[conf->num_online_cpus - 1].cpu_id;

/* Retrieve the chip ID (physical_package_id) for each CPU. */
Expand Down

0 comments on commit 6afe34c

Please sign in to comment.