Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1288713 > unrolled thread

[PATCH] mailbox: pcc: fix channel calculation in get_pcc_channel()

Started byAlexey Klimov <alexey.klimov@arm.com>
First post2015-12-10 18:30 +0100
Last post2015-12-10 19:20 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] mailbox: pcc: fix channel calculation in get_pcc_channel() Alexey Klimov <alexey.klimov@arm.com> - 2015-12-10 18:30 +0100
    Re: [PATCH] mailbox: pcc: fix channel calculation in get_pcc_channel() Ashwin Chaugule <ashwin.chaugule@linaro.org> - 2015-12-10 19:20 +0100

#1288713 — [PATCH] mailbox: pcc: fix channel calculation in get_pcc_channel()

FromAlexey Klimov <alexey.klimov@arm.com>
Date2015-12-10 18:30 +0100
Subject[PATCH] mailbox: pcc: fix channel calculation in get_pcc_channel()
Message-ID<qEdcw-Km-61@gated-at.bofh.it>
This patch fixes the calculation of pcc_chan for non-zero id.
After the compiler ignores the (unsigned long) cast the
pcc_mbox_channels pointer is type-cast and then the type-cast
offset is added which results in address outside of the range
leading to the kernel crashing.

We might add braces and make it:

pcc_chan = (struct mbox_chan *)
		((unsigned long) pcc_mbox_channels +
		(id * sizeof(*pcc_chan)));

but let's go with array approach here and use id as index.

Tested on Juno board.

Acked-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Alexey Klimov <alexey.klimov@arm.com>
---
 drivers/mailbox/pcc.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c
index 45d85ae..8f779a1 100644
--- a/drivers/mailbox/pcc.c
+++ b/drivers/mailbox/pcc.c
@@ -81,16 +81,10 @@ static struct mbox_controller pcc_mbox_ctrl = {};
  */
 static struct mbox_chan *get_pcc_channel(int id)
 {
-	struct mbox_chan *pcc_chan;
-
 	if (id < 0 || id > pcc_mbox_ctrl.num_chans)
 		return ERR_PTR(-ENOENT);
 
-	pcc_chan = (struct mbox_chan *)
-		(unsigned long) pcc_mbox_channels +
-		(id * sizeof(*pcc_chan));
-
-	return pcc_chan;
+	return &pcc_mbox_channels[id];
 }
 
 /**
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1288788

FromAshwin Chaugule <ashwin.chaugule@linaro.org>
Date2015-12-10 19:20 +0100
Message-ID<qEdYT-1hY-33@gated-at.bofh.it>
In reply to#1288713
On 10 December 2015 at 12:28, Alexey Klimov <alexey.klimov@arm.com> wrote:
> This patch fixes the calculation of pcc_chan for non-zero id.
> After the compiler ignores the (unsigned long) cast the
> pcc_mbox_channels pointer is type-cast and then the type-cast
> offset is added which results in address outside of the range
> leading to the kernel crashing.
>
> We might add braces and make it:
>
> pcc_chan = (struct mbox_chan *)
>                 ((unsigned long) pcc_mbox_channels +
>                 (id * sizeof(*pcc_chan)));
>
> but let's go with array approach here and use id as index.
>
> Tested on Juno board.
>
> Acked-by: Sudeep Holla <sudeep.holla@arm.com>
> Signed-off-by: Alexey Klimov <alexey.klimov@arm.com>
> ---
>  drivers/mailbox/pcc.c | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)
>
> diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c
> index 45d85ae..8f779a1 100644
> --- a/drivers/mailbox/pcc.c
> +++ b/drivers/mailbox/pcc.c
> @@ -81,16 +81,10 @@ static struct mbox_controller pcc_mbox_ctrl = {};
>   */
>  static struct mbox_chan *get_pcc_channel(int id)
>  {
> -       struct mbox_chan *pcc_chan;
> -
>         if (id < 0 || id > pcc_mbox_ctrl.num_chans)
>                 return ERR_PTR(-ENOENT);
>
> -       pcc_chan = (struct mbox_chan *)
> -               (unsigned long) pcc_mbox_channels +
> -               (id * sizeof(*pcc_chan));
> -
> -       return pcc_chan;
> +       return &pcc_mbox_channels[id];
>  }
>


Strange that we didn't catch this even with a non-zero id. But the
change makes sense so..

Acked-by: Ashwin Chaugule <ashwin.chaugule@linaro.org>

Thanks,
Ashwin.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web