1272 Commits

Author SHA1 Message Date
Matthew Parkinson
88a2740fe3 Add stricter double free checking on large allocs (#550)
Although, double frees are generally caught on large allocs.  This is
done very late in the process after many operations more operations have
occurred.

This change brings that check much earlier in the process.
2022-09-02 16:53:20 +01:00
Matthew Parkinson
f8efcb7f10 Use a more portable way to access the configuration. 2022-08-23 11:09:21 +01:00
Matthew Parkinson
a19ad550e7 Update BUILDING.md (#549) 2022-08-23 11:08:51 +01:00
Nathaniel Wesley Filardo
09bc0c6be7 NFC: external_pointer address_cast earlier
Make it easier to justify our avoidance of capptr_from_client and
capptr_reveal in external_pointer by performing address_cast earlier.
In particular, with this change, we can see that the pointer (and so its
authority, in CHERI) is not passed to any called function other than
address_cast and pointer_offset, and so authority is merely propagated
and neither exercised nor amplified.

Remove the long-disused capptr_reveal_wild, which was added for earlier
versions of external_pointer.
2022-07-07 16:57:47 +01:00
Nathaniel Wesley Filardo
db3ae1c8e3 NFC: Rename ConceptPAL to IsPAL 2022-07-07 16:57:47 +01:00
Nathaniel Wesley Filardo
9e0fefc3b0 NFC: Rename ConceptAAL to IsAAL 2022-07-07 16:57:47 +01:00
Nathaniel Wesley Filardo
b2c75dffb7 NFC: rename ConceptBound to IsBound 2022-07-07 16:57:47 +01:00
Nathaniel Wesley Filardo
df1dbc997f Add Morello CI 2022-06-21 15:08:52 +01:00
Nathaniel Wesley Filardo
467c28b2d3 Add buffer append method for {,u}intptr_t
Otherwise, on platforms for which {,u}intptr_t aren't just typedef-s of
other scalar types, it's ambiguous which way an implicit cast should go.
2022-06-21 13:57:53 +01:00
Matthias Wahl
c560a9aa27 Fix wrong ifdef in pal_linux.h (#546) 2022-06-17 10:48:27 +01:00
Matthias Wahl
6b0bda01c7 Support older linux systems (#545)
* Fix pal_linux.h for older linux systems

Where MADV_FREE is not defined - replaced with MADV_DONTNEED
Where GRND_NONBLOCK is not defined in <sys/random.h> but in <linux/random.h>

* Check for linux/random.h in CMake

as __has_include seems to not be reliable

* Use CMake module CheckIncludeFilesCXX

as C language isn't enabled by default everywhere

* Move madvise flag ifdefs into constexpr for cleaner code
2022-06-17 06:16:32 +01:00
Nathaniel Wesley Filardo
3e72ef63ad NFC: cmake: add SNMALLOC_LINK_ICF, default on
ICF currently breaks building on Morello, so allow cmake to notch it out.
2022-06-09 14:20:36 +01:00
Nathaniel Wesley Filardo
da19291d4e RFC: Add tests for some CHERI-specific behaviors 2022-06-09 01:05:04 +01:00
Nathaniel Wesley Filardo
095e8f13db func-malloc: expand CHERI tests to check no-VMEM 2022-06-09 01:05:04 +01:00
Nathaniel Wesley Filardo
3fce61eafb docs: Update StrictProvenance 2022-06-09 01:05:04 +01:00
Nathaniel Wesley Filardo
1f79c7638a mem/pool: Alloc-bound pooled things
These pieces of metadata (specifically, the Allocator structures) are never
deallocated at the moment, so we need not consider how we might amplify these
bounded pointers back to higher authority.
2022-06-09 01:05:04 +01:00
Nathaniel Wesley Filardo
94957f0f72 StrictProvenance support in Backend
Wrap the FrontendSlabMetadata with a struct that holds the Arena-bounded
authority for Chunks that the Backend ships out to the Frontend or, for
non-StrictProvenance architecture, encapsulates the sleight of hand that turns
Chunk-bounded CapPtr-s to Arena-bounded ones.
2022-06-09 01:05:04 +01:00
Nathaniel Wesley Filardo
86124ba26c backend ranges: use Arena bounds throughout
Update the backend concept so that metadata allocations are Arena-bounded.
2022-06-09 01:05:04 +01:00
Nathaniel Wesley Filardo
a78a16e637 smallbuddy ranges are only for small things
Now that we've split the range Pipe-line externally, the small-buddy ranges
should never be seeing large requests.
2022-06-09 01:05:04 +01:00
Nathaniel Wesley Filardo
83ac7c691e backend ranges: hide object_range behind accessor
This allows us to have a single Pipe-line of ranges where we can, nevertheless,
jump over the small buddy allocator when making large allocations.  This, in
turn, will let us differentiate the types coming from the small end and the
large "tap" on this Pipe-line.
2022-06-09 01:05:04 +01:00
Nathaniel Wesley Filardo
aa61b59a8f NFC: Generalize smallbuddyrange bounds annotations
Make these generic, with the SmallBuddyRange taking its cue from the parent
Range, since we're about to change them anyway and might want to vary them again
in the future.
2022-06-09 01:05:04 +01:00
Nathaniel Wesley Filardo
f41bb321f7 RFC: Hide CapPtr constructor
Expose a static CapPtr<T,B>::unsafe_from() and use that everywhere instead
(though continue to allow implicit and explicit construction of CapPtr from
nullptr).
2022-06-09 01:05:04 +01:00
Nathaniel Wesley Filardo
41128a3387 NFC: additional generalization for CHERI 2022-06-09 01:05:04 +01:00
Nathaniel Wesley Filardo
d5b155bf25 NFC: Generalize Default Pagemap Entry
Do not hard-code FrontendSlabMetadata, but rather take it as a template argment.
We're going to plumb other types through for StrictProvenance.
2022-06-09 01:05:04 +01:00
Nathaniel Wesley Filardo
966f2f1627 NFC: capptr: re-introduce Arena bounds 2022-06-09 01:05:04 +01:00
Nathaniel Wesley Filardo
6a5f3c2b82 NFC: backend_helper: generalize chunk bounds
Most ranges just deal with whatever kinds of ranges their parent deal with, but
that might be Chunk- or (soon) Arena-bounded.  This commit does not yet
introduce nuance, but just sets the stage.
2022-06-09 01:05:04 +01:00
Matthew Parkinson
e17672d3c1 Missing PRIVATE in cmake. (#539) 2022-06-07 16:13:36 +01:00
David CARLIER
e7e558badf exposes macOs malloc_good_size (#538) 2022-06-07 16:09:55 +01:00
Nathaniel Filardo
392acff4d5 RFC, NFC: refactor ranges to be nested templates (#535)
This way, we don't have to specify a Parent when we're just interested in
Pipe-ing things together.

We could have called these inner classes Apply and left the Pipe implementation
alone, but it's probably better to call them Type and adjust the Pipe code.
2022-06-06 12:04:37 +01:00
Matthew Parkinson
9464556129 Add a TID to the PAL (#536)
Making this part of the PAL allows other platforms to replace with
something more suitable.
2022-05-31 16:42:17 +01:00
Matthew Parkinson
53d9fd2abe Alter PAGE_SIZE usage (#534)
* Sanity check on parameters to large buddy.

* Check commit occurs at page granularity

* Alter PAGE_SIZE usage

Using PAGE_SIZE as the minimum size of the CHUNK means that if this is
configured to 2MiB, then there is a gap between
MAX_SMALL_SIZECLASS_SIZE, and MIN_CHUNK_SIZE, and thus
we can't represent certain sizes,
2022-05-31 13:59:42 +01:00
Matthew Parkinson
03c9da6aa4 Refactor interface between backend and frontend (#530)
* Rename to use Config, rather than StateHandle/Globals/Backend
* Make Backend a type on Config that contains the address space management implementation
* Make Ranges part of the Backend configuration, so we can reuse code for different ways of managing memory
* Pull the common chains of range definitions into separate files for reuse.
* Move PagemapEntry to CommonConfig
* Expose Pagemap through backend, so frontend doesn't see Pagemap directly
* Remove global Pal and use DefaultPal, where one is not pass explicitly.

Co-authored-by: David Chisnall <davidchisnall@users.noreply.github.com>
Co-authored-by: Nathaniel Filardo <105816689+nwf-msr@users.noreply.github.com>
2022-05-31 10:45:04 +01:00
David Carlier
1b8aa6bc0d Haiku build fix post refactoring. 2022-05-26 08:11:46 +01:00
Matthew Parkinson
7ff10c30f1 Enable accessing parent ranges. (#529)
This exposes a feature on Ranges to access ranges higher up the
stack of ranges.  This could be useful for applying operations in the
middle of a pipeline like

   object_range.ancestor<SpecialRange>().init(...);

This allows some initialisation to be added to the middle of pipeline
without breaking the current coding pattern.

It also allows for bypassing some ranges

   object_range.ancestor<LargeObjectsRange>().alloc_chunk(...);

Neither are done in this commit, but both will occur in future commits.

Co-authored-by: Nathaniel Wesley Filardo <nfilardo@microsoft.com>
2022-05-19 21:19:49 +01:00
Matthew Parkinson
c445de8eb4 Alter FailFast behaviour of memcpy (#526)
This commit changes the codegen for error messages for failed memcpys.
This no longer generates a stack frame and correctly tail calls the
error messages generator.

It also turns the error messages on in Release builds.  This will lead
to better adoption experience.
2022-05-19 14:20:45 +01:00
Matthew Parkinson
87d71cce21 Add a pipe operation to ranges (#527)
The ranges are naturally put together with pipes. This
commit does some template magic to make the code more
readable.  There should be now functional changes with
this change.
2022-05-17 16:34:00 +01:00
Matthew Parkinson
888d182bac Check size is correct if specified
Some secure allocators check that the C++ supplied size is correct
relative to the meta-data. This adds a check to the secure version of
snmalloc to do that.
2022-05-12 10:12:07 +01:00
Matthew Parkinson
967f1f2033 Allow check_client messages to have parameters
Make the check_client macro use the new "pretty" format.
2022-05-12 10:12:07 +01:00
Matthew Parkinson
22d7c04cb8 debug_check_empty (#521)
Currently a failing debug_check_empty does not provide any information.
This change allows it to print the size of the one of the allocations
that has not been freed.
2022-05-12 09:37:03 +01:00
Jakub Panek
c4f31bb279 Fix markdown (#522)
* Fix markdown link to ./docs/AddressSpace

* Fix footnotes in docs/StrictProvenance.md
2022-05-10 15:51:59 +01:00
Matthew Parkinson
d5c732f3c1 Preparation for 0.6.0 (#517)
Co-authored-by: David Chisnall <davidchisnall@users.noreply.github.com>
Co-authored-by: Robert Norton <1412774+rmn30@users.noreply.github.com>
Co-authored-by: Nathaniel Wesley Filardo <nfilardo@microsoft.com>
Co-authored-by: Istvan Haller <31476121+ihaller@users.noreply.github.com>
2022-05-09 13:38:12 +01:00
Matthew Parkinson
5906b14586 Out-of-memory can fail silently
If this test fails to allocate memory, that should not cause the test to
fail.  The 'abort' was added previously to confirm a infrequent failure
was caused by out-of-memory causing the test to assign to nullptr.

This was confirmed in a CI run, and now the test can be made to ignore
allocation failure.
2022-05-09 13:02:28 +01:00
Matthew Parkinson
2d44ae9db4 Check for allocation failure. 2022-05-08 20:55:29 +01:00
Matthew Parkinson
325c013e85 Add some tracing to the backend 2022-05-08 20:55:29 +01:00
Matthew Parkinson
9f9964239e Ensure logging doesn't affect errno 2022-05-08 20:55:29 +01:00
Matthew Parkinson
14b7b40a82 Add a Stats combiner to make code cleaner. 2022-05-05 17:27:31 +01:00
Matthew Parkinson
d47c44783d Remove redundant params. 2022-05-05 17:27:31 +01:00
Matthew Parkinson
563d5a5cee Make clang on Windows use /Debug 2022-05-03 15:59:31 +01:00
Matthew Parkinson
d927a9a179 Modified Metadata range to have separate pool
The Metadata range should not be shared with the object range.  This
change ensures that their are separate requests to the Pal for meta-data
and object data ranges.  The requests are never combined, and thus
memory cannot flow from being used in malloc to later be used in meta-
data.
2022-05-03 15:59:31 +01:00
Matthew Parkinson
56ccb5c794 Enable memcpy checks for check shim (#515)
Build three levels of checking
  - None
  - Checks memcpy only
  - Checks (full)

Currently you can build checks without enabling the memcpy protection.
This PR fixes that.
2022-05-03 14:26:25 +01:00