Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1014069pxm; Thu, 3 Mar 2022 08:42:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsiDAwNM0UQapMSYSyHL6T8wP8P1pdDosEKryE6dFOm3eNyQ+UvCbFDIHi/ePp/ru4QMlQ X-Received: by 2002:a17:907:2d0b:b0:6da:9df0:499b with SMTP id gs11-20020a1709072d0b00b006da9df0499bmr1842191ejc.543.1646325734609; Thu, 03 Mar 2022 08:42:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646325734; cv=none; d=google.com; s=arc-20160816; b=tLhgpBBXueS+fw65lWhKWpwCTVvUrGMyQ0y+2NZ6nOQ966+20t18XiMDNiwYm695ab TEovcXebpsAjkgtfWFqsnQEO+GmqEvdbHEwW6pFsqKLkuXo5cFQL79oJXFMhEFQWN/So 6XS42f1T7889XElUkklrXS9h8U6rRQH4VFzPJPigwtJHv4VbzgPJtxq3I8nGFkFNzBwU LrQ0uhuUtA7N9RHn6c3NhEbjsa+1H0P0dhcT+yiXqJCI/GgXsl0yBk7Lf2FvPnmYdZ6l 8KDw5PtyGw7s6XHBYQwezeTh5ITc6m1vI70hBz3jJVSaEt6wSxpWoorh5zaboySBj2TZ oFzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=xjf7xcPnWoI0EmyQHNCO6i8JFgGrOiQy+SEC4WXwkvc=; b=vdwMF8u8kjpifQBED5kZuJiaxz4+EEcFB3PxiMOfHfPwFoplYwpjqP5+W31Ig0VrAY 0NpLXkiTJNvOPFAK6m23NpjlTySCBOEOl9XlrFfs5XoE7tdh37dJhAuplJNMmuHkAJGV OGwODNge8q7Xr0qMBB77zJMUDjxQKeGvvl5szM0d+6AIO8ljElQ66Shg1CxOw7IkhqZ5 CgzwUCUt0iEhsnariwZyiWQFEeNLnE8XkW/T5SxxOfGuPSlKGpKiEnRPtud7lY/U7v3i u641pfFdGgIWHLrsvHcDoRaYU8ywI77EK5KHv4xuOOwWyBjPGM9ymmmCXBRdUyDz5XKQ ub9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dUbzGqsH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb28-20020a1709077e9c00b006da8ab260f5si1873018ejc.1000.2022.03.03.08.41.51; Thu, 03 Mar 2022 08:42:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dUbzGqsH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234890AbiCCQF5 (ORCPT + 99 others); Thu, 3 Mar 2022 11:05:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234793AbiCCQFf (ORCPT ); Thu, 3 Mar 2022 11:05:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 150E8197B47; Thu, 3 Mar 2022 08:04:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A1D4F60C26; Thu, 3 Mar 2022 16:04:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF2ACC340F0; Thu, 3 Mar 2022 16:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646323488; bh=xd/ksvyLQUW2y1zrJT9Hnz3UCVLnr9jF+4S7+2ediM0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dUbzGqsHmw8LdiIS/pqHeFDLxIZ3w4fF0dNkjrebnIyE3t9g1p8j6KVDaNbnxLBAT xHkv8uTQlR+mtx2fLvJiokUpaXHBUJXcIMxxIbzT1Tvf+goMBhgVhBYw3LTb6WP0Fn 8WjtqPFkMFnS3BiNfuAS5DlLxkc+4xKzoqdhb2VmlK+ysxLlxNM/5sdWsAZOo1BopT DSIeN5JOe9T7UVtwdg3IpRs6G9wd5vw+jtSliYKkiRXq4N4i6xBJWlpCu02/GnxCod 4Iwc5VoLz7VURBChhGvHVjjDUgU/dEQbLUra42f1bOVJpes8fCdUJE6dEi4Ho0B4mn rUWR7vCmg1/Xg== Date: Thu, 3 Mar 2022 08:04:46 -0800 From: Jakub Kicinski To: Jianglei Nie Cc: davem@davemloft.net, caihuoqing@baidu.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] net: arc_emac: Fix use after free in arc_mdio_probe() Message-ID: <20220303080446.0acabae9@kicinski-fedora-PC1C0HJN.hsd1.ca.comcast.net> In-Reply-To: <20220303013022.459154-1-niejianglei2021@163.com> References: <20220303013022.459154-1-niejianglei2021@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 3 Mar 2022 09:30:22 +0800 Jianglei Nie wrote: > If bus->state is equal to MDIOBUS_ALLOCATED, mdiobus_free(bus) will free > the "bus". But bus->name is still used in the next line, which will lead > to a use after free. > > We can fix it by assigning dev_err_probe() to dev_err before the bus is > freed to avoid the uaf. > > Signed-off-by: Jianglei Nie > --- > drivers/net/ethernet/arc/emac_mdio.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/arc/emac_mdio.c b/drivers/net/ethernet/arc/emac_mdio.c > index 9acf589b1178..795a25c5848a 100644 > --- a/drivers/net/ethernet/arc/emac_mdio.c > +++ b/drivers/net/ethernet/arc/emac_mdio.c > @@ -165,9 +165,10 @@ int arc_mdio_probe(struct arc_emac_priv *priv) > > error = of_mdiobus_register(bus, priv->dev->of_node); > if (error) { > - mdiobus_free(bus); > - return dev_err_probe(priv->dev, error, > + int dev_err = dev_err_probe(priv->dev, error, > "cannot register MDIO bus %s\n", bus->name); Bus name is a constant please put it in a local variable: const char *name = "Synopsys MII Bus"; ... bus->name = name; and then you can use name in the error message without referring to bus. > + mdiobus_free(bus); > + return dev_err; > } > > return 0;