public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Question on release_one_tty
@ 2014-08-07  8:25 Cyrill Gorcunov
  2014-08-07  8:28 ` Pavel Emelyanov
  0 siblings, 1 reply; 7+ messages in thread
From: Cyrill Gorcunov @ 2014-08-07  8:25 UTC (permalink / raw)
  To: LKML, Jiri Slaby, Greg Kroah-Hartman; +Cc: Pavel Emelyanov

Hi guys, could you please explain me the sequence

static void release_one_tty(struct work_struct *work)
{
	struct tty_struct *tty =
		container_of(work, struct tty_struct, hangup_work);
	struct tty_driver *driver = tty->driver;

	if (tty->ops->cleanup)
		tty->ops->cleanup(tty);

	tty->magic = 0;
-->	tty_driver_kref_put(driver);
-->	module_put(driver->owner);

why tty_driver_kref_put is called before module_put? As far as I understand
tty_driver_kref_put may call the destruct_tty_driver which eventually does

static void destruct_tty_driver(struct kref *kref)
{
	struct tty_driver *driver = container_of(kref, struct tty_driver, kref);
	...
	kfree(driver->cdevs);
	kfree(driver->ports);
	kfree(driver->termios);
	kfree(driver->ttys);
-->	kfree(driver);
}

so that the module_put(driver->owner) would access freed memory. Should not we
call the reverse module_put and then tty_driver_kref_put, or I miss something
obvious?

	Cyrill

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-08-07 20:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-07  8:25 Question on release_one_tty Cyrill Gorcunov
2014-08-07  8:28 ` Pavel Emelyanov
2014-08-07  8:34   ` Cyrill Gorcunov
2014-08-07  9:05     ` Pavel Emelyanov
2014-08-07  9:18       ` Cyrill Gorcunov
2014-08-07  9:34         ` [PATCH] tty: Fix potential use after free in release_one_tty Cyrill Gorcunov
2014-08-07 20:22           ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox