Skip to content

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions regression/cbmc-library/syscall-01/main.c
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;
Copy link
Collaborator

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 ?

errno = 0;
rc = syscall(SYS_chmod, "/etc/passwd", 0444);
assert(!(rc != -1) || (errno == 0));
}
10 changes: 10 additions & 0 deletions regression/cbmc-library/syscall-01/test.desc
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
48 changes: 48 additions & 0 deletions src/ansi-c/library/unistd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
To be overaproximating shouldn't this abstraction havoc all pointer arguments that were given to the syscall function ? This would maybe require handling this internally when typechecking calls to syscall.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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;
}