summaryrefslogtreecommitdiff
path: root/fs/super.c
diff options
context:
space:
mode:
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>2014-05-17 20:56:38 +0900
committerLuis Henriques <luis.henriques@canonical.com>2014-11-14 15:20:08 +0000
commite64a0bc3636b0bc57d54f0b977df0ef51737f9fc (patch)
treebb146290a5a0fdfe8454ebf8cb780b3fdb00e5b6 /fs/super.c
parent4595138c089fd550ef3e773205dfed626dbbfe3d (diff)
fs: Fix theoretical division by 0 in super_cache_scan().
commit 475d0db742e3755c6b267f48577ff7cbb7dfda0d upstream. total_objects could be 0 and is used as a denom. While total_objects is a "long", total_objects == 0 unlikely happens for 3.12 and later kernels because 32-bit architectures would not be able to hold (1 << 32) objects. However, total_objects == 0 may happen for kernels between 3.1 and 3.11 because total_objects in prune_super() was an "int" and (e.g.) x86_64 architecture might be able to hold (1 << 32) objects. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
Diffstat (limited to 'fs/super.c')
-rw-r--r--fs/super.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/fs/super.c b/fs/super.c
index d20d5b11dedf..abb8c7f9599b 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -81,6 +81,8 @@ static unsigned long super_cache_scan(struct shrinker *shrink,
inodes = list_lru_count_node(&sb->s_inode_lru, sc->nid);
dentries = list_lru_count_node(&sb->s_dentry_lru, sc->nid);
total_objects = dentries + inodes + fs_objects + 1;
+ if (!total_objects)
+ total_objects = 1;
/* proportion the scan between the caches */
dentries = mult_frac(sc->nr_to_scan, dentries, total_objects);