mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: "Alvin Šipraga" <alsi@bang-olufsen.dk>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Vladimir Oltean" <olteanv@gmail.com>,
	"Luiz Angelo Daros de Luca" <luizluca@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	kernel@pengutronix.de, "Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net 1/2] net: dsa: realtek: fix out-of-bounds access
Date: Wed, 15 Mar 2023 16:34:38 +0100	[thread overview]
Message-ID: <23ced57d-27d5-4faa-70bb-9732a357a3cc@pengutronix.de> (raw)
In-Reply-To: <CACRpkdbowrfYZpNKA32S8GT=8x_h+ZW4gd2Kj6FZkP1SZmDEPw@mail.gmail.com>

Hi Linus,

On 15.03.23 14:15, Linus Walleij wrote:
> On Wed, Mar 15, 2023 at 2:09 PM Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:
> 
>> The probe function sets priv->chip_data to (void *)priv + sizeof(*priv)
>> with the expectation that priv has enough trailing space.
>>
>> However, only realtek-smi actually allocated this chip_data space.
>> Do likewise in realtek-mdio to fix out-of-bounds accesses.
>>
>> Fixes: aac94001067d ("net: dsa: realtek: add new mdio interface for drivers")
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> 
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Thanks for the review.
 
> That this worked for so long is kind of scary, and the reason why we run Kasan
> over so much code, I don't know if Kasan would have found this one.

It still worked. I looked into it some more and for some reason, struct realtek_priv
has a char buf[4096] member that's unused. I assume it caused kmalloc to return a 8K
slab, where the out-of-bound writes didn't overwrite anything of value. That buffer
ought to be removed, but that's for net-next.

I just checked with KASAN and it does detect the OOB on ARM64. I first noticed the
bug on barebox though, which has a near verbatim port of the Linux driver, but a
TLSF allocator, which fits allocations more tightly, hence it crashes not long
after driver probe unlike Linux.

> Rewriting the whole world in Rust will fix this problem, but it will
> take a while...

^^'.

Cheers,
Ahmad



> 
> Yours,
> Linus Walleij
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


  reply	other threads:[~2023-03-15 15:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-15 13:09 Ahmad Fatoum
2023-03-15 13:09 ` [PATCH net 2/2] net: dsa: realtek: fix missing new lines in error messages Ahmad Fatoum
2023-03-15 13:16   ` Linus Walleij
2023-03-15 13:21   ` Alvin Šipraga
2023-03-15 20:22   ` Florian Fainelli
2023-03-17  4:05   ` Jakub Kicinski
2023-03-22 15:47     ` Ahmad Fatoum
2023-03-15 13:15 ` [PATCH net 1/2] net: dsa: realtek: fix out-of-bounds access Linus Walleij
2023-03-15 15:34   ` Ahmad Fatoum [this message]
2023-03-15 13:21 ` Alvin Šipraga
2023-03-15 13:30 ` Andrew Lunn
2023-03-15 13:35   ` Ahmad Fatoum
2023-03-15 13:45     ` Andrew Lunn
2023-03-15 20:22 ` Florian Fainelli
2023-03-16 17:41 ` Luiz Angelo Daros de Luca
2023-03-17  4:07 ` Jakub Kicinski
2023-03-22 15:51   ` Ahmad Fatoum
2023-03-22 18:21     ` Jakub Kicinski

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=23ced57d-27d5-4faa-70bb-9732a357a3cc@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=alsi@bang-olufsen.dk \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luizluca@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    /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

all inboxes | Powered by JetHome®