public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix vulnerability in file operations of scsi target interface
@ 2010-11-09 14:01 Hillf Danton
  2010-11-09 18:15 ` Joe Eykholt
  0 siblings, 1 reply; 8+ messages in thread
From: Hillf Danton @ 2010-11-09 14:01 UTC (permalink / raw)
  To: linux-scsi

Ring buffers are setup for exchanging data between K and U spaces, but
they could not survive multiple open operations.

The registered misc interface is monitored and prevented from multiple
opens for fixing the vulnerability.

A typo, -BUSY, is also cleaned up.

btw, the ring buffers could be setup in a per file manner?

Signed-off-by: Hillf Danton <dhillf@gmail.com>
---

--- a/drivers/scsi/scsi_tgt_if.c	2010-09-13 07:07:38.000000000 +0800
+++ b/drivers/scsi/scsi_tgt_if.c	2010-11-09 21:42:48.000000000 +0800
@@ -85,7 +85,7 @@ static int tgt_uspace_send_event(u32 typ
 	if (!ev->hdr.status)
 		tgt_ring_idx_inc(ring);
 	else
-		err = -BUSY;
+		err = -EBUSY;

 	spin_unlock_irqrestore(&ring->tr_lock, flags);

@@ -319,20 +319,33 @@ static int tgt_mmap(struct file *filp, s
 	return err;
 }

+static unsigned long tgt_open_cnt = 0;
+
 static int tgt_open(struct inode *inode, struct file *file)
 {
+	if (tgt_open_cnt)
+		return -EBUSY;
+	tgt_open_cnt++;
+
 	tx_ring.tr_idx = rx_ring.tr_idx = 0;

 	cycle_kernel_lock();
 	return 0;
 }

+static int tgt_release(struct inode *inode, struct file *file)
+{
+	tgt_open_cnt--;
+	return 0;
+}
+
 static const struct file_operations tgt_fops = {
 	.owner		= THIS_MODULE,
 	.open		= tgt_open,
 	.poll		= tgt_poll,
 	.write		= tgt_write,
 	.mmap		= tgt_mmap,
+	.release	= tgt_release,
 };

 static struct miscdevice tgt_miscdev = {

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

end of thread, other threads:[~2010-11-16 14:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-09 14:01 [PATCH] fix vulnerability in file operations of scsi target interface Hillf Danton
2010-11-09 18:15 ` Joe Eykholt
2010-11-11 13:45   ` Hillf Danton
2010-11-11 18:47     ` Joe Eykholt
2010-11-12 13:42       ` Hillf Danton
2010-11-12 17:28         ` Joe Eykholt
2010-11-13 10:45           ` Hillf Danton
2010-11-16 14:15       ` Hillf Danton

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