zig icon indicating copy to clipboard operation
zig copied to clipboard

Integer overflow when using >=4096 buffers in IoUring setup_buf_ring

Open karlbohlmark opened this issue 1 year ago • 0 comments

Zig Version

0.13.0-dev.46+3648d7df1

Steps to Reproduce and Observed Behavior

pub fn main() !void {
    var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){};
    const allocator = gpa.allocator();
    var ring = IoUring.init(256, 0) catch |err| {
        std.debug.print("Failed to initialize io_uring: {s}\n", .{@errorName(err)});
        return;
    };
    defer IoUring.deinit(&ring);
    const buffer_size = 1536;
    const num_buffers = 4096;
    const group_buffers = try allocator.alignedAlloc(u8, std.mem.page_size, buffer_size * num_buffers);
    _ = BufferGroup.init(
        &ring,
        1,
        group_buffers,
        buffer_size,
        num_buffers,
    ) catch |err| switch (err) {
        error.ArgumentsInvalid => return error.KernelTooOld,
        else => return err,
    };
}
thread 134544 panic: integer overflow
/home/karboh/.zvm/master/lib/std/os/linux/IoUring.zig:1562:31: 0x104d2d3 in setup_buf_ring (main)
    const mmap_size = entries * @sizeOf(linux.io_uring_buf);
                              ^
/home/karboh/.zvm/master/lib/std/os/linux/IoUring.zig:1482:38: 0x104d4df in init (main)
        const br = try setup_buf_ring(ring.fd, buffers_count, group_id);
                                     ^
/home/karboh/test/src/main.zig:18:25: 0x104dacb in main (main)
    _ = BufferGroup.init(
                        ^
/home/karboh/.zvm/master/lib/std/start.zig:511:37: 0x104acdf in posixCallMainAndExit (main)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x0 in ??? (???)
Aborted (core dumped)

Expected Behavior

According to the liburing docs: "The maximum size allowed is 2^15 (32768)"

karlbohlmark avatar May 03 '24 07:05 karlbohlmark