Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp563228pxp; Wed, 9 Mar 2022 08:14:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJwn8W/nCz08fp2703FZup6Ukdvzr87sY2SDDY2e6Sc9Vm69MeP9bQPQ5ub6+YuhDuJrk7Yb X-Received: by 2002:a50:ee05:0:b0:413:7c4b:c677 with SMTP id g5-20020a50ee05000000b004137c4bc677mr160009eds.251.1646842463841; Wed, 09 Mar 2022 08:14:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646842463; cv=none; d=google.com; s=arc-20160816; b=FyBryC3NhpGR29kmdmZGhxf3mvEalvcBCLfoz7GRdw7XCzaOOZpnBTaKVhU6JZ5C5Z 03jBCDsJOokg0VS85Ok3HzT0k3p23sXCOFGsxrxeq+q2ugr91DC44n1OOGf6McYQ7w/+ 1vp/M8nS+G5X981jkPcMnlH9UH51FEsNejyG7seQKXPMIiihWpiaR3iVwyQTEneRVKj+ NI9tCwutauN69AANqs9lp7EE5po/zO0Msi51xEj8WHAEhNRydm3Pr+UMial7zvWEawxn UOtBdHuMpHZaShgn/sjxHaB8cQG9r0GFNhIax1IudxHc5FxVnNd1t41iN0M/jZhyk3a9 gVIA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=79aUx1c7CPT8LgoaiDSdBrkYa0kTdsJauFmLg37A0L0=; b=PLBPA3IbpR75YHB51TXPzSBjEpLkwEEDqY699pGYNf6fbDikRa5rQ24KK/YdE1tMSN Qw+TyFrwxfTx0uLuLxiGAYnUyu0zkoZMqSQmoZUOWP1jKPAJm8IEZebeuE8NuXqizuz8 Hi69adro5BMDZ/L6OPR+bgkc8SScsbGLgOyEN506Oncs9mDmV3D+I5gDa1Hajl4Ph6Dp q2yhki2oREf0A/KpCzzG3es61S9lAKj5iM/jVIKSjGai9rEQcPhj4emAZGRujgwJquzh zXBRNktrHrwURsl7x3Xe3biKTc4nn54UPusR4J6IFL3Wh1FUM+87Gc2iWXG6/rLI0kVl k/5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=VoPwc4VT; 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=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s5-20020a170906a18500b006d0a2c1bbe7si1498803ejy.944.2022.03.09.08.14.00; Wed, 09 Mar 2022 08:14:23 -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=@163.com header.s=s110527 header.b=VoPwc4VT; 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=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232507AbiCIMUJ (ORCPT + 99 others); Wed, 9 Mar 2022 07:20:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbiCIMUH (ORCPT ); Wed, 9 Mar 2022 07:20:07 -0500 Received: from mail-m972.mail.163.com (mail-m972.mail.163.com [123.126.97.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B617312F404; Wed, 9 Mar 2022 04:19:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=79aUx 1c7CPT8LgoaiDSdBrkYa0kTdsJauFmLg37A0L0=; b=VoPwc4VTZ8G5D9wgi9/jX JBS9L4MPrTsSb+8aAfvIYuOaRWQY3t7wSBgCx2n7Yo3BYEeUCzPdQ6KRn2iddndf tJBmSaInX5oCUmZ/JC92qIahUdUPMrMvymtXuH8Y7g7av/4+YVUJtGNvMLptDPEC N8AcFML5UuZnbc5fMsr6Mg= Received: from localhost.localdomain (unknown [218.106.182.227]) by smtp2 (Coremail) with SMTP id GtxpCgDXZW4TmyhiJ7pvBA--.12980S4; Wed, 09 Mar 2022 20:18:35 +0800 (CST) From: Jianglei Nie To: davem@davemloft.net, kuba@kernel.org, caihuoqing@baidu.com, andrew@lunn.ch Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH v2] net: arc_emac: Fix use after free in arc_mdio_probe() Date: Wed, 9 Mar 2022 20:18:24 +0800 Message-Id: <20220309121824.36529-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GtxpCgDXZW4TmyhiJ7pvBA--.12980S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kr4fXFWUKFW7KFyrCFyrCrg_yoW8Xw4xpa yUu3srA3s2qw1UKF4kAay0v343tayrJryj9FyIvws0qw15Zr1fGrW7KFWq9w1UKF4qkF1a qa1xZFyrAFZ8JwUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zR4E_iUUUUU= X-Originating-IP: [218.106.182.227] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiDxu+jFUMb4IN1gAAsJ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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 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 putting the name in a local variable and make the bus->name point to the rodata section "name",then use the name in the error message without referring to bus 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..87f40c2ba904 100644 --- a/drivers/net/ethernet/arc/emac_mdio.c +++ b/drivers/net/ethernet/arc/emac_mdio.c @@ -132,6 +132,7 @@ int arc_mdio_probe(struct arc_emac_priv *priv) { struct arc_emac_mdio_bus_data *data = &priv->bus_data; struct device_node *np = priv->dev->of_node; + const char *name = "Synopsys MII Bus"; struct mii_bus *bus; int error; @@ -142,7 +143,7 @@ int arc_mdio_probe(struct arc_emac_priv *priv) priv->bus = bus; bus->priv = priv; bus->parent = priv->dev; - bus->name = "Synopsys MII Bus"; + bus->name = name; bus->read = &arc_mdio_read; bus->write = &arc_mdio_write; bus->reset = &arc_mdio_reset; @@ -167,7 +168,7 @@ int arc_mdio_probe(struct arc_emac_priv *priv) if (error) { mdiobus_free(bus); return dev_err_probe(priv->dev, error, - "cannot register MDIO bus %s\n", bus->name); + "cannot register MDIO bus %s\n", name); } return 0; -- 2.25.1