Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FC23C7618D for ; Wed, 15 Mar 2023 15:35:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232591AbjCOPe7 (ORCPT ); Wed, 15 Mar 2023 11:34:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232830AbjCOPex (ORCPT ); Wed, 15 Mar 2023 11:34:53 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AFDF48E35 for ; Wed, 15 Mar 2023 08:34:51 -0700 (PDT) Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=[127.0.0.1]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1pcT9G-0003vH-Kw; Wed, 15 Mar 2023 16:34:42 +0100 Message-ID: <23ced57d-27d5-4faa-70bb-9732a357a3cc@pengutronix.de> Date: Wed, 15 Mar 2023 16:34:38 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 From: Ahmad Fatoum Subject: Re: [PATCH net 1/2] net: dsa: realtek: fix out-of-bounds access To: Linus Walleij Cc: =?UTF-8?Q?Alvin_=c5=a0ipraga?= , Andrew Lunn , Florian Fainelli , Vladimir Oltean , Luiz Angelo Daros de Luca , "David S. Miller" , kernel@pengutronix.de, Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230315130917.3633491-1-a.fatoum@pengutronix.de> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: a.fatoum@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Linus, On 15.03.23 14:15, Linus Walleij wrote: > On Wed, Mar 15, 2023 at 2:09 PM Ahmad Fatoum 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 > > Reviewed-by: Linus Walleij 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 |