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]
Message-ID: <87bogx5lg7.fsf@xmission.com>
Date:	Sat, 22 Sep 2012 22:59:04 -0700
From:	ebiederm@...ssion.com (Eric W. Biederman)
To:	Al Viro <viro@...IV.linux.org.uk>
Cc:	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Kay Sievers <kay.sievers@...y.org>,
	"Serge E. Hallyn" <serge@...lyn.com>,
	containers@...ts.linux-foundation.org,
	Dave Hansen <haveblue@...ibm.com>,
	linux-kernel@...r.kernel.org, Andy Whitcroft <apw@...onical.com>,
	sukadev@...ux.vnet.ibm.com,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Alan Cox <alan@...rguk.ukuu.org.uk>,
	Serge Hallyn <serge.hallyn@...onical.com>
Subject: Re: [PATCH 3/4] devpts: Make the newinstance option historical

Al Viro <viro@...IV.linux.org.uk> writes:

> On Sat, Sep 22, 2012 at 08:50:44PM -0700, Eric W. Biederman wrote:
>
>> +struct inode *devpts_redirect(struct file *filp)
>> +{
>> +	struct inode *inode;
>> +	struct file *filp2;
>> +
>> +	/* Is the inode already a devpts inode? */
>> +	inode = filp->f_dentry->d_inode;
>> +	if (filp->f_dentry->d_sb->s_magic == DEVPTS_SUPER_MAGIC)
>> +		goto out;
>> +
>> +	/* Is f_dentry->d_parent usable? */
>> +	inode = ERR_PTR(-ENODEV);
>> +	if (filp->f_vfsmnt->mnt_root == filp->f_dentry)
>> +		goto out;
>> +
>> +	/* Is there a devpts inode we can use instead? */
>> +	
>> +	filp2 = file_open_root(filp->f_dentry->d_parent, filp->f_vfsmnt,
>> +			       "pts/ptmx", O_PATH);
>> +	if (!IS_ERR(filp2)) {
>> +		if (filp2->f_dentry->d_sb->s_magic == DEVPTS_SUPER_MAGIC) {
>> +			struct path old;
>> +			old = filp->f_path;
>> +			filp->f_path = filp2->f_path;
>> +			inode = filp->f_dentry->d_inode;
>> +			path_get(&filp->f_path);
>> +			path_put(&old);
>
> You are welcome to supply an analysis of the reasons why ->open() pulling
> such tricks will not break all kinds of code in VFS.


>> +		}
>> +		fput(filp2);
>
> ... starting with "what happens when some joker binds /dev/ptmx on
> /dev/pts/ptmx"

The test:
>> +	if (filp->f_vfsmnt->mnt_root == filp->f_dentry)
kicks in and no redirection is performed.


> Or does mknod /tmp/ptmx c 5 2; mkdir /tmp/pts; ln /tmp/ptmx /tmp/pts/ptmx,
> for that matter...

The test:
>> +		if (filp2->f_dentry->d_sb->s_magic == DEVPTS_SUPER_MAGIC) {n
fails and no redirection is performed.

> NAK.  This violates asserts made by VFS (namely, that ->f_path is not
> changed since dentry_open() has set it and until __fput() rips the thing
> out) *and* by your own code (attack mentioned above, just from looking
> at it for a minute).  Far too brittle...

This code seems much more robust than your quick analysis.

But if the constraint that the path in struct file must not be
changed between dentry_open and __fput that is doable to it just
needs a little more reorganizing of the data structures.  It is
definitely not a fundamental limitation.

Eric





--
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