All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] staging: android: ion: Add __GFP_NOWARN for system contig heap
@ 2018-01-05 19:14 Laura Abbott
  2018-01-05 19:14 ` [PATCH 2/2] staging: android: ion: Switch from WARN to pr_warn Laura Abbott
  2018-01-05 19:36 ` [PATCH 1/2] staging: android: ion: Add __GFP_NOWARN for system contig heap Chris Wilson
  0 siblings, 2 replies; 4+ messages in thread
From: Laura Abbott @ 2018-01-05 19:14 UTC (permalink / raw)
  To: Greg KH, Sumit Semwal; +Cc: Laura Abbott, devel, LKML, Dan Carpenter

syzbot reported a warning from Ion:

  WARNING: CPU: 1 PID: 3485 at mm/page_alloc.c:3926

  ...
   __alloc_pages_nodemask+0x9fb/0xd80 mm/page_alloc.c:4252
  alloc_pages_current+0xb6/0x1e0 mm/mempolicy.c:2036
  alloc_pages include/linux/gfp.h:492 [inline]
  ion_system_contig_heap_allocate+0x40/0x2c0
  drivers/staging/android/ion/ion_system_heap.c:374
  ion_buffer_create drivers/staging/android/ion/ion.c:93 [inline]
  ion_alloc+0x2c1/0x9e0 drivers/staging/android/ion/ion.c:420
  ion_ioctl+0x26d/0x380 drivers/staging/android/ion/ion-ioctl.c:84
  vfs_ioctl fs/ioctl.c:46 [inline]
  do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:686
  SYSC_ioctl fs/ioctl.c:701 [inline]
  SyS_ioctl+0x8f/0xc0 fs/ioctl.c:692

This is a warning about attempting to allocate order > MAX_ORDER. This
is coming from a userspace Ion allocation request. Since userspace is
free to request however much memory it wants (and the kernel is free to
deny its allocation), silence the allocation attempt with __GFP_NOWARN
in case it fails.

Reported-by: syzbot+76e7efc4748495855a4d@syzkaller.appspotmail.com
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Laura Abbott <labbott@redhat.com>
---
 drivers/staging/android/ion/ion_system_heap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
