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

Securing map free blocks if asan was used #3005

Merged
merged 1 commit into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions configure
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/sh
# From configure.ac 528bd2111.
# From configure.ac 18224d007.
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69.
#
Expand Down Expand Up @@ -3969,8 +3969,12 @@ if test "${enable_sanitize+set}" = set; then :
enable_sanitize="$enableval"
case $enableval in
"no");;
"yes");;
"full");;
"yes")
CPPFLAGS="$CPPFLAGS -DSANITIZE"
;;
"full")
CPPFLAGS="$CPPFLAGS -DSANITIZE"
;;
*) as_fn_error $? "invalid argument --enable-sanitize=$enableval... stopping" "$LINENO" 5;;
esac

Expand Down
8 changes: 6 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,12 @@ AC_ARG_ENABLE(
enable_sanitize="$enableval"
case $enableval in
"no");;
"yes");;
"full");;
"yes")
CPPFLAGS="$CPPFLAGS -DSANITIZE"
;;
"full")
CPPFLAGS="$CPPFLAGS -DSANITIZE"
;;
*) AC_MSG_ERROR([[invalid argument --enable-sanitize=$enableval... stopping]]);;
esac
],
Expand Down
20 changes: 19 additions & 1 deletion src/map/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ static inline void map_block_free_expand(void)
{
map->block_free_list_size += 100;
RECREATE(map->block_free, struct block_list *, map->block_free_list_size);
#ifdef SANITIZE
RECREATE(map->block_free_sanitize, int *, map->block_free_list_size);
#endif
}

/*==========================================
Expand Down Expand Up @@ -151,7 +154,11 @@ static int map_freeblock(struct block_list *bl)
if( map->block_free_count >= map->block_free_list_size )
map_block_free_expand();

map->block_free[map->block_free_count++] = bl;
map->block_free[map->block_free_count] = bl;
#ifdef SANITIZE
map->block_free_sanitize[map->block_free_count] = aMalloc(4);
#endif
map->block_free_count++;
}

return map->block_free_lock;
Expand All @@ -172,6 +179,10 @@ static int map_freeblock_unlock(void)
if ((--map->block_free_lock) == 0) {
int i;
for (i = 0; i < map->block_free_count; i++) {
#ifdef SANITIZE
aFree(map->block_free_sanitize[i]);
map->block_free_sanitize[i] = NULL;
#endif
if( map->block_free[i]->type == BL_ITEM )
ers_free(map->flooritem_ers, map->block_free[i]);
else
Expand Down Expand Up @@ -6511,6 +6522,10 @@ int do_final(void)

if( map->block_free )
aFree(map->block_free);
#ifdef SANITIZE
if (map->block_free_sanitize)
aFree(map->block_free_sanitize);
#endif
if( map->bl_list )
aFree(map->bl_list);

Expand Down Expand Up @@ -7140,6 +7155,9 @@ void map_defaults(void)
map->iwall_db = NULL;

map->block_free = NULL;
#ifdef SANITIZE
map->block_free_sanitize = NULL;
#endif
map->block_free_count = 0;
map->block_free_lock = 0;
map->block_free_list_size = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/map/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,9 @@ struct map_interface {
struct DBMap *iwall_db;
struct block_list **block_free;
int block_free_count, block_free_lock, block_free_list_size;
#ifdef SANITIZE
int **block_free_sanitize;
#endif // SANITIZE
struct block_list **bl_list;
int bl_list_count, bl_list_size;
BEGIN_ZEROED_BLOCK; // This block is zeroed in map_defaults()
Expand Down