-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for copyinstr() subroutine
The copyinstr() subroutine is very similar to the copyin() subroutine. The differences are: - the 2nd argument (max size) is optional (default is strsize) - if a size is given, it is capped at strsize - data is copied using bpf_probe_read_user_str (or bpf_probe_read_str) Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com> Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
- Loading branch information
Showing
17 changed files
with
373 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2022, 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 copyinstr() size must not exceed the (adjusted) scratchsize. | ||
* | ||
* SECTION: Actions and Subroutines/copyinstr() | ||
* User Process Tracing/copyin() and copyinstr() | ||
*/ | ||
|
||
#pragma D option scratchsize=64 | ||
|
||
BEGIN | ||
{ | ||
copyinstr(0, 65); | ||
exit(0); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(1); | ||
} |
24 changes: 24 additions & 0 deletions
24
test/unittest/funcs/copyinstr/err.D_PROTO_ARG.non_scalar_arg1.d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2022, 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: Argument 1 for copyinstr() must be a scalar. | ||
* | ||
* SECTION: Actions and Subroutines/copyinstr() | ||
* User Process Tracing/copyin() and copyinstr() | ||
*/ | ||
|
||
BEGIN | ||
{ | ||
copyinstr("1", 2); | ||
exit(1); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(0); | ||
} |
24 changes: 24 additions & 0 deletions
24
test/unittest/funcs/copyinstr/err.D_PROTO_ARG.non_scalar_arg2.d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2022, 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: Argument 2 for copyinstr() must be a scalar. | ||
* | ||
* SECTION: Actions and Subroutines/copyinstr() | ||
* User Process Tracing/copyin() and copyinstr() | ||
*/ | ||
|
||
BEGIN | ||
{ | ||
copyinstr(1, "2"); | ||
exit(1); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(0); | ||
} |
24 changes: 24 additions & 0 deletions
24
test/unittest/funcs/copyinstr/err.D_PROTO_LEN.missing_arg.d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2022, 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: Arguments are required for copyinstr(). | ||
* | ||
* SECTION: Actions and Subroutines/copyinstr() | ||
* User Process Tracing/copyin() and copyinstr() | ||
*/ | ||
|
||
BEGIN | ||
{ | ||
copyinstr(); | ||
exit(1); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(0); | ||
} |
24 changes: 24 additions & 0 deletions
24
test/unittest/funcs/copyinstr/err.D_PROTO_LEN.too_many_args.d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2022, 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: No more than two arguments can be passed for copyinstr(). | ||
* | ||
* SECTION: Actions and Subroutines/copyinstr() | ||
* User Process Tracing/copyin() and copyinstr() | ||
*/ | ||
|
||
BEGIN | ||
{ | ||
copyinstr(1, 2, 3); | ||
exit(1); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2022, 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: Using copyinstr() with an invalid source address reports a fault. | ||
* | ||
* SECTION: Actions and Subroutines/copyinstr() | ||
* User Process Tracing/copyin() and copyinstr() | ||
*/ | ||
|
||
BEGIN | ||
{ | ||
copyinstr(0x1234, 8); | ||
exit(0); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FUNCTION:NAME | ||
:ERROR | ||
|
||
-- @@stderr -- | ||
dtrace: script 'test/unittest/funcs/copyinstr/err.badaddr.d' matched 2 probes | ||
dtrace: error on enabled probe ID 3 (ID 1: dtrace:::BEGIN): invalid address ({ptr}) in action #1 at BPF pc NNN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2022, 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 copyinstr() size must not exceed the (adjusted) scratchsize. | ||
* | ||
* SECTION: Actions and Subroutines/copyinstr() | ||
* User Process Tracing/copyin() and copyinstr() | ||
*/ | ||
|
||
#pragma D option scratchsize=64 | ||
|
||
BEGIN | ||
{ | ||
sz = 65; | ||
copyinstr(0, sz); | ||
exit(0); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2022, 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: Using copyinstr() with a NULL source address reports a fault. | ||
* | ||
* SECTION: Actions and Subroutines/copyinstr() | ||
* User Process Tracing/copyin() and copyinstr() | ||
*/ | ||
|
||
BEGIN | ||
{ | ||
copyinstr(0, 8); | ||
exit(0); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FUNCTION:NAME | ||
:ERROR | ||
|
||
-- @@stderr -- | ||
dtrace: script 'test/unittest/funcs/copyinstr/err.null_arg1.d' matched 2 probes | ||
dtrace: error on enabled probe ID 3 (ID 1: dtrace:::BEGIN): invalid address ({ptr}) in action #1 at BPF pc NNN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2006, 2022, 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: It is possible to read a string from userspace addresses. | ||
* | ||
* SECTION: Actions and Subroutines/copyinstr() | ||
* User Process Tracing/copyin() and copyinstr() Subroutines | ||
*/ | ||
|
||
#pragma D option quiet | ||
#pragma D option destructive | ||
|
||
BEGIN | ||
{ | ||
system("echo dtrace-copyinstr-test"); | ||
} | ||
|
||
syscall::write:entry | ||
/(s = copyinstr(arg1, 8))[6] == '-'/ | ||
{ | ||
printf("'%s'", s); | ||
exit(0); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dtrace-copyinstr-test | ||
'dtrace-' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2006, 2022, 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: It is possible to read a string from userspace addresses. | ||
* | ||
* SECTION: Actions and Subroutines/copyinstr() | ||
* User Process Tracing/copyin() and copyinstr() Subroutines | ||
*/ | ||
|
||
#pragma D option quiet | ||
#pragma D option destructive | ||
|
||
BEGIN | ||
{ | ||
system("echo dtrace-copyinstr-test"); | ||
} | ||
|
||
syscall::write:entry | ||
/(s = copyinstr(arg1))[6] == '-'/ | ||
{ | ||
printf("'%s'", s); | ||
exit(0); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dtrace-copyinstr-test | ||
'dtrace-copyinstr-test | ||
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2006, 2022, 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: It is possible to read a string from userspace addresses. | ||
* | ||
* SECTION: Actions and Subroutines/copyinstr() | ||
* User Process Tracing/copyin() and copyinstr() Subroutines | ||
*/ | ||
|
||
#pragma D option quiet | ||
#pragma D option destructive | ||
|
||
BEGIN | ||
{ | ||
system("echo dtrace-copyinstr-test"); | ||
} | ||
|
||
syscall::write:entry | ||
/(s = copyinstr(arg1, 32))[6] == '-'/ | ||
{ | ||
printf("'%s'", s); | ||
exit(0); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(1); | ||
} |
Oops, something went wrong.