Skip to contentSkip to conversation

fix notify_change() potential null dereference.

PATCH Dave Jones 3 participants 3 messages Apr 16, 2004 VFS

lore
Share & tools
lore

Dave Jones

author
#0 lore raw
fs/attr.c renamed from fs/attr.c~ +2 -1
@@ -130,7 +130,7 @@
 int notify_change(struct dentry * dentry, struct iattr * attr)
 {
 	struct inode *inode = dentry->d_inode;
-	mode_t mode = inode->i_mode;
+	mode_t mode;
 	int error;
 	struct timespec now = CURRENT_TIME;
 	unsigned int ia_valid = attr->ia_valid;
@@ -138,6 +138,7 @@
 	if (!inode)
 		BUG();
 
+	mode = inode->i_mode;
 	attr->ia_ctime = now;
 	if (!(ia_valid & ATTR_ATIME_SET))
 		attr->ia_atime = now;
#1 lore raw

I disagree on this one - at least with the message.

The fact is, "inode" can't be NULL. We have a BUG() check for it, but getting a page fault would be equally effective.

Linus

Quoted 21 lines · Dave Jones
fs/attr.c renamed from fs/attr.c~ +2 -1
@@ -130,7 +130,7 @@
 int notify_change(struct dentry * dentry, struct iattr * attr)
 {
 	struct inode *inode = dentry->d_inode;
-	mode_t mode = inode->i_mode;
+	mode_t mode;
 	int error;
 	struct timespec now = CURRENT_TIME;
 	unsigned int ia_valid = attr->ia_valid;
@@ -138,6 +138,7 @@
 	if (!inode)
 		BUG();
 
+	mode = inode->i_mode;
 	attr->ia_ctime = now;
 	if (!(ia_valid & ATTR_ATIME_SET))
 		attr->ia_atime = now;
#2 lore raw
In reply to Dave Jones

fs/attr.c line 133

Quoted 9 lines · Dave Jones
fs/attr.c renamed from fs/attr.c~ +1 -1
@@ -130,7 +130,7 @@
 int notify_change(struct dentry * dentry, struct iattr * attr)
 {
 	struct inode *inode = dentry->d_inode;
-	mode_t mode = inode->i_mode;
+	mode_t mode;

Passing a NULL argument to notify_change() is invalid.