From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 731204C6C for ; Sat, 17 Jan 2026 03:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768619749; cv=none; b=OTj1GhlE5QI+CF6KnmL1ztGDVPgy0khMOZG/QAUAj5I6lV0MglhT8760R0sH9iUWqfrVJTFkcFjuSS8/9gaIoPCriMM/O4FTSBuSvqGqpiBGNkmwxAJ/T/GkSO3gQtwOsPdx+VOp00w1oYB6K92MFrOpJ2d8OXnp1kSqlVKPVVA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768619749; c=relaxed/simple; bh=AEuJsBZga2sgQ+YUwrhip4kmR5jp2K/1ez8pEZNQrrk=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=sOHK9bKc22FUdV/dSwazzkY8ygLk07Azic3PG9JMNshAyZitMa4jZPqhE7WQR1ubN7M3xY7HT7kWwL9wJ7tnUf/m+EqHKDxMsEYY18MMMEFkznKQX3EYK0SWmGSjqXLdQjyjs6XcAzbgN7bIBpyaGQdvdjtFlzHaQUapA5gYA1A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=BVfXgtUB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="BVfXgtUB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8721C4CEF7; Sat, 17 Jan 2026 03:15:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1768619748; bh=AEuJsBZga2sgQ+YUwrhip4kmR5jp2K/1ez8pEZNQrrk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=BVfXgtUB5tysAneIN4Zzd6wIPIyNQu4pnN56U+tajD4nhDBBMhmTbCliACzR62xm4 E6JmCg7a84DEOdSiQRrqlDSz1ucw2pMDCtY3XxE+9eFQi06BMEXGjmUAadgUQ2qgQs fFF8p8rm0iTtJCxOg29SKShvO6myIcGfCRmWY7Kw= Date: Fri, 16 Jan 2026 19:15:48 -0800 From: Andrew Morton To: Dennis Zhou Cc: Tejun Heo , Christoph Lameter , Chris Mason , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sebastian Andrzej Siewior Subject: Re: [PATCH v2] percpu: add basic double free check Message-Id: <20260116191548.7df814c2a9eea1a9fa3c4cb5@linux-foundation.org> In-Reply-To: <20260116023216.14515-1-dennis@kernel.org> References: <20260116023216.14515-1-dennis@kernel.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 15 Jan 2026 18:32:16 -0800 Dennis Zhou 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. > > This is a respin of [1] adding the requested changes from me and > Christoph. > > ... > > @@ -1276,18 +1277,24 @@ static int pcpu_alloc_area(struct pcpu_chunk *chunk, int alloc_bits, > static int pcpu_free_area(struct pcpu_chunk *chunk, int off) > { > struct pcpu_block_md *chunk_md = &chunk->chunk_md; > + int region_bits = pcpu_chunk_map_bits(chunk); > int bit_off, bits, end, oslot, freed; > > lockdep_assert_held(&pcpu_lock); > - pcpu_stats_area_dealloc(chunk); > > oslot = pcpu_chunk_slot(chunk); > > bit_off = off / PCPU_MIN_ALLOC_SIZE; > + if (unlikely(bit_off < 0 || bit_off >= region_bits)) > + return 0; This (which looks sensible) wasn't changelogged? > @@ -2242,6 +2252,13 @@ void free_percpu(void __percpu *ptr) > > spin_lock_irqsave(&pcpu_lock, flags); > size = pcpu_free_area(chunk, off); > + if (size == 0) { > + spin_unlock_irqrestore(&pcpu_lock, flags); > + > + if (__ratelimit(&_rs)) > + WARN(1, "percpu double free or bad ptr\n"); Is ratelimiting really needed? A WARN_ON_ONCE is enough to tell people that this kernel is wrecked? > + return; > + } The patch does appear to do that which it set out to do. But do we want to do it? Is there a history of callers double-freeing percpu memory? Was there some bug which would have been more rapidly and easily solved had this change been in place?