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

epoll: fix epoll close error, report by kasan #5846

Merged
merged 1 commit into from
Mar 27, 2022
Merged
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
19 changes: 15 additions & 4 deletions fs/vfs/fs_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ static const struct file_operations g_epoll_ops =
#endif
};

static struct inode g_epoll_inode =
{
.i_crefs = 1,
.i_flags = FSNODEFLAG_TYPE_DRIVER,
.u =
{
.i_ops = &g_epoll_ops,
},
};
pkarashchenko marked this conversation as resolved.
Show resolved Hide resolved

/****************************************************************************
* Private Functions
****************************************************************************/
Expand All @@ -109,12 +119,12 @@ static FAR struct epoll_head *epoll_head_from_fd(int fd)
return NULL;
}

return (FAR struct epoll_head *)filep->f_inode->i_private;
return (FAR struct epoll_head *)filep->f_priv;
}

static int epoll_do_open(FAR struct file *filep)
{
FAR struct epoll_head *eph = filep->f_inode->i_private;
FAR struct epoll_head *eph = filep->f_priv;
int ret;

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

static int epoll_do_close(FAR struct file *filep)
{
FAR struct epoll_head *eph = filep->f_inode->i_private;
FAR struct epoll_head *eph = filep->f_priv;
int ret;

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

/* Alloc the file descriptor */

fd = files_allocate(&eph->in, flags, 0, eph, 0);
fd = files_allocate(&g_epoll_inode, flags, 0, eph, 0);
if (fd < 0)
{
nxsem_destroy(&eph->sem);
Expand All @@ -196,6 +206,7 @@ static int epoll_do_create(int size, int flags)
return -1;
}

inode_addref(&g_epoll_inode);
nxsem_post(&eph->sem);
return fd;
}
Expand Down