mirror of
				https://github.com/GrapheneOS/hardened_malloc.git
				synced 2025-11-04 01:36:33 +01:00 
			
		
		
		
	Compare commits
	
		
			3 commits
		
	
	
		
			7d79bec225
			...
			8e9b94b3ed
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							 | 
						8e9b94b3ed | ||
| 
							 | 
						ff99511eb4 | ||
| 
							 | 
						9ca3279507 | 
					 7 changed files with 86 additions and 7 deletions
				
			
		
							
								
								
									
										12
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								README.md
									
										
									
									
									
								
							| 
						 | 
					@ -65,14 +65,14 @@ used instead as this allocator fundamentally doesn't support that environment.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Dependencies
 | 
					## Dependencies
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Debian stable (currently Debian 12) determines the most ancient set of
 | 
					Debian stable (currently Debian 13) determines the most ancient set of
 | 
				
			||||||
supported dependencies:
 | 
					supported dependencies:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* glibc 2.36
 | 
					* glibc 2.41
 | 
				
			||||||
* Linux 6.1
 | 
					* Linux 6.12
 | 
				
			||||||
* Clang 14.0.6 or GCC 12.2.0
 | 
					* Clang 19.1.7 or GCC 14.2.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
For Android, the Linux GKI 5.10, 5.15 and 6.1 branches are supported.
 | 
					For Android, the Linux GKI 6.1, 6.6 and 6.12 branches are supported.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
However, using more recent releases is highly recommended. Older versions of
 | 
					However, using more recent releases is highly recommended. Older versions of
 | 
				
			||||||
the dependencies may be compatible at the moment but are not tested and will
 | 
					the dependencies may be compatible at the moment but are not tested and will
 | 
				
			||||||
| 
						 | 
					@ -83,7 +83,7 @@ there will be custom integration offering better performance in the future
 | 
				
			||||||
along with other hardening for the C standard library implementation.
 | 
					along with other hardening for the C standard library implementation.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
For Android, only the current generation, actively developed maintenance branch of the Android
 | 
					For Android, only the current generation, actively developed maintenance branch of the Android
 | 
				
			||||||
Open Source Project will be supported, which currently means `android15-release`.
 | 
					Open Source Project will be supported, which currently means `android16-release`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Testing
 | 
					## Testing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										3
									
								
								test/.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								test/.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
					@ -41,4 +41,7 @@ overflow_small_8_byte
 | 
				
			||||||
uninitialized_read_large
 | 
					uninitialized_read_large
 | 
				
			||||||
uninitialized_read_small
 | 
					uninitialized_read_small
 | 
				
			||||||
realloc_init
 | 
					realloc_init
 | 
				
			||||||
 | 
					realloc_c23_undefined_behaviour
 | 
				
			||||||
 | 
					realloc_c23_undefined_behaviour_double_free
 | 
				
			||||||
 | 
					realloc_c23_undefined_behaviour_use_after_free
 | 
				
			||||||
__pycache__/
 | 
					__pycache__/
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -67,7 +67,10 @@ EXECUTABLES := \
 | 
				
			||||||
    invalid_malloc_object_size_small \
 | 
					    invalid_malloc_object_size_small \
 | 
				
			||||||
    invalid_malloc_object_size_small_quarantine \
 | 
					    invalid_malloc_object_size_small_quarantine \
 | 
				
			||||||
    impossibly_large_malloc \
 | 
					    impossibly_large_malloc \
 | 
				
			||||||
    realloc_init
 | 
					    realloc_init \
 | 
				
			||||||
 | 
					    realloc_c23_undefined_behaviour \
 | 
				
			||||||
 | 
					    realloc_c23_undefined_behaviour_double_free \
 | 
				
			||||||
 | 
					    realloc_c23_undefined_behaviour_use_after_free
 | 
				
			||||||
 | 
					
 | 
				
			||||||
all: $(EXECUTABLES)
 | 
					all: $(EXECUTABLES)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										19
									
								
								test/realloc_c23_undefined_behaviour.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								test/realloc_c23_undefined_behaviour.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,19 @@
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "test_util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					OPTNONE int main(void) {
 | 
				
			||||||
 | 
					    char *p, *q, *r;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    p = malloc(16);
 | 
				
			||||||
 | 
					    if (!p) {
 | 
				
			||||||
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    q = realloc(p, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    free(q);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										19
									
								
								test/realloc_c23_undefined_behaviour_double_free.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								test/realloc_c23_undefined_behaviour_double_free.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,19 @@
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "test_util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					OPTNONE int main(void) {
 | 
				
			||||||
 | 
					    char *p, *q, *r;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    p = malloc(16);
 | 
				
			||||||
 | 
					    if (!p) {
 | 
				
			||||||
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    q = realloc(p, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    free(p);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										21
									
								
								test/realloc_c23_undefined_behaviour_use_after_free.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								test/realloc_c23_undefined_behaviour_use_after_free.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,21 @@
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "test_util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					OPTNONE int main(void) {
 | 
				
			||||||
 | 
					    char *p, *q, *r;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    p = malloc(256 * 1024);
 | 
				
			||||||
 | 
					    if (!p) {
 | 
				
			||||||
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    q = realloc(p, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    printf("%c\n", *p);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    free(q);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -169,6 +169,20 @@ class TestSimpleMemoryCorruption(unittest.TestCase):
 | 
				
			||||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
					        self.assertEqual(stderr.decode("utf-8"),
 | 
				
			||||||
                         "fatal allocator error: invalid realloc\n")
 | 
					                         "fatal allocator error: invalid realloc\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_realloc_c23_undefined_behaviour(self):
 | 
				
			||||||
 | 
					        _stdout, stderr, returncode = self.run_test("realloc_c23_undefined_behaviour")
 | 
				
			||||||
 | 
					        self.assertEqual(returncode, 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_realloc_c23_undefined_behaviour_double_free(self):
 | 
				
			||||||
 | 
					        _stdout, stderr, returncode = self.run_test("realloc_c23_undefined_behaviour_double_free")
 | 
				
			||||||
 | 
					        self.assertEqual(returncode, -6)
 | 
				
			||||||
 | 
					        self.assertEqual(stderr.decode("utf-8"),
 | 
				
			||||||
 | 
					                         "fatal allocator error: double free (quarantine)\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_realloc_c23_undefined_behaviour_use_after_free(self):
 | 
				
			||||||
 | 
					        _stdout, stderr, returncode = self.run_test("realloc_c23_undefined_behaviour_use_after_free")
 | 
				
			||||||
 | 
					        self.assertEqual(returncode, -11)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_write_after_free_large_reuse(self):
 | 
					    def test_write_after_free_large_reuse(self):
 | 
				
			||||||
        _stdout, _stderr, returncode = self.run_test(
 | 
					        _stdout, _stderr, returncode = self.run_test(
 | 
				
			||||||
            "write_after_free_large_reuse")
 | 
					            "write_after_free_large_reuse")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue