[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20130820160418.5639c4f9975b84dc8dede014@linux-foundation.org>
Date: Tue, 20 Aug 2013 16:04:18 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Wanpeng Li <liwanp@...ux.vnet.ibm.com>
Cc: Dave Hansen <dave.hansen@...ux.intel.com>,
Rik van Riel <riel@...hat.com>,
Fengguang Wu <fengguang.wu@...el.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Johannes Weiner <hannes@...xchg.org>,
Tejun Heo <tj@...nel.org>,
Yasuaki Ishimatsu <isimatu.yasuaki@...fujitsu.com>,
David Rientjes <rientjes@...gle.com>,
KOSAKI Motohiro <kosaki.motohiro@...fujitsu.com>,
Jiri Kosina <jkosina@...e.cz>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/4] mm/pgtable: Fix continue to preallocate pmds
even if failure occurrence
On Tue, 20 Aug 2013 14:54:53 +0800 Wanpeng Li <liwanp@...ux.vnet.ibm.com> wrote:
> preallocate_pmds will continue to preallocate pmds even if failure
> occurrence, and then free all the preallocate pmds if there is
> failure, this patch fix it by stop preallocate if failure occurrence
> and go to free path.
>
> ...
>
> --- a/arch/x86/mm/pgtable.c
> +++ b/arch/x86/mm/pgtable.c
> @@ -196,21 +196,18 @@ static void free_pmds(pmd_t *pmds[])
> static int preallocate_pmds(pmd_t *pmds[])
> {
> int i;
> - bool failed = false;
>
> for(i = 0; i < PREALLOCATED_PMDS; i++) {
> pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
> if (pmd == NULL)
> - failed = true;
> + goto err;
> pmds[i] = pmd;
> }
>
> - if (failed) {
> - free_pmds(pmds);
> - return -ENOMEM;
> - }
> -
> return 0;
> +err:
> + free_pmds(pmds);
> + return -ENOMEM;
> }
Nope. If the error path is taken, free_pmds() will free uninitialised
items from pmds[], which is a local in pgd_alloc() and contains random
stack junk. The kernel will crash.
You could pass an nr_pmds argument to free_pmds(), or zero out the
remaining items on the error path. However, although the current code
is a bit kooky, I don't see that it is harmful in any way.
> Reviewed-by: Dave Hansen <dave.hansen@...ux.intel.com>
Ahem.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists