Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1574848pxp; Sun, 20 Mar 2022 23:04:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyImBuJwpquQqGN7rhmjuKs4PZf1AmAqSDrh+gzGAZEEBeD2+9raRvBYcq74u9s64HugyZ9 X-Received: by 2002:a17:906:79c4:b0:6cf:5489:da57 with SMTP id m4-20020a17090679c400b006cf5489da57mr19027273ejo.48.1647842648682; Sun, 20 Mar 2022 23:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647842648; cv=none; d=google.com; s=arc-20160816; b=lc/LJ9d7E7Xuy+EfNBcUuocrcrGB8nkj7Kfnjn7w9v9BIaK3pFTNVIFUqIIyYqRr7Q zUU+7oGzP3cD++S6GtgObneNBCsLJQfskAXpWvkiyz8B1gj8LMWly1iBYLbG8ZNCvA5n M5DJ7oUrML40qgmplQb31m2WbeLK4iEURQXP9dAQd5fuuOyWn4C1Wjzy38p3eFhwhs7L cSFW/mBzCGmZY8Xho+pHQ54BoJOw8k+BCc56hHoBNBLO7yLROa6O6IJHkdg5fuQLgL2/ DJLP4BW4u1R5F+IpkGfKL6erftR3JopHT7ohn72QjO4UvvCFCgpIoiJeDhktG6OckMy/ g1yA== 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:date:subject:cc:to:from; bh=QRt5SoDCVZBA46z1fjmw+/BB91ZXwNfUgdOlev073h0=; b=c56cfDgE3Ah1h3Yj7fz+ZcO6nEvJOI0ozFModoVx/0QK1lBlJD7m3k15BGyx7LcV61 RsyBObbti34MdDdBvDlzTpjlo4V1MYkBnFnZALZRdfvzVyKfPsK+5UQs3UKSE6MogAgg jXna2zMcuJUze8bXx7RSBXsUKKNGTUUAxdwniK6nMPPTvvlt3IEhSjwTst4mtxX3qtUU Z4upSc2lggQepbfDAMcwPB8910ake0ZXdlNJ3ffZFhWdgRgMNhOHG48774SJZbTPWqQJ tWHMGKMuEiPrGIdwXTQzqq+mcwetad4BzHy0FqhanDA2Ut1Z6lElcUcCkAoaMV+mkf3m 19FQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 28-20020a50875c000000b0041901f9db85si7699998edv.368.2022.03.20.23.03.42; Sun, 20 Mar 2022 23:04:08 -0700 (PDT) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242594AbiCSJgS (ORCPT + 99 others); Sat, 19 Mar 2022 05:36:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234179AbiCSJgR (ORCPT ); Sat, 19 Mar 2022 05:36:17 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 538FC274296; Sat, 19 Mar 2022 02:34:56 -0700 (PDT) Received: from canpemm500006.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KLG036wLQzfYl1; Sat, 19 Mar 2022 17:33:23 +0800 (CST) Received: from localhost.localdomain (10.175.104.82) by canpemm500006.china.huawei.com (7.192.105.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Sat, 19 Mar 2022 17:34:54 +0800 From: Ziyang Xuan To: , , , CC: , , Subject: [PATCH net-next v3 1/3] net: ipvlan: fix potential UAF problem for phy_dev Date: Sat, 19 Mar 2022 17:52:37 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500006.china.huawei.com (7.192.105.130) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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 There is a known scenario can trigger UAF problem for lower netdevice as following: Someone module puts the NETDEV_UNREGISTER event handler to a work, and lower netdevice is accessed in the work handler. But when the work is excuted, lower netdevice has been destroyed because upper netdevice did not get reference to lower netdevice correctly. Although it can not happen for ipvlan now because there is no way to access phy_dev outside ipvlan. But it is necessary to add the reference operation to phy_dev to avoid the potential UAF problem in the future. Signed-off-by: Ziyang Xuan --- drivers/net/ipvlan/ipvlan_main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c index 696e245f6d00..dcdc01403f22 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c @@ -158,6 +158,10 @@ static int ipvlan_init(struct net_device *dev) } port = ipvlan_port_get_rtnl(phy_dev); port->count += 1; + + /* Get ipvlan's reference to phy_dev */ + dev_hold(phy_dev); + return 0; } @@ -665,6 +669,14 @@ void ipvlan_link_delete(struct net_device *dev, struct list_head *head) } EXPORT_SYMBOL_GPL(ipvlan_link_delete); +static void ipvlan_dev_free(struct net_device *dev) +{ + struct ipvl_dev *ipvlan = netdev_priv(dev); + + /* Get rid of the ipvlan's reference to phy_dev */ + dev_put(ipvlan->phy_dev); +} + void ipvlan_link_setup(struct net_device *dev) { ether_setup(dev); @@ -674,6 +686,7 @@ void ipvlan_link_setup(struct net_device *dev) dev->priv_flags |= IFF_UNICAST_FLT | IFF_NO_QUEUE; dev->netdev_ops = &ipvlan_netdev_ops; dev->needs_free_netdev = true; + dev->priv_destructor = ipvlan_dev_free; dev->header_ops = &ipvlan_header_ops; dev->ethtool_ops = &ipvlan_ethtool_ops; } -- 2.25.1