Skip to content

Commit 55816c6

Browse files
ryaotonyhutter
authored andcommitted
FreeBSD: Fix integer conversion for vnlru_free{,_vfsops}()
When reviewing openzfs#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 openzfs#13882
1 parent 8dcd6af commit 55816c6

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
@@ -161,6 +161,12 @@ arc_prune_task(void *arg)
161161
int64_t nr_scan = (intptr_t)arg;
162162

163163
arc_reduce_target_size(ptob(nr_scan));
164+
165+
#ifndef __ILP32__
166+
if (nr_scan > INT_MAX)
167+
nr_scan = INT_MAX;
168+
#endif
169+
164170
#if __FreeBSD_version >= 1300139
165171
sx_xlock(&arc_vnlru_lock);
166172
vnlru_free_vfsops(nr_scan, &zfs_vfsops, arc_vnlru_marker);

0 commit comments

Comments
 (0)