public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Untrusted Data Abstraction
@ 2024-09-25 20:52 Benno Lossin
  2024-09-25 20:53 ` [PATCH v2 1/2] rust: add untrusted data abstraction Benno Lossin
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Benno Lossin @ 2024-09-25 20:52 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross
  Cc: Greg KH, Simona Vetter, rust-for-linux

Enable marking certain data as untrusted. For example data coming from
userspace, hardware or any other external data source.

This idea originates from a discussion with Greg at Kangrejos. As far as I
understand the rationale, it is to prevent accidentally reading untrusted data
and using it for *logic* within the kernel. For example reading the length from
the hardware and not validating that it isn't too big. This is a big source for
logic bugs that later turn into vulnerabilities.

The API introduced in this series is not a silver bullet, users are still able
to access the untrusted value (otherwise how would they be able to validate
it?). But it provides additional guardrails to remind users that they ought to
validate the value before using it.

There are still some things to iron out on the Rust side:
- allow better handling of `Untrusted<T>`, for example allow comparing
  `Untrusted<[u8]>` for equality (we should do this via a trait extending
  `PartialEq`)
- rebase this on Gary's patch to enable arbitrary self types.
- get more feedback as to what `Untrusted` should make available

In this version I removed the API showcase using tarfs. I did this,
because I have added the API to `uaccess.rs`. Also, this version
requires [1] to compile the doctests.

[1]: https://lore.kernel.org/rust-for-linux/DM4PR14MB7276E6948E67B3B23D8EA847E9652@DM4PR14MB7276.namprd14.prod.outlook.com/

Benno Lossin (2):
  rust: add untrusted data abstraction
  rust: switch uaccess to untrusted data API

 rust/kernel/lib.rs      |   1 +
 rust/kernel/page.rs     |   8 +-
 rust/kernel/uaccess.rs  | 135 ++++-----
 rust/kernel/validate.rs | 602 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 677 insertions(+), 69 deletions(-)
 create mode 100644 rust/kernel/validate.rs

---

Changelog

v1: https://lore.kernel.org/rust-for-linux/20240913112643.542914-1-benno.lossin@proton.me/
- split `Untrusted` into `Untrusted` and `Unvalidated` (great suggestion
  by Simona Vetter)
- remove `validate_bytes`, `untrusted*` (Simona Vetter)
- rename `Validator` -> `Validate`
- change `Validator::Input` to an generic parameter (Fiona Behrens)
- remove `Validator::Output` and change return type to
  `Result<Self, Self::Err>` (Simona Vetter)
- use the new API on the `uaccess` module (Simona Vetter)
- add support for in-place validation (Simona Vetter)


base-commit: a2f11547052001bd448ccec81dd1e68409078fbb
-- 
2.46.0



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2024-12-09 14:56 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-25 20:52 [PATCH v2 0/2] Untrusted Data Abstraction Benno Lossin
2024-09-25 20:53 ` [PATCH v2 1/2] rust: add untrusted data abstraction Benno Lossin
2024-09-26  7:08   ` Dirk Behme
2024-09-26 10:40   ` Simona Vetter
2024-09-30 14:04     ` Benno Lossin
2024-11-26  8:05       ` Simona Vetter
2024-09-26 20:31   ` kernel test robot
2024-09-26 21:40     ` Benno Lossin
2024-09-26 21:56       ` Miguel Ojeda
2024-09-26 22:15         ` Benno Lossin
2024-09-27  8:39           ` Miguel Ojeda
2024-09-27  9:06             ` Benno Lossin
2024-09-26 21:57       ` Miguel Ojeda
2024-09-25 20:53 ` [PATCH v2 2/2] rust: switch uaccess to untrusted data API Benno Lossin
2024-09-26 11:09   ` Simona Vetter
2024-09-26 23:56   ` kernel test robot
2024-12-05  9:06 ` [PATCH v2 0/2] Untrusted Data Abstraction Greg KH
2024-12-09 12:25   ` Benno Lossin
2024-12-09 14:56   ` Simona Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox