eclipse-score / eclipse-score/baselibs

Fix unsafe `st_uid` conversion to `int64_t` in `StatBuffer`

Closed
#527 3 comments 0 reactions 0 assignees View on GitHub
comp-osal
Dominant language
C++
Stars
26
Forks
85
Avg merge
2d 13h
Merged PRs (30d)
47

Description

### Description

In the definition of `StatBuffer` in https://github.com/eclipse-score/baselibs/blob/main/score/os/stat.h#L43 the library score/os types `st_uid` to `std::int64_t`.

But POSIX defines the type as "an arithmetic type with appropriate length" and further "as an integer type" (https://pubs.opengroup.org/onlinepubs/007904875/basedefs/sys/types.h.html#tag_13_67).
There is no restriction, that it is a signed integer.

Thus, the `static_cast` in https://github.com/eclipse-score/baselibs/blob/main/score/os/stat_impl.cpp#L106 is unsound when the system uses as underlying type `std::uint64_t` and the user id is higher than `std::numeric_limits::max()`.

Arguably this is rare to happen but also not ruled out. Therefore, this remains a safety issue.

CodeQL finding that raised this issue downstream: https://github.com/eclipse-score/communication/security/code-scanning/14104

### Analysis results

_No response_

### Solution

_No response_

### Error Occurrence Rate

None

### How to reproduce

_No response_

### Supporting Information

_No response_

### Classification

Minor

### First Affected Release

not released (main)

### Last Affected Release

not released (main)

### Expected Fixed Release

before release (main)

### Category

- [x] Safety Relevant
- [ ] Security Relevant

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the StatBuffer definition in score/os/stat.h and the st_uid conversion in score/os/stat_impl.cpp around line 106. Check how the POSIX uid type is represented on systems where it is unsigned and identify the existing tests covering StatBuffer. Done means the conversion no longer risks narrowing a valid st_uid value and the relevant tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.