lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260114122209.1075584-1-clm@meta.com>
Date: Wed, 14 Jan 2026 04:22:00 -0800
From: Chris Mason <clm@...a.com>
To: Dennis Zhou <dennis@...nel.org>
CC: Chris Mason <clm@...a.com>, Tejun Heo <tj@...nel.org>,
        Christoph Lameter
	<cl@...ux.com>,
        Andrew Morton <akpm@...ux-foundation.org>, <linux-mm@...ck.org>,
        <linux-kernel@...r.kernel.org>,
        "Sebastian Andrzej
 Siewior" <bigeasy@...utronix.de>
Subject: Re: [PATCH] percpu: add basic double free check

On Fri, 19 Dec 2025 16:27:37 -0800 Dennis Zhou <dennis@...nel.org> wrote:

> This adds a basic double free check by validating the first bit of the
> allocation in alloc_map and bound_map are set. If the alloc_map bit is
> not set, then this means the area is currently unallocated. If the
> bound_map bit is not set, then we are not freeing from the beginning of
> the allocation.

Hi Dennis,

I ran mm-new through the AI review prompts, and this one was flagged:

> diff --git a/mm/percpu.c b/mm/percpu.c
> --- a/mm/percpu.c
> +++ b/mm/percpu.c

[ ... ]

> @@ -1285,6 +1286,11 @@ static int pcpu_free_area(struct pcpu_chunk *chunk, int off)
>
> 	bit_off = off / PCPU_MIN_ALLOC_SIZE;
>
> +	/* check double free */
> +	if (!test_bit(bit_off, chunk->alloc_map) ||
> +	    !test_bit(bit_off, chunk->bound_map))
> +		return 0;

Does this early return corrupt pcpu_stats.nr_cur_alloc and
chunk->nr_alloc?

Looking at pcpu_free_area(), earlier in the function (before this new
check) there is a call to pcpu_stats_area_dealloc(chunk) which decrements
these counters:

    static int pcpu_free_area(struct pcpu_chunk *chunk, int off)
    {
        ...
        lockdep_assert_held(&pcpu_lock);
        pcpu_stats_area_dealloc(chunk);   <-- decrements counters here
        ...
        bit_off = off / PCPU_MIN_ALLOC_SIZE;

        /* check double free */
        if (!test_bit(bit_off, chunk->alloc_map) ||
            !test_bit(bit_off, chunk->bound_map))
            return 0;                     <-- returns without actual free
        ...
    }

When a double-free is detected:

  1. pcpu_stats_area_dealloc() runs, decrementing pcpu_stats.nr_cur_alloc
     and chunk->nr_alloc
  2. The check detects the double-free and returns 0
  3. No actual memory is freed, but the counters are now wrong

Should pcpu_stats_area_dealloc() be moved after the double-free check,
or should there be a compensating increment on the early return path?

This could also affect percpu_stats_show() in mm/percpu-stats.c, which
uses chunk->nr_alloc via find_max_nr_alloc() to size a buffer:

    buffer = vmalloc_array(2 * max_nr_alloc + 1, sizeof(int));

If nr_alloc is underreported due to this bug, the buffer may be undersized
for the actual number of allocations tracked in alloc_map, which
chunk_map_stats() iterates based on the actual bitmap contents.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