Skip to content

Commit

Permalink
msm: adsprpc: Handle UAF in process shell memory
Browse files Browse the repository at this point in the history
Added flag to indicate memory used
in process initialization. And, this memory
would not removed in internal unmap to avoid
UAF or double free.

Change-Id: Ifa621dee171b3d1f98b82302c847f4d767f3e736
Signed-off-by: Swathi K <[email protected]>
  • Loading branch information
Swathi K authored and Gerrit - the friendly Code Review server committed Jul 23, 2021
1 parent a89e3b7 commit 9d849b4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions drivers/char/adsprpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ struct fastrpc_mmap {
int uncached;
int secure;
uintptr_t attr;
bool is_filemap; /*flag to indicate map used in process init*/
};

enum fastrpc_perfkeys {
Expand Down Expand Up @@ -710,9 +711,10 @@ static int fastrpc_mmap_remove(struct fastrpc_file *fl, uintptr_t va,

spin_lock(&me->hlock);
hlist_for_each_entry_safe(map, n, &me->maps, hn) {
if (map->raddr == va &&
if (map->refs == 1 && map->raddr == va &&
map->raddr + map->len == va + len &&
map->refs == 1) {
/*Remove map if not used in process initialization*/
!map->is_filemap) {
match = map;
hlist_del_init(&map->hn);
break;
Expand All @@ -724,9 +726,10 @@ static int fastrpc_mmap_remove(struct fastrpc_file *fl, uintptr_t va,
return 0;
}
hlist_for_each_entry_safe(map, n, &fl->maps, hn) {
if (map->raddr == va &&
if (map->refs == 1 && map->raddr == va &&
map->raddr + map->len == va + len &&
map->refs == 1) {
/*Remove map if not used in process initialization*/
!map->is_filemap) {
match = map;
hlist_del_init(&map->hn);
break;
Expand Down Expand Up @@ -872,6 +875,7 @@ static int fastrpc_mmap_create(struct fastrpc_file *fl, int fd,
map->fl = fl;
map->fd = fd;
map->attr = attr;
map->is_filemap = false;
if (mflags == ADSP_MMAP_HEAP_ADDR ||
mflags == ADSP_MMAP_REMOTE_HEAP_ADDR) {
unsigned long dma_attrs = DMA_ATTR_SKIP_ZEROING |
Expand Down Expand Up @@ -2277,6 +2281,8 @@ static int fastrpc_init_process(struct fastrpc_file *fl,
mutex_lock(&fl->fl_map_mutex);
VERIFY(err, !fastrpc_mmap_create(fl, init->filefd, 0,
init->file, init->filelen, mflags, &file));
if (file)
file->is_filemap = true;
mutex_unlock(&fl->fl_map_mutex);
if (err)
goto bail;
Expand Down

0 comments on commit 9d849b4

Please sign in to comment.