linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Cochran <richardcochran@gmail.com>
To: Vladis Dronov <vdronov@redhat.com>
Cc: linux-fsdevel@vger.kernel.org,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Al Viro <aviro@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] ptp: fix the race between the release of ptp_clock and cdev
Date: Fri, 27 Dec 2019 07:02:19 -0800	[thread overview]
Message-ID: <20191227150218.GA1435@localhost> (raw)
In-Reply-To: <20191227022627.24476-1-vdronov@redhat.com>

On Fri, Dec 27, 2019 at 03:26:27AM +0100, Vladis Dronov wrote:
> Here cdev is embedded in posix_clock which is embedded in ptp_clock.
> The race happens because ptp_clock's lifetime is controlled by two
> refcounts: kref and cdev.kobj in posix_clock. This is wrong.
> 
> Make ptp_clock's sysfs device a parent of cdev with cdev_device_add()
> created especially for such cases. This way the parent device with its
> ptp_clock is not released until all references to the cdev are released.
> This adds a requirement that an initialized but not exposed struct
> device should be provided to posix_clock_register() by a caller instead
> of a simple dev_t.
> 
> This approach was adopted from the commit 72139dfa2464 ("watchdog: Fix
> the race between the release of watchdog_core_data and cdev"). See
> details of the implementation in the commit 233ed09d7fda ("chardev: add
> helper function to register char devs with a struct device").

Thanks for digging into this!

Acked-by: Richard Cochran <richardcochran@gmail.com>

>  /**
>   * posix_clock_register() - register a new clock
> - * @clk:   Pointer to the clock. Caller must provide 'ops' and 'release'
> - * @devid: Allocated device id
> + * @clk:   Pointer to the clock. Caller must provide 'ops' field
> + * @dev:   Pointer to the initialized device. Caller must provide
> + *         'release' filed

field

Thanks,
Richard

  reply	other threads:[~2019-12-27 15:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-25 12:53 [PATCH] fs: fix use-after-free in __fput() when a chardev is removed but a file is still open Vladis Dronov
2019-12-08 19:49 ` Al Viro
2019-12-08 19:53   ` Al Viro
2019-12-27  2:26     ` [PATCH v2] ptp: fix the race between the release of ptp_clock and cdev Vladis Dronov
2019-12-27 15:02       ` Richard Cochran [this message]
2019-12-27 17:24         ` Vladis Dronov
2019-12-31  4:19       ` David Miller

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=20191227150218.GA1435@localhost \
    --to=richardcochran@gmail.com \
    --cc=aviro@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=vdronov@redhat.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;
as well as URLs for NNTP newsgroup(s).