rust-lang / rust-lang/libc

epoll_event cannot carry provenance on user data

Open
#4,885 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
2.6k
Forks
1.3k
Avg merge
1d 22h
Merged PRs (30d)
69

Description

The epoll_event type is declared like this in C:

       struct epoll_event {
           uint32_t      events;  /* Epoll events */
           epoll_data_t  data;    /* User data variable */
       };

       union epoll_data {
           void     *ptr;
           int       fd;
           uint32_t  u32;
           uint64_t  u64;
       };

       typedef union epoll_data  epoll_data_t;

However, the Rust version in libc is different -- it just uses u64 for the data field. That is, unfortunately, not equivalent -- u64 cannot carry pointer provenance, so programs that want to store a pointer in data (which is quite common) need to use exposed-provenance APIs (i.e., ptr/int casts). Tokio carries some funky hacks to avoid that.

Since the C API is actually compatible with strict provenance here, it would be nice to expose that in libc as well. Given this is a breaking change it can only happen for libc 1.0 -- though it would be possible to have a separate event_data type and event_ctl declaration in its own module even in libc 0.2.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the existing Rust libc declaration of epoll_event and compare it with the C definitions quoted in the issue. Determine whether libc 1.0 should expose the union directly or whether libc 0.2 needs separate event_data and event_ctl APIs; done means the chosen provenance-preserving interface is implemented and checked against pointer-carrying use cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.