get_fs_type: Validate fs type string argument
PATCH 1/1 get_fs_type: Validate fs type string argument
On ppc64, When a non-nul terminated string is passed as an argument to the mount(2) syscall, copy_mount_string() ends up allocating 64k (the PAGE_SIZE on ppc64) worth of space for holding the string in kernel's address space.
Later, in set_precision() (invoked indirectly by get_fs_type()), we end up assigning 65535 as the value to 'struct printf_spec'->precision member. This field has a width of 16 bits and hence a truncated version of the original value ends up being 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 validating the length of the "filesystem type" argument passed to get_fs_type() function.
--- fs/filesystems.c | 3 +++ 1 file changed, 3 insertions(+)
fs/filesystems.c +3 -0
@@ -275,6 +275,9 @@ struct file_system_type *get_fs_type(const char *name)const char *dot =strchr (name,'.' );int len = dot ? dot - name :strlen (name); +if (len >=PATH_MAX ) +return NULL ; + fs =__get_fs_type (name, len);if (!fs && (request_module ("fs-%.*s" , len, name) ==0 )) { fs =__get_fs_type (name, len);
Signature · 1 line
2.9.4
PATCH v2 1/1 get_fs_type: Validate fs type string argument
On ppc64, When a non-nul terminated string is passed as an argument to the mount(2) syscall, copy_mount_string() ends up allocating 64k (the PAGE_SIZE on ppc64) worth of space for holding the string in kernel's address space.
Later, in set_precision() (invoked indirectly by get_fs_type()), we end up assigning 65535 as the value to 'struct printf_spec'->precision member. This field has a width of 16 bits and also it is 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 validating the length of the "filesystem type" argument passed to get_fs_type() function.
---
Changelog:v1->v2: Fix commit message.
fs/filesystems.c | 3 +++ 1 file changed, 3 insertions(+)
fs/filesystems.c +3 -0
@@ -275,6 +275,9 @@ struct file_system_type *get_fs_type(const char *name)const char *dot =strchr (name,'.' );int len = dot ? dot - name :strlen (name); +if (len >=PATH_MAX ) +return NULL ; + fs =__get_fs_type (name, len);if (!fs && (request_module ("fs-%.*s" , len, name) ==0 )) { fs =__get_fs_type (name, len);
Signature · 1 line
2.9.4
Quoted 31 lines · IST Chandan Rajendra
On ppc64, When a non-nul terminated string is passed as an argument to the mount(2) syscall,
copy_mount_string()ends up allocating 64k (thePAGE_SIZEon ppc64) worth of space for holding the string in kernel's address space.Later, in
set_precision()(invoked indirectly byget_fs_type()), we end up assigning 65535 as the value to 'struct printf_spec'->precision member. This field has a width of 16 bits and also it is 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 insideset_precision()to be executed.This commit fixes the bug by validating the length of the "filesystem type" argument passed to
get_fs_type()function.Signed-off-by Chandan Rajendra <[email protected]>Reported-by Abdul Haleem <[email protected]>Suggested-by Joe Perches <[email protected]>---
Changelog:v1->v2: Fix commit message.fs/filesystems.c | 3 +++ 1 file changed, 3 insertions(+)fs/filesystems.c +0
-0
fs/filesystems.c struct file_system_type *get_fs_type(const char *name) · line 283
Quoted 9 lines
fs/filesystems.c +3
-0@@ -275,6 +275,9 @@ struct file_system_type *get_fs_type(const char *name)const char *dot =strchr (name,'.' );int len = dot ? dot - name :strlen (name); +if (len >=PATH_MAX ) +return NULL ; + fs =__get_fs_type (name, len);if (!fs && (request_module ("fs-%.*s" , len, name) ==0 )) { fs =__get_fs_type (name, len);
Hi Al Viro,
Can you please let me know if you have any review comments about this patch.
Signature · 1 line
chandan