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: <20140124161922.GA14195@redhat.com>
Date:	Fri, 24 Jan 2014 17:19:22 +0100
From:	Oleg Nesterov <oleg@...hat.com>
To:	Denys Vlasenko <dvlasenk@...hat.com>
Cc:	Al Viro <viro@...iv.linux.org.uk>,
	Jan Kratochvil <jan.kratochvil@...hat.com>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] dcache: error out if the name buffer is too short

On 01/24, Denys Vlasenko wrote:
>
> This change makes __dentry_path() and d_path()
> immediately return ENAMETOOLONG if buflen < 2.

I am not sure about d_path, but as for __dentry_path:

> @@ -3122,13 +3125,14 @@ static char *__dentry_path(struct dentry *dentry, char *buf, int buflen)
>  	int len, seq = 0;
>  	int error = 0;
>  
> +	if (buflen < 2)
> +		goto Elong;
> +
>  	rcu_read_lock();
>  restart:
>  	end = buf + buflen;
>  	len = buflen;
>  	prepend(&end, &len, "\0", 1);
> -	if (buflen < 1)
> -		goto Elong;

you forgot to mention that this change fixes a bug, this "goto Elong"
leaks rcu_read_lock().

And probably you are right, the fix should be as simple as possible.
But can't we also simplify __dentry_path? Unless I missed something
we can move prepend() up, before rcu_read_lock(), "move Get '/' right"
into that prepend, and even kill retval... OK, most probably I missed
something, but at first glance we can do something like

	static char *__dentry_path(struct dentry *dentry, char *buf, int buflen)
	{
		int len, seq = 0;
		int error = 0;
		char *end;

		buf += buflen;
		/* Get '/' right, write "/\0" at the end */
		if (prepend(&buf, &buflen, "/", 2))
			goto Elong;

		rcu_read_lock();
	restart:
		end = buf;
		len = buflen;
		read_seqbegin_or_lock(&rename_lock, &seq);
		while (!IS_ROOT(dentry)) {
			struct dentry *parent = dentry->d_parent;
			int error;

			prefetch(parent);
			error = prepend_name(&end, &len, &dentry->d_name);
			if (error)
				break;

			dentry = parent;
		}
		if (!(seq & 1))
			rcu_read_unlock();
		if (need_seqretry(&rename_lock, seq)) {
			seq = 1;
			goto restart;
		}
		done_seqretry(&rename_lock, seq);
		if (!error)
			return end;
	Elong:
		return ERR_PTR(-ENAMETOOLONG);
	}

Oleg.

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