mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Rik van Riel <riel@surriel.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>, Chris Mason <clm@meta.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC v2 PATCH] mm/cma: don't release CMA pages still in use
Date: Tue, 11 Aug 2026 17:24:50 +0200	[thread overview]
Message-ID: <0a052bbb-4923-43c1-80dd-099ef4c1fb4a@kernel.org> (raw)
In-Reply-To: <007c8bf2717346bdba791e1a5079f4d0abad41f5.camel@surriel.com>

On 8/11/26 05:49, Rik van Riel wrote:
> On Mon, 2026-08-10 at 20:53 +0200, David Hildenbrand (Arm) wrote:
>> On 8/10/26 18:27, Rik van Riel wrote:
>>> When a driver calls dma_free_contiguous() before quiescing DMA, the
>>> page still has a reference from the device. put_page_testzero()
>>> there
>>> returns false, WARN fires, but the code proceeds to
>>> free_contig_frozen_range() putting a live page onto buddy and
>>> clearing
>>> the bitmap. Later cma_alloc() hands the same PFN to a new owner
>>> while
>>> the original holder still references it.
>>
>> Hm, it rather sounds like it's really the drivers job to quiescing
>> DMA. Are you
>> aware of an in-tree driver that can trigger this, and if so, how?
>>
>> Freeing memory through CMA, while the memory is still in use is
>> problematic for
>> CMA as you discovered :)
> 
> I agree the driver should not be doing that. 
> 
> I do not know of any driver that currently does it, but
> it has led to CVE-2025-37837 in the past, and there
> appear to have been other cases of this issue happening.
> 
>>> +	WARN(skipped, "%lu pages are still in use!\n", skipped);
>>
>>
>> We still issue a WARN, which itself is problematic. See "Do not WARN
>> lightly" in
>> Documentation/process/coding-style.rst.
>>
>> So it's either
>>
>> (a) This scenario is valid to be triggered. In that case, WARN is not
>> appropriate.
>>
>> (b) This scenario is not valid to be triggered. In that case, this is
>> not a fix.
> 
> If a driver does it with the current code, it can 
> cause free list corruption, with potential for
> temporary data exposure, until the system crashes.
> 
> If we get rid of the free list corruption, it
> can continue to be a WARN, since it will no longer
> kill the system.
> 
> If we continue to corrupt the free list when this
> happens, it should probably be a panic?
> 
> A simpler fix may be to not free any of the memory,
> or the CMA address space, if there are still pages
> in use at cma_release() time.

Yes, keep it as simple as possible and complain.

This is really something that must not happen, and the CVE in that above case is
not this code's fault but the driver's fault.

-- 
Cheers,

David

      reply	other threads:[~2026-08-11 15:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10 16:27 Rik van Riel
2026-08-10 18:53 ` David Hildenbrand (Arm)
2026-08-11  3:49   ` Rik van Riel
2026-08-11 15:24     ` David Hildenbrand (Arm) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0a052bbb-4923-43c1-80dd-099ef4c1fb4a@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=clm@meta.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=riel@surriel.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®