linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars Povlsen <lars.povlsen@microchip.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Lars Povlsen <lars.povlsen@microchip.com>,
	Steen Hegelund <Steen.Hegelund@microchip.com>,
	<UNGLinuxDriver@microchip.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-gpio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-hardening@vger.kernel.org>
Subject: Re: [REPORT][next] pinctrl: pinctrl-microchip-sgpio: out-of-bounds bug in sgpio_clrsetbits()
Date: Wed, 3 Feb 2021 13:00:47 +0100	[thread overview]
Message-ID: <87o8h1uzrk.fsf@microchip.com> (raw)
In-Reply-To: <20210202113423.GA277746@embeddedor>


Gustavo A. R. Silva writes:

> Hi,
>
> While addressing some out-of-bounds warnings, I found the following bug:
>
> drivers/pinctrl/pinctrl-microchip-sgpio.c:154:57: warning: array subscript 10 is above array bounds of ‘const u8[10]’ {aka ‘const unsigned char[10]’} [-Warray-bounds]
>
> The bug was introduced by commit be2dc859abd4 ("pinctrl: pinctrl-microchip-sgpio: Add irq support (for sparx5)"):
>
> 575         sgpio_clrsetbits(bank->priv, REG_INT_TRIGGER + SGPIO_MAX_BITS, addr.bit,
> 576                          BIT(addr.port), (!!(type & 0x2)) << addr.port);
>
> REG_INT_TRIGGER + SGPIO_MAX_BITS turns out to be 10, which is outside the boundaries
> of priv->properties->regoff[] at line 154:

Hi Gustavo!

Thanks for spotting this - the "+" is misplaced. I will submit a patch
asap.

Cheers,

---Lars

>
> 151 static inline void sgpio_clrsetbits(struct sgpio_priv *priv,
> 152                                     u32 rno, u32 off, u32 clear, u32 set)
> 153 {
> 154         u32 __iomem *reg = &priv->regs[priv->properties->regoff[rno] + off];
> 155         u32 val = readl(reg);
> 156
> 157         val &= ~clear;
> 158         val |= set;
> 159
> 160         writel(val, reg);
> 161 }
>
> because priv->properties->regoff[] is an array of MAXREG elements, with MAXREG
> representing the value of 10 in the following enum:
>
>  28 enum {
>  29         REG_INPUT_DATA,
>  30         REG_PORT_CONFIG,
>  31         REG_PORT_ENABLE,
>  32         REG_SIO_CONFIG,
>  33         REG_SIO_CLOCK,
>  34         REG_INT_POLARITY,
>  35         REG_INT_TRIGGER,
>  36         REG_INT_ACK,
>  37         REG_INT_ENABLE,
>  38         REG_INT_IDENT,
>  39         MAXREG
>  40 };
>
>  52 struct sgpio_properties {
>  53         int arch;
>  54         int flags;
>  55         u8 regoff[MAXREG];
>  56 };
>
> Thanks


-- 
Lars Povlsen,
Microchip

      reply	other threads:[~2021-02-03 12:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02 11:34 [REPORT][next] pinctrl: pinctrl-microchip-sgpio: out-of-bounds bug in sgpio_clrsetbits() Gustavo A. R. Silva
2021-02-03 12:00 ` Lars Povlsen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o8h1uzrk.fsf@microchip.com \
    --to=lars.povlsen@microchip.com \
    --cc=Steen.Hegelund@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=gustavoars@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).