lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 31 May 2007 15:37:12 -0700
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Matthias Kaehlcke <matthias.kaehlcke@...il.com>
Cc:	Christoph Hellwig <hch@...radead.org>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] use mutex instead of semaphore in tty_io.c

On Thu, 31 May 2007 15:42:26 +0200
Matthias Kaehlcke <matthias.kaehlcke@...il.com> wrote:

> drivers/char/tty_io.c: Use spinlock instead of a (binary) semaphore
> 

hm.

> 
> --
> 
> diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
> index 7a32df5..ff27587 100644
> --- a/drivers/char/tty_io.c
> +++ b/drivers/char/tty_io.c

We end up with this:

	/* find a device that is not in use. */
	if (!idr_pre_get(&allocated_ptys, GFP_KERNEL))
		return -ENOMEM;

	spin_lock(&allocated_ptys_lock);

	idr_ret = idr_get_new(&allocated_ptys, NULL, &index);
	if (idr_ret < 0) {
		spin_unlock(&allocated_ptys_lock);
		if (idr_ret == -EAGAIN)
			return -ENOMEM;
		return -EIO;
	}
	if (index >= pty_limit) {
		idr_remove(&allocated_ptys, index);
		spin_unlock(&allocated_ptys_lock);
		return -EIO;
	}
	spin_unlock(&allocated_ptys_lock);

this leaves a small window in which another thread can come in and steal
away the idr tree's reserves, causing the idr_get_new() to fail.  It's
highly improbable, but it's real.

Hence I think a straight semaphore->mutex conversion would be better.

The IDR API absolutely blows chunks: it should require caller-provided
locking, like radix-tree.  But then it'd need gunk like radix_tree_preload
to be reliable.  Fact is, storage librares which need to allocate memory at
insert-time are always going to be problematic in-kernel.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