summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoonwon Kang <joonwonkang@google.com>2025-11-26 09:22:50 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-03-13 19:20:24 +0300
commit01d9a8c2615d436b2b30c19c1afe9fcd5726ff6d (patch)
treeeae3821612d79bd9af9363d16d4c639c313a6c5c
parentac75c29c9c955c17680e516df7be6156849a8173 (diff)
downloadlinux-01d9a8c2615d436b2b30c19c1afe9fcd5726ff6d.tar.xz
mailbox: Prevent out-of-bounds access in fw_mbox_index_xlate()
[ Upstream commit fcd7f96c783626c07ee3ed75fa3739a8a2052310 ] Although it is guided that `#mbox-cells` must be at least 1, there are many instances of `#mbox-cells = <0>;` in the device tree. If that is the case and the corresponding mailbox controller does not provide `fw_xlate` and of_xlate` function pointers, `fw_mbox_index_xlate()` will be used by default and out-of-bounds accesses could occur due to lack of bounds check in that function. Cc: stable@vger.kernel.org Signed-off-by: Joonwon Kang <joonwonkang@google.com> Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/mailbox/mailbox.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
index 892aa0a048e0..b4d52b814055 100644
--- a/drivers/mailbox/mailbox.c
+++ b/drivers/mailbox/mailbox.c
@@ -504,12 +504,10 @@ EXPORT_SYMBOL_GPL(mbox_free_channel);
static struct mbox_chan *fw_mbox_index_xlate(struct mbox_controller *mbox,
const struct fwnode_reference_args *sp)
{
- int ind = sp->args[0];
-
- if (ind >= mbox->num_chans)
+ if (sp->nargs < 1 || sp->args[0] >= mbox->num_chans)
return ERR_PTR(-EINVAL);
- return &mbox->chans[ind];
+ return &mbox->chans[sp->args[0]];
}
/**