mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 14:53:47 +08:00
mm/mempool: Fix mempool tag kasan error
The address needs to be reset only when comparing addition, subtraction, multiplication and division addresses. Otherwise, the original address is always returned or saved. Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
This commit is contained in:
committed by
Xiang Xiao
parent
183ff9b6cc
commit
dd57400e7b
@@ -170,7 +170,7 @@ mempool_multiple_alloc_chunk(FAR struct mempool_multiple_s *mpool,
|
|||||||
mpool->alloced += mpool->alloc_size(mpool->arg, ret);
|
mpool->alloced += mpool->alloc_size(mpool->arg, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
return kasan_reset_tag(ret);
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
chunk = (FAR struct mpool_chunk_s *)sq_peek(&mpool->chunk_queue);
|
chunk = (FAR struct mpool_chunk_s *)sq_peek(&mpool->chunk_queue);
|
||||||
@@ -186,8 +186,6 @@ retry:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = kasan_reset_tag(tmp);
|
|
||||||
|
|
||||||
mpool->alloced += mpool->alloc_size(mpool->arg, tmp);
|
mpool->alloced += mpool->alloc_size(mpool->arg, tmp);
|
||||||
chunk = (FAR struct mpool_chunk_s *)(tmp + mpool->chunk_size);
|
chunk = (FAR struct mpool_chunk_s *)(tmp + mpool->chunk_size);
|
||||||
chunk->end = tmp + mpool->chunk_size;
|
chunk->end = tmp + mpool->chunk_size;
|
||||||
@@ -319,8 +317,8 @@ mempool_multiple_get_dict(FAR struct mempool_multiple_s *mpool,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr = (FAR void *)ALIGN_DOWN(blk, mpool->expandsize);
|
addr = (FAR void *)ALIGN_DOWN((uintptr_t)blk, mpool->expandsize);
|
||||||
if (blk == addr)
|
if (kasan_reset_tag(blk) == kasan_reset_tag(addr))
|
||||||
{
|
{
|
||||||
/* It is not a memory block allocated by mempool
|
/* It is not a memory block allocated by mempool
|
||||||
* Because the blk is need not aligned with the expandsize
|
* Because the blk is need not aligned with the expandsize
|
||||||
@@ -338,9 +336,12 @@ mempool_multiple_get_dict(FAR struct mempool_multiple_s *mpool,
|
|||||||
|
|
||||||
row = index >> mpool->dict_col_num_log2;
|
row = index >> mpool->dict_col_num_log2;
|
||||||
col = index - (row << mpool->dict_col_num_log2);
|
col = index - (row << mpool->dict_col_num_log2);
|
||||||
if (mpool->dict[row] == NULL ||
|
|
||||||
mpool->dict[row][col].addr != addr ||
|
addr = kasan_reset_tag(addr);
|
||||||
(FAR char *)blk - (FAR char *)addr >= mpool->dict[row][col].size)
|
if (kasan_reset_tag(mpool->dict[row]) == NULL ||
|
||||||
|
kasan_reset_tag(mpool->dict[row][col].addr) != addr ||
|
||||||
|
((FAR char *)kasan_reset_tag(blk) -
|
||||||
|
(FAR char *)addr >= mpool->dict[row][col].size))
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -596,7 +597,6 @@ FAR void *mempool_multiple_realloc(FAR struct mempool_multiple_s *mpool,
|
|||||||
return mempool_multiple_alloc(mpool, size);
|
return mempool_multiple_alloc(mpool, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
oldblk = kasan_reset_tag(oldblk);
|
|
||||||
dict = mempool_multiple_get_dict(mpool, oldblk);
|
dict = mempool_multiple_get_dict(mpool, oldblk);
|
||||||
if (dict == NULL)
|
if (dict == NULL)
|
||||||
{
|
{
|
||||||
@@ -635,15 +635,15 @@ int mempool_multiple_free(FAR struct mempool_multiple_s *mpool,
|
|||||||
{
|
{
|
||||||
FAR struct mpool_dict_s *dict;
|
FAR struct mpool_dict_s *dict;
|
||||||
|
|
||||||
blk = kasan_reset_tag(blk);
|
|
||||||
dict = mempool_multiple_get_dict(mpool, blk);
|
dict = mempool_multiple_get_dict(mpool, blk);
|
||||||
if (dict == NULL)
|
if (dict == NULL)
|
||||||
{
|
{
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
blk = (FAR char *)blk - (((FAR char *)blk -
|
blk = (FAR char *)blk - (((FAR char *)kasan_reset_tag(blk) -
|
||||||
((FAR char *)dict->addr + mpool->minpoolsize)) %
|
((FAR char *)kasan_reset_tag(dict->addr) +
|
||||||
|
mpool->minpoolsize)) %
|
||||||
MEMPOOL_REALBLOCKSIZE(dict->pool));
|
MEMPOOL_REALBLOCKSIZE(dict->pool));
|
||||||
mempool_release(dict->pool, blk);
|
mempool_release(dict->pool, blk);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -671,7 +671,6 @@ ssize_t mempool_multiple_alloc_size(FAR struct mempool_multiple_s *mpool,
|
|||||||
|
|
||||||
DEBUGASSERT(blk != NULL);
|
DEBUGASSERT(blk != NULL);
|
||||||
|
|
||||||
blk = kasan_reset_tag(blk);
|
|
||||||
dict = mempool_multiple_get_dict(mpool, blk);
|
dict = mempool_multiple_get_dict(mpool, blk);
|
||||||
if (dict == NULL)
|
if (dict == NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user