Skip to contentSkip to conversation

proc: proc_get_inode should de_put when inode already initialized

PATCH In review Krzysztof Sachanowicz 3 participants 4 messages Feb 23, 2009 – Feb 24, 2009 Proc filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 proc: proc_get_inode should de_put when inode already initialized

de_get is called before every proc_get_inode, but corresponding de_put is called only when dropping last reference to an inode. This might cause something like
remove_proc_entry: /proc/stats busy, count=14496
to be printed to the syslog.

The fix is to call de_put in case of an already initialized inode in proc_get_inode.

---

fs/proc/inode.c +3 -1
@@ -485,8 +485,10 @@ struct inode *proc_get_inode(struct supe
 			}
 		}
 		unlock_new_inode(inode);
-	} else
+	} else {
 	       module_put(de->owner);
+	       de_put(de);
+	}
 	return inode;
 
 out_ino:
#1 lore raw
Quoted 16 lines · On Mon, 23 Feb 2009 22:21:55 +0100 Krzysztof Sachanowicz <[email protected]>…

de_get is called before every proc_get_inode, but corresponding de_put is called only when dropping last reference to an inode. This might cause something like
remove_proc_entry: /proc/stats busy, count=14496
to be printed to the syslog.

The fix is to call de_put in case of an already initialized inode in proc_get_inode.

---

fs/proc/inode.c +0 -0
@@ -485,8 +485,10 @@ struct inode *proc_get_inode(struct supe
 			}

fs/proc/inode.c struct inode *proc_get_inode(struct supe · line 494

Quoted 10 lines
fs/proc/inode.c +3 -1
 		}
 		unlock_new_inode(inode);
-	} else
+	} else {
 	       module_put(de->owner);
+	       de_put(de);
+	}
 	return inode;
 
 out_ino:

This code area looks quite different in linux-next, although the changes there are removing proc_dir_entry.owner altogether and aren't obviously targetted at fixing this bug.

Also...

It's unpleasing to have the de_get() inside the caller and the de_put() inside the callee - it is better to have them both happening at the same level. If it is the case that "de_get is called before every proc_get_inode", then perhaps that operation should simply be moved into proc_get_inode().

#2 lore raw

Tuesday 24 February 2009 00:25:55 Andrew Morton napisał(a):

Quoted 34 lines

On Mon, 23 Feb 2009 22:21:55 +0100

Quoted 16 lines · Krzysztof Sachanowicz

de_get is called before every proc_get_inode, but corresponding de_put is called only when dropping last reference to an inode. This might cause something like
remove_proc_entry: /proc/stats busy, count=14496
to be printed to the syslog.

The fix is to call de_put in case of an already initialized inode in proc_get_inode.

---
--- linux-2.6.29-rc6.orig/fs/proc/inode.c 2009-02-23 20:43:32.000000000
+0100 +++ linux-2.6.29-rc6/fs/proc/inode.c 2009-02-23 20:46:37.000000000
+0100 @@ -485,8 +485,10 @@ struct inode *proc_get_inode(struct supe

fs/proc/inode.c +0 -0
 			}

fs/proc/inode.c struct inode *proc_get_inode(struct supe · line 494

Quoted 10 lines
fs/proc/inode.c +3 -1
 		}
 		unlock_new_inode(inode);
-	} else
+	} else {
 	       module_put(de->owner);
+	       de_put(de);
+	}
 	return inode;
 
 out_ino:

This code area looks quite different in linux-next, although the changes there are removing proc_dir_entry.owner altogether and aren't obviously targetted at fixing this bug.

Quoted 7 lines

Also...

It's unpleasing to have the de_get() inside the caller and the de_put() inside the callee - it is better to have them both happening at the same level. If it is the case that "de_get is called before every proc_get_inode", then perhaps that operation should simply be moved into proc_get_inode().

Yes, but unfortunately in proc_lookup_de() (fs/proc/generic.c) we have:

 391                        de_get(de);
 392                        spin_unlock(&proc_subdir_lock);
 393                        error = -EINVAL;
 394                        inode = proc_get_inode(dir->i_sb, ino, de);

So if we move de_get() into proc_get_inode(), we will also have to move spin_unlock there. Then we will have spin_lock in proc_lookup_de but spin_unlock in proc_get_inode...

Maybe my solution is not that bad, because usually de_put is called from proc_delete_inode(). Only if iget_locked() returns an already initialized inode we want de_put to be called in proc_get_inode. So the callee need not care about who will eventually call de_put.

#3 lore raw
In reply to Andrew Morton
Quoted 28 lines · Andrew Morton
Quoted 25 lines · On Mon, 23 Feb 2009 22:21:55 +0100 Krzysztof Sachanowicz <[email protected]>…

de_get is called before every proc_get_inode, but corresponding de_put is called only when dropping last reference to an inode. This might cause something like
remove_proc_entry: /proc/stats busy, count=14496
to be printed to the syslog.

The fix is to call de_put in case of an already initialized inode in proc_get_inode.

---

fs/proc/inode.c +3 -1
@@ -485,8 +485,10 @@ struct inode *proc_get_inode(struct supe
 			}
 		}
 		unlock_new_inode(inode);
-	} else
+	} else {
 	       module_put(de->owner);
+	       de_put(de);
+	}
 	return inode;
 
Quoted 5 lines

fs/proc/inode.c struct inode *proc_get_inode(struct supe · line 494

Quoted 1 line
fs/proc/inode.c +0 -0
 out_ino:

This code area looks quite different in linux-next, although the changes there are removing proc_dir_entry.owner altogether and aren't obviously targetted at fixing this bug.

->owner issue is independent of this leak, I'll rebase/edit patches as needed.

Quoted 7 lines

Also...

It's unpleasing to have the de_get() inside the caller and the de_put() inside the callee - it is better to have them both happening at the same level. If it is the case that "de_get is called before every proc_get_inode", then perhaps that operation should simply be moved into proc_get_inode().

Well, yes, this sucks. But unlock_new_inode() will clear I_NEW state, so after function returns, there is no way to distinguish.