All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] proc: reject "." and ".." as filenames
@ 2018-03-10  0:12 Alexey Dobriyan
  2018-03-10  0:19 ` Florian Westphal
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Alexey Dobriyan @ 2018-03-10  0:12 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, eric.dumazet, xiyou.wangcong, fw

Various subsystems can create files and directories in /proc
with names directly controlled by userspace.

Which means "/", "." and ".." are no-no.

"/" split is already taken care of, do the other 2 prohibited names.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 fs/proc/generic.c |    8 ++++++++
 1 file changed, 8 insertions(+)

--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -366,6 +366,14 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
 		WARN(1, "name len %u\n", qstr.len);
 		return NULL;
 	}
+	if (qstr.len == 1 && fn[0] == '.') {
+		WARN(1, "name '.'\n");
+		return NULL;
+	}
+	if (qstr.len == 2 && fn[0] == '.' && fn[1] == '.') {
+		WARN(1, "name '..'\n");
+		return NULL;
+	}
 	if (*parent == &proc_root && name_to_int(&qstr) != ~0U) {
 		WARN(1, "create '/proc/%s' by hand\n", qstr.name);
 		return NULL;

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

* Re: [PATCH] proc: reject "." and ".." as filenames
  2018-03-10  0:12 [PATCH] proc: reject "." and ".." as filenames Alexey Dobriyan
@ 2018-03-10  0:19 ` Florian Westphal
  2018-03-11 21:30 ` Pavel Machek
  2018-03-12 23:00 ` Andrew Morton
  2 siblings, 0 replies; 7+ messages in thread
From: Florian Westphal @ 2018-03-10  0:19 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: akpm, linux-kernel, eric.dumazet, xiyou.wangcong, fw

Alexey Dobriyan <adobriyan@gmail.com> wrote:
> Various subsystems can create files and directories in /proc
> with names directly controlled by userspace.
> 
> Which means "/", "." and ".." are no-no.
> 
> "/" split is already taken care of, do the other 2 prohibited names.

Acked-by: Florian Westphal <fw@strlen.de>

I'll send a patch for xtables too to reject bogus names
coming from userspace (syzbot reports WARN() ).

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

* Re: [PATCH] proc: reject "." and ".." as filenames
  2018-03-10  0:12 [PATCH] proc: reject "." and ".." as filenames Alexey Dobriyan
  2018-03-10  0:19 ` Florian Westphal
@ 2018-03-11 21:30 ` Pavel Machek
  2018-03-11 21:35   ` Alexey Dobriyan
  2018-03-12 23:00 ` Andrew Morton
  2 siblings, 1 reply; 7+ messages in thread
From: Pavel Machek @ 2018-03-11 21:30 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: akpm, linux-kernel, eric.dumazet, xiyou.wangcong, fw

