Skip to content

Commit 490e018

Browse files
authored
api/glfs: Fix use after free in readdir (#4477)
There is a code path in glfs readdir where we might end up using a free'ed memory. A possible case is when we use the fd to read the offset 0 after reading the content at least once, and the during the second time, the readdir return 0, probably due to the contents got deleted. Change-Id: I08fa6cc9b924b90597ef4498e081cae9339fbd6a Fixes: #3955 Signed-off-by: Mohammed Rafi KC <[email protected]>
1 parent 909a01f commit 490e018

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

api/src/glfs-fops.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ glfs_mark_glfd_for_deletion(struct glfs_fd *glfd)
4848
LOCK(&glfd->lock);
4949
{
5050
glfd->state = GLFD_CLOSE;
51+
glfd->next = NULL;
5152
}
5253
UNLOCK(&glfd->lock);
5354

@@ -4014,6 +4015,11 @@ glfd_entry_refresh(struct glfs_fd *glfd, int plus)
40144015
}
40154016

40164017
list_splice_init(&glfd->entries, &old.list);
4018+
/* If glfd->next is non null means, this entry is from the old
4019+
* list, there is no point in keeping the free'ed data. Hence
4020+
* set to NULL;
4021+
*/
4022+
glfd->next = NULL;
40174023
list_splice_init(&entries.list, &glfd->entries);
40184024

40194025
/* spurious errno is dangerous for glfd_entry_next() */

0 commit comments

Comments
 (0)