On Sun, Sep 15, 2024 at 10:31 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote: > > From: Wedson Almeida Filho <wedsonaf@xxxxxxxxx> > > Add a wrapper around `struct cred` called `Credential`, and provide > functionality to get the `Credential` associated with a `File`. > > Rust Binder must check the credentials of processes when they attempt to > perform various operations, and these checks usually take a > `&Credential` as parameter. The security_binder_set_context_mgr function > would be one example. This patch is necessary to access these security_* > methods from Rust. > > This Rust abstraction makes the following assumptions about the C side: > * `struct cred` is refcounted with `get_cred`/`put_cred`. > * It's okay to transfer a `struct cred` across threads, that is, you do > not need to call `put_cred` on the same thread as where you called > `get_cred`. > * The `euid` field of a `struct cred` never changes after > initialization. > * The `f_cred` field of a `struct file` never changes after > initialization. > > Signed-off-by: Wedson Almeida Filho <wedsonaf@xxxxxxxxx> > Co-developed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx> > Reviewed-by: Trevor Gross <tmgross@xxxxxxxxx> > Reviewed-by: Benno Lossin <benno.lossin@xxxxxxxxx> > Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@xxxxxxxxx> > Reviewed-by: Gary Guo <gary@xxxxxxxxxxx> > Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx> > --- > rust/bindings/bindings_helper.h | 1 + > rust/helpers/cred.c | 13 +++++++ > rust/helpers/helpers.c | 1 + > rust/kernel/cred.rs | 76 +++++++++++++++++++++++++++++++++++++++++ > rust/kernel/fs/file.rs | 13 +++++++ > rust/kernel/lib.rs | 1 + > 6 files changed, 105 insertions(+) Reviewed-by: Paul Moore <paul@xxxxxxxxxxxxxx> -- paul-moore.com