copy_file_range and splice accept a negative offset

Đang mở
#467 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
65/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c
Lĩnh vực
operating-systems

Hướng nghiên cứu

Start in src/syscall/io.c at io_copy_chunked, then trace the corresponding offset checks in the splice path. Use the issue’s negative-offset cases for copy_file_range and splice as a guide. Done means a negative offset passed by pointer returns the specified Linux errno before copying, while a null pointer still uses the descriptor position.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug

copy_file_range and splice read *off_in and *off_out from guest memory into an int64_t that starts at -1, and the copy code treats any negative value as "use the descriptor's position" (io_copy_chunked in src/syscall/io.c, and the same >= 0 tests in the splice path). A guest that passes a pointer to a negative offset therefore gets a copy from or to the file position instead of an error.

Linux rejects these calls. Measured with a static aarch64 probe that writes 8 bytes to a regular file and calls each syscall with a pointer to -1 and a count of 4:

Call Linux (qemu) elfuse
copy_file_range, *off_in = -1 -1, EOVERFLOW 4
copy_file_range, *off_out = -1 -1, EOVERFLOW 4
splice file to pipe, *off_in = -1 -1, EINVAL 4
splice pipe to file, *off_out = -1 -1, EINVAL 4

On Linux, copy_file_range gives EOVERFLOW because generic_copy_file_checks adds the size_t count to the loff_t position, the negative position promotes to a huge unsigned value, and the sum wraps. splice gives EINVAL from the rw_verify_area check on a negative position.

Goal: a negative offset passed by pointer is refused with the Linux errno before anything is copied, and the "no pointer" case keeps using the descriptor position. That means the sentinel would have to be "pointer was NULL" rather than "value is negative".

Found while answering review on #463; not changed there because it is outside RLIMIT_FSIZE.

Ngôn ngữ chính
C
Star
287
Fork
33
Merge trung bình
2 ngày 17 giờ
Pull request đã merge (30 ngày)
18

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của sysprog21/elfuse

Tất cả issue của sysprog21/elfuse

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.