mirror of
				https://github.com/GrapheneOS/hardened_malloc.git
				synced 2025-10-30 19:28:55 -04:00 
			
		
		
		
	add header for configuration
This commit is contained in:
		
							parent
							
								
									99d68238d2
								
							
						
					
					
						commit
						d398384b90
					
				
					 3 changed files with 12 additions and 7 deletions
				
			
		
							
								
								
									
										2
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
										
									
									
									
								
							|  | @ -7,7 +7,7 @@ hardened_malloc.so: $(OBJECTS) | |||
| 	$(CC) $(CFLAGS) $(LDFLAGS) -shared $^ $(LDLIBS) -o $@ | ||||
| 
 | ||||
| chacha.o: chacha.c chacha.h | ||||
| malloc.o: malloc.c malloc.h memory.h pages.h random.h util.h | ||||
| malloc.o: malloc.c malloc.h config.h memory.h pages.h random.h util.h | ||||
| memory.o: memory.c memory.h util.h | ||||
| pages.o: pages.c pages.h memory.h util.h | ||||
| random.o: random.c random.h chacha.h util.h | ||||
|  |  | |||
							
								
								
									
										7
									
								
								config.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								config.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,7 @@ | |||
| #ifndef CONFIG_H | ||||
| #define CONFIG_H | ||||
| 
 | ||||
| #define GUARD_SLABS true | ||||
| #define WRITE_AFTER_FREE_CHECK true | ||||
| 
 | ||||
| #endif | ||||
							
								
								
									
										10
									
								
								malloc.c
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								malloc.c
									
										
									
									
									
								
							|  | @ -11,6 +11,7 @@ | |||
| 
 | ||||
| #include "third_party/libdivide.h" | ||||
| 
 | ||||
| #include "config.h" | ||||
| #include "malloc.h" | ||||
| #include "memory.h" | ||||
| #include "pages.h" | ||||
|  | @ -19,9 +20,6 @@ | |||
| 
 | ||||
| static_assert(sizeof(void *) == 8, "64-bit only"); | ||||
| 
 | ||||
| static const bool guard_slabs = true; | ||||
| static const bool enable_write_after_free_check = true; | ||||
| 
 | ||||
| // either sizeof(uint64_t) or 0
 | ||||
| static const size_t canary_size = sizeof(uint64_t); | ||||
| 
 | ||||
|  | @ -165,7 +163,7 @@ static struct slab_metadata *alloc_metadata(struct size_class *c, size_t slab_si | |||
|         return NULL; | ||||
|     } | ||||
|     c->metadata_count++; | ||||
|     if (guard_slabs) { | ||||
|     if (GUARD_SLABS) { | ||||
|         c->metadata_count++; | ||||
|     } | ||||
|     return metadata; | ||||
|  | @ -245,13 +243,13 @@ static void *slot_pointer(size_t size, void *slab, size_t slot) { | |||
| } | ||||
| 
 | ||||
| static void write_after_free_check(char *p, size_t size) { | ||||
|     if (!enable_write_after_free_check) { | ||||
|     if (!WRITE_AFTER_FREE_CHECK) { | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     for (size_t i = 0; i < size; i += sizeof(uint64_t)) { | ||||
|         if (*(uint64_t *)(p + i)) { | ||||
|             fatal_error("write after free"); | ||||
|             fatal_error("detected write after free"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Daniel Micay
						Daniel Micay