Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs: Fix theoretical division by 0 in super_cache_scan().

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>
Cc: stable <stable@kernel.org> # 3.1+
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by

Tetsuo Handa and committed by
Al Viro
475d0db7 b8314f93

+2
+2
fs/super.c
··· 80 80 inodes = list_lru_count_node(&sb->s_inode_lru, sc->nid); 81 81 dentries = list_lru_count_node(&sb->s_dentry_lru, sc->nid); 82 82 total_objects = dentries + inodes + fs_objects + 1; 83 + if (!total_objects) 84 + total_objects = 1; 83 85 84 86 /* proportion the scan between the caches */ 85 87 dentries = mult_frac(sc->nr_to_scan, dentries, total_objects);