Actions
Bug #21883
openIO::Buffer can be unlocked and freed by another thread during syscall
Bug #21883:
IO::Buffer can be unlocked and freed by another thread during syscall
Description
# Assume this file is on a very slow device such as NFS.
io = File.open('/mnt/slowfs/slow')
buf = IO::Buffer.new(100)
t1 = Thread.new do
buf.locked do
sleep 0.5
end
buf.free
end
t2 = Thread.new do
buf.read(io) # syscall takes 1 second
# When the kernal writes to the memory, buf is already freed, thus use-after-free
end
t1.join
t2.join
io_buffer_blocking_region skips taking a lock when the buffer is already locked, but this lock may be owned by another thread and can be unlocked during the syscall.
Actions