]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Fix copy_file_range(2) for an unlikely race during hole finding.
authorrmacklem <rmacklem@FreeBSD.org>
Thu, 8 Aug 2019 19:53:07 +0000 (19:53 +0000)
committerrmacklem <rmacklem@FreeBSD.org>
Thu, 8 Aug 2019 19:53:07 +0000 (19:53 +0000)
commit565bed2b159e0eddff5923c5f9864030ea73b50d
tree494a80da15852c63aebc2cf6fe8fe131cf691347
parent9c182fc73e8fa6017d9a2c9df152850e4958faa8
Fix copy_file_range(2) for an unlikely race during hole finding.

Since the VOP_IOCTL(FIOSEEKDATA/FIOSEEKHOLE) calls are done with the
vnode unlocked, it is possible for another thread to do:
- truncate(), lseek(), write()
between the two calls and create a hole where FIOSEEKDATA returned the
start of data.
For this case, VOP_IOCTL(FIOSEEKHOLE) will return the same offset for
the hole location. This could result in an infinite loop in the copy
code, since copylen is set to 0 and the copy doesn't advance.
Usually, this race is avoided because of the use of rangelocks, but the
NFS server does not do range locking and could do a sequence like the
above to create the hole.

This patch checks for this case and makes the hole search fail, to avoid
the infinite loop.

At this time, it is an open question as to whether or not the NFS server
should do range locking to avoid this race.
sys/kern/vfs_vnops.c