]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mailbox: Prevent out-of-bounds access in fw_mbox_index_xlate()
authorJoonwon Kang <joonwonkang@google.com>
Wed, 26 Nov 2025 06:22:50 +0000 (06:22 +0000)
committerJassi Brar <jassisinghbrar@gmail.com>
Sun, 18 Jan 2026 18:50:45 +0000 (12:50 -0600)
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>
drivers/mailbox/mailbox.c

index 2acc6ec229a4580b345ae4e2cc28bce3349c7db8..617ba505691d37f1ed2e95cd00307f2546266503 100644 (file)
@@ -489,12 +489,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]];
 }
 
 /**