mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
nilfs2: validate segment number in nilfs_sufile_get_suinfo()
nilfs_sufile_get_suinfo() subtracts the caller-provided segment number
from the total number of segments without first checking its range. If
the requested number is greater than the total, the unsigned subtraction
wraps and the function may process segment numbers outside the filesystem.
Cache the total while holding the metadata semaphore and return no entries
when the starting segment number is at or beyond the end.
Fixes: 6c98cd4ecb ("nilfs2: segment usage file")
Cc: stable+noautosel@kernel.org # Non-fatal bug fix; defer backport until a real issue is reported
Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
Acked-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Reviewed-by: Viacheslav Dubeyko <slava@dubeyko.com>
Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
This commit is contained in:
parent
c59ddba036
commit
c298301279
|
|
@ -870,10 +870,14 @@ ssize_t nilfs_sufile_get_suinfo(struct inode *sufile, __u64 segnum, void *buf,
|
|||
|
||||
down_read(&NILFS_MDT(sufile)->mi_sem);
|
||||
|
||||
nsegs = nilfs_sufile_get_nsegments(sufile);
|
||||
if (segnum >= nsegs) {
|
||||
ret = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
segusages_per_block = nilfs_sufile_segment_usages_per_block(sufile);
|
||||
nsegs = min_t(unsigned long,
|
||||
nilfs_sufile_get_nsegments(sufile) - segnum,
|
||||
nsi);
|
||||
nsegs = min_t(unsigned long, nsegs - segnum, nsi);
|
||||
for (i = 0; i < nsegs; i += n, segnum += n) {
|
||||
n = min_t(unsigned long,
|
||||
segusages_per_block -
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user