Skip to content

Commit ccec88f

Browse files
authored
FreeBSD: Fix integer conversion for vnlru_free{,_vfsops}()
When reviewing #13875, I noticed that our FreeBSD code has an issue where it converts from `int64_t` to `int` when calling `vnlru_free{,_vfsops}()`. The result is that if the int64_t is `1 << 36`, the int will be 0, since the low bits are 0. Even when some low bits are set, a value such as `((1 << 36) + 1)` would truncate to 1, which is wrong. There is protection against this on 32-bit platforms, but on 64-bit platforms, there is no check to protect us, so we add a check. Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Ryan Moeller <ryan@iXsystems.com> Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu> Closes #13882
1 parent 4a6e8b9 commit ccec88f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

module/os/freebsd/zfs/arc_os.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ arc_prune_task(void *arg)
142142
int64_t nr_scan = (intptr_t)arg;
143143

144144
arc_reduce_target_size(ptob(nr_scan));
145+
146+
#ifndef __ILP32__
147+
if (nr_scan > INT_MAX)
148+
nr_scan = INT_MAX;
149+
#endif
150+
145151
#if __FreeBSD_version >= 1300139
146152
sx_xlock(&arc_vnlru_lock);
147153
vnlru_free_vfsops(nr_scan, &zfs_vfsops, arc_vnlru_marker);

0 commit comments

Comments
 (0)