Skip to contentSkip to conversation

xen/sched: fix scheduler callback verification on init

PATCH Superseded Ruslan Ruslichenko 3 participants 4 messages Apr 10 – Apr 16

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/sched: fix scheduler callback verification on init

From: Ruslan Ruslichenko <[email protected]>

During core scheduler initialization, each registered scheduler is sanity tested in two steps:

- it must provide required callbacks (e.g. init, do_schedule).
- if global_init callback is present, it must succeed.

If any of the steps fail, scheduler entry is cleared in global 'schedulers' array.

However, in the current implementation, if verification fails during the first step, the scheduler entry is cleared but verification sequence is not interrupted. This lead to NULL pointer dereference when subsequent required callbacks verified, and possible during the second step.

The patch fixes the crashes by adding check inside sched_test_func macro and skipping the call to a global_init if first step did not pass.

---
 xen/common/sched/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
xen/common/sched/core.c +4 -1
index a57d5dd929..4270c89491 100644
@@ -3017,7 +3017,7 @@ void __init scheduler_init(void)
     for ( i = 0; i < NUM_SCHEDULERS; i++)
     {
 #define sched_test_func(f)                               \
-        if ( !schedulers[i]->f )                         \
+        if ( schedulers[i] && !schedulers[i]->f )        \
         {                                                \
             printk("scheduler %s misses .%s, dropped\n", \
                    schedulers[i]->opt_name, #f);         \
@@ -3034,6 +3034,9 @@ void __init scheduler_init(void)
 
 #undef sched_test_func
 
+        if ( !schedulers[i] )
+            continue;
+
         if ( schedulers[i]->global_init && schedulers[i]->global_init() < 0 )
         {
             printk("scheduler %s failed initialization, dropped\n",
Signature · 1 line
2.43.0
#1 lore raw
Quoted 38 lines · Ruslan Ruslichenko

From: Ruslan Ruslichenko <[email protected]>

During core scheduler initialization, each registered scheduler is sanity tested in two steps:

- it must provide required callbacks (e.g. init, do_schedule).
- if global_init callback is present, it must succeed.

If any of the steps fail, scheduler entry is cleared in global 'schedulers' array.

However, in the current implementation, if verification fails during the first step, the scheduler entry is cleared but verification sequence is not interrupted. This lead to NULL pointer dereference when subsequent required callbacks verified, and possible during the second step.

The patch fixes the crashes by adding check inside sched_test_func macro and skipping the call to a global_init if first step did not pass.

---
  xen/common/sched/core.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
xen/common/sched/core.c +1 -1
index a57d5dd929..4270c89491 100644
@@ -3017,7 +3017,7 @@ void __init scheduler_init(void)
      for ( i = 0; i < NUM_SCHEDULERS; i++)
      {
  #define sched_test_func(f)                               \
-        if ( !schedulers[i]->f )                         \
+        if ( schedulers[i] && !schedulers[i]->f )        \
          {                                                \
              printk("scheduler %s misses .%s, dropped\n", \
                     schedulers[i]->opt_name, #f);         \
Quoted 1 line
              schedulers[i] = NULL;                        \

Maybe it would be cleaner to just add "continue" here?

Quoted 10 lines
xen/common/sched/core.c +3 -0
@@ -3034,6 +3034,9 @@ void __init scheduler_init(void)
 
  #undef sched_test_func
 
+        if ( !schedulers[i] )
+            continue;
+
          if ( schedulers[i]->global_init && schedulers[i]->global_init() < 0 )
          {
              printk("scheduler %s failed initialization, dropped\n",
Signature · 1 line
Mykyta
#2 lore raw
Quoted 27 lines · Mykyta Poturai
Quoted 25 lines · Ruslan Ruslichenko

From: Ruslan Ruslichenko <[email protected]>

During core scheduler initialization, each registered scheduler is sanity tested in two steps:

- it must provide required callbacks (e.g. init, do_schedule).
- if global_init callback is present, it must succeed.

If any of the steps fail, scheduler entry is cleared in global 'schedulers' array.

However, in the current implementation, if verification fails during the first step, the scheduler entry is cleared but verification sequence is not interrupted. This lead to NULL pointer dereference when subsequent required callbacks verified, and possible during the second step.

The patch fixes the crashes by adding check inside sched_test_func macro and skipping the call to a global_init if first step did not pass.

---
  xen/common/sched/core.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 17 lines
Quoted 13 lines
xen/common/sched/core.c +1 -1
index a57d5dd929..4270c89491 100644
@@ -3017,7 +3017,7 @@ void __init scheduler_init(void)
      for ( i = 0; i < NUM_SCHEDULERS; i++)
      {
  #define sched_test_func(f)                               \
-        if ( !schedulers[i]->f )                         \
+        if ( schedulers[i] && !schedulers[i]->f )        \
          {                                                \
              printk("scheduler %s misses .%s, dropped\n", \
                     schedulers[i]->opt_name, #f);         \
Quoted 1 line
              schedulers[i] = NULL;                        \

Maybe it would be cleaner to just add "continue" here?

Probably, yes. This will also skip unneeded checks after the first missing callback.
I will update the patch then.

--
BR,
Ruslan

Quoted 13 lines

xen/common/sched/core.c void __init scheduler_init(void) · line 3042

Quoted 10 lines
xen/common/sched/core.c +3 -0
@@ -3034,6 +3034,9 @@ void __init scheduler_init(void)
 
  #undef sched_test_func
 
+        if ( !schedulers[i] )
+            continue;
+
          if ( schedulers[i]->global_init && schedulers[i]->global_init() < 0 )
          {
              printk("scheduler %s failed initialization, dropped\n",

--
Mykyta

#3 lore raw
In reply to Ruslan Ruslichenko
Quoted 17 lines · Ruslan Ruslichenko

From: Ruslan Ruslichenko <[email protected]>

During core scheduler initialization, each registered scheduler is sanity tested in two steps:

- it must provide required callbacks (e.g. init, do_schedule).
- if global_init callback is present, it must succeed.

If any of the steps fail, scheduler entry is cleared in global 'schedulers' array.

However, in the current implementation, if verification fails during the first step, the scheduler entry is cleared but verification sequence is not interrupted. This lead to NULL pointer dereference when subsequent required callbacks verified, and possible during the second step.

Quoted 4 lines

The patch fixes the crashes by adding check inside sched_test_func macro and skipping the call to a global_init if first step did not pass.

This likely also wants a Fixes: tag.

Jan