Re: [bug report] mm, compaction: capture a page under direct compaction

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 26 Feb 2020 18:04:56 +0100 Vlastimil Babka <vbabka@xxxxxxx> wrote:

> On 2/24/20 7:35 AM, Dan Carpenter wrote:
> > Hello Mel Gorman,
> > 
> > This is a semi-automatic email about new static checker warnings.
> > 
> > The patch 5e1f0f098b46: "mm, compaction: capture a page under direct 
> > compaction" from Mar 5, 2019, leads to the following Smatch complaint:
> > 
> >     mm/compaction.c:2321 compact_zone_order()
> >      error: we previously assumed 'capture' could be null (see line 2313)
> > 
> 
> ----8<----
> >From fb264bb52576a0582e8a92952cf91e8b61d105c3 Mon Sep 17 00:00:00 2001
> From: Vlastimil Babka <vbabka@xxxxxxx>
> Date: Wed, 26 Feb 2020 17:53:54 +0100
> Subject: [PATCH] mm, compaction: fully assume capture can be NULL in
>  compact_zone_order()
> 
> Dan reports:
> 
> The patch 5e1f0f098b46: "mm, compaction: capture a page under direct
> compaction" from Mar 5, 2019, leads to the following Smatch complaint:
> 
>     mm/compaction.c:2321 compact_zone_order()
>      error: we previously assumed 'capture' could be null (see line 2313)
> 
> mm/compaction.c
>   2288  static enum compact_result compact_zone_order(struct zone *zone, int order,
>   2289                  gfp_t gfp_mask, enum compact_priority prio,
>   2290                  unsigned int alloc_flags, int classzone_idx,
>   2291                  struct page **capture)
>                                       ^^^^^^^
> 
>   2313		if (capture)
>                     ^^^^^^^
> Check for NULL
> 
>   2314			current->capture_control = &capc;
>   2315
>   2316		ret = compact_zone(&cc, &capc);
>   2317
>   2318		VM_BUG_ON(!list_empty(&cc.freepages));
>   2319		VM_BUG_ON(!list_empty(&cc.migratepages));
>   2320
>   2321		*capture = capc.page;
>                 ^^^^^^^^
> Unchecked dereference.
> 
>   2322		current->capture_control = NULL;
>   2323
> 
> In practice this is not an issue, as the only caller path passes non-NULL
> capture:
> 
> __alloc_pages_direct_compact()
>   struct page *page = NULL;
>   try_to_compact_pages(capture = &page);
>     compact_zone_order(capture = capture);
> 
> Hence no stable tag needed, but let's make this more robust and remove the
> warning by assuming capture might be NULL in the second dereference.
> 
> ...
>
> --- mm/compaction.c
> +++ mm/compaction.c
> @@ -2318,8 +2318,10 @@ static enum compact_result compact_zone_order(struct zone *zone, int order,
>  	VM_BUG_ON(!list_empty(&cc.freepages));
>  	VM_BUG_ON(!list_empty(&cc.migratepages));
>  
> -	*capture = capc.page;
> -	current->capture_control = NULL;
> +	if (capture) {
> +		*capture = capc.page;
> +		current->capture_control = NULL;
> +	}
>  
>  	return ret;
>  }

Why don't we instead remove the first check for NULL?  Remove some dead
code instead of adding some?




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux