Skip to content

scheduler: fix SCHED_DEADLINE upper bound check to reject 2^63 - #2232

Open
Rajkaran-122 wants to merge 2 commits into
containers:mainfrom
Rajkaran-122:issue-2190-sched-deadline-range
Open

scheduler: fix SCHED_DEADLINE upper bound check to reject 2^63#2232
Rajkaran-122 wants to merge 2 commits into
containers:mainfrom
Rajkaran-122:issue-2190-sched-deadline-range

Conversation

@Rajkaran-122

Copy link
Copy Markdown
Contributor

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:

  • Valid upper boundary (2^63 - 1)
  • Invalid upper boundary (2^63) for runtime, deadline, and period
  • Valid lower boundary (1024)

Fixes #2190

@Rajkaran-122
Rajkaran-122 force-pushed the issue-2190-sched-deadline-range branch from 271f7b4 to ead13d8 Compare September 3, 2026 11:11
@packit-as-a-service

Copy link
Copy Markdown

Ephemeral COPR build failed. @containers/packit-build please check.

@giuseppe

giuseppe commented Sep 3, 2026

Copy link
Copy Markdown
Member

tests are failing

@eriksjolund PTAL

@Rajkaran-122
Rajkaran-122 force-pushed the issue-2190-sched-deadline-range branch from ead13d8 to 88a96d9 Compare September 3, 2026 16:01
Comment thread src/libcrun/scheduler.c
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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's easier to just change max to

-      const uint64_t max = 1ULL << 63;
+      const uint64_t max = (1ULL << 63) - 1;

?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@Rajkaran-122
Rajkaran-122 force-pushed the issue-2190-sched-deadline-range branch from 88a96d9 to 6d87085 Compare September 3, 2026 17:13
@eriksjolund

Copy link
Copy Markdown
Contributor

LGTM

(I just reviewed the changes in src/libcrun/scheduler.c‎)

Comment thread src/libcrun/scheduler.c Outdated
Comment on lines +129 to +135
@@ -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,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just keep the old error messages?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kolyshkin kolyshkin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@Rajkaran-122
Rajkaran-122 force-pushed the issue-2190-sched-deadline-range branch from 6d87085 to 11e58bc Compare September 4, 2026 08:29
@kolyshkin

Copy link
Copy Markdown
Collaborator

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?

@Rajkaran-122 ^^^

@Rajkaran-122
Rajkaran-122 force-pushed the issue-2190-sched-deadline-range branch from 051e55f to 7b5baa0 Compare September 9, 2026 19:13
@giuseppe

Copy link
Copy Markdown
Member

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.
@Rajkaran-122
Rajkaran-122 force-pushed the issue-2190-sched-deadline-range branch from 7b5baa0 to 115c65d Compare September 10, 2026 16:53
@Rajkaran-122

Rajkaran-122 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

@giuseppe sir PTAL .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCHED_DEADLINE range check allows value equal to 2^63 (off-by-one vs. cited spec)

4 participants