Linux-Fsdevel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] copy_mount_string: Limit string length to PATH_MAX
@ 2019-01-22  6:51 Chandan Rajendra
  2019-01-28  8:41 ` Miklos Szeredi
  2019-02-01  6:58 ` Al Viro
  0 siblings, 2 replies; 3+ messages in thread
From: Chandan Rajendra @ 2019-01-22  6:51 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Chandan Rajendra, viro, joe, miklos

On ppc64le, When a string with PAGE_SIZE - 1 (i.e. 64k-1) length is
passed as a "filesystem type" argument to the mount(2) syscall,
copy_mount_string() ends up allocating 64k (the PAGE_SIZE on ppc64le)
worth of space for holding the string in kernel's address space.

Later, in set_precision() (invoked by get_fs_type() ->
__request_module() -> vsnprintf()), we end up assigning
strlen(fs-type-string) i.e. 65535 as the
value to 'struct printf_spec'->precision member. This field has a width
of 16 bits and it is a signed data type. Hence an invalid value ends
up getting assigned. This causes the "WARN_ONCE(spec->precision != prec,
"precision %d too large", prec)" statement inside set_precision() to be
executed.

This commit fixes the bug by limiting the length of the string passed by
copy_mount_string() to strndup_user() to PATH_MAX.

Signed-off-by: Chandan Rajendra <chandan@linux.ibm.com>
Reported-by: Abdul Haleem <abdhalee@linux.ibm.com>
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/namespace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 09d2aec0f88c..103513f07483 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2831,7 +2831,7 @@ void *copy_mount_options(const void __user * data)
 
 char *copy_mount_string(const void __user *data)
 {
-	return data ? strndup_user(data, PAGE_SIZE) : NULL;
+	return data ? strndup_user(data, PATH_MAX) : NULL;
 }
 
 /*
-- 
2.19.1


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

* Re: [PATCH] copy_mount_string: Limit string length to PATH_MAX
  2019-01-22  6:51 [PATCH] copy_mount_string: Limit string length to PATH_MAX Chandan Rajendra
@ 2019-01-28  8:41 ` Miklos Szeredi
  2019-02-01  6:58 ` Al Viro
  1 sibling, 0 replies; 3+ messages in thread
From: Miklos Szeredi @ 2019-01-28  8:41 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-fsdevel, Chandan Rajendra, joe

On Tue, Jan 22, 2019 at 7:51 AM Chandan Rajendra <chandan@linux.ibm.com> wrote:
>
> On ppc64le, When a string with PAGE_SIZE - 1 (i.e. 64k-1) length is
> passed as a "filesystem type" argument to the mount(2) syscall,
> copy_mount_string() ends up allocating 64k (the PAGE_SIZE on ppc64le)
> worth of space for holding the string in kernel's address space.
>
> Later, in set_precision() (invoked by get_fs_type() ->
> __request_module() -> vsnprintf()), we end up assigning
> strlen(fs-type-string) i.e. 65535 as the
> value to 'struct printf_spec'->precision member. This field has a width
> of 16 bits and it is a signed data type. Hence an invalid value ends
> up getting assigned. This causes the "WARN_ONCE(spec->precision != prec,
> "precision %d too large", prec)" statement inside set_precision() to be
> executed.
>
> This commit fixes the bug by limiting the length of the string passed by
> copy_mount_string() to strndup_user() to PATH_MAX.
>
> Signed-off-by: Chandan Rajendra <chandan@linux.ibm.com>
> Reported-by: Abdul Haleem <abdhalee@linux.ibm.com>
> Suggested-by: Al Viro <viro@zeniv.linux.org.uk>

Acked-by: Miklos Szeredi <mszeredi@redhat.com>

> ---
>  fs/namespace.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/namespace.c b/fs/namespace.c
> index 09d2aec0f88c..103513f07483 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -2831,7 +2831,7 @@ void *copy_mount_options(const void __user * data)
>
>  char *copy_mount_string(const void __user *data)
>  {
> -       return data ? strndup_user(data, PAGE_SIZE) : NULL;
> +       return data ? strndup_user(data, PATH_MAX) : NULL;
>  }
>
>  /*
> --
> 2.19.1
>

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

* Re: [PATCH] copy_mount_string: Limit string length to PATH_MAX
  2019-01-22  6:51 [PATCH] copy_mount_string: Limit string length to PATH_MAX Chandan Rajendra
  2019-01-28  8:41 ` Miklos Szeredi
@ 2019-02-01  6:58 ` Al Viro
  1 sibling, 0 replies; 3+ messages in thread
From: Al Viro @ 2019-02-01  6:58 UTC (permalink / raw)
  To: Chandan Rajendra; +Cc: linux-fsdevel, joe, miklos

On Tue, Jan 22, 2019 at 12:21:52PM +0530, Chandan Rajendra wrote:
> On ppc64le, When a string with PAGE_SIZE - 1 (i.e. 64k-1) length is
> passed as a "filesystem type" argument to the mount(2) syscall,
> copy_mount_string() ends up allocating 64k (the PAGE_SIZE on ppc64le)
> worth of space for holding the string in kernel's address space.
> 
> Later, in set_precision() (invoked by get_fs_type() ->
> __request_module() -> vsnprintf()), we end up assigning
> strlen(fs-type-string) i.e. 65535 as the
> value to 'struct printf_spec'->precision member. This field has a width
> of 16 bits and it is a signed data type. Hence an invalid value ends
> up getting assigned. This causes the "WARN_ONCE(spec->precision != prec,
> "precision %d too large", prec)" statement inside set_precision() to be
> executed.
> 
> This commit fixes the bug by limiting the length of the string passed by
> copy_mount_string() to strndup_user() to PATH_MAX.
> 
> Signed-off-by: Chandan Rajendra <chandan@linux.ibm.com>
> Reported-by: Abdul Haleem <abdhalee@linux.ibm.com>
> Suggested-by: Al Viro <viro@zeniv.linux.org.uk>

Applied

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-22  6:51 [PATCH] copy_mount_string: Limit string length to PATH_MAX Chandan Rajendra
2019-01-28  8:41 ` Miklos Szeredi
2019-02-01  6:58 ` Al Viro

Linux-Fsdevel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-fsdevel/0 linux-fsdevel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-fsdevel linux-fsdevel/ https://lore.kernel.org/linux-fsdevel \
		linux-fsdevel@vger.kernel.org linux-fsdevel@archiver.kernel.org
	public-inbox-index linux-fsdevel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-fsdevel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox