Skip to content

Commit fcd7f96

Browse files
make-things-betterJassi Brar
authored andcommitted
mailbox: Prevent out-of-bounds access in fw_mbox_index_xlate()
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>
1 parent b562abd commit fcd7f96

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

drivers/mailbox/mailbox.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,10 @@ EXPORT_SYMBOL_GPL(mbox_free_channel);
489489
static struct mbox_chan *fw_mbox_index_xlate(struct mbox_controller *mbox,
490490
const struct fwnode_reference_args *sp)
491491
{
492-
int ind = sp->args[0];
493-
494-
if (ind >= mbox->num_chans)
492+
if (sp->nargs < 1 || sp->args[0] >= mbox->num_chans)
495493
return ERR_PTR(-EINVAL);
496494

497-
return &mbox->chans[ind];
495+
return &mbox->chans[sp->args[0]];
498496
}
499497

500498
/**

0 commit comments

Comments
 (0)