-
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.
alloca: allow passing alloca pointers to actions and subrs
A great many subrs and a good few actions allow the passing-in of pointers (mostly, but not entirely, char *) which may be in alloca()ed space. Since they then usually go on to dereference these pointers, the pointers must be bounds-checked. We already handled actions earlier (they don't do formal dereferences except insofar as it is already done via the deref operator, so we only needed to check them for nullity); but subrs remain unhandled. For non-alloca pointers we can just keep on doing null checking; for alloca pointers, we need to do the usual access_check/ptr dance, with a length derived from the parser's idea of the length (which is passed through identifiers accurately). In addition to subrs, we also need to handle alloca'ed pointers in codegen for stringof(), since the arg to stringof() might be in alloca()ed space too. A new test that tests more or less all of this is added: it has no expected results because all we actually care about is that there are no verifier failures. Signed-off-by: Nick Alcock <nick.alcock@oracle.com> Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
- Loading branch information
1 parent
91c2062
commit a24181d
Showing
5 changed files
with
237 additions
and
19 deletions.
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,164 @@ | ||
/* | ||
* 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: Function calls to alloca()ed space work. | ||
* | ||
* SECTION: Actions and Subroutines/alloca() | ||
*/ | ||
|
||
#pragma D option quiet | ||
|
||
/* | ||
* Everything is in an independent clause with its own alloca(), | ||
* to try to make sure that the verifier's bound proofs don't leak | ||
* from one test to the next. | ||
*/ | ||
|
||
BEGIN | ||
{ | ||
x = (char *) alloca(8); | ||
x[0] = 'a'; | ||
x[1] = '/'; | ||
x[2] = 'b'; | ||
x[3] = 0; | ||
printf("%s\n", stringof(x)); | ||
trace(x); | ||
} | ||
|
||
BEGIN | ||
{ | ||
x = (char *) alloca(8); | ||
x[0] = 'a'; | ||
x[1] = '/'; | ||
x[2] = 'b'; | ||
x[3] = 0; | ||
trace(basename(x)); | ||
} | ||
|
||
BEGIN | ||
{ | ||
x = (char *) alloca(8); | ||
y = (char *) alloca(8); | ||
x[0] = 'a'; | ||
x[1] = '/'; | ||
x[2] = 'b'; | ||
x[3] = 0; | ||
y[0] = '/'; | ||
y[1] = 0; | ||
trace(index(x, y)); | ||
} | ||
|
||
BEGIN | ||
{ | ||
x = (char *) alloca(8); | ||
y = (char *) alloca(8); | ||
x[0] = 'a'; | ||
x[1] = '/'; | ||
x[2] = 'b'; | ||
x[3] = 0; | ||
y[0] = '/'; | ||
y[1] = 0; | ||
trace(rindex(x, y)); | ||
} | ||
|
||
BEGIN | ||
{ | ||
x = (char *) alloca(8); | ||
x[0] = 'a'; | ||
x[1] = '/'; | ||
x[2] = 'b'; | ||
x[3] = 0; | ||
trace(strchr(x, '/')); | ||
} | ||
|
||
BEGIN | ||
{ | ||
x = (char *) alloca(8); | ||
x[0] = 'a'; | ||
x[1] = '/'; | ||
x[2] = 'b'; | ||
x[3] = 0; | ||
trace(strrchr(x, '/')); | ||
} | ||
|
||
BEGIN | ||
{ | ||
x = (char *) alloca(8); | ||
x[0] = 'a'; | ||
x[1] = '/'; | ||
x[2] = 'b'; | ||
x[3] = 0; | ||
trace(strlen(x)); | ||
} | ||
|
||
BEGIN | ||
{ | ||
x = (char *) alloca(8); | ||
y = (char *) alloca(8); | ||
x[0] = 'a'; | ||
x[1] = '/'; | ||
x[2] = 'b'; | ||
x[3] = 0; | ||
y[0] = '/'; | ||
y[1] = 0; | ||
trace(strjoin(x, y)); | ||
} | ||
|
||
BEGIN | ||
{ | ||
x = (char *) alloca(8); | ||
y = (char *) alloca(8); | ||
x[0] = 'a'; | ||
x[1] = '/'; | ||
x[2] = 'b'; | ||
x[3] = 0; | ||
y[0] = '/'; | ||
y[1] = 0; | ||
trace(strstr(x, y)); | ||
} | ||
|
||
BEGIN | ||
{ | ||
x = (char *) alloca(8); | ||
y = (char *) alloca(8); | ||
x[0] = 'a'; | ||
x[1] = '/'; | ||
x[2] = 'b'; | ||
x[3] = 0; | ||
y[0] = '/'; | ||
y[1] = 0; | ||
trace(strtok(x, y)); | ||
} | ||
|
||
BEGIN | ||
{ | ||
x = (char *) alloca(8); | ||
x[0] = '/'; | ||
x[1] = 0; | ||
trace(strtok(NULL, x)); | ||
} | ||
|
||
BEGIN | ||
{ | ||
x = (char *) alloca(8); | ||
x[0] = 'a'; | ||
x[1] = '/'; | ||
x[2] = 'b'; | ||
x[3] = 0; | ||
trace(substr(x, 0, 1)); | ||
} | ||
|
||
BEGIN | ||
{ | ||
exit(0); | ||
} | ||
|
||
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,2 @@ | ||
a/b | ||
8b11/b/b3a/b//baba |
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,29 @@ | ||
/* | ||
* 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: You can copy a string into an alloca'ed region and read | ||
* it out again. | ||
* | ||
* SECTION: Actions and Subroutines/alloca() | ||
*/ | ||
|
||
#pragma D option quiet | ||
#pragma D option scratchsize=512 | ||
|
||
BEGIN | ||
{ | ||
x = (string *)alloca(sizeof(string) + 1); | ||
*x = "abc"; | ||
trace(*x); | ||
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 @@ | ||
abc |