public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* BUG? "Call fasync() functions without the BKL" is racy
@ 2008-11-28 19:25 Oleg Nesterov
  2008-12-01 11:34 ` Andi Kleen
  0 siblings, 1 reply; 12+ messages in thread
From: Oleg Nesterov @ 2008-11-28 19:25 UTC (permalink / raw)
  To: Andi Kleen, Jonathan Corbet; +Cc: Al Viro, Vitaly Mayatskikh, linux-kernel

Hi.

Let's suppose we have the tasks T1, T2, T3 which share the same file,
all do sys_fcntl(file, F_SETFL) in parallel. file->f_flags == 0.

setfl(arg) does:

	if ((arg ^ filp->f_flags) & FASYNC)
// --- WINDOW_1 ---
		filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0)
// --- WINDOW_2 ---
	filp->f_flags = arg;

T1 calls setfl(FASYNC), preempted in WINDOW_1.

T2 calls setfl(FASYNC), does all job and returns.

T3 calls setfl(0), sees ->f_flags & FASYNC, does ->fasync(on => 0),
preempted in WINDOW_2.

T1 resumes, does ->fasync(on => 1) again, update ->f_flags (it
already has FASYNC) and returns.

T3 resumes, and clears FASYNC from ->f_flags.



Now, this file was added into some "struct fasync_struct", but
->f_flags doesn't have FASYNC. This means __fput() will skip
->fasync(on => 0) and the next kill_fasync() can crash because
fa_file points to the freed/reused memory.

I think a238b790d5f99c7832f9b73ac8847025815b85f7 should be reverted.
Or do you see the better fix?

Unless I missed something of course.

Oleg.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-12-05 23:13 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-28 19:25 BUG? "Call fasync() functions without the BKL" is racy Oleg Nesterov
2008-12-01 11:34 ` Andi Kleen
2008-12-01 19:15   ` Oleg Nesterov
2008-12-01 19:34     ` Jonathan Corbet
2008-12-02 12:29       ` Oleg Nesterov
2008-12-02 16:30         ` Andi Kleen
2008-12-03 19:06           ` Oleg Nesterov
2008-12-03 21:21             ` Andi Kleen
2008-12-03 22:45               ` Jonathan Corbet
2008-12-04 14:34                 ` Oleg Nesterov
2008-12-05 23:12                 ` [PATCH 2.6.28] Fix FASYNC race Jonathan Corbet
2008-12-02  0:15     ` BUG? "Call fasync() functions without the BKL" is racy Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox