Moving fasync_struct into struct file?
Hi guys,
Stephen Rothwell pointed out that if you set up SIGIO from an
fd, fork, and exit, and PIDs wrap, the new process may be clobbered by the SIGIO. IMVHO the best way to clean this up is to check the fasync_list in sys_close, and if pid == filp->f_owner.pid and fd == fasync_list->fa_fd, unregister the SIGIO.
This means we need a move the "struct fasync_structfasync_list" into struct file (up from all the subsystems which use it, eg. struct socket).
See any problems with this?
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Quoted 3 lines
the SIGIO. IMVHO the best way to clean this up is to check the
fasync_listinsys_close, and if pid ==filp->f_owner.pidand fd ==fasync_list->fa_fd, unregister the SIGIO.
We already clean up fasync structures on close, its the drivers responsibility to do so. If you wanted to be more strict you could do a similar helper call in the other closing callback for each fd close.
Quoted 3 lines
This means we need a move the "struct
fasync_structfasync_list" into struct file (up from all the subsystems which use it, eg. struct socket).
Any reason for not just caching the 32bit task ident field ? Using the slightly confusingly p->parent_exec_id, which is basically a 32bit process ident for example
Hello!
Quoted 1 line
We already clean up fasync structures on close,
We do not.
Quoted 2 lines
responsibility to do so. If you wanted to be more strict you could do a similar helper call in the other closing callback for each fd close.
This is technical issue how to implement this exactly.
BTW, sed -e 's/more strict/not so buggy/' :-)
Alexey
Quoted 2 lines
Quoted 1 line
We already clean up fasync structures on close,
We do not.
Then fix your driver. All the drivers I looked at do stuff like this... which seems to do the job nicely
static int close_pad(struct inode * inode, struct file * file)
{
lock_kernel();
fasync_pad(-1, file, 0);
if (!--active)
outb(0x30, current_params.io+2); /* switch off digitiser */
unlock_kernel();
return 0;
}Hello!
Quoted 2 lines
Then fix your driver. All the drivers I looked at do stuff like this... which seems to do the job nicely
But this code is even not reached in the case which Paul tells about.
It should be executed earlier, as you noticed.
Alexey
Hi,
Quoted 5 lines · Rusty Russell
This means we need a move the "struct
fasync_structfasync_list" into struct file (up from all the subsystems which use it, eg. struct socket).See any problems with this?
At first I thought I would clean up the drivers a little moving common code from the release routine. The release code is not called in the example you gave because of the fork, correct ?
Then I realised what happens if several processes all request SIGIO notification on different descriptors. The driver still needs to keep a private list of all the processes registered with it. struct file should at best contain a pointer back to the relevant structure in the driver private list for cleanup ?
Signature · 1 line
Bob Dunlop
Hello!
Quoted 11 lines
Stephen Rothwell pointed out that if you set up SIGIO from an
fd, fork, and exit, and PIDs wrap, the new process may be clobbered by the SIGIO. IMVHO the best way to clean this up is to check thefasync_listinsys_close, and if pid ==filp->f_owner.pidand fd ==fasync_list->fa_fd, unregister the SIGIO.This means we need a move the "struct
fasync_structfasync_list" into struct file (up from all the subsystems which use it, eg. struct socket).See any problems with this?
I do not see.
It is a long known piece of shit in the kernel crying about repair. I remember Al Viro planned to do something with this for 2.4, but this has been forgotten again.
Alexey