Skip to contentSkip to conversation

vfs: Fix possible chmod/truncate race condition.

PATCH In review Dmitri Monakhov 2 participants 3 messages Oct 15, 2008 – Oct 27, 2008 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfs: Fix possible chmod/truncate race condition.

---
 fs/open.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
fs/open.c +1 -2
index 07da935..3423b94 100644
@@ -214,10 +214,9 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
 		newattrs.ia_valid |= ATTR_FILE;
 	}
 
+	mutex_lock(&dentry->d_inode->i_mutex);
 	/* Remove suid/sgid on truncate too */
 	newattrs.ia_valid |= should_remove_suid(dentry);
-
-	mutex_lock(&dentry->d_inode->i_mutex);
 	err = notify_change(dentry, &newattrs);
 	mutex_unlock(&dentry->d_inode->i_mutex);
 	return err;
Signature · 1 line
1.5.4.3
#1 lore raw
Quoted 12 lines · On Wed, 15 Oct 2008 23:35:27 +0400 Dmitri Monakhov <[email protected]> wrote:
---
 fs/open.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
fs/open.c +0 -0
index 07da935..3423b94 100644
@@ -214,10 +214,9 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
 		newattrs.ia_valid |= ATTR_FILE;

fs/open.c int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs, · line 222

Quoted 10 lines
fs/open.c +1 -2
 	}
 
+	mutex_lock(&dentry->d_inode->i_mutex);
 	/* Remove suid/sgid on truncate too */
 	newattrs.ia_valid |= should_remove_suid(dentry);
-
-	mutex_lock(&dentry->d_inode->i_mutex);
 	err = notify_change(dentry, &newattrs);
 	mutex_unlock(&dentry->d_inode->i_mutex);
 	return err;

OK, I give up. What race?

#2 lore raw
Quoted 16 lines · Andrew Morton
Quoted 14 lines · On Wed, 15 Oct 2008 23:35:27 +0400 Dmitri Monakhov <[email protected]> wrote:
---
 fs/open.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
fs/open.c +0 -0
index 07da935..3423b94 100644
@@ -214,10 +214,9 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
 		newattrs.ia_valid |= ATTR_FILE;
 	}
 
Quoted 10 lines

fs/open.c int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs, · line 222

Quoted 8 lines
fs/open.c +1 -2
+	mutex_lock(&dentry->d_inode->i_mutex);
 	/* Remove suid/sgid on truncate too */
 	newattrs.ia_valid |= should_remove_suid(dentry);
-
-	mutex_lock(&dentry->d_inode->i_mutex);
 	err = notify_change(dentry, &newattrs);
 	mutex_unlock(&dentry->d_inode->i_mutex);
 	return err;

OK, I give up. What race?

i_mode read not protected by i_mutex in should_remove_suid() and we may have race condition with chown(). Sorry, seems I've been too crazy about this. The truth is:
1: No one will call truncate() and chown() concurrently.
2: This race is still possible regardless to this fix.