public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Dylan Yudaken <[email protected]>,
	"[email protected]" <[email protected]>
Cc: "[email protected]" <[email protected]>
Subject: Re: [PATCH] io_uring: add overflow checks for poll refcounting
Date: Wed, 23 Mar 2022 19:48:12 +0000	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

On 3/23/22 15:07, Dylan Yudaken wrote:
> On Wed, 2022-03-23 at 11:14 +0000, Pavel Begunkov wrote:
>>
> ...
>>   
>> -#define IO_POLL_CANCEL_FLAG    BIT(31)
>> -#define IO_POLL_REF_MASK       GENMASK(30, 0)
>> +/* keep the sign bit unused to improve overflow detection */
>> +#define IO_POLL_CANCEL_FLAG    BIT(30)
>> +#define IO_POLL_REF_MASK       GENMASK(29, 0)
>> +
>> +/* 2^16 is choosen arbitrary, would be funky to have more than that
>> */
>> +#define io_poll_ref_check_overflow(refs) ((unsigned int)refs >=
>> 65536u)
>> +#define io_poll_ref_check_underflow(refs) ((int)refs < 0)
>>   
> 
> I believe if the cancel flag is set, then this will not catch an
> underflow but the result will be the cancel flag unset. You could fix
> by also checking for overflow on the masked bits.

Good point. I'm thinking now about using bit(0) for IO_POLL_CANCEL_FLAG
and 1-31 for refs. We'd need to do +2 in io_poll_get_ownership() but
the sign logic should work w/o extra weirdness.

-- 
Pavel Begunkov

  reply	other threads:[~2022-03-23 19:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-23 11:14 [PATCH] io_uring: add overflow checks for poll refcounting Pavel Begunkov
2022-03-23 12:33 ` Jens Axboe
2022-03-23 15:07 ` Dylan Yudaken
2022-03-23 19:48   ` Pavel Begunkov [this message]
2022-03-23 20:19     ` Dylan Yudaken

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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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