]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
SCSI: sg: fix races with ioctl(SG_IO)
authorTony Battersby <tonyb@cybernetics.com>
Tue, 20 Jan 2009 22:00:09 +0000 (17:00 -0500)
committerChris Wright <chrisw@sous-sol.org>
Mon, 27 Apr 2009 17:37:02 +0000 (10:37 -0700)
commitd4845ceede8c4087233198d2847b788a4e6f65b5
treefa98e959bd881aae4ba2ffe811619086981265a0
parentb21c6d2897cd455fa396f4041a0c8165784e949f
SCSI: sg: fix races with ioctl(SG_IO)

upstream commit: a2dd3b4cea335713b58996bb07b3abcde1175f47

sg_io_owned needs to be set before the command is sent to the midlevel;
otherwise, a quickly-completing command may cause a different CPU
to see "srp->done == 1 && !srp->sg_io_owned", which would lead to
incorrect behavior.

Check srp->done and set srp->orphan while holding rq_list_lock to
prevent races with sg_rq_end_io().

There is no need to check sfp->closed from read/write/ioctl/poll/etc.
since the kernel guarantees that this won't happen.

The usefulness of sg_srp_done() was questionable before; now it is
definitely not needed.

Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
drivers/scsi/sg.c