Skip to contentSkip to conversation

em28xx: use after free in em28xx_v4l2_close()

PATCH In review Dan Carpenter 2 participants 4 messages Aug 14, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 em28xx: use after free in em28xx_v4l2_close()

We need to move the unlock before the kfree(dev);

---
Applies to linux-next.

drivers/media/video/em28xx/em28xx-video.c +1 -1
index ecb23df..78d6ebd 100644
@@ -2264,9 +2264,9 @@ static int em28xx_v4l2_close(struct file *filp)
 		if (dev->state & DEV_DISCONNECTED) {
 			em28xx_release_resources(dev);
 			kfree(dev->alt_max_pkt_size);
+			mutex_unlock(&dev->lock);
 			kfree(dev);
 			kfree(fh);
-			mutex_unlock(&dev->lock);
 			return 0;
 		}
 
#1 lore raw

Hi Dan,

drivers/media/video/em28xx/em28xx-video.c static int em28xx_v4l2_close(struct file *filp) · line 2265

Quoted 13 lines · Dan Carpenter

We need to move the unlock before the kfree(dev);

---
Applies to linux-next.

drivers/media/video/em28xx/em28xx-video.c +0 -0
index ecb23df..78d6ebd 100644
@@ -2264,9 +2264,9 @@ static int em28xx_v4l2_close(struct file *filp)
                if (dev->state & DEV_DISCONNECTED) {
                        em28xx_release_resources(dev);

Why not unlocking here?

drivers/media/video/em28xx/em28xx-video.c static int em28xx_v4l2_close(struct file *filp) · line 2269

Quoted 5 lines
drivers/media/video/em28xx/em28xx-video.c +1 -1
                        kfree(dev->alt_max_pkt_size);
+                       mutex_unlock(&dev->lock);
                        kfree(dev);
                        kfree(fh);
-                       mutex_unlock(&dev->lock);

Thanks,
Ezequiel.

#2 lore raw
Quoted 9 lines · Ezequiel Garcia

Hi Dan,

Quoted 6 lines · Dan Carpenter

We need to move the unlock before the kfree(dev);

---
Applies to linux-next.

Quoted 9 lines

drivers/media/video/em28xx/em28xx-video.c static int em28xx_v4l2_close(struct file *filp) · line 2265

Quoted 7 lines
drivers/media/video/em28xx/em28xx-video.c +0 -0
index ecb23df..78d6ebd 100644
@@ -2264,9 +2264,9 @@ static int em28xx_v4l2_close(struct file *filp)
                if (dev->state & DEV_DISCONNECTED) {
                        em28xx_release_resources(dev);

Why not unlocking here?

I don't see a reason to prefer one over the other.

regards,
dan carpenter

Quoted 13 lines

drivers/media/video/em28xx/em28xx-video.c static int em28xx_v4l2_close(struct file *filp) · line 2269

Quoted 6 lines
drivers/media/video/em28xx/em28xx-video.c +1 -1
                        kfree(dev->alt_max_pkt_size);
+                       mutex_unlock(&dev->lock);
                        kfree(dev);
                        kfree(fh);
-                       mutex_unlock(&dev->lock);

Thanks,
Ezequiel.
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 20 lines · Dan Carpenter
Quoted 9 lines · Ezequiel Garcia

Hi Dan,

Quoted 6 lines · Dan Carpenter

We need to move the unlock before the kfree(dev);

---
Applies to linux-next.

Quoted 9 lines

drivers/media/video/em28xx/em28xx-video.c static int em28xx_v4l2_close(struct file *filp) · line 2265

Quoted 7 lines
drivers/media/video/em28xx/em28xx-video.c +0 -0
index ecb23df..78d6ebd 100644
@@ -2264,9 +2264,9 @@ static int em28xx_v4l2_close(struct file *filp)
                if (dev->state & DEV_DISCONNECTED) {
                        em28xx_release_resources(dev);

Why not unlocking here?

Quoted 2 lines

I don't see a reason to prefer one over the other.

Mmm, I see now what you mean,

Thanks and sorry for dumb question,
Ezequiel.