`SCHED_DEADLINE` range check allows value equal to 2^63 (off-by-one vs. cited spec)
- Dominant language
- C
- Stars
- 4.1k
- Forks
- 444
- Avg merge
- 2d 40m
- Merged PRs (30d)
- 47
Description
I asked Claude Opus 4.8
```
Is there any mistake bug in src/libcrun/scheduler.c ?
I wonder if there is any mismatch between the if statement checks and the error messages.
```
Claude wrote a lot of text. I then wrote:
```
Can you draft a minimal issue (in markdown format) for the issue you found?
```
Click me for claude output
## `SCHED_DEADLINE` range check allows value equal to 2^63 (off-by-one vs. cited spec)
### Description
In `src/libcrun/scheduler.c`, `diagnose_scheduler_failure()` validates the
`SCHED_DEADLINE` runtime/deadline/period against a `[min, max]` range. The code
comment quotes sched(7) as requiring values "at least 1024 ... and less than
2^63", i.e. the valid range is `[1024, 2^63)`. However the upper-bound guard uses
`> max` with `max = 1ULL << 63`, so a value of exactly `2^63` passes the check
even though the spec says it must be *less than* `2^63`. The error message
("must be between 1024 and 2^63") is worded consistently with the buggy check
rather than the spec.
### Location
`src/libcrun/scheduler.c`, in `diagnose_scheduler_failure()` (runtime, deadline,
and period range checks).
### Current code
```c
const uint64_t min = 1024;
const uint64_t max = 1ULL << 63; /* == 2^63 */
if (attr->sched_runtime < min || attr->sched_runtime > max)
return crun_make_error (err, errno,
"sched_setattr: `SCHED_DEADLINE` runtime (%" PRIu64
") must be between %" PRIu64 " and %" PRIu64,
attr->sched_runtime, min, max);
```
### Expected vs. actual
- Expected: a value equal to `2^63` is rejected (spec: `< 2^63`).
- Actual: `> max` lets `2^63` through; only `> 2^63` is rejected.
### Suggested fix
Reject the endpoint and align the message, e.g.:
```c
if (attr->sched_runtime < min || attr->sched_runtime >= max)
return crun_make_error (err, errno,
"sched_setattr: `SCHED_DEADLINE` runtime (%" PRIu64
") must be >= %" PRIu64 " and < %" PRIu64,
attr->sched_runtime, min, max);
```
(or set `max = (1ULL << 63) - 1` and keep `>`). The same change applies to all
three range checks, which share `min`/`max`.
### Notes
Low severity: this affects diagnostic accuracy rather than behavior — the kernel
would reject such a value anyway, and crun would fall through to the generic
"invalid parameters" error.
Contributor guide
Research direction
Start in src/libcrun/scheduler.c at diagnose_scheduler_failure() and inspect the shared SCHED_DEADLINE runtime, deadline, and period range checks against the cited sched(7) bounds. Confirm that the exact 2^63 endpoint is rejected for all three values and that the resulting error messages describe the inclusive lower and exclusive upper bounds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100