index 71c4228f8238..bc19cdd30637 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -362,7 +362,7 @@ static int ion_system_contig_heap_allocate(struct ion_heap *heap,
 	unsigned long i;
 	int ret;
 
-	page = alloc_pages(low_order_gfp_flags, order);
+	page = alloc_pages(low_order_gfp_flags | __GFP_NOWARN, order);
 	if (!page)
 		return -ENOMEM;
 
-- 
2.14.3

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

* [PATCH 2/2] staging: android: ion: Switch from WARN to pr_warn
  2018-01-05 19:14 [PATCH 1/2] staging: android: ion: Add __GFP_NOWARN for system contig heap Laura Abbott
@ 2018-01-05 19:14 ` Laura Abbott
  2018-01-05 19:36 ` [PATCH 1/2] staging: android: ion: Add __GFP_NOWARN for system contig heap Chris Wilson
  1 sibling, 0 replies; 4+ messages in thread
From: Laura Abbott @ 2018-01-05 19:14 UTC (permalink / raw)
  To: Greg KH, Sumit Semwal; +Cc: Laura Abbott, devel, LKML, Dan Carpenter

Syzbot reported a warning with Ion:

WARNING: CPU: 0 PID: 3502 at drivers/staging/android/ion/ion-ioctl.c:73 ion_ioctl+0x2db/0x380 drivers/staging/android/ion/ion-ioctl.c:73
Kernel panic - not syncing: panic_on_warn set ...

This is a warning that validation of the ioctl fields failed. This was
deliberately added as a warning to make it very obvious to developers that
something needed to be fixed. In reality, this is overkill and disturbs
fuzzing. Switch to pr_warn for a message instead.

Reported-by: syzbot+fa2d5f63ee5904a0115a@syzkaller.appspotmail.com
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Laura Abbott <labbott@redhat.com>
---
 drivers/staging/android/ion/ion-ioctl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c
index 6ed2cc15c8c0..a8d3cc412fb9 100644
--- a/drivers/staging/android/ion/ion-ioctl.c
+++ b/drivers/staging/android/ion/ion-ioctl.c
@@ -60,8 +60,10 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		return -EFAULT;
 
 	ret = validate_ioctl_arg(cmd, &data);
-	if (WARN_ON_ONCE(ret))
+	if (ret) {
+		pr_warn_once("%s: ioctl validate failed\n", __func__);
 		return ret;
+	}
 
 	if (!(dir & _IOC_WRITE))
 		memset(&data, 0, sizeof(data));
-- 
2.14.3

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

* Re: [PATCH 1/2] staging: android: ion: Add __GFP_NOWARN for system contig heap
  2018-01-05 19:14 [PATCH 1/2] staging: android: ion: Add __GFP_NOWARN for system contig heap Laura Abbott
  2018-01-05 19:14 ` [PATCH 2/2] staging: android: ion: Switch from WARN to pr_warn Laura Abbott
@ 2018-01-05 19:36 ` Chris Wilson
  2018-01-05 21:46   ` Laura Abbott
  1 sibling, 1 reply; 4+ messages in thread
From: Chris Wilson @ 2018-01-05 19:36 UTC (permalink / raw)
  To: Laura Abbott, Greg KH, Sumit Semwal
  Cc: Laura Abbott, devel, LKML, Dan Carpenter

Quoting Laura Abbott (2018-01-05 19:14:08)
> syzbot reported a warning from Ion:
> 
>   WARNING: CPU: 1 PID: 3485 at mm/page_alloc.c:3926
> 
>   ...
>    __alloc_pages_nodemask+0x9fb/0xd80 mm/page_alloc.c:4252
>   alloc_pages_current+0xb6/0x1e0 mm/mempolicy.c:2036
>   alloc_pages include/linux/gfp.h:492 [inline]
>   ion_system_contig_heap_allocate+0x40/0x2c0
>   drivers/staging/android/ion/ion_system_heap.c:374
>   ion_buffer_create drivers/staging/android/ion/ion.c:93 [inline]
>   ion_alloc+0x2c1/0x9e0 drivers/staging/android/ion/ion.c:420
>   ion_ioctl+0x26d/0x380 drivers/staging/android/ion/ion-ioctl.c:84
>   vfs_ioctl fs/ioctl.c:46 [inline]
>   do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:686
>   SYSC_ioctl fs/ioctl.c:701 [inline]
>   SyS_ioctl+0x8f/0xc0 fs/ioctl.c:692
> 
> This is a warning about attempting to allocate order > MAX_ORDER. This
> is coming from a userspace Ion allocation request. Since userspace is
> free to request however much memory it wants (and the kernel is free to
> deny its allocation), silence the allocation attempt with __GFP_NOWARN
> in case it fails.
> 
> Reported-by: syzbot+76e7efc4748495855a4d@syzkaller.appspotmail.com
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Signed-off-by: Laura Abbott <labbott@redhat.com>
> ---
>  drivers/staging/android/ion/ion_system_heap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
> index 71c4228f8238..bc19cdd30637 100644
> --- a/drivers/staging/android/ion/ion_system_heap.c
> +++ b/drivers/staging/android/ion/ion_system_heap.c
> @@ -362,7 +362,7 @@ static int ion_system_contig_heap_allocate(struct ion_heap *heap,
>         unsigned long i;
>         int ret;
>  
> -       page = alloc_pages(low_order_gfp_flags, order);
> +       page = alloc_pages(low_order_gfp_flags | __GFP_NOWARN, order);

There's both high_order_gfp and low_order_gfp. The former includes
NOWARN and NORETRY.

Interesting, ion_system_heap_create_pools() tries to mix low_order and
high_order, but it only ever uses high_order flags. (orders[0] == 8
forcing a permanent switch from low_order_gfp to high_order_gfp).

There's no good reason for low_order_gfp, high_order_gfp to be static
rewritable variables.

For this instance, I would go farther and suggest you may want
__GFP_RETRY_MAYFAIL | __GFP_NOWARN to prevent userspace from triggering
the lowmemkiller/oomkiller here.
 
(I would kill low_order_gfp_flags / high_order_gfp_flags and avoid the
obfuscation.)
-Chris

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

* Re: [PATCH 1/2] staging: android: ion: Add __GFP_NOWARN for system contig heap
  2018-01-05 19:36 ` [PATCH 1/2] staging: android: ion: Add __GFP_NOWARN for system contig heap Chris Wilson
@ 2018-01-05 21:46   ` Laura Abbott
  0 siblings, 0 replies; 4+ messages in thread
From: Laura Abbott @ 2018-01-05 21:46 UTC (permalink / raw)
  To: Chris Wilson, Greg KH, Sumit Semwal; +Cc: devel, LKML, Dan Carpenter

On 01/05/2018 11:36 AM, Chris Wilson wrote:
> Quoting Laura Abbott (2018-01-05 19:14:08)
>> syzbot reported a warning from Ion:
>>
>>    WARNING: CPU: 1 PID: 3485 at mm/page_alloc.c:3926
>>
>>    ...
>>     __alloc_pages_nodemask+0x9fb/0xd80 mm/page_alloc.c:4252
>>    alloc_pages_current+0xb6/0x1e0 mm/mempolicy.c:2036
>>    alloc_pages include/linux/gfp.h:492 [inline]
>>    ion_system_contig_heap_allocate+0x40/0x2c0
>>    drivers/staging/android/ion/ion_system_heap.c:374
>>    ion_buffer_create drivers/staging/android/ion/ion.c:93 [inline]
>>    ion_alloc+0x2c1/0x9e0 drivers/staging/android/ion/ion.c:420
>>    ion_ioctl+0x26d/0x380 drivers/staging/android/ion/ion-ioctl.c:84
>>    vfs_ioctl fs/ioctl.c:46 [inline]
>>    do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:686
>>    SYSC_ioctl fs/ioctl.c:701 [inline]
>>    SyS_ioctl+0x8f/0xc0 fs/ioctl.c:692
>>
>> This is a warning about attempting to allocate order > MAX_ORDER. This
>> is coming from a userspace Ion allocation request. Since userspace is
>> free to request however much memory it wants (and the kernel is free to
>> deny its allocation), silence the allocation attempt with __GFP_NOWARN
>> in case it fails.
>>
>> Reported-by: syzbot+76e7efc4748495855a4d@syzkaller.appspotmail.com
>> Reported-by: syzbot <syzkaller@googlegroups.com>
>> Signed-off-by: Laura Abbott <labbott@redhat.com>
>> ---
>>   drivers/staging/android/ion/ion_system_heap.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
>> index 71c4228f8238..bc19cdd30637 100644
>> --- a/drivers/staging/android/ion/ion_system_heap.c
>> +++ b/drivers/staging/android/ion/ion_system_heap.c
>> @@ -362,7 +362,7 @@ static int ion_system_contig_heap_allocate(struct ion_heap *heap,
>>          unsigned long i;
>>          int ret;
>>   
>> -       page = alloc_pages(low_order_gfp_flags, order);
>> +       page = alloc_pages(low_order_gfp_flags | __GFP_NOWARN, order);
> 
> There's both high_order_gfp and low_order_gfp. The former includes
> NOWARN and NORETRY.
> 
> Interesting, ion_system_heap_create_pools() tries to mix low_order and
> high_order, but it only ever uses high_order flags. (orders[0] == 8
> forcing a permanent switch from low_order_gfp to high_order_gfp).
> 

Good find, that got lost in a refactor back in 4.9.

> There's no good reason for low_order_gfp, high_order_gfp to be static
> rewritable variables.
> 
> For this instance, I would go farther and suggest you may want
> __GFP_RETRY_MAYFAIL | __GFP_NOWARN to prevent userspace from triggering
> the lowmemkiller/oomkiller here.
>   
> (I would kill low_order_gfp_flags / high_order_gfp_flags and avoid the
> obfuscation.)
> -Chris
> 

Yeah, I think this all needs some refactoring. The high_order/low_order
flags were originally for the system heap to allocate pages for the
page pool and I don't think they should be reused for the contig heap.
I'll see about doing a refactor.

Thanks for the review!

Laura

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

end of thread, other threads:[~2018-01-05 21:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-05 19:14 [PATCH 1/2] staging: android: ion: Add __GFP_NOWARN for system contig heap Laura Abbott
2018-01-05 19:14 ` [PATCH 2/2] staging: android: ion: Switch from WARN to pr_warn Laura Abbott
2018-01-05 19:36 ` [PATCH 1/2] staging: android: ion: Add __GFP_NOWARN for system contig heap Chris Wilson
2018-01-05 21:46   ` Laura Abbott

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.