Skip to content

Commit 4beecaf

Browse files
committed
epoll: fix epoll close error, report by kasan
VELAPLATFO-1942 -apache#9 0xf7abf899 in __asan::__asan_report_load2 (addr=4072681776) at ../../../../../src/libsanitizer/asan/asan_rtl.cc:117 -apache#10 0x5693f718 in inode_release (node=0xf2c03124) at inode/fs_inoderelease.c:69 -apache#11 0x568ea61b in file_close (filep=0xf55fedd0) at vfs/fs_close.c:79 -apache#12 0x568e7e56 in nx_close (fd=3) at inode/fs_files.c:528 -apache#13 0x568e7f0e in close (fd=3) at inode/fs_files.c:562 -apache#14 0x56e76c39 in epoll_close (epfd=3) at vfs/fs_epoll.c:252 -apache#15 0x56c33829 in sensor_service_delete (ctrl=0x578b8540 <control>) at src/common.c:439 -apache#16 0x56a0561e in sensor_middle_service_main (argc=1, argv=0xf55de820) at sensor_main.c:118 -apache#17 0x56878675 in nxtask_startup (entrypt=0x56a054cc <sensor_middle_service_main>, argc=1, argv=0xf55de820) at sched/task_startup.c:70 -apache#18 0x5684427a in nxtask_start () at task/task_start.c:133 -apache#19 0xdeadbeef in ?? () reason: epoll_close -> close -> epoll_do_close (free inode) -> inode_release (reuse inode, crash) fix: use the global inode to match the fd which will return to user. like the g_sock_inode in fs/socket/socket.c Change-Id: I0096ac691ce9cf4169d1fb8bfa6d27a8c1ee7d52 Signed-off-by: ligd <liguiding1@xiaomi.com>
1 parent b59dd92 commit 4beecaf

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

fs/vfs/fs_epoll.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ static const struct file_operations g_epoll_ops =
8383
#endif
8484
};
8585

86+
static struct inode g_epoll_inode =
87+
{
88+
.i_crefs = 1,
89+
.i_flags = FSNODEFLAG_TYPE_DRIVER,
90+
.u =
91+
{
92+
.i_ops = &g_epoll_ops,
93+
},
94+
};
95+
8696
/****************************************************************************
8797
* Private Functions
8898
****************************************************************************/
@@ -109,12 +119,12 @@ static FAR struct epoll_head *epoll_head_from_fd(int fd)
109119
return NULL;
110120
}
111121

112-
return (FAR struct epoll_head *)filep->f_inode->i_private;
122+
return (FAR struct epoll_head *)filep->f_priv;
113123
}
114124

115125
static int epoll_do_open(FAR struct file *filep)
116126
{
117-
FAR struct epoll_head *eph = filep->f_inode->i_private;
127+
FAR struct epoll_head *eph = filep->f_priv;
118128
int ret;
119129

120130
ret = nxsem_wait(&eph->sem);
@@ -130,7 +140,7 @@ static int epoll_do_open(FAR struct file *filep)
130140

131141
static int epoll_do_close(FAR struct file *filep)
132142
{
133-
FAR struct epoll_head *eph = filep->f_inode->i_private;
143+
FAR struct epoll_head *eph = filep->f_priv;
134144
int ret;
135145

136146
ret = nxsem_wait(&eph->sem);
@@ -187,7 +197,7 @@ static int epoll_do_create(int size, int flags)
187197

188198
/* Alloc the file descriptor */
189199

190-
fd = files_allocate(&eph->in, flags, 0, eph, 0);
200+
fd = files_allocate(&g_epoll_inode, flags, 0, eph, 0);
191201
if (fd < 0)
192202
{
193203
nxsem_destroy(&eph->sem);
@@ -196,6 +206,7 @@ static int epoll_do_create(int size, int flags)
196206
return -1;
197207
}
198208

209+
inode_addref(&g_epoll_inode);
199210
nxsem_post(&eph->sem);
200211
return fd;
201212
}

0 commit comments

Comments
 (0)