diff options
author | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2008-10-26 07:03:37 -0400 |
---|---|---|
committer | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2008-10-31 03:48:26 -0400 |
commit | 638570b54346f140bc09b986d93e76025d35180f (patch) | |
tree | b3ffd423bcabe679cb5d218d9f4d2aed4a9ae50e /drivers/ieee1394 | |
parent | 233976e539a93de1320fc7625b24076b1f9e2c9c (diff) |
ieee1394: raw1394: fix possible deadlock in multithreaded clients
Regression in 2.6.28-rc1: When I added the new state_mutex which
prevents corruption of raw1394's internal state when accessed by
multithreaded client applications, the following possible though
highly unlikely deadlock slipped in:
Thread A: Thread B:
- acquire mmap_sem - raw1394_write() or raw1394_ioctl()
- raw1394_mmap() - acquire state_mutex
- acquire state_mutex - copy_to/from_user(), possible page fault:
acquire mmap_sem
The simplest fix is to use mutex_trylock() instead of mutex_lock() in
raw1394_mmap(). This changes the behavior under contention in a way
which is visible to userspace clients. However, since multithreaded
access was entirely buggy before state_mutex was added and libraw1394's
documentation advised application programmers to use a handle only in a
single thread, this change in behaviour should not be an issue in
practice at all.
Since we have to use mutex_trylock() in raw1394_mmap() regardless
whether /dev/raw1394 was opened with O_NONBLOCK or not, we now use
mutex_trylock() unconditionally everywhere for state_mutex, just to have
consistent behavior.
Reported-by: Johannes Weiner <hannes@saeurebad.de>
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Diffstat (limited to 'drivers/ieee1394')
-rw-r--r-- | drivers/ieee1394/raw1394.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c index 2cf4ae75beca..4bdfff0a9191 100644 --- a/drivers/ieee1394/raw1394.c +++ b/drivers/ieee1394/raw1394.c | |||
@@ -2268,7 +2268,8 @@ static ssize_t raw1394_write(struct file *file, const char __user * buffer, | |||
2268 | return -EFAULT; | 2268 | return -EFAULT; |
2269 | } | 2269 | } |
2270 | 2270 | ||
2271 | mutex_lock(&fi->state_mutex); | 2271 | if (!mutex_trylock(&fi->state_mutex)) |
2272 | return -EAGAIN; | ||
2272 | 2273 | ||
2273 | switch (fi->state) { | 2274 | switch (fi->state) { |
2274 | case opened: | 2275 | case opened: |
@@ -2548,7 +2549,8 @@ static int raw1394_mmap(struct file *file, struct vm_area_struct *vma) | |||
2548 | struct file_info *fi = file->private_data; | 2549 | struct file_info *fi = file->private_data; |
2549 | int ret; | 2550 | int ret; |
2550 | 2551 | ||
2551 | mutex_lock(&fi->state_mutex); | 2552 | if (!mutex_trylock(&fi->state_mutex)) |
2553 | return -EAGAIN; | ||
2552 | 2554 | ||
2553 | if (fi->iso_state == RAW1394_ISO_INACTIVE) | 2555 | if (fi->iso_state == RAW1394_ISO_INACTIVE) |
2554 | ret = -EINVAL; | 2556 | ret = -EINVAL; |
@@ -2669,7 +2671,8 @@ static long raw1394_ioctl(struct file *file, unsigned int cmd, | |||
2669 | break; | 2671 | break; |
2670 | } | 2672 | } |
2671 | 2673 | ||
2672 | mutex_lock(&fi->state_mutex); | 2674 | if (!mutex_trylock(&fi->state_mutex)) |
2675 | return -EAGAIN; | ||
2673 | 2676 | ||
2674 | switch (fi->iso_state) { | 2677 | switch (fi->iso_state) { |
2675 | case RAW1394_ISO_INACTIVE: | 2678 | case RAW1394_ISO_INACTIVE: |