From: Nick Alcock <nick.alcock@oracle.com>
To: Kris Van Hees <kris.van.hees@oracle.com>,
<dtrace@lists.linux.dev>, <dtrace-devel@oss.oracle.com>
Subject: Re: [DTrace-devel] [PATCH 1/4] parser, cg: Implement the return() action
Date: Tue, 15 Jul 2025 11:32:42 +0100 [thread overview]
Message-ID: <87h5zdwxpx.fsf@esperi.org.uk> (raw)
In-Reply-To: <SJ0PR10MB5672B1209A91191478708DBEC257A@SJ0PR10MB5672.namprd10.prod.outlook.com> (Kris Van Hees via DTrace-devel's message of "Tue, 15 Jul 2025 01:47:36 -0400")
On 15 Jul 2025, Kris Van Hees via DTrace-devel outgrape:
> The return(n) action can be used for error injection by forcing a
> given return value for a kernel function.
I am amazed this is even possible! I can see all sorts of uses.
Presumably we need to tell people to turn on CONFIG_BPF_KPROBE_OVERRIDE
somewhere... UEK already has it on, good. Not many functions
covered... I suppose it'll let them trace a *few* functions, and if they
use this they're probably used to hacking in more error-injection points
anyway.
> Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Nick Alcock <nick.alcock@oracle.com>
modulo the tiny nits below.
> diff --git a/libdtrace/dt_lex.l b/libdtrace/dt_lex.l
> index cc165c1e..bdcca415 100644
> --- a/libdtrace/dt_lex.l
> +++ b/libdtrace/dt_lex.l
> @@ -104,7 +104,6 @@ if (yypcb->pcb_token != 0) {
> <S0>provider return DT_KEY_PROVIDER;
> <S0>register return DT_KEY_REGISTER;
> <S0>restrict return DT_KEY_RESTRICT;
> -<S0>return return DT_KEY_RETURN;
> <S0>self return DT_KEY_SELF;
> <S0>short return DT_KEY_SHORT;
> <S0>signed return DT_KEY_SIGNED;
I guess these are here for C/C++ header parsing :) a somewhat hopeful
approach. I wonder if this change will cause breakage for non-bracketed
returns in C code in static inlines... and returns of non-integral
types, and just plain return... ugh. I suppose inlines barely work
anyway and the right way to do that is to simply have the parser ignore
static inlines in C headers anyway, not have it try to parse them :)
> diff --git a/libdtrace/dt_open.c b/libdtrace/dt_open.c
> index c67455e7..08394a11 100644
> --- a/libdtrace/dt_open.c
> +++ b/libdtrace/dt_open.c
> @@ -269,6 +269,8 @@ static const dt_ident_t _dtrace_globals[] = {
> &dt_idops_func, "void(int)" },
> { "rand", DT_IDENT_FUNC, 0, DIF_SUBR_RAND, DT_ATTR_STABCMN, DT_VERS_1_0,
> &dt_idops_func, "int()" },
> +{ "return", DT_IDENT_ACTFUNC, 0, DT_ACT_RETURN, DT_ATTR_STABCMN, DT_VERS_2_0,
> + &dt_idops_func, "void(int)" },
The "problem" (if this actually is a problem) is that this is not the C
prototype, which is not expressible in C :(
> diff --git a/test/unittest/actions/return/err.D_PROTO_LEN.missing_arg.d b/test/unittest/actions/return/err.D_PROTO_LEN.missing_arg.d
> new file mode 100644
> index 00000000..97ed0762
> --- /dev/null
> +++ b/test/unittest/actions/return/err.D_PROTO_LEN.missing_arg.d
> @@ -0,0 +1,20 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2025, 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.
> + */
> +
> +/*
> + * ASSERTION: The return() action takes exactly one argument.
> + *
> + * SECTION: Actions and Subroutines/return()
> + */
> +
> +#pragma D option quiet
> +
> +BEGIN
> +{
> + return();
> + exit(0);
> +}
You might want to try a straight 'return;' as well :)
> diff --git a/test/unittest/actions/return/err.D_PROTO_LEN.too_many_args.r b/test/unittest/actions/return/err.D_PROTO_LEN.too_many_args.r
> new file mode 100644
> index 00000000..37ff4d9d
> --- /dev/null
> +++ b/test/unittest/actions/return/err.D_PROTO_LEN.too_many_args.r
> @@ -0,0 +1,2 @@
> +-- @@stderr --
> +dtrace: failed to compile script test/unittest/actions/return/err.D_PROTO_LEN.too_many_args.d: [D_PROTO_LEN] line 18: return( ) prototype mismatch: 2 args passed, 1 expected
> diff --git a/test/unittest/actions/return/err.destructive.d b/test/unittest/actions/return/err.destructive.d
> new file mode 100644
> index 00000000..4c4a246a
> --- /dev/null
> +++ b/test/unittest/actions/return/err.destructive.d
> @@ -0,0 +1,26 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2025, 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.
> + */
> +
> +/*
> + * ASSERTION: return() is allowed when destructive execution is allowed
return() is forbidden when destructive execution is not allowed.
next prev parent reply other threads:[~2025-07-15 10:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-15 5:47 [PATCH 1/4] parser, cg: Implement the return() action Kris Van Hees
2025-07-15 10:32 ` Nick Alcock [this message]
2025-07-15 15:03 ` [DTrace-devel] " Kris Van Hees
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=87h5zdwxpx.fsf@esperi.org.uk \
--to=nick.alcock@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
--cc=kris.van.hees@oracle.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox