[DTrace-devel] [PATCH 2/2] Forbid increasing iregs above default
Kris Van Hees
kris.van.hees at oracle.com
Fri Apr 28 23:50:29 UTC 2023
On Thu, Mar 09, 2023 at 11:51:54AM -0500, eugene.loh--- via DTrace-devel wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
>
> If iregs is set larger than the default, code is generated using
> nonexistent registers and the BPF verifier emits confusing errors.
>
> Simply do not allow users to increase iregs beyond the default.
>
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
> libdtrace/dt_options.c | 2 +-
> test/unittest/options/err.iregs.d | 16 ++++++++++++++++
> test/unittest/options/err.iregs.r | 2 ++
> 3 files changed, 19 insertions(+), 1 deletion(-)
> create mode 100644 test/unittest/options/err.iregs.d
> create mode 100644 test/unittest/options/err.iregs.r
>
> diff --git a/libdtrace/dt_options.c b/libdtrace/dt_options.c
> index 1c32dc3d..d25b2ac9 100644
> --- a/libdtrace/dt_options.c
> +++ b/libdtrace/dt_options.c
> @@ -264,7 +264,7 @@ dt_opt_iregs(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
> {
> int n;
>
> - if (arg == NULL || (n = atoi(arg)) <= 0)
> + if (arg == NULL || (n = atoi(arg)) <= 0 || n > DIF_DIR_NREGS)
> return dt_set_errno(dtp, EDT_BADOPTVAL);
>
> dtp->dt_conf.dtc_difintregs = n;
> diff --git a/test/unittest/options/err.iregs.d b/test/unittest/options/err.iregs.d
> new file mode 100644
> index 00000000..ace21d6d
> --- /dev/null
> +++ b/test/unittest/options/err.iregs.d
> @@ -0,0 +1,16 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2023, 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.
> + */
> +
> +/* DTrace should recognize when iregs is too great for # of BPF registers */
> +#pragma D option iregs=9
> +
> +BEGIN
> +{
> + a = 1;
> + trace(a);
> + exit(0);
> +}
> diff --git a/test/unittest/options/err.iregs.r b/test/unittest/options/err.iregs.r
> new file mode 100644
> index 00000000..536c3eb8
> --- /dev/null
> +++ b/test/unittest/options/err.iregs.r
> @@ -0,0 +1,2 @@
> +-- @@stderr --
> +dtrace: failed to compile script test/unittest/options/err.iregs.d: line 9: failed to set option 'iregs' to '9': Invalid value for specified option
> --
> 2.18.4
>
>
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel
More information about the DTrace-devel
mailing list