Skip to content

About set_thread_res_uid and Uid types #1453

@rusty-snake

Description

@rusty-snake
Contributor

Uid in rustix has a strange history of not liking the value -1. While it is nowadays sound (no unsafe) to create one, it is still incorrect.

At the same time the set_thread_res_uid takes three Uids that have a clear use of being -1 in this syscall interface.

It is possible to implement set_thread_euid like

set_thread_res_uid(
    Uid::from_raw_unchecked(-1_i32 as u32),
    euid,
    Uid::from_raw_unchecked(-1_i32 as u32),
)?;

this is

  • ugly, complicated and long
  • documented as being incorrect

So my suggestion is to change set_thread_res_uid to take three Option<Uid> in a semver compatible way.

Activity

sunfishcode

sunfishcode commented on Apr 30, 2025

@sunfishcode
Member

Good catch; I agree we should change set_thread_res_uid to take three Option<Uid>s, in a semver-compatible way, by deprecating the current function and adding a new function with a different name.

rusty-snake

rusty-snake commented on May 1, 2025

@rusty-snake
ContributorAuthor

I would just go with

fn set_thread_res_uid<R, E, S>(real: R, effective: E, saved_set: S)
where
    R: Into<Option<Uid>>,
    E: Into<Option<Uid>>,
    S: Into<Option<Uid>>,

This way you can keep passing a Uid directly without writing Some or passing None.

rusty-snake

rusty-snake commented on May 1, 2025

@rusty-snake
ContributorAuthor

The think is how do we want to implement?

  1. set_thread_res_uid does Uid::from_raw_unchecked(-1_i32 as u32) and backend::setresuid_thread is unchanged.
  2. set_thread_res_uid converts to RawUid and backend::setresuid_thread takes RawUid.
  3. set_thread_res_uid converts to Option<Uid> and backend::setresuid_thread takes Option<Uid> and does Uid::from_raw_unchecked(-1_i32 as u32) or converts to RawUid.
rusty-snake

rusty-snake commented on May 1, 2025

@rusty-snake
ContributorAuthor
  1. Doesn't sound funny with ArgReg

  1. Still needs to exploit from_raw_unchecked(-1_i32 as u32)

So I would go with 3. and impl<'a, Num: ArgNumber> From<Option<Uid>> for ArgReg<'a, Num>

linked a pull request that will close this issue on May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @sunfishcode@rusty-snake

      Issue actions

        About `set_thread_res_uid` and Uid types · Issue #1453 · bytecodealliance/rustix