* [PATCH v3] rust: mm: warn once on invalid VMA range @ 2026-11-26 14:52 Ivan Tverdokhleb 2026-11-30 14:15 ` Alice Ryhl 0 siblings, 1 reply; 5+ messages in thread From: Ivan Tverdokhleb @ 2026-11-26 14:52 UTC (permalink / raw) To: Alice Ryhl, Miguel Ojeda Cc: Liam R . Howlett, FUJITA Tomonori, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein, Alexandre Courbot, Onur Özkan, Nicolás Antinori, linux-mm, rust-for-linux, Ivan Tverdokhleb Use `debug_assert!()` and `pr_warn_once!()` in `Vma::zap_vma_range()` to report invalid ranges. Signed-off-by: Ivan Tverdokhleb <mbkchelofficialdev@gmail.com> --- Changes in v2: - Drop the `warn_once!()` macro and its KUnit test. - Use `debug_assert!()` and `pr_warn_once!()` in `Vma::zap_vma_range()` as suggested by Miguel. Changes in v3: - Add `#[cfg(CONFIG_DEBUG_VM)]` in 'pr_warn_once!()' as suggested by Nicolás. rust/kernel/mm/virt.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rust/kernel/mm/virt.rs b/rust/kernel/mm/virt.rs index 63eb730b0..289511dc1 100644 --- a/rust/kernel/mm/virt.rs +++ b/rust/kernel/mm/virt.rs @@ -115,8 +115,10 @@ pub fn end(&self) -> usize { #[inline] pub fn zap_vma_range(&self, address: usize, size: usize) { let (end, did_overflow) = address.overflowing_add(size); + debug_assert!(!did_overflow && address >= self.start() && self.end() >= end); if did_overflow || address < self.start() || self.end() < end { - // TODO: call WARN_ONCE once Rust version of it is added + #[cfg(CONFIG_DEBUG_VM)] + crate::pr_warn_once!("Attempt to zap invalid VMA range\n"); return; } -- 2.56.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3] rust: mm: warn once on invalid VMA range 2026-11-26 14:52 [PATCH v3] rust: mm: warn once on invalid VMA range Ivan Tverdokhleb @ 2026-11-30 14:15 ` Alice Ryhl 2026-12-01 2:06 ` FUJITA Tomonori 0 siblings, 1 reply; 5+ messages in thread From: Alice Ryhl @ 2026-11-30 14:15 UTC (permalink / raw) To: Ivan Tverdokhleb Cc: Alice Ryhl, Miguel Ojeda, Liam R . Howlett, FUJITA Tomonori, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein, Alexandre Courbot, Onur Özkan, Nicolás Antinori, linux-mm, rust-for-linux On Thu, Nov 26, 2026 at 04:52:57PM +0200, Ivan Tverdokhleb wrote: > Use `debug_assert!()` and `pr_warn_once!()` in > `Vma::zap_vma_range()` to report invalid ranges. > > Signed-off-by: Ivan Tverdokhleb <mbkchelofficialdev@gmail.com> (Minor nit: the struct is `VmaRef`, not `Vma`.) > --- a/rust/kernel/mm/virt.rs > +++ b/rust/kernel/mm/virt.rs > @@ -115,8 +115,10 @@ pub fn end(&self) -> usize { > #[inline] > pub fn zap_vma_range(&self, address: usize, size: usize) { > let (end, did_overflow) = address.overflowing_add(size); > + debug_assert!(!did_overflow && address >= self.start() && self.end() >= end); > if did_overflow || address < self.start() || self.end() < end { > - // TODO: call WARN_ONCE once Rust version of it is added > + #[cfg(CONFIG_DEBUG_VM)] > + crate::pr_warn_once!("Attempt to zap invalid VMA range\n"); > return; > } I agree with Gary's reply on v1 [1] that we actually want `warn_on_once!()` here rather than `debug_assert!()` + `pr_warn_once!()`. The TODO in `zap_vma_range()` specifically exists because we want a real `WARN_ON_ONCE` here. Fujita mentioned on v1 that he already has a `warn_on_once!()` patch that works across all architectures (including UML, ARM, and LoongArch), so I'd prefer to wait for `warn_on_once!()` and use that directly instead of this change. [1] https://lore.kernel.org/r/DN59EXEWINPV.3UUBOIK6EROAC@garyguo.net Alice ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] rust: mm: warn once on invalid VMA range 2026-11-30 14:15 ` Alice Ryhl @ 2026-12-01 2:06 ` FUJITA Tomonori 2026-12-01 8:52 ` Ivan Tverdokhleb 2026-12-01 10:24 ` Alice Ryhl 0 siblings, 2 replies; 5+ messages in thread From: FUJITA Tomonori @ 2026-12-01 2:06 UTC (permalink / raw) To: aliceryhl Cc: mbkchelofficialdev, ojeda, liam, fujita.tomonori, boqun, gary, bjorn3_gh, lossin, a.hindborg, tmgross, dakr, daniel.almeida, tamird, acourbot, work, nico.antinori.7, linux-mm, rust-for-linux On Mon, 30 Nov 2026 14:15:43 +0000 Alice Ryhl <aliceryhl@google.com> wrote: > On Thu, Nov 26, 2026 at 04:52:57PM +0200, Ivan Tverdokhleb wrote: >> Use `debug_assert!()` and `pr_warn_once!()` in >> `Vma::zap_vma_range()` to report invalid ranges. >> >> Signed-off-by: Ivan Tverdokhleb <mbkchelofficialdev@gmail.com> > > (Minor nit: the struct is `VmaRef`, not `Vma`.) > >> --- a/rust/kernel/mm/virt.rs >> +++ b/rust/kernel/mm/virt.rs >> @@ -115,8 +115,10 @@ pub fn end(&self) -> usize { >> #[inline] >> pub fn zap_vma_range(&self, address: usize, size: usize) { >> let (end, did_overflow) = address.overflowing_add(size); >> + debug_assert!(!did_overflow && address >= self.start() && self.end() >= end); >> if did_overflow || address < self.start() || self.end() < end { >> - // TODO: call WARN_ONCE once Rust version of it is added >> + #[cfg(CONFIG_DEBUG_VM)] >> + crate::pr_warn_once!("Attempt to zap invalid VMA range\n"); >> return; >> } > > I agree with Gary's reply on v1 [1] that we actually want `warn_on_once!()` > here rather than `debug_assert!()` + `pr_warn_once!()`. > > The TODO in `zap_vma_range()` specifically exists because we want a real > `WARN_ON_ONCE` here. Fujita mentioned on v1 that he already has a > `warn_on_once!()` patch that works across all architectures (including UML, > ARM, and LoongArch), so I'd prefer to wait for `warn_on_once!()` and use > that directly instead of this change. I posted warn_on_once!(): https://lore.kernel.org/rust-for-linux/20261130230914.739923-1-tomo@flapping.org/ With the current Rust Binder, a bug in user space could trigger WARN_ON_ONCE() here. If a process unmaps the tail of its Binder mapping, the shrinker looks up the vma with inner.vma_addr and calls zap_vma_range() with an address outside the vma. I reproduced this on QEMU. Shouldn't this be fixed first, so that only a kernel bug can trigger the warning? ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] rust: mm: warn once on invalid VMA range 2026-12-01 2:06 ` FUJITA Tomonori @ 2026-12-01 8:52 ` Ivan Tverdokhleb 2026-12-01 10:24 ` Alice Ryhl 1 sibling, 0 replies; 5+ messages in thread From: Ivan Tverdokhleb @ 2026-12-01 8:52 UTC (permalink / raw) To: FUJITA Tomonori Cc: aliceryhl, ojeda, liam, fujita.tomonori, boqun, gary, bjorn3_gh, lossin, a.hindborg, tmgross, dakr, daniel.almeida, tamird, acourbot, work, nico.antinori.7, linux-mm, rust-for-linux Hi Fujita, Alice, Thanks for catching that Binder issue. Makes sense to fix it first so user space can't trigger WARN_ON_ONCE(). I'll also update the docs to use VmaRef instead of Vma as Alice noted. I already tested your warn_on_once!() series and sent a Tested-by. Once both your series and the Binder fix land in linux-next, I'll rebase and send v4. Thanks, Ivan вт, 1 дек. 2026 г. в 04:06, FUJITA Tomonori <tomo@flapping.org>: > > On Mon, 30 Nov 2026 14:15:43 +0000 > Alice Ryhl <aliceryhl@google.com> wrote: > > > On Thu, Nov 26, 2026 at 04:52:57PM +0200, Ivan Tverdokhleb wrote: > >> Use `debug_assert!()` and `pr_warn_once!()` in > >> `Vma::zap_vma_range()` to report invalid ranges. > >> > >> Signed-off-by: Ivan Tverdokhleb <mbkchelofficialdev@gmail.com> > > > > (Minor nit: the struct is `VmaRef`, not `Vma`.) > > > >> --- a/rust/kernel/mm/virt.rs > >> +++ b/rust/kernel/mm/virt.rs > >> @@ -115,8 +115,10 @@ pub fn end(&self) -> usize { > >> #[inline] > >> pub fn zap_vma_range(&self, address: usize, size: usize) { > >> let (end, did_overflow) = address.overflowing_add(size); > >> + debug_assert!(!did_overflow && address >= self.start() && self.end() >= end); > >> if did_overflow || address < self.start() || self.end() < end { > >> - // TODO: call WARN_ONCE once Rust version of it is added > >> + #[cfg(CONFIG_DEBUG_VM)] > >> + crate::pr_warn_once!("Attempt to zap invalid VMA range\n"); > >> return; > >> } > > > > I agree with Gary's reply on v1 [1] that we actually want `warn_on_once!()` > > here rather than `debug_assert!()` + `pr_warn_once!()`. > > > > The TODO in `zap_vma_range()` specifically exists because we want a real > > `WARN_ON_ONCE` here. Fujita mentioned on v1 that he already has a > > `warn_on_once!()` patch that works across all architectures (including UML, > > ARM, and LoongArch), so I'd prefer to wait for `warn_on_once!()` and use > > that directly instead of this change. > > I posted warn_on_once!(): > > https://lore.kernel.org/rust-for-linux/20261130230914.739923-1-tomo@flapping.org/ > > With the current Rust Binder, a bug in user space could trigger > WARN_ON_ONCE() here. If a process unmaps the tail of its Binder > mapping, the shrinker looks up the vma with inner.vma_addr and calls > zap_vma_range() with an address outside the vma. I reproduced this on > QEMU. > > Shouldn't this be fixed first, so that only a kernel bug can trigger > the warning? ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] rust: mm: warn once on invalid VMA range 2026-12-01 2:06 ` FUJITA Tomonori 2026-12-01 8:52 ` Ivan Tverdokhleb @ 2026-12-01 10:24 ` Alice Ryhl 1 sibling, 0 replies; 5+ messages in thread From: Alice Ryhl @ 2026-12-01 10:24 UTC (permalink / raw) To: FUJITA Tomonori Cc: Alice Ryhl, Ivan Tverdokhleb, Miguel Ojeda, Liam R . Howlett, FUJITA Tomonori, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein, Alexandre Courbot, Onur Özkan, Nicolás Antinori, linux-mm, rust-for-linux On Tue, Dec 01, 2026 at 11:06:43AM +0900, FUJITA Tomonori wrote: > I posted warn_on_once!(): > > https://lore.kernel.org/rust-for-linux/20261130230914.739923-1-tomo@flapping.org/ > > With the current Rust Binder, a bug in user space could trigger > WARN_ON_ONCE() here. If a process unmaps the tail of its Binder > mapping, the shrinker looks up the vma with inner.vma_addr and calls > zap_vma_range() with an address outside the vma. I reproduced this on > QEMU. > > Shouldn't this be fixed first, so that only a kernel bug can trigger > the warning? Good catch, thanks for finding and reproducing that! I just sent a fix for Rust Binder to check `user_page_addr < vma.end()` before calling `zap_vma_range()` [1]. I think it's fine to land the fix separately from your series, so your series should be good to go now. [1] https://lore.kernel.org/r/20261201-binder-vma-lookup-v1-1-5e8b1150975b@google.com Alice ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-01 10:25 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-26 14:52 [PATCH v3] rust: mm: warn once on invalid VMA range Ivan Tverdokhleb 2026-11-30 14:15 ` Alice Ryhl 2026-12-01 2:06 ` FUJITA Tomonori 2026-12-01 8:52 ` Ivan Tverdokhleb 2026-12-01 10:24 ` Alice Ryhl
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.