[-- Attachment #1: Type: text/plain, Size: 692 bytes --]

On Sat 2018-03-10 03:12:23, Alexey Dobriyan wrote:
> Various subsystems can create files and directories in /proc
> with names directly controlled by userspace.
> 
> Which means "/", "." and ".." are no-no.
> 
> "/" split is already taken care of, do the other 2 prohibited names.

Hmm, patch is probably good idea, but now it means that userspace can
trigger WARN()s, and can hide objects from root by naming them '.' and
'..'... which is not good.

If you know where this happens, it would be nice to fix them in
addition to this patch.
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: [PATCH] proc: reject "." and ".." as filenames
  2018-03-11 21:30 ` Pavel Machek
@ 2018-03-11 21:35   ` Alexey Dobriyan
  2018-03-11 21:41     ` Pavel Machek
  0 siblings, 1 reply; 7+ messages in thread
From: Alexey Dobriyan @ 2018-03-11 21:35 UTC (permalink / raw)
  To: Pavel Machek; +Cc: akpm, linux-kernel, eric.dumazet, xiyou.wangcong, fw

On Sun, Mar 11, 2018 at 10:30:58PM +0100, Pavel Machek wrote:
> On Sat 2018-03-10 03:12:23, Alexey Dobriyan wrote:
> > Various subsystems can create files and directories in /proc
> > with names directly controlled by userspace.
> > 
> > Which means "/", "." and ".." are no-no.
> > 
> > "/" split is already taken care of, do the other 2 prohibited names.
> 
> Hmm, patch is probably good idea, but now it means that userspace can
> trigger WARN()s, and can hide objects from root by naming them '.' and
> '..'... which is not good.

Patch rejects creation of such entries.

And they should be harmless as VFS lookup won't find them, only readdir
would. It not clear how they could be useful.

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

* Re: [PATCH] proc: reject "." and ".." as filenames
  2018-03-11 21:35   ` Alexey Dobriyan
@ 2018-03-11 21:41     ` Pavel Machek
  0 siblings, 0 replies; 7+ messages in thread
From: Pavel Machek @ 2018-03-11 21:41 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: akpm, linux-kernel, eric.dumazet, xiyou.wangcong, fw

[-- Attachment #1: Type: text/plain, Size: 1282 bytes --]

On Mon 2018-03-12 00:35:34, Alexey Dobriyan wrote:
> On Sun, Mar 11, 2018 at 10:30:58PM +0100, Pavel Machek wrote:
> > On Sat 2018-03-10 03:12:23, Alexey Dobriyan wrote:
> > > Various subsystems can create files and directories in /proc
> > > with names directly controlled by userspace.
> > > 
> > > Which means "/", "." and ".." are no-no.
> > > 
> > > "/" split is already taken care of, do the other 2 prohibited names.
> > 
> > Hmm, patch is probably good idea, but now it means that userspace can
> > trigger WARN()s, and can hide objects from root by naming them '.' and
> > '..'... which is not good.
> 
> Patch rejects creation of such entries.
> 
> And they should be harmless as VFS lookup won't find them, only readdir
> would. It not clear how they could be useful.

Yeah, as I said, that's half of problem.

If I can name my object "." and it will be hidden from root, that
sounds like a security hole to be prevented.

So if you know _which_ subsystem allow creating files and directories
in /proc with names directly controlled by userspace, please let us
know, we want to fix that.

								Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: [PATCH] proc: reject "." and ".." as filenames
  2018-03-10  0:12 [PATCH] proc: reject "." and ".." as filenames Alexey Dobriyan
  2018-03-10  0:19 ` Florian Westphal
  2018-03-11 21:30 ` Pavel Machek
@ 2018-03-12 23:00 ` Andrew Morton
  2018-03-13  7:20   ` Alexey Dobriyan
  2 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2018-03-12 23:00 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: linux-kernel, eric.dumazet, xiyou.wangcong, fw

On Sat, 10 Mar 2018 03:12:23 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:

> Various subsystems can create files and directories in /proc
> with names directly controlled by userspace.
> 
> Which means "/", "." and ".." are no-no.
> 
> "/" split is already taken care of, do the other 2 prohibited names.
> 
> --- a/fs/proc/generic.c
> +++ b/fs/proc/generic.c
> @@ -366,6 +366,14 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
>  		WARN(1, "name len %u\n", qstr.len);
>  		return NULL;
>  	}
> +	if (qstr.len == 1 && fn[0] == '.') {
> +		WARN(1, "name '.'\n");
> +		return NULL;
> +	}
> +	if (qstr.len == 2 && fn[0] == '.' && fn[1] == '.') {
> +		WARN(1, "name '..'\n");
> +		return NULL;
> +	}
>  	if (*parent == &proc_root && name_to_int(&qstr) != ~0U) {
>  		WARN(1, "create '/proc/%s' by hand\n", qstr.name);
>  		return NULL;

--- a/fs/proc/generic.c~proc-reject-and-as-filenames-fix
+++ a/fs/proc/generic.c
@@ -387,10 +387,8 @@ static struct proc_dir_entry *__proc_cre
 		WARN(1, "name len %u\n", qstr.len);
 		return NULL;
 	}
-	if (qstr.len == 1 && fn[0] == '.') {
-		WARN(1, "name '.'\n");
+	if (WARN(qstr.len == 1 && fn[0] == '.', "name '.'\n"))
 		return NULL;
-	}
 	if (qstr.len == 2 && fn[0] == '.' && fn[1] == '.') {
 		WARN(1, "name '..'\n");
 		return NULL;

is neater, but the whole function should be thus converted and I'll let
you decide on that.

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

* Re: [PATCH] proc: reject "." and ".." as filenames
  2018-03-12 23:00 ` Andrew Morton
@ 2018-03-13  7:20   ` Alexey Dobriyan
  0 siblings, 0 replies; 7+ messages in thread
From: Alexey Dobriyan @ 2018-03-13  7:20 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, eric.dumazet, xiyou.wangcong, fw

On Mon, Mar 12, 2018 at 04:00:18PM -0700, Andrew Morton wrote:
> -	if (qstr.len == 1 && fn[0] == '.') {
> -		WARN(1, "name '.'\n");
> +	if (WARN(qstr.len == 1 && fn[0] == '.', "name '.'\n"))
>  		return NULL;
> -	}

Oh, I hate this style of WARN.
For one thing it overlaps with comma operator.

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

end of thread, other threads:[~2018-03-13  7:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-10  0:12 [PATCH] proc: reject "." and ".." as filenames Alexey Dobriyan
2018-03-10  0:19 ` Florian Westphal
2018-03-11 21:30 ` Pavel Machek
2018-03-11 21:35   ` Alexey Dobriyan
2018-03-11 21:41     ` Pavel Machek
2018-03-12 23:00 ` Andrew Morton
2018-03-13  7:20   ` Alexey Dobriyan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.