linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sysctl: redefine zero as a unsigned long
@ 2019-04-05  6:52 Hou Tao
  2019-04-05 15:49 ` Kees Cook
  2019-04-05 16:27 ` Matthew Wilcox
  0 siblings, 2 replies; 4+ messages in thread
From: Hou Tao @ 2019-04-05  6:52 UTC (permalink / raw)
  To: mcgrof, keescook; +Cc: linux-kernel, linux-fsdevel

We have got KASAN splat when tried to set /proc/sys/fs/file-max:

  BUG: KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax+0x3e4/0x8f0
  Read of size 8 at addr ffff20000f9b2980 by task file-max.sh/36819

  Call trace:
   dump_backtrace+0x0/0x3f8
   show_stack+0x3c/0x60
   dump_stack+0x150/0x1a8
   print_address_description+0x2b8/0x5a0
   kasan_report+0x278/0x648
   __asan_load8+0x124/0x170
   __do_proc_doulongvec_minmax+0x3e4/0x8f0
   proc_doulongvec_minmax+0x80/0xa0
   proc_sys_call_handler+0x188/0x2a0
   proc_sys_write+0x5c/0x80
   __vfs_write+0x118/0x578
   vfs_write+0x184/0x418
   ksys_write+0xfc/0x1e8
   __arm64_sys_write+0x88/0xa8
   el0_svc_common+0x1a4/0x500
   el0_svc_handler+0xb8/0x180
   el0_svc+0x8/0xc

  The buggy address belongs to the variable:
   zero+0x0/0x40

The cause is that proc_doulongvec_minmax() is trying to cast an int
pointer (namely &zero) to a unsigned long pointer, and dereferencing it.

Although the warning seems does no harm, because zero will be placed
in a .bss section, but it's better to kill the KASAN warning by
redefining zero as a unsigned long, so it's OK whenever it is accessed
as an int or a a unsigned long.

An alternative fix seems to be set the minimal value of file-max to be 1,
so one_ul can be used instead, but I'm not sure whether or not a file-max
with a value of zero has special purpose (e.g., prohibit the file-related
activities of all no-privileged users).

Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 kernel/sysctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index e5da394d1ca3..03846e015013 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -124,7 +124,7 @@ static int sixty = 60;
 
 static int __maybe_unused neg_one = -1;
 
-static int zero;
+static unsigned long zero;
 static int __maybe_unused one = 1;
 static int __maybe_unused two = 2;
 static int __maybe_unused four = 4;
-- 
2.16.2.dirty


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

* Re: [PATCH] sysctl: redefine zero as a unsigned long
  2019-04-05  6:52 [PATCH] sysctl: redefine zero as a unsigned long Hou Tao
@ 2019-04-05 15:49 ` Kees Cook
  2019-04-05 16:27 ` Matthew Wilcox
  1 sibling, 0 replies; 4+ messages in thread
From: Kees Cook @ 2019-04-05 15:49 UTC (permalink / raw)
  To: Hou Tao; +Cc: Luis R. Rodriguez, LKML, linux-fsdevel

On Thu, Apr 4, 2019 at 11:48 PM Hou Tao <houtao1@huawei.com> wrote:
>
> We have got KASAN splat when tried to set /proc/sys/fs/file-max:
>
>   BUG: KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax+0x3e4/0x8f0
>   Read of size 8 at addr ffff20000f9b2980 by task file-max.sh/36819
>
>   Call trace:
>    dump_backtrace+0x0/0x3f8
>    show_stack+0x3c/0x60
>    dump_stack+0x150/0x1a8
>    print_address_description+0x2b8/0x5a0
>    kasan_report+0x278/0x648
>    __asan_load8+0x124/0x170
>    __do_proc_doulongvec_minmax+0x3e4/0x8f0
>    proc_doulongvec_minmax+0x80/0xa0
>    proc_sys_call_handler+0x188/0x2a0
>    proc_sys_write+0x5c/0x80
>    __vfs_write+0x118/0x578
>    vfs_write+0x184/0x418
>    ksys_write+0xfc/0x1e8
>    __arm64_sys_write+0x88/0xa8
>    el0_svc_common+0x1a4/0x500
>    el0_svc_handler+0xb8/0x180
>    el0_svc+0x8/0xc
>
>   The buggy address belongs to the variable:
>    zero+0x0/0x40
>
> The cause is that proc_doulongvec_minmax() is trying to cast an int
> pointer (namely &zero) to a unsigned long pointer, and dereferencing it.
>
> Although the warning seems does no harm, because zero will be placed
> in a .bss section, but it's better to kill the KASAN warning by
> redefining zero as a unsigned long, so it's OK whenever it is accessed
> as an int or a a unsigned long.
>
> An alternative fix seems to be set the minimal value of file-max to be 1,
> so one_ul can be used instead, but I'm not sure whether or not a file-max
> with a value of zero has special purpose (e.g., prohibit the file-related
> activities of all no-privileged users).
>
> Signed-off-by: Hou Tao <houtao1@huawei.com>

Acked-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  kernel/sysctl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index e5da394d1ca3..03846e015013 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -124,7 +124,7 @@ static int sixty = 60;
>
>  static int __maybe_unused neg_one = -1;
>
> -static int zero;
> +static unsigned long zero;
>  static int __maybe_unused one = 1;
>  static int __maybe_unused two = 2;
>  static int __maybe_unused four = 4;
> --
> 2.16.2.dirty
>


-- 
Kees Cook

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

* Re: [PATCH] sysctl: redefine zero as a unsigned long
  2019-04-05  6:52 [PATCH] sysctl: redefine zero as a unsigned long Hou Tao
  2019-04-05 15:49 ` Kees Cook
@ 2019-04-05 16:27 ` Matthew Wilcox
  2019-04-06  5:47   ` Hou Tao
  1 sibling, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2019-04-05 16:27 UTC (permalink / raw)
  To: Hou Tao; +Cc: mcgrof, keescook, linux-kernel, linux-fsdevel

On Fri, Apr 05, 2019 at 02:52:17PM +0800, Hou Tao wrote:
> We have got KASAN splat when tried to set /proc/sys/fs/file-max:

Matteo Croce already has a patch in-flight for this.

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

* Re: [PATCH] sysctl: redefine zero as a unsigned long
  2019-04-05 16:27 ` Matthew Wilcox
@ 2019-04-06  5:47   ` Hou Tao
  0 siblings, 0 replies; 4+ messages in thread
From: Hou Tao @ 2019-04-06  5:47 UTC (permalink / raw)
  To: mcroce, akpm
  Cc: mcgrof, keescook, linux-kernel, linux-fsdevel, Matthew Wilcox

Hi,

Cc Andrew for patch inclusion

On 2019/4/6 0:27, Matthew Wilcox wrote:
> On Fri, Apr 05, 2019 at 02:52:17PM +0800, Hou Tao wrote:
>> We have got KASAN splat when tried to set /proc/sys/fs/file-max:
> 
> Matteo Croce already has a patch in-flight for this.
> 
> 
Yes, I find it now: https://lkml.org/lkml/2019/3/28/320. And the fix posted
by Matteo has also been acked by Kees and has the Fixes tag.

So Andrew, could you please take Matteo's patch in your tree ?

Regards,
Tao


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

end of thread, other threads:[~2019-04-06  5:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-05  6:52 [PATCH] sysctl: redefine zero as a unsigned long Hou Tao
2019-04-05 15:49 ` Kees Cook
2019-04-05 16:27 ` Matthew Wilcox
2019-04-06  5:47   ` Hou Tao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).