fasync fix for v4.18
-----BEGIN PGP SIGNATURE----- iQIcBAABAgAGBQJbFTxwAAoJEAAOaEEZVoIVfOQQAIMmcJjx8c+86TS5bVpi9yWN z6C2QEW1vMN2Z65dvjquSbF81yY54oCgiV3/6iGOtcOOI3rH/7f+CKb+4xRskpFv PSVXKXkXKOGRnnhcz2X8F+FBbd4xLxzyB+Ff9HCWVv2L76d7Uu8wUcbSpOdC7GOd pXHQkA+WNPEnHpr4To09ZwS14IzVCAhFii7MvOU6IXxzbP473/aPpFjrwa+mbkkz J7U4bijaLL5eGJGE0ElHOaeF/iAhOBEFGrkT3lR78ZA+spnqVXlv2U9E29zg9H98 JyFM7vMe9MtR///Ve6BeLNKrDnwCmBo9ScMR8eWUWhrOInGX9yU0UR9XkD5TzA3U hQHW2ckjloykp+HuvbUOF/Aut8GczbyaDsAHZ6/fAxgNGnFeJ7yjR5IPKFkKekPt H+ls9j4C9yZpTLXioNqJz6d2IOS5MKfjPFC0c2ItO11jzNdbmjO7ciIq4EecSR51 FKeoUHyjhfak94Dh7x3IQEtnm1o5CbbSNvQ8g6PJYXFBi88jcmQkLmZlULDV3vyg 9febfSYpJhamJ+GUn8av+HziJG/1o1sOLrIVi2qGRIBJiUO5tAYY6UVvo1xKuzQ3 BMSRVnqVbs749lUV0QrYoFVdMvVxL6l0+8p4Xgx7q5BR4gG73e4yaBnXLeStMIYo oSFy/EH3MYR87m5Yk45E =rqcZ -----END PGP SIGNATURE----- Merge tag 'locks-v4.18-1' of git://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux Pull fasync fix from Jeff Layton: "Just a single fix for a deadlock in the fasync handling code that Kirill observed while testing. The fix is to change the fa_lock to be rwlock_t, and use a read lock in kill_fasync_rcu" * tag 'locks-v4.18-1' of git://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux: fasync: Fix deadlock between task-context and interrupt-context kill_fasync()
This commit is contained in:
commit
9214407d12
15
fs/fcntl.c
15
fs/fcntl.c
|
@ -871,9 +871,9 @@ int fasync_remove_entry(struct file *filp, struct fasync_struct **fapp)
|
|||
if (fa->fa_file != filp)
|
||||
continue;
|
||||
|
||||
spin_lock_irq(&fa->fa_lock);
|
||||
write_lock_irq(&fa->fa_lock);
|
||||
fa->fa_file = NULL;
|
||||
spin_unlock_irq(&fa->fa_lock);
|
||||
write_unlock_irq(&fa->fa_lock);
|
||||
|
||||
*fp = fa->fa_next;
|
||||
call_rcu(&fa->fa_rcu, fasync_free_rcu);
|
||||
|
@ -918,13 +918,13 @@ struct fasync_struct *fasync_insert_entry(int fd, struct file *filp, struct fasy
|
|||
if (fa->fa_file != filp)
|
||||
continue;
|
||||
|
||||
spin_lock_irq(&fa->fa_lock);
|
||||
write_lock_irq(&fa->fa_lock);
|
||||
fa->fa_fd = fd;
|
||||
spin_unlock_irq(&fa->fa_lock);
|
||||
write_unlock_irq(&fa->fa_lock);
|
||||
goto out;
|
||||
}
|
||||
|
||||
spin_lock_init(&new->fa_lock);
|
||||
rwlock_init(&new->fa_lock);
|
||||
new->magic = FASYNC_MAGIC;
|
||||
new->fa_file = filp;
|
||||
new->fa_fd = fd;
|
||||
|
@ -987,14 +987,13 @@ static void kill_fasync_rcu(struct fasync_struct *fa, int sig, int band)
|
|||
{
|
||||
while (fa) {
|
||||
struct fown_struct *fown;
|
||||
unsigned long flags;
|
||||
|
||||
if (fa->magic != FASYNC_MAGIC) {
|
||||
printk(KERN_ERR "kill_fasync: bad magic number in "
|
||||
"fasync_struct!\n");
|
||||
return;
|
||||
}
|
||||
spin_lock_irqsave(&fa->fa_lock, flags);
|
||||
read_lock(&fa->fa_lock);
|
||||
if (fa->fa_file) {
|
||||
fown = &fa->fa_file->f_owner;
|
||||
/* Don't send SIGURG to processes which have not set a
|
||||
|
@ -1003,7 +1002,7 @@ static void kill_fasync_rcu(struct fasync_struct *fa, int sig, int band)
|
|||
if (!(sig == SIGURG && fown->signum == 0))
|
||||
send_sigio(fown, fa->fa_fd, band);
|
||||
}
|
||||
spin_unlock_irqrestore(&fa->fa_lock, flags);
|
||||
read_unlock(&fa->fa_lock);
|
||||
fa = rcu_dereference(fa->fa_next);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1250,7 +1250,7 @@ static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl)
|
|||
}
|
||||
|
||||
struct fasync_struct {
|
||||
spinlock_t fa_lock;
|
||||
rwlock_t fa_lock;
|
||||
int magic;
|
||||
int fa_fd;
|
||||
struct fasync_struct *fa_next; /* singly linked list */
|
||||
|
|
Loading…
Reference in New Issue