io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: Jens Axboe <axboe@kernel.dk>, io-uring@vger.kernel.org
Subject: Re: [RFC][BUG] io_uring: fix work corruption for poll_add
Date: Thu, 23 Jul 2020 22:10:08 +0300	[thread overview]
Message-ID: <8ff4be9e-fada-e471-4a3f-3e8ac5f7ae61@gmail.com> (raw)
In-Reply-To: <ecb56297-ec6d-de6f-a619-6d19549d2272@kernel.dk>

On 23/07/2020 21:19, Jens Axboe wrote:
> On 7/23/20 12:15 PM, Pavel Begunkov wrote:
>> On 23/07/2020 21:12, Pavel Begunkov wrote:
>>> poll_add can have req->work initialised, which will be overwritten in
>>> __io_arm_poll_handler() because of the union. Luckily, hash_node is
>>> zeroed in the end, so the damage is limited to lost put for work.creds,
>>> and probably corrupted work.list.
>>>
>>> That's the easiest and really dirty fix, which rearranges members in the
>>> union, arm_poll*() modifies and zeroes only work.files and work.mm,
>>> which are never taken for poll add.
>>> note: io_kiocb is exactly 4 cachelines now.
>>
>> Please, tell me if anybody has a good lean solution, because I'm a bit
>> too tired at the moment to fix it properly.
>> BTW, that's for 5.8, for-5.9 it should be done differently because of
>> io_kiocb compaction. 
> 
> Do you have a test case that leaks the reference?

link-timeout.c::test_timeout_link_chain2()
- add IOSQE_ASYNC after poll_add_prep() (probably, not even needed)
- close() pipes fds at the end.
- while(1) test_timeout_link_chain2()

That's what I did to test it. Confirmed with printk + it killed the
system in 10-30 minutes. I can get something faster sometime later.

-- 
Pavel Begunkov

  reply	other threads:[~2020-07-23 19:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-23 18:12 [RFC][BUG] io_uring: fix work corruption for poll_add Pavel Begunkov
2020-07-23 18:15 ` Pavel Begunkov
2020-07-23 18:19   ` Jens Axboe
2020-07-23 19:10     ` Pavel Begunkov [this message]
2020-07-23 22:16 ` Jens Axboe
2020-07-23 22:24   ` Jens Axboe
2020-07-24 12:46     ` Pavel Begunkov
2020-07-24 12:52       ` Pavel Begunkov
2020-07-24 14:12         ` Jens Axboe
2020-07-24 14:23           ` Pavel Begunkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8ff4be9e-fada-e471-4a3f-3e8ac5f7ae61@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).