Skip to content
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 CN specs to MKM #142

Merged
merged 42 commits into from
Feb 13, 2025
Merged

Add CN specs to MKM #142

merged 42 commits into from
Feb 13, 2025

Conversation

podhrmic
Copy link
Collaborator

@podhrmic podhrmic commented Dec 2, 2024

This PR adds CN functional specifications to the MKM code in client.c, as well as various supporting files. These specifications are intended to be run-time tested as well as verified.

Files:

  • client.c - target function definitions
  • client.h - types, and CN predicates defining the types
  • cn_stubs.h - specifications and redefinitions for various library functions that can't be supported directly
  • run-cn-test.sh - run the CN test generator using the necessary flags
  • process-cn-test.sh - run the preprocessor. Called by run-cn-test.sh

Unfortunately, the CN verifier and test generators require different code-level annotations at various points. We handle this using a pair of macros:

  • CN_ENV - set when calling CN in either verify or test modes
  • CN_TEST - set when calling CN in test mode

Testing the PR

To run the verifier, run:

$ make cn_proof

Note this may be quite slow. It takes around 3m30s to complete on my newish MBP.

To run the tests, run:

$ ./run-cn-test.sh client.c test_directory 

Outstanding bugs

  • The run-cn-test.sh script pauses during execution and only continues when I press return. I assume this is due to some call in client.c which is blocking, but I haven't figured out the culprit yet. FIXED
  • Various points in the code include TODO notes. These generally indicate places I'm working around a limitation in CN of some kind. But some of these might be possible to resolve.

Changes:

  • CN specs for memory safety
  • CN specs for functional correctness
  • Scripts for executing the run-time testing capabilities
  • Integration of proofs into CI
  • Integration of testing into CI
  • Fix bugs / limitations (see above)

Base automatically changed from 98-mkm-server to main December 11, 2024 00:59
@septract septract force-pushed the 139-feature-verify-test-mkm-module branch from 667e47c to a4f9a2a Compare December 18, 2024 21:56
@septract septract force-pushed the 139-feature-verify-test-mkm-module branch from a4f9a2a to 218a2f2 Compare December 18, 2024 22:42
@podhrmic podhrmic linked an issue Dec 31, 2024 that may be closed by this pull request
4 tasks
@septract
Copy link
Contributor

@peterohanley @podhrmic PR ready to be re-reviewed when you have time. We now supports verification and functional correctness proofs of MKM, and testing of MKM. I've removed a lot of the limitations that existed before (but introduced some new ones caused by the test generator...).

@septract septract mentioned this pull request Jan 1, 2025
Copy link
Contributor

@peterohanley peterohanley left a comment

Choose a reason for hiding this comment

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

The changes to failing malloc are big improvements.

septract and others added 6 commits January 16, 2025 14:18
This is due to cerberus issue 437. The CN_TEST definition is not enough,
we would need another definition so that CN sees them but they are not
in the code passed to cc.
@spernsteiner
Copy link
Contributor

I fixed the CI errors from the mkm and mkm_client unit tests by uncommenting an HMAC call in policy.c, which @septract commented out in 76862a7. I suspect this may have broken cn verify and/or cn test on policy.c, but we don't currently run CN on that file in CI or in make cn_proof/make cn_test, so I'm not sure whether we care about keeping it working.

Copy link
Collaborator Author

@podhrmic podhrmic left a comment

Choose a reason for hiding this comment

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

@septract I pointed out the remaining documentation issues - TL;DR; if you have TODO in the code, it should be explained / linked to an issue. Otherwise change it to NOTE or completely remove that comment.

int client_epoll_ctl(struct client* c, int epfd, int op) {
int client_epoll_ctl(struct client* c, int epfd, int op)
/*$
// TODO fill in an actual spec here, depending what's needed
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@septract please either provide specs, or explain why we are not providing them (e.g. unsupported by the CN)

let pos = (u64) Client_in.pos;
ensures
take Client_out = ClientObject(c);
// TODO more compact notation?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@septract please remove the TODOs, or add explanation why we still have those

@@ -133,7 +261,15 @@ enum client_event_result client_read(struct client* c) {
return RES_DONE;
}

int ret = read(c->fd, buf + c->pos, buf_size - c->pos);
// TODO Mysterious why this particular case split is needed
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@septract is there a ticket filled that captures this mystery?

@@ -158,7 +303,21 @@ enum client_event_result client_write(struct client* c) {
return RES_DONE;
}

int ret = write(c->fd, buf + c->pos, buf_size - c->pos);
// TODO Mysterious why this particular case split is needed
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@septract please remove the TODOs

ensures
take Client_out = ClientObject(c);

// TODO more compact notation needed saying 'all fields except but X remains unchanged'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@septract is this captured in a ticket? (CN redesign?)

uint8_t hmac_message[MEASURE_SIZE + NONCE_SIZE] = {0};
// TODO gross hack caused by weird CN type lifting
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Please provide more context/link to an issue

@@ -75,7 +179,22 @@ const uint8_t* policy_match(uint8_t key_id[KEY_ID_SIZE], uint8_t nonce[NONCE_SIZ
}

// Now check each policy entry in turn to find one that matches.
for (size_t i = 0; i < policy_table_len; ++i) {
// TODO: can't use prefix ++i due to #807
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
// TODO: can't use prefix ++i due to #807
// TODO: can't use prefix ++i
// see https://github.com/rems-project/cerberus/issues/807

@@ -85,3 +204,4 @@ const uint8_t* policy_match(uint8_t key_id[KEY_ID_SIZE], uint8_t nonce[NONCE_SIZ
fprintf(stderr, "policy_match: no match\n");
return NULL;
}
#endif
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
#endif
#endif

/*$ function (u64) KEY_SIZE () $*/
static uint64_t c_KEY_SIZE() /*$ cn_function KEY_SIZE; $*/ { return KEY_SIZE; }
#else
// TODO: Have to hardcode the values as CN test doesn't support cn_function :(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Link to an issue please...

@@ -31,6 +59,7 @@ int policy_add(
const uint8_t key_id[KEY_ID_SIZE],
const uint8_t measure[MEASURE_SIZE],
const uint8_t key[KEY_SIZE]);
// TODO: can't write a spec here thanks to #371
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
// TODO: can't write a spec here thanks to #371
// TODO: can't write a spec here, see https://github.com/rems-project/cerberus/issues/371

@septract
Copy link
Contributor

I've fixed the TODOs in client.c and client.h. With policy.c and policy.h I think we should revert these files to their state on master, and make a new branch with the changes on it. The reason is this bit of the proof is only half-completed and needs more work. I don't want to eliminate all the TODOs yet, and I don't have time right now to fix everything.

@podhrmic how does that sound?

@podhrmic
Copy link
Collaborator Author

Thanks for the changes @septract ! I am a bit hesitant to keep a separate branch as it makes the OpenSUT delivery more difficult. Maybe merge as is and deal with the TODOs later?

@septract
Copy link
Contributor

septract commented Feb 12, 2025

I and @podhrmic discussed this and we think the easiest route is just to merge as-is. We can open a new ticket / PR to continue work on protocol.c.

@podhrmic if you're happy once you've complete a final review, please go ahead and merge. Otherwise, ping me and I'll perform any fixes before Friday

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Verify / test MKM module
4 participants