aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChao Yu <chao2.yu@samsung.com>2014-05-27 20:56:09 -0400
committerJaegeuk Kim <jaegeuk@kernel.org>2014-06-04 00:34:30 -0400
commitbfec07d0f8ed78b10df3ca3bc23e27de1166ea45 (patch)
treec6134dfc647176474944cbb244bd15de4d4607ac
parentd631abdac9d541d282a1461b5aeae70aa3866e9f (diff)
f2fs: avoid overflow when large directory feathure is enabled
When large directory feathure is enable, We have one case which could cause overflow in dir_buckets() as following: special case: level + dir_level >= 32 and level < MAX_DIR_HASH_DEPTH / 2. Here we define MAX_DIR_BUCKETS to limit the return value when the condition could trigger potential overflow. Changes from V1 o modify description of calculation in f2fs.txt suggested by Changman Lee. Suggested-by: Changman Lee <cm224.lee@samsung.com> Signed-off-by: Chao Yu <chao2.yu@samsung.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--Documentation/filesystems/f2fs.txt8
-rw-r--r--fs/f2fs/dir.c4
-rw-r--r--include/linux/f2fs_fs.h3
3 files changed, 9 insertions, 6 deletions
diff --git a/Documentation/filesystems/f2fs.txt b/Documentation/filesystems/f2fs.txt
index 25311e113e75..51afba17bbae 100644
--- a/Documentation/filesystems/f2fs.txt
+++ b/Documentation/filesystems/f2fs.txt
@@ -461,11 +461,11 @@ The number of blocks and buckets are determined by,
461 # of blocks in level #n = | 461 # of blocks in level #n = |
462 `- 4, Otherwise 462 `- 4, Otherwise
463 463
464 ,- 2^ (n + dir_level), 464 ,- 2^(n + dir_level),
465 | if n < MAX_DIR_HASH_DEPTH / 2, 465 | if n + dir_level < MAX_DIR_HASH_DEPTH / 2,
466 # of buckets in level #n = | 466 # of buckets in level #n = |
467 `- 2^((MAX_DIR_HASH_DEPTH / 2 + dir_level) - 1), 467 `- 2^((MAX_DIR_HASH_DEPTH / 2) - 1),
468 Otherwise 468 Otherwise
469 469
470When F2FS finds a file name in a directory, at first a hash value of the file 470When F2FS finds a file name in a directory, at first a hash value of the file
471name is calculated. Then, F2FS scans the hash table in level #0 to find the 471name is calculated. Then, F2FS scans the hash table in level #0 to find the
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index c3f148555c37..966acb039e3b 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -23,10 +23,10 @@ static unsigned long dir_blocks(struct inode *inode)
23 23
24static unsigned int dir_buckets(unsigned int level, int dir_level) 24static unsigned int dir_buckets(unsigned int level, int dir_level)
25{ 25{
26 if (level < MAX_DIR_HASH_DEPTH / 2) 26 if (level + dir_level < MAX_DIR_HASH_DEPTH / 2)
27 return 1 << (level + dir_level); 27 return 1 << (level + dir_level);
28 else 28 else
29 return 1 << ((MAX_DIR_HASH_DEPTH / 2 + dir_level) - 1); 29 return MAX_DIR_BUCKETS;
30} 30}
31 31
32static unsigned int bucket_blocks(unsigned int level) 32static unsigned int bucket_blocks(unsigned int level)
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
index 8c03f71307c6..ba6f3127738f 100644
--- a/include/linux/f2fs_fs.h
+++ b/include/linux/f2fs_fs.h
@@ -394,6 +394,9 @@ typedef __le32 f2fs_hash_t;
394/* MAX level for dir lookup */ 394/* MAX level for dir lookup */
395#define MAX_DIR_HASH_DEPTH 63 395#define MAX_DIR_HASH_DEPTH 63
396 396
397/* MAX buckets in one level of dir */
398#define MAX_DIR_BUCKETS (1 << ((MAX_DIR_HASH_DEPTH / 2) - 1))
399
397#define SIZE_OF_DIR_ENTRY 11 /* by byte */ 400#define SIZE_OF_DIR_ENTRY 11 /* by byte */
398#define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \ 401#define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \
399 BITS_PER_BYTE) 402 BITS_PER_BYTE)