Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp376671pxm; Wed, 2 Mar 2022 17:46:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJzqnRboIjxfX4ceeEa49IhpF2E0ngnsyKnxh3fvjJQroMxN6+cdRK/CJAczflAPkSZ+F0Ni X-Received: by 2002:a17:903:1246:b0:151:94d9:eeb2 with SMTP id u6-20020a170903124600b0015194d9eeb2mr7059096plh.165.1646271975744; Wed, 02 Mar 2022 17:46:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646271975; cv=none; d=google.com; s=arc-20160816; b=cfcsn85GlIc3WlqUMv4fYi6vQN2OogatLAZhM9L19wA+BzxcCjfvvnWqqIKlCm/8RL b4dFGGLVyEyTLdPdTxfrB03DmxWZuL3hG3u2Gz+M36c8m/bprr4R88Q/563bWK+KqvgY ei+guvDpzsZ7n4+bivuHeDcgI2yKmqtZ/AJqYcX8blDsI2D+Scd2Tt2cq2yoNtMTPlNG CdpkOIsBSMH/Gpsq6qr3Asj7qSfjmLXcmJOWgW7jVX4lwahziPel+UDxJPKvbLIMK/UH BaRsywAf/xyrCVh489s5Y1OR1+JTk1rjRHJI0cCZK2Az02GiWTIvDL/Tqwe45YrmPmdS SKhQ== 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=XAi7Dk9Yg7EF/mSMo8raLyxYjVznmUNk90i0YbDYo5A=; b=Gfg5blAypspeHZpvMR4fBYhOA9P3GF9lnP3fIn5P+abG8a14EPNNIQcSC/ioQw/J07 RbTn4+RLTk0Ddj3lp14xgKItGGKHMp2F8xa9TWzOeWgPB7/O3nzt0coJuJEsGrDTrKkE q8GC7+HRDZTvNVA7jLUles5QuNyzlZDMZYafqOHbwV7739Pw39E6/2+FBYwLnw3gqJ+u gALHG9jvQXu4AgqsHCrPti/L2upiT24naXgW/EArQwcT+NG6lxiy1Ls/uI5mA19QdmCE Ltcnv2sG+3Fw+Mz3wB8gyKb4MFOW4SAPUTigB4I4C1c3YzHsXXsjgoQRHNQtyfGiN8DN yk8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="ZEmq/qzr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m3-20020a170902db0300b0014fc38b33b7si731885plx.400.2022.03.02.17.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 17:46:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="ZEmq/qzr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BF5781B6E32; Wed, 2 Mar 2022 17:46:13 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231474AbiCCBqz (ORCPT + 99 others); Wed, 2 Mar 2022 20:46:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231445AbiCCBqx (ORCPT ); Wed, 2 Mar 2022 20:46:53 -0500 X-Greylist: delayed 914 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 02 Mar 2022 17:46:07 PST Received: from mail-m974.mail.163.com (mail-m974.mail.163.com [123.126.97.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 67AC21B6E18; Wed, 2 Mar 2022 17:46: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=XAi7D k9Yg7EF/mSMo8raLyxYjVznmUNk90i0YbDYo5A=; b=ZEmq/qzrJtrY9zC207PgZ REzIQycl5G5Qj/X4NlmoD0WDcQJJIo/2XwUaDq+pebvUyOZ0q/RK6IWhS58FaZaj NLHKooZXW2WFd1/q87NjPrpNq51uyfD7UAx3EZeW/lM1eAo2Q/pFkztOqoXHwAnJ FqL/lfJ8JYmk+SV6qQxKps= Received: from localhost.localdomain (unknown [218.106.182.227]) by smtp4 (Coremail) with SMTP id HNxpCgBnPKQzGiBi+_cuEw--.7369S4; Thu, 03 Mar 2022 09:30:37 +0800 (CST) From: Jianglei Nie To: davem@davemloft.net, kuba@kernel.org, caihuoqing@baidu.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH] net: arc_emac: Fix use after free in arc_mdio_probe() Date: Thu, 3 Mar 2022 09:30:22 +0800 Message-Id: <20220303013022.459154-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: HNxpCgBnPKQzGiBi+_cuEw--.7369S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7Gw45KFyDGF47urW7GrW3Wrg_yoWDZFgE9w 18Za43Jw43tr90gw4j9F4ayryvk3yUXrs3uF4fKr9xAr9rCr47X3WkuF93Jr1kuws2qF9I qayayrW7u348KjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xREzuWtUUUUU== X-Originating-IP: [218.106.182.227] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiQx24jFc7XpwVewAAsq X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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); + mdiobus_free(bus); + return dev_err; } return 0; -- 2.25.1