Make sure the selrecord() function is only called from within system

polling contexts in the LinuxKPI.

After the kqueue() support was added to the LinuxKPI in r319409 the
Linux poll file operation will be used outside the system file polling
callback function, which can cause a NULL-pointer panic inside
selrecord() because curthread->td_sel is set to NULL. This patch moves
the selrecord() call away from poll_wait() and to the system file poll
callback function in the LinuxKPI, which essentially wraps the Linux
one. This is similar to what the cuse(3) module is currently doing.
Refer to sys/fs/cuse/*.[ch] for more details.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
This commit is contained in:
Hans Petter Selasky 2017-06-01 16:49:48 +00:00
parent 91601d8c5d
commit 8600ba1aa9
2 changed files with 7 additions and 5 deletions

View file

@ -43,7 +43,7 @@ typedef struct poll_table_struct {
static inline void
poll_wait(struct linux_file *filp, wait_queue_head_t *wait_address, poll_table *p)
{
selrecord(curthread, &filp->f_selinfo);
/* NOP */
}
extern void linux_poll_wakeup(struct linux_file *);

View file

@ -956,9 +956,10 @@ linux_dev_poll(struct cdev *dev, int events, struct thread *td)
file = td->td_fpop;
filp->f_flags = file->f_flag;
linux_set_current(td);
if (filp->f_op->poll)
if (filp->f_op->poll != NULL) {
selrecord(td, &filp->f_selinfo);
revents = filp->f_op->poll(filp, NULL) & events;
else
} else
revents = 0;
return (revents);
@ -1263,9 +1264,10 @@ linux_file_poll(struct file *file, int events, struct ucred *active_cred,
filp = (struct linux_file *)file->f_data;
filp->f_flags = file->f_flag;
linux_set_current(td);
if (filp->f_op->poll)
if (filp->f_op->poll != NULL) {
selrecord(td, &filp->f_selinfo);
revents = filp->f_op->poll(filp, NULL) & events;
else
} else
revents = 0;
return (revents);