Re: [PATCH] io_uring: fix sq array offset calculation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/17/20 7:48 AM, Dmitry Vyukov wrote:
> On Sat, Jul 11, 2020 at 6:16 PM Dmitry Vyukov <dvyukov@xxxxxxxxxx> wrote:
>>
>> On Sat, Jul 11, 2020 at 5:52 PM Hristo Venev <hristo@xxxxxxxxxx> wrote:
>>>
>>> On Sat, 2020-07-11 at 17:31 +0200, Dmitry Vyukov wrote:
>>>> Looking at the code more, I am not sure how it may not corrupt
>>>> memory.
>>>> There definitely should be some combinations where accessing
>>>> sq_entries*sizeof(u32) more memory won't be OK.
>>>> May be worth adding a test that allocates all possible sizes for
>>>> sq/cq
>>>> and fills both rings.
>>>
>>> The layout (after the fix) is roughly as follows:
>>>
>>> 1. struct io_rings - ~192 bytes, maybe 256
>>> 2. cqes - (32 << n) bytes
>>> 3. sq_array - (4 << n) bytes
>>>
>>> The bug was that the sq_array was offset by (4 << n) bytes. I think
>>> issues can only occur when
>>>
>>>     PAGE_ALIGN(192 + (32 << n) + (4 << n) + (4 << n))
>>>     !=
>>>     PAGE_ALIGN(192 + (32 << n) + (4 << n))
>>>
>>> It looks like this never happens. We got lucky.
>>
>> Interesting. CQ entries are larger and we have at least that many of
>> them as SQ entries. I guess this + power-of-2-pages can make it never
>> overflow.
> 
> Hi Jens,
> 
> I see this patch is in block/for-5.9/io_uring
> Is this tree merged into linux-next? I don't see it in linux-next yet.
> Or is it possible to get it into 5.8?

Yes, that tree is in linux-next, and I'm surprised you don't see it there
as it's been queued up for almost a week. Are you sure?

I'm not going to apply it to both 5.9 and 5.8 trees. The bug has
been there for a while, but doesn't really impact functionality.
Hence I just queued it up for 5.9. If this had been a 5.8 commit
that introduced it, I would have queued it up for 5.8.

> The reason I am asking is that we have an intern (Necip in CC) working
> on significantly extending io_uring coverage in syzkaller:
> https://github.com/google/syzkaller/pull/1926
> Unfortunately we had to hardcode offset computation logic b/c the
> intended way of using io_uring for normal programs represents an
> additional obstacle for the fuzzer and the relations between syscalls
> and writes to shared memory are even hard to express for the fuzzer.
> We want to hardcode this new updated way of computing offsets, but
> this means we probably won't get good coverage until the intern term
> ends (+ may be good to discover some io_uring bugs before the
> release).

Sounds good

> If it won't get into linux-next/mainline until 5.9, it's not a big
> deal, but I wanted to ask.

That's the plan, it'll go in as part of the 5.9 merge window.

-- 
Jens Axboe




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux