-
Notifications
You must be signed in to change notification settings - Fork 273
Adds an over-approximation for syscall function #7937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <sys/syscall.h> | ||
|
||
#include <assert.h> | ||
#include <errno.h> | ||
#include <unistd.h> | ||
|
||
int main() | ||
{ | ||
long int rc; | ||
errno = 0; | ||
rc = syscall(SYS_chmod, "/etc/passwd", 0444); | ||
assert(!(rc != -1) || (errno == 0)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CORE unix | ||
main.c | ||
--pointer-check --bounds-check --conversion-check | ||
^\[main.assertion.\d+\] line \d+ assertion !\(rc != -1\) || \(errno == 0\): SUCCESS$ | ||
^\*\* 1 of \d+ failed .*$ | ||
^VERIFICATION SUCCESSFUL$ | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^\*\*\*\* WARNING: no body for function syscall |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -385,3 +385,51 @@ __CPROVER_HIDE:; | |
// Thus, modelling it as non-deterministic. | ||
return retval; | ||
} | ||
|
||
/* FUNCTION: syscall */ | ||
|
||
#ifndef __CPROVER_ERRNO_H_INCLUDED | ||
# include <errno.h> | ||
# define __CPROVER_ERRNO_H_INCLUDED | ||
#endif | ||
|
||
long int __VERIFIER_nondet_long_int(void); | ||
int __VERIFIER_nondet_int(void); | ||
|
||
// This overapproximation is based on the syscall specification available at | ||
// https://man7.org/linux/man-pages/man2/syscall.2.html and | ||
// https://www.gnu.org/software/libc/manual/html_node/System-Calls.html. | ||
// | ||
// sysno is the system call number. The remaining arguments are the arguments | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some system calls take pointer arguments and write data to the objects pointed to by these pointers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this lists all signatures for linux : |
||
// for the system call. Each kind of system call has a definite number of | ||
// arguments, from zero to five. If you code more arguments than the system | ||
// call takes, the extra ones to the right are ignored. | ||
#ifdef __APPLE__ | ||
int syscall(int sysno, ...); | ||
int syscall(int sysno, ...) | ||
#else | ||
long int syscall(long int sysno, ...); | ||
long int syscall(long int sysno, ...) | ||
#endif | ||
{ | ||
__CPROVER_HIDE:; | ||
(void)sysno; | ||
|
||
#ifdef __APPLE__ | ||
int retval = __VERIFIER_nondet_int(); | ||
#else | ||
long int retval = __VERIFIER_nondet_long_int(); | ||
#endif | ||
|
||
if(retval == -1) | ||
{ | ||
// We should keep errno as non-deterministic as possible, since this model | ||
// never takes into account any input. | ||
errno = __VERIFIER_nondet_int(); | ||
} | ||
|
||
// The return value is the return value from the system call, unless the | ||
// system call failed. This over-approximation doesn't take into account | ||
// any system call operation, so we leave the return value as non-det. | ||
return retval; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this also use the APPLE env to change the type as in the definition ?