Linux-WPAN Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] ieee802154: mcr20a: read out of bounds in mcr20a_set_channel()
@ 2018-08-29 14:49 Dan Carpenter
       [not found] ` <CAJuUDwtjRi0HnR95uaFp4zviSC7Yrs68o8jsK1nY6jWu6909bg@mail.gmail.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2018-08-29 14:49 UTC (permalink / raw)
  To: Xue Liu
  Cc: Alexander Aring, Stefan Schmidt, David S. Miller, linux-wpan,
	netdev, kernel-janitors

The "channel" variable can be any u8 value.  We need to make sure we
don't read outside of the PLL_INT[] or PLL_FRAC[] arrays.

Fixes: 8c6ad9cc5157 ("ieee802154: Add NXP MCR20A IEEE 802.15.4 transceiver driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
This patch is obviously harmless, but it's from static analysis.  I'm
pretty sure this is required, but I can't swear.

diff --git a/drivers/net/ieee802154/mcr20a.c b/drivers/net/ieee802154/mcr20a.c
index e428277781ac..4f41d1d3588e 100644
--- a/drivers/net/ieee802154/mcr20a.c
+++ b/drivers/net/ieee802154/mcr20a.c
@@ -512,6 +512,9 @@ mcr20a_set_channel(struct ieee802154_hw *hw, u8 page, u8 channel)
 
 	dev_dbg(printdev(lp), "%s\n", __func__);
 
+	if (channel < 11 || channel - 11 >= ARRAY_SIZE(PLL_INT))
+		return -EINVAL;
+
 	/* freqency = ((PLL_INT+64) + (PLL_FRAC/65536)) * 32 MHz */
 	ret = regmap_write(lp->regmap_dar, DAR_PLL_INT0, PLL_INT[channel - 11]);
 	if (ret)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ieee802154: mcr20a: read out of bounds in mcr20a_set_channel()
       [not found] ` <CAJuUDwtjRi0HnR95uaFp4zviSC7Yrs68o8jsK1nY6jWu6909bg@mail.gmail.com>
@ 2018-08-30  7:54   ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2018-08-30  7:54 UTC (permalink / raw)
  To: Xue Liu
  Cc: alex. aring, Stefan Schmidt, David S. Miller, linux-wpan - ML,
	netdev, kernel-janitors

On Wed, Aug 29, 2018 at 07:50:51PM +0200, Xue Liu wrote:
> Hello Dan,
> 
> 
> On Wed, 29 Aug 2018 at 16:49, Dan Carpenter <dan.carpenter@oracle.com>
> wrote:
> 
> > The "channel" variable can be any u8 value.  We need to make sure we
> > don't read outside of the PLL_INT[] or PLL_FRAC[] arrays.
> >
> I think the “channel” variable can not be any u8 value. This values is
> already checked before set_channel function is called.
> https://github.com/torvalds/linux/blob/master/net/ieee802154/nl802154.c#L978

Oh...  Hm...  I should have reviewed more carefully.  This patch isn't
correct.  But there may still be a bug.  What Smatch is worried about is
the other call tree:

ieee802154_start_req() calls (struct ieee802154_mlme_ops)->start_req
  -> mac802154_mlme_start_req()
     -> mac802154_dev_set_page_channel()
        -> drv_set_channel() calls local->ops->set_channel(&local->hw, page, channel);
           -> mcr20a_set_channel()

So maybe we could move the check from nl802154_set_channel() to
drv_set_channel() so channel is checked on both call trees.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-29 14:49 [PATCH] ieee802154: mcr20a: read out of bounds in mcr20a_set_channel() Dan Carpenter
     [not found] ` <CAJuUDwtjRi0HnR95uaFp4zviSC7Yrs68o8jsK1nY6jWu6909bg@mail.gmail.com>
2018-08-30  7:54   ` Dan Carpenter

Linux-WPAN Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-wpan/0 linux-wpan/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-wpan linux-wpan/ https://lore.kernel.org/linux-wpan \
		linux-wpan@vger.kernel.org
	public-inbox-index linux-wpan

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-wpan


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git