mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	syzkaller <syzkaller@googlegroups.com>
Subject: Re: [PATCH] timerfd: Protect the might cancel mechanism proper
Date: Fri, 10 Feb 2017 11:13:04 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.20.1702040903470.3930@nanos> (raw)
In-Reply-To: <CACT4Y+bn8D6ZjrD=7Tmm1OPDcyDgt-8J0ULnk3NuaNrNB96zdQ@mail.gmail.com>

Dmitry,

On Thu, 2 Feb 2017, Dmitry Vyukov wrote:

> On Thu, Feb 2, 2017 at 7:54 PM, Thomas Gleixner <tglx@linutronix.de> wrote:
> > On Wed, 1 Feb 2017, Dmitry Vyukov wrote:
> >>
> >> Can't we still end up with an inconsistently setup timer?
> >> do_timerfd_settime executes timerfd_setup_cancel and timerfd_setup as
> >> two separate non-atomic actions. So if there are 2 concurrent
> >> timerfd_settime calls, one that needs cancel and another that does not
> >> need cancel, can't we end up with inconsistent setup? E.g. setup timer
> >> that needs cancel, but it won't be in cancel_list. Or vice versa.
> >
> > Do we really care? If an application arms the timer with cancel in one
> > thread and the same timer without cancel in another thread, then it's
> > probably completely irrelevant whether the state pair timeout/cancel is
> > correct or not. That's clearly an application bug and I don't want to add
> > more locking just to make something which is broken by definition pseudo
> > 'atomic'.
> 
> I agree that the program is bogus, and don't have to ensure any sane
> behavior for it. But I am concerned about potential kernel corruptions
> due to this. For example, maybe kernel code will decide to not remove
> such timer from the cancel list on destruction because based on
> clockid/flags it should not be in the cancel list, but the timer is
> actually there and we will end up with a leak or a dangling pointer. I
> did not check that this actually happens, such inconsistent state just
> looks like a red flag for me.

That can't happen.

ctx->might_cancel and ctx->clist are always in sync with the new lock and
that's the only interesting thing. On destruction we don't look at clockid
or such, we only care about might_cancel.

What is not guaranteed to be in sync is the timer expiry time and the
cancel stuff, if two threads operate on the same timerfd in
parallel. That's what I do not care about at all.

Thanks,

	tglx

  reply	other threads:[~2017-02-10 11:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-31 14:24 Thomas Gleixner
2017-02-01 12:43 ` Dmitry Vyukov
2017-02-02 18:54   ` Thomas Gleixner
2017-02-02 19:04     ` Dmitry Vyukov
2017-02-10 10:13       ` Thomas Gleixner [this message]
2017-02-10 10:26         ` Dmitry Vyukov
2017-02-10 10:51           ` Thomas Gleixner
2017-02-10 10:19 ` [tip:timers/core] " tip-bot for Thomas Gleixner

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=alpine.DEB.2.20.1702040903470.3930@nanos \
    --to=tglx@linutronix.de \
    --cc=dvyukov@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzkaller@googlegroups.com \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®