-
Notifications
You must be signed in to change notification settings - Fork 100
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
Add support for non-deterministic pointer #2300
Comments
My understanding is that |
In my trial, using |
You can see documentation for I'm not sure what you are trying to achieve with cc. @tautschnig |
You can also perform the pointer allocation in the harness, e.g. use std::alloc::{alloc, dealloc, Layout};
pub struct Context {
pub len: u32,
}
fn entry(a0: usize) -> Result<usize, ()> {
let ctx = a0 as *mut Context;
unsafe {
if (*ctx).len > 10 {
// this is the violating condition
return Err(());
}
}
Ok(0)
}
#[kani::proof]
#[kani::unwind(64)]
fn main() {
let layout = Layout::new::<Context>();
let ptr = unsafe { alloc(layout) };
unsafe {
(*(ptr as *mut Context)).len = kani::any();
}
let r0 = ptr as usize;
//let r0 = kani::any(); // let's say that this value is passed from an external interface (e.g., hardware)
// // and we want to assume the pointer's validity after some sanity checks
let ret = entry(r0);
unsafe {
dealloc(ptr, layout);
}
} Does this achieve what you're looking for? |
@zhassan-aws, thank you a lot for the concrete example. pub struct Context {
pub len: u32,
}
fn entry(a0: usize) -> Result<usize, ()> {
let ctx = a0 as *mut Context;
unsafe {
if (*ctx).len > 10 {
// this is the violating condition
return Err(());
}
}
Ok(0)
}
#[kani::proof]
#[kani::unwind(64)]
fn main() {
let mut ctx = Context {
len: kani::any(),
};
let r0 = &mut ctx as *mut Context as usize;
let ret = entry(r0);
} One problem in either using the local assignment or using |
Thank you for the comment and the reference. What I want is giving an assumption about the pointer allocations, which might be against the CBMC's general discipline about dealing with pointers. Using |
Yes, the only difference is that in one, the pointer points to the stack (local variable), and in the other, the pointer points to the heap.
Can you clarify the semantics you're trying to achieve? Are you looking to create a pointer whose value itself is arbitrary? Is a model of the Sender included in the program? |
Sure. Creating a pointer whose value itself is arbitrary is exactly what I want. The model of the Sender is not included in the program. The below is the semantics I have in mind. [semantics]
[optional]
|
I see, thanks for the clarification. AFAIK, this cannot be achieved from Kani today as CBMC manages the addresses that are given to pointers. Some of the semantics you mention are achieved by |
Hi @zpzigi754, we have recently added a PointerGenerator to generate pointers with Arbitrary allocation status. This is not quite yet completely arbitrary pointers, but it satisfies most of the semantics you posted. Please let me know if that makes sense. |
Hi @celinval, good to hear from you that there is a support for the pointers with the arbitrary allocation status. I appreciate your effort and the update. |
Here are a few limitations: 1. Harness for`write_bytes` was disabled due to: - Issue model-checking/kani#90. 2. The harnesses explicitly disable cases where a pointer is dangling. - Kani cannot make assumptions on pointer allocation for dead or dangling pointers (model-checking/kani#2300). 3. Actual intrinsics are very hard to verify with Kani. The cases we can verify are those that have wrappers around the actual intrinsic. - Issue model-checking/kani#3345 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Michael Tautschnig <mt@debian.org> Co-authored-by: Michael Tautschnig <tautschn@amazon.com>
Requested feature: assuming the validity of pointers
Use case: system verification
Let's say that an object is allocated in one place (place A) and its pointer is passed through an external interface (e.g., user-kernel boundary) to an another place (place B). In this case where place B cannot keep track of place A's objects, how can place B assume that the passed pointer is valid?
If I try to use the passed pointer directly, it generates a series of dereference failure such as
If I treat the passed pointer as dynamic object with
__CPROVER_assume(__CPROVER_DYNAMIC_OBJECT(p));
,one failure still remains.
How could I remove that remaining failure?
Test case:
To run the harness with the CPROVER functions, I've used the below stub
with the command
cargo kani --enable-unstable --c-lib stub64.c
.The text was updated successfully, but these errors were encountered: