linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk-Mmb7MZpHnFY@public.gmane.org>
To: "Michael Kerrisk (man-pages)"
	<mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Jeff Smith <jsmith.lkml-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	"linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Jan Kara <jack-AlSwsSmVLrQ@public.gmane.org>,
	Eric Paris <eparis-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH 1/1] inotify.7: Bug 77111 - watch descriptor reuse
Date: Sun, 01 Jun 2014 13:29:39 +0200	[thread overview]
Message-ID: <538B0EA3.5040205@gmx.de> (raw)
In-Reply-To: <538AE6C9.2060202-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

On 01.06.2014 10:39, Michael Kerrisk (man-pages) wrote:
> On 05/31/2014 11:25 PM, Heinrich Schuchardt wrote:
>> On 30.05.2014 15:12, Michael Kerrisk (man-pages) wrote:
>>> [Adding Jan and Eric to the CC, in case they want to comment.]
>>>
>>> Background is bugs https://bugzilla.kernel.org/show_bug.cgi?id=76851
>>> and https://bugzilla.kernel.org/show_bug.cgi?id=77111 . The point is:
>>>
>>> 1. When an inotify watch descriptor is removed, pending unread
>>>      events remain pending.
>>> 2. When allocating a new watch descriptor, a past WD may
>>>      be recycled.
>>> 3. In theory, it could happen that events left over at 1 could
>>>      be interpreted as though they belonged to the filesystem
>>>      object watch in step 2.
>>>
>>> On 05/29/2014 07:39 PM, Heinrich Schuchardt wrote:
>>>> Watch descriptor IDs are returned by inotify_add_watch.
>>>> When calling inotify_rm_watch an IN_IGNORE is placed on the inotify queue
>>>> pointing to the ID of the removed watch.
>>>>
>>>> inotify_add_watch should not return a watch descriptor ID for which events are
>>>> still on the queue but should return an unused ID.
>>>>
>>>> Unfortunately the existing Kernel code does not provide such a guarantee.
>>>
>>> It's unfortunate, but I'm not sure that it's very serious. I mean, in
>>> order to trigger this bug you need to
>>>
>>> 0. Remove your watch descriptor (wd1),
>>> 1. Leave some unread events for wd1 on the queue. and in the meantime,
>>> 2. Cycle through INT_MAX watch descriptors until you reuse wd1.
>>>
>>> Unless I'm missing something, the chances of that are vanishingly small.
>>> However, that's not to say that the issue shouldn't be documented. Rather,
>>> if the issue is as unlikely to be hit as it appears to me in the above
>>> formulation, then I thing the tome of the write-up should indicate
>>> that the problem is more theoretical than practical. Perhaps Jan or Eric
>>> has a comment about this.
>>
>> 68 events per second add up to INT_MAX events a year.
>>
>> A server application restarted only once a year and handling a few
>> hundred request a second may be at risk. My idling workstation rebooted
>> once a day will never be hit.
>
> Yes, but you skip the other piece of the puzzle. This bug relies on us
> not reading events while at the same time cycling through INT_MAX watches.
> That's pretty unlikey in a sane application.

In my example code there were just three events waiting on the queue and 
they started waiting only **after** cycling through INT_MAX watches.

Best regards

Heinrich

>
>> I would feel more comfortable if the problem were not only documented
>> but fixed.
>
> Agreed, it's better if the bug were not there. It's a question of
> how much effort is required, and if there would be any significant
> performance hit associated with the fix. Weighed up against the risk
> that the bug could be hit.
>
>> Maybe Jan or Eric can comment on the following solution idea:
>>
>> Couldn't the idr ID be released in inotify_read when hitting IN_IGNORED
>> instead of being released inside inotify_rm_watch?
>
> See comments above. What would be the performance impact here? This
> would be some kind of check on *every* read(), no?
> Cheers,
>
> Michael
>
>

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2014-06-01 11:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-29 17:39 [PATCH 1/1] inotify.7: Bug 77111 - watch descriptor reuse Heinrich Schuchardt
     [not found] ` <1401385143-19306-1-git-send-email-xypron.glpk-Mmb7MZpHnFY@public.gmane.org>
2014-05-30 13:12   ` Michael Kerrisk (man-pages)
     [not found]     ` <538883D9.5090709-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-05-31 21:25       ` Heinrich Schuchardt
     [not found]         ` <538A48D0.8020402-Mmb7MZpHnFY@public.gmane.org>
2014-06-01  8:39           ` Michael Kerrisk (man-pages)
     [not found]             ` <538AE6C9.2060202-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-01 11:29               ` Heinrich Schuchardt [this message]
     [not found]                 ` <538B0EA3.5040205-Mmb7MZpHnFY@public.gmane.org>
2014-06-23  7:36                   ` Michael Kerrisk (man-pages)
2014-06-22 14:45       ` [PATCH 1/1 v2] " Heinrich Schuchardt
     [not found]         ` <1403448323-13459-1-git-send-email-xypron.glpk-Mmb7MZpHnFY@public.gmane.org>
2014-06-23  8:21           ` Michael Kerrisk (man-pages)
     [not found]             ` <53A7E39C.7050505-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-23  9:45               ` Heinrich Schuchardt
2014-06-23 10:04                 ` Michael Kerrisk (man-pages)

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=538B0EA3.5040205@gmx.de \
    --to=xypron.glpk-mmb7mzphnfy@public.gmane.org \
    --cc=eparis-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=jack-AlSwsSmVLrQ@public.gmane.org \
    --cc=jsmith.lkml-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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).