scheduler: fix SCHED_DEADLINE upper bound check to reject 2^63 - #2232
scheduler: fix SCHED_DEADLINE upper bound check to reject 2^63#2232Rajkaran-122 wants to merge 2 commits into
Conversation
271f7b4 to
ead13d8
Compare
|
Ephemeral COPR build failed. @containers/packit-build please check. |
|
tests are failing @eriksjolund PTAL |
ead13d8 to
88a96d9
Compare
| return crun_make_error (err, errno, "sched_setattr: `SCHED_DEADLINE` period (%" PRIu64 ") must be between %" PRIu64 " and %" PRIu64, | ||
| if (attr->sched_period != 0 && (attr->sched_period < min || attr->sched_period >= max)) | ||
| return crun_make_error (err, errno, "sched_setattr: `SCHED_DEADLINE` period (%" PRIu64 ") must be >= %" PRIu64 " and < %" PRIu64, | ||
| attr->sched_period, min, max); |
There was a problem hiding this comment.
Perhaps it's easier to just change max to
- const uint64_t max = 1ULL << 63;
+ const uint64_t max = (1ULL << 63) - 1;?
There was a problem hiding this comment.
An advantage of using
const uint64_t max = (1ULL << 63) - 1;
is that the variable max will be set to the maximum allowed value. (The variable name then makes more sense)
88a96d9 to
6d87085
Compare
|
LGTM (I just reviewed the changes in src/libcrun/scheduler.c) |
| @@ -130,16 +123,16 @@ diagnose_scheduler_failure (libcrun_error_t *err, runtime_spec_schema_config_sch | |||
| /* sched(7) says "under the current implementation, all of the parameter values | |||
| * must be at least 1024 <...> and less than 2^63". */ | |||
| const uint64_t min = 1024; | |||
| const uint64_t max = 1ULL << 63; | |||
| const uint64_t max = (1ULL << 63) - 1; | |||
|
|
|||
| 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, | |||
| return crun_make_error (err, errno, "sched_setattr: `SCHED_DEADLINE` runtime (%" PRIu64 ") must be >= %" PRIu64 " and <= %" PRIu64, | |||
| attr->sched_runtime, min, max); | |||
| if (attr->sched_deadline < min || attr->sched_deadline > max) | |||
| return crun_make_error (err, errno, "sched_setattr: `SCHED_DEADLINE` deadline (%" PRIu64 ") must be between %" PRIu64 " and %" PRIu64, | |||
| return crun_make_error (err, errno, "sched_setattr: `SCHED_DEADLINE` deadline (%" PRIu64 ") must be >= %" PRIu64 " and <= %" PRIu64, | |||
| attr->sched_deadline, min, max); | |||
| if (attr->sched_period != 0 && (attr->sched_period < min || attr->sched_period > max)) | |||
| return crun_make_error (err, errno, "sched_setattr: `SCHED_DEADLINE` period (%" PRIu64 ") must be between %" PRIu64 " and %" PRIu64, | |||
| return crun_make_error (err, errno, "sched_setattr: `SCHED_DEADLINE` period (%" PRIu64 ") must be >= %" PRIu64 " and <= %" PRIu64, | |||
There was a problem hiding this comment.
Can we just keep the old error messages?
kolyshkin
left a comment
There was a problem hiding this comment.
I took a brief look at the test cases -- and it is ridiculous to have 20+ lines of code to check each and every boundary values.
Maybe the new tests does not make any sense?
6d87085 to
11e58bc
Compare
@Rajkaran-122 ^^^ |
051e55f to
7b5baa0
Compare
|
please apply the fixup and commit the final clean patch |
Per sched(7), SCHED_DEADLINE parameters must be at least 1024 and less than 2^63. The current code uses greater than max with max = 2^63, which incorrectly accepts values equal to 2^63. Change the check to greater than or equal to max to reject the endpoint as required by the kernel spec. Add regression test for the specific bug (2^63 rejection). Fixes containers#2190 Signed-off-by: Rajkaran Yadav <yadavrajkaran854@gmail.com>
Per sched(7), SCHED_DEADLINE parameters must be at least 1024 and less than 2^63. The current code uses greater than max with max = 2^63, which incorrectly accepts values equal to 2^63. Change the check to greater than or equal to max to reject the endpoint as required by the kernel spec. Add regression test for the specific bug (2^63 rejection). Fixes containers#2190 Signed-off-by: Rajkaran Yadav <yadavrajkaran854@gmail.com> Fixup: simplify max to (1ULL << 63) - 1 and restore original error messages. Per review feedback, adjust max to (1ULL << 63) - 1 instead of changing comparisons to >=. Restore original "must be between" error messages.
7b5baa0 to
115c65d
Compare
|
@giuseppe sir PTAL . |
Per sched(7), SCHED_DEADLINE parameters must be at least 1024 and less than 2^63. The current code uses greater than max with max = 2^63, which incorrectly accepts values equal to 2^63. Change the check to greater than or equal to max to reject the endpoint as required by the kernel spec.
Update error messages to accurately reflect the valid range using must be greater than or equal to 1024 and less than 2^63 instead of must be between.
Add regression tests for:
Fixes #2190