diff options
author | Anton Altaparmakov <anton@tuxera.com> | 2011-01-28 15:45:28 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-30 21:58:11 -0500 |
commit | af5eb745efe97d91d2cbe793029838b3311c15da (patch) | |
tree | c2e410318a3f38928255ebf9ab18332b871e17f0 | |
parent | 9fbf0c08d441888b977f7c459c8aa57f2c0cb6ad (diff) |
NTFS: Fix invalid pointer dereference in ntfs_mft_record_alloc().
In ntfs_mft_record_alloc() when mapping the new extent mft record with
map_extent_mft_record() we overwrite @m with the return value and on
error, we then try to use the old @m but that is no longer there as @m
now contains an error code instead so we crash when dereferencing the
error code as if it were a pointer.
The simple fix is to use a temporary variable to store the return value
thus preserving the original @m for later use. This is a backport from
the commercial Tuxera-NTFS driver and is well tested...
Thanks go to Julia Lawall for pointing this out (whilst I had fixed it
in the commercial driver I had failed to fix it in the Linux kernel).
Signed-off-by: Anton Altaparmakov <anton@tuxera.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | Documentation/filesystems/ntfs.txt | 2 | ||||
-rw-r--r-- | fs/ntfs/mft.c | 11 |
2 files changed, 9 insertions, 4 deletions
diff --git a/Documentation/filesystems/ntfs.txt b/Documentation/filesystems/ntfs.txt index 6ef8cf3bc9a3..933bc66ccff1 100644 --- a/Documentation/filesystems/ntfs.txt +++ b/Documentation/filesystems/ntfs.txt | |||
@@ -460,6 +460,8 @@ Note, a technical ChangeLog aimed at kernel hackers is in fs/ntfs/ChangeLog. | |||
460 | 2.1.30: | 460 | 2.1.30: |
461 | - Fix writev() (it kept writing the first segment over and over again | 461 | - Fix writev() (it kept writing the first segment over and over again |
462 | instead of moving onto subsequent segments). | 462 | instead of moving onto subsequent segments). |
463 | - Fix crash in ntfs_mft_record_alloc() when mapping the new extent mft | ||
464 | record failed. | ||
463 | 2.1.29: | 465 | 2.1.29: |
464 | - Fix a deadlock when mounting read-write. | 466 | - Fix a deadlock when mounting read-write. |
465 | 2.1.28: | 467 | 2.1.28: |
diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c index b572b6727181..326e7475a22a 100644 --- a/fs/ntfs/mft.c +++ b/fs/ntfs/mft.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /** | 1 | /** |
2 | * mft.c - NTFS kernel mft record operations. Part of the Linux-NTFS project. | 2 | * mft.c - NTFS kernel mft record operations. Part of the Linux-NTFS project. |
3 | * | 3 | * |
4 | * Copyright (c) 2001-2006 Anton Altaparmakov | 4 | * Copyright (c) 2001-2011 Anton Altaparmakov and Tuxera Inc. |
5 | * Copyright (c) 2002 Richard Russon | 5 | * Copyright (c) 2002 Richard Russon |
6 | * | 6 | * |
7 | * This program/include file is free software; you can redistribute it and/or | 7 | * This program/include file is free software; you can redistribute it and/or |
@@ -2576,6 +2576,8 @@ mft_rec_already_initialized: | |||
2576 | flush_dcache_page(page); | 2576 | flush_dcache_page(page); |
2577 | SetPageUptodate(page); | 2577 | SetPageUptodate(page); |
2578 | if (base_ni) { | 2578 | if (base_ni) { |
2579 | MFT_RECORD *m_tmp; | ||
2580 | |||
2579 | /* | 2581 | /* |
2580 | * Setup the base mft record in the extent mft record. This | 2582 | * Setup the base mft record in the extent mft record. This |
2581 | * completes initialization of the allocated extent mft record | 2583 | * completes initialization of the allocated extent mft record |
@@ -2588,11 +2590,11 @@ mft_rec_already_initialized: | |||
2588 | * attach it to the base inode @base_ni and map, pin, and lock | 2590 | * attach it to the base inode @base_ni and map, pin, and lock |
2589 | * its, i.e. the allocated, mft record. | 2591 | * its, i.e. the allocated, mft record. |
2590 | */ | 2592 | */ |
2591 | m = map_extent_mft_record(base_ni, bit, &ni); | 2593 | m_tmp = map_extent_mft_record(base_ni, bit, &ni); |
2592 | if (IS_ERR(m)) { | 2594 | if (IS_ERR(m_tmp)) { |
2593 | ntfs_error(vol->sb, "Failed to map allocated extent " | 2595 | ntfs_error(vol->sb, "Failed to map allocated extent " |
2594 | "mft record 0x%llx.", (long long)bit); | 2596 | "mft record 0x%llx.", (long long)bit); |
2595 | err = PTR_ERR(m); | 2597 | err = PTR_ERR(m_tmp); |
2596 | /* Set the mft record itself not in use. */ | 2598 | /* Set the mft record itself not in use. */ |
2597 | m->flags &= cpu_to_le16( | 2599 | m->flags &= cpu_to_le16( |
2598 | ~le16_to_cpu(MFT_RECORD_IN_USE)); | 2600 | ~le16_to_cpu(MFT_RECORD_IN_USE)); |
@@ -2603,6 +2605,7 @@ mft_rec_already_initialized: | |||
2603 | ntfs_unmap_page(page); | 2605 | ntfs_unmap_page(page); |
2604 | goto undo_mftbmp_alloc; | 2606 | goto undo_mftbmp_alloc; |
2605 | } | 2607 | } |
2608 | BUG_ON(m != m_tmp); | ||
2606 | /* | 2609 | /* |
2607 | * Make sure the allocated mft record is written out to disk. | 2610 | * Make sure the allocated mft record is written out to disk. |
2608 | * No need to set the inode dirty because the caller is going | 2611 | * No need to set the inode dirty because the caller is going |