]> git.baikalelectronics.ru Git - kernel.git/commit
[SCSI] sg: use rwsem to solve race during exclusive open
authorVaughan Cao <vaughan.cao@oracle.com>
Thu, 29 Aug 2013 02:00:36 +0000 (10:00 +0800)
committerJames Bottomley <JBottomley@Parallels.com>
Tue, 3 Sep 2013 14:28:09 +0000 (07:28 -0700)
commit04fb0bb729bc0beec474e5cfd35420bff4ebaea9
treea62209c714df581942342acb0a167889fe2e25da
parentc2c12d0622a0a6985e78182c21c4e1e0d2bfa022
[SCSI] sg: use rwsem to solve race during exclusive open

A race condition may happen if two threads are both trying to open the same sg
with O_EXCL simultaneously. It's possible that they both find fsds list is
empty and get_exclude(sdp) returns 0, then they both call set_exclude() and
break out from wait_event_interruptible and resume open.

Now use rwsem to protect this process. Exclusive open gets write lock and
others get read lock. The lock will be held until file descriptor is closed.
This also leads 'exclude' only a status rather than a check mark.

Signed-off-by: Vaughan Cao <vaughan.cao@oracle.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
drivers/scsi/sg.c