From 5e3649654858e3ccc3930254a5a8640c535b3e27 Mon Sep 17 00:00:00 2001 From: Brad Campbell Date: Fri, 28 Jun 2024 12:09:07 -0700 Subject: [PATCH] ipc: avoid double grant entry Check if the app is using IPC incorrectly and trying to notify itself. If it is we need to return early so we do not double enter a grant. --- kernel/src/ipc.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/src/ipc.rs b/kernel/src/ipc.rs index b1ccf09b20..e285577ff2 100644 --- a/kernel/src/ipc.rs +++ b/kernel/src/ipc.rs @@ -73,6 +73,13 @@ impl IPC { ) -> Result<(), process::Error> { let schedule_on_id = schedule_on.index().ok_or(process::Error::NoSuchApp)?; let called_from_id = called_from.index().ok_or(process::Error::NoSuchApp)?; + + // Verify that IPC is not trying to share with the same app. If so, this + // will cause a double grant enter if we don't return now. + if schedule_on_id == called_from_id { + return Err(process::Error::AlreadyInUse); + } + self.data.enter(schedule_on, |_, schedule_on_data| { self.data.enter(called_from, |_, called_from_data| { // If the other app shared a buffer with us, make