Skip to contentSkip to conversation

udf: Fix deadlock in udf_release_file()

PATCH In review Jan Kara 2 participants 3 messages Feb 20, 2012

Subsystems (2)
lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

PATCH 1/1 udf: Fix deadlock in udf_release_file()

udf_release_file() can be called from munmap() path with mmap_sem held. Thus we cannot take i_mutex there because that ranks above mmap_sem. Luckily, i_mutex is not needed in udf_release_file() anymore since protection by i_data_sem is enough to protect from races with write and truncate.

---
 fs/udf/file.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

If noone objects, I will add this patch to my tree and push it to Linus.

fs/udf/file.c +0 -2
index dca0c38..d567b84 100644
@@ -201,12 +201,10 @@ out:
 static int udf_release_file(struct inode *inode, struct file *filp)
 {
 	if (filp->f_mode & FMODE_WRITE) {
-		mutex_lock(&inode->i_mutex);
 		down_write(&UDF_I(inode)->i_data_sem);
 		udf_discard_prealloc(inode);
 		udf_truncate_tail_extent(inode);
 		up_write(&UDF_I(inode)->i_data_sem);
-		mutex_unlock(&inode->i_mutex);
 	}
 	return 0;
 }
Signature · 1 line
1.7.1
Reviewed-by on v1 1/1
#1 lore raw

2012/2/21 Jan Kara <[email protected]>:

Quoted 7 lines

udf_release_file() can be called from munmap() path with mmap_sem held.  Thus we cannot take i_mutex there because that ranks above mmap_sem. Luckily, i_mutex is not needed in udf_release_file() anymore since protection by i_data_sem is enough to protect from races with write and truncate.

HI. Jan.
Looks reasonable to me. And I think that this patch should be added in stable kernel.
So I add cc: [email protected].

Quoted 26 lines

---
 fs/udf/file.c |    2 --

 1 files changed, 0 insertions(+), 2 deletions(-)

 If noone objects, I will add this patch to my tree and push it to Linus.

fs/udf/file.c +0 -3
index dca0c38..d567b84 100644
@@ -201,12 +201,10 @@ out:
  static int udf_release_file(struct inode *inode, struct file *filp)
  {
        if (filp->f_mode & FMODE_WRITE) {
-               mutex_lock(&inode->i_mutex);
                down_write(&UDF_I(inode)->i_data_sem);
                udf_discard_prealloc(inode);
                udf_truncate_tail_extent(inode);
                up_write(&UDF_I(inode)->i_data_sem);
-               mutex_unlock(&inode->i_mutex);
        }
        return 0;
  }
--

1.7.1

Quoted 4 lines

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

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

author reviewer
#2 lore raw
Quoted 6 lines · Namjae Jeon

2012/2/21 Jan Kara <[email protected]>:

Quoted 5 lines

udf_release_file() can be called from munmap() path with mmap_sem held.  Thus we cannot take i_mutex there because that ranks above mmap_sem. Luckily, i_mutex is not needed in udf_release_file() anymore since protection by i_data_sem is enough to protect from races with write and truncate.

Quoted 6 lines
Quoted 2 lines

HI. Jan.
Looks reasonable to me. And I think that this patch should be added in stable kernel.
So I add cc: [email protected].

Good point. Added.

Quoted 1 line

Thanks.

Honza

Quoted 30 lines
Quoted 30 lines

---
 fs/udf/file.c |    2 --

 1 files changed, 0 insertions(+), 2 deletions(-)

 If noone objects, I will add this patch to my tree and push it to Linus.

fs/udf/file.c +0 -3
index dca0c38..d567b84 100644
@@ -201,12 +201,10 @@ out:
  static int udf_release_file(struct inode *inode, struct file *filp)
  {
        if (filp->f_mode & FMODE_WRITE) {
-               mutex_lock(&inode->i_mutex);
                down_write(&UDF_I(inode)->i_data_sem);
                udf_discard_prealloc(inode);
                udf_truncate_tail_extent(inode);
                up_write(&UDF_I(inode)->i_data_sem);
-               mutex_unlock(&inode->i_mutex);
        }
        return 0;
  }
--

1.7.1

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

Signature · 6 lines
Jan Kara <[email protected]>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html