Skip to contentSkip to conversation

ibmasm driver: don't use previously freed pointer

PATCH In review Max Asbock 2 participants 4 messages Feb 3, 2006 – Feb 7, 2006 Char and misc drivers

lore
Share & tools
lore

Max Asbock

author
#0 lore raw

PATCH 1/1 ibmasm driver: don't use previously freed pointer

ibmasm driver:
Fix the command_put() function which uses a pointer for a spinlock that can be freed before dereferencing it.

---

drivers/misc/ibmasm/ibmasm.h +3 -2
diff -burpN linux-2.6.16-rc1/drivers/misc/ibmasm/ibmasm.h linux-2.6.16-rc1.ibmasm/drivers/misc/ibmasm/ibmasm.h
@@ -101,10 +101,11 @@ struct command {
 static inline void command_put(struct command *cmd)
 {
 	unsigned long flags;
+	spinlock_t *lock = cmd->lock;
 
-	spin_lock_irqsave(cmd->lock, flags);
+	spin_lock_irqsave(lock, flags);
         kobject_put(&cmd->kobj);
-	spin_unlock_irqrestore(cmd->lock, flags);
+	spin_unlock_irqrestore(lock, flags);
 }
 
 static inline void command_get(struct command *cmd)
#1 lore raw
Quoted 13 lines · Max Asbock

ibmasm driver:
Fix the command_put() function which uses a pointer for a spinlock that can be freed before dereferencing it.

---

diff -burpN linux-2.6.16-rc1/drivers/misc/ibmasm/ibmasm.h linux-2.6.16-rc1.ibmasm/drivers/misc/ibmasm/ibmasm.h

drivers/misc/ibmasm/ibmasm.h +0 -0
@@ -101,10 +101,11 @@ struct command {
 static inline void command_put(struct command *cmd)

drivers/misc/ibmasm/ibmasm.h struct command { · line 109

Quoted 10 lines
drivers/misc/ibmasm/ibmasm.h +3 -2
 {
 	unsigned long flags;
+	spinlock_t *lock = cmd->lock;
 
-	spin_lock_irqsave(cmd->lock, flags);
+	spin_lock_irqsave(lock, flags);
         kobject_put(&cmd->kobj);
-	spin_unlock_irqrestore(cmd->lock, flags);
+	spin_unlock_irqrestore(lock, flags);
 }

If this patch is true, doesn't the spinlock the pointer is pointing out still get deleted?

Yes you save a pointer off, but it looks like the problem is still present.

Or am I missing something?

thanks,

greg k-h

author
#2 lore raw
Quoted 28 lines · Greg KH
Quoted 13 lines · Max Asbock

ibmasm driver:
Fix the command_put() function which uses a pointer for a spinlock that can be freed before dereferencing it.

---

diff -burpN linux-2.6.16-rc1/drivers/misc/ibmasm/ibmasm.h linux-2.6.16-rc1.ibmasm/drivers/misc/ibmasm/ibmasm.h

drivers/misc/ibmasm/ibmasm.h +0 -0
@@ -101,10 +101,11 @@ struct command {
 static inline void command_put(struct command *cmd)

drivers/misc/ibmasm/ibmasm.h struct command { · line 109

Quoted 10 lines
drivers/misc/ibmasm/ibmasm.h +3 -2
 {
 	unsigned long flags;
+	spinlock_t *lock = cmd->lock;
 
-	spin_lock_irqsave(cmd->lock, flags);
+	spin_lock_irqsave(lock, flags);
         kobject_put(&cmd->kobj);
-	spin_unlock_irqrestore(cmd->lock, flags);
+	spin_unlock_irqrestore(lock, flags);
 }

If this patch is true, doesn't the spinlock the pointer is pointing out still get deleted?

Quoted 5 lines

Yes you save a pointer off, but it looks like the problem is still present.

Or am I missing something?

The lock pointer in struct command points to a spinlock outside the structure that doesn't get deleted.

max

#3 lore raw
Quoted 29 lines · Max Asbock
Quoted 28 lines · Greg KH
Quoted 13 lines · Max Asbock

ibmasm driver:
Fix the command_put() function which uses a pointer for a spinlock that can be freed before dereferencing it.

---

diff -burpN linux-2.6.16-rc1/drivers/misc/ibmasm/ibmasm.h linux-2.6.16-rc1.ibmasm/drivers/misc/ibmasm/ibmasm.h

drivers/misc/ibmasm/ibmasm.h +0 -0
@@ -101,10 +101,11 @@ struct command {
 static inline void command_put(struct command *cmd)

drivers/misc/ibmasm/ibmasm.h struct command { · line 109

Quoted 10 lines
drivers/misc/ibmasm/ibmasm.h +3 -2
 {
 	unsigned long flags;
+	spinlock_t *lock = cmd->lock;
 
-	spin_lock_irqsave(cmd->lock, flags);
+	spin_lock_irqsave(lock, flags);
         kobject_put(&cmd->kobj);
-	spin_unlock_irqrestore(cmd->lock, flags);
+	spin_unlock_irqrestore(lock, flags);
 }

If this patch is true, doesn't the spinlock the pointer is pointing out still get deleted?

Quoted 8 lines
Quoted 5 lines

Yes you save a pointer off, but it looks like the problem is still present.

Or am I missing something?

The lock pointer in struct command points to a spinlock outside the structure that doesn't get deleted.

Ok, that's what I was missing, nevermind then :)

thanks,

greg k-h