nibblebits / PeachOS

Simple kernel designed for a online course
GNU General Public License v2.0
133 stars 55 forks source link

Garbage value loaded into CR3 when no task is running and keyboard interrupt occurs. #19

Closed yuvraj1803 closed 1 year ago

yuvraj1803 commented 1 year ago

In src/keyboard/classic.c: line 92

task_page() is called.

When there is no task running, and the keyboard interrupt occurs, current_task is NULL/garbage. CR3 is loaded with some garbage value causing unexpected behaviour.

Regards, Yuvraj Sakshith

yuvraj1803 commented 1 year ago

In src/keyboard/classic.c

Screenshot 2023-05-04 at 5 43 40 PM

In line 92, task_page() is called.

In src/task/task.c

Screenshot 2023-05-04 at 5 44 03 PM

In line 191, task_page() calls task_switch(current_task). But current_task can be NULL, because,...

Screenshot 2023-05-04 at 5 44 28 PM

In src/task/task.c:13 It was initialised as NULL.

This leads to an invalid page directory being loaded (see below)

Screenshot 2023-05-04 at 5 45 11 PM

task is NULL, and task->page_directory is being loaded into CR3

I hope this makes it clear :)

yuvraj1803 commented 1 year ago

Suggested fix:

In src/keyboard/classic.c:

Line 92: if(task_current()) task_page();

nibblebits commented 1 year ago

Hello, I don't believe this to be an issue because their isnt a senario where their cant be a task. If I remember correctly if the program crashes a new task is spawned, you are welcome to put a panic in your code if you wish but I don't beleive this is neccessary. I did write the kernel a while ago so if you believe I'm wrong on that if you can show me I can look into it further, however I do not see a cause for a concern in this regard given that their will always be a task running. Even when a task is killed I believe we spawn another task

Thanks Dan