From patchwork Wed Feb 9 08:19:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 12739754 X-Patchwork-Delegate: kuba@kernel.org 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 C8DE9C433FE for ; Wed, 9 Feb 2022 08:20:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240664AbiBIIUF (ORCPT ); Wed, 9 Feb 2022 03:20:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239476AbiBIIT4 (ORCPT ); Wed, 9 Feb 2022 03:19:56 -0500 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F166BC05CB82 for ; Wed, 9 Feb 2022 00:19:59 -0800 (PST) Received: by mail-qv1-xf35.google.com with SMTP id p7so1183980qvk.11 for ; Wed, 09 Feb 2022 00:19:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7ugFbCfvGmcJBACcTLS7UCyTobcismt6IcYHAvw06J0=; b=D1+gYjmSJPm0d+dtsurtz6DimxuYq4Nihia6kLEgLKfZ6oWSHyzk0cvjgM8rfzzZCQ rDXVaEk9du4iP5oTBrl2wPNh6csdpDfNlcwRPlf3pLiQsCAFVo7FO2X6wyiKDvCZCoD8 8Kxrm7a/SfdnJ0VOlcP5dVNbEROZwK5zM/o41Edg3phIn+JMxKwaLeHT7XfRNzqkbUtF uK43suNyA0d6+shErcLzKIenjS5u4NBPnPkFKlkdFLsbHz+byqtMUsEUuCEAtx9Hxjdp GGxIt5zGXEC4EbLOuwF4XtKeP2CNcO//fAcu4FYnVmHfPaPB69czLSAXYyDXr/34DNaz 4gFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7ugFbCfvGmcJBACcTLS7UCyTobcismt6IcYHAvw06J0=; b=ja/2dN6wma5oFsKpuodiq0gsXk0537gjyK+/nchNSiWp9tI7uL4Low+IIZUVv9hu1c WXltQupYQ0ZBo5SucbcuegRwb2ZDJ18OJwHvu+CBGvn+T0ZSjlQODZBnj+UDMRyzO9KX Ci5zc2CfiDbIJh5Zp3Kc5T6jtvjGZGrOk0CBST4xfo5Ft5184bGsYEjYkXkuskMbmeT2 rSeO4dBQvHMalkg77xayzRSuqM0QkhNm+0V/k70x6D25FQVAv79ktXcUOFAS54lTUUt5 nCzYb8ayfVMIjb3WGFgQ6fxxA0FCgck/455Uc0cMCobQ+g/5xbbVMTJ+mn7SN5Ex3tNu Bf+g== X-Gm-Message-State: AOAM53250ET384eWiCo96f7gdOpUJY6yVT/pw4+KyHEMuhayy/qLsiFp qjeV2IyaYUd+Nuvl0v9514lhVV2GmiqtjQ== X-Google-Smtp-Source: ABdhPJzHS7IQBDnfOIbDBSpIs7wnk3tHRvSEWS7b85QQaCIbo4E7YLa//J6Bl4tU6rilT7TOWbo89w== X-Received: by 2002:a05:6214:5298:: with SMTP id kj24mr712104qvb.67.1644394798962; Wed, 09 Feb 2022 00:19:58 -0800 (PST) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id x18sm8837717qta.57.2022.02.09.00.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 00:19:58 -0800 (PST) From: Xin Long To: network dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Ziyang Xuan Subject: [PATCH net 1/2] vlan: introduce vlan_dev_free_egress_priority Date: Wed, 9 Feb 2022 03:19:55 -0500 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This patch is to introduce vlan_dev_free_egress_priority() to free egress priority for vlan dev, and keep vlan_dev_uninit() static as .ndo_uninit. It makes the code more clear and safer when adding new code in vlan_dev_uninit() in the future. Signed-off-by: Xin Long --- net/8021q/vlan.h | 2 +- net/8021q/vlan_dev.c | 7 ++++++- net/8021q/vlan_netlink.c | 7 ++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h index 1a705a4ef7fa..5eaf38875554 100644 --- a/net/8021q/vlan.h +++ b/net/8021q/vlan.h @@ -129,6 +129,7 @@ void vlan_dev_set_ingress_priority(const struct net_device *dev, u32 skb_prio, u16 vlan_prio); int vlan_dev_set_egress_priority(const struct net_device *dev, u32 skb_prio, u16 vlan_prio); +void vlan_dev_free_egress_priority(const struct net_device *dev); int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask); void vlan_dev_get_realdev_name(const struct net_device *dev, char *result, size_t size); @@ -139,7 +140,6 @@ int vlan_check_real_dev(struct net_device *real_dev, void vlan_setup(struct net_device *dev); int register_vlan_dev(struct net_device *dev, struct netlink_ext_ack *extack); void unregister_vlan_dev(struct net_device *dev, struct list_head *head); -void vlan_dev_uninit(struct net_device *dev); bool vlan_dev_inherit_address(struct net_device *dev, struct net_device *real_dev); diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index 26d031a43cc1..e5d23e75572a 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -622,7 +622,7 @@ static int vlan_dev_init(struct net_device *dev) } /* Note: this function might be called multiple times for the same device. */ -void vlan_dev_uninit(struct net_device *dev) +void vlan_dev_free_egress_priority(const struct net_device *dev) { struct vlan_priority_tci_mapping *pm; struct vlan_dev_priv *vlan = vlan_dev_priv(dev); @@ -636,6 +636,11 @@ void vlan_dev_uninit(struct net_device *dev) } } +static void vlan_dev_uninit(struct net_device *dev) +{ + vlan_dev_free_egress_priority(dev); +} + static netdev_features_t vlan_dev_fix_features(struct net_device *dev, netdev_features_t features) { diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c index 0db85aeb119b..53b1955b027f 100644 --- a/net/8021q/vlan_netlink.c +++ b/net/8021q/vlan_netlink.c @@ -183,10 +183,11 @@ static int vlan_newlink(struct net *src_net, struct net_device *dev, return -EINVAL; err = vlan_changelink(dev, tb, data, extack); - if (!err) - err = register_vlan_dev(dev, extack); if (err) - vlan_dev_uninit(dev); + return err; + err = register_vlan_dev(dev, extack); + if (err) + vlan_dev_free_egress_priority(dev); return err; } From patchwork Wed Feb 9 08:19:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 12739753 X-Patchwork-Delegate: kuba@kernel.org 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 8A25BC433F5 for ; Wed, 9 Feb 2022 08:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240831AbiBIIUE (ORCPT ); Wed, 9 Feb 2022 03:20:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240664AbiBIIT4 (ORCPT ); Wed, 9 Feb 2022 03:19:56 -0500 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3888C05CB85 for ; Wed, 9 Feb 2022 00:20:00 -0800 (PST) Received: by mail-qk1-x735.google.com with SMTP id 200so1035428qki.2 for ; Wed, 09 Feb 2022 00:20:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fXXsTLbqQsfurYNa2/nCRcydix2xehGGYSxX54I0elE=; b=j/OwUWTc9AaNmdnhrADamQj29YnwGmw0BC/zVLA6zuiqHc68kjvlZPM1DVFVzTlnAi hi7xqTkzMYBMbY0I2ZANuKQ3O7Hdq59LFMnVMZF8KR3I14f97Gdf+uEGAXP9DpO6+5mC i0oQfrbeXy0okdZYzHiSXZ29iBUUeJBN6Uj99nqjFYvNW2ZvWC3Mdy44XTqj3VsduZOa R5nmPKUCfW9V+uBONxVNRSZPF/OwcfyxJfxewXjEm1hFsPLkUT6vU0I8ctiBliB0hQ/V q3i95cyVu/8yodl8s/Rdnmp61dFTrEJKQldwTWVGEt+qUYmM3ns1euVYiOdEuSvKCIw0 09aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fXXsTLbqQsfurYNa2/nCRcydix2xehGGYSxX54I0elE=; b=fzcprgqH9HDkKoxU+6gU+Sk/avzV7oeBXo0yhVI90nd+gM7BV5rTLWIo4n7UqcV75+ fNjTQNgpijOOWROdjO3taYfToA8Lf1Tur3RISuq31CiXnj21mCMtsbQ8vUw9SE/OuB8S QMGQoY8Ktr0UBIAyNzDhzm0/4pKPpnVxiN2zomoCV8snBBchmiYwtxCrj2dZYfHBG9qo xzQhIXIFASWpmOL9OxUqrJcyglRhT3cvWxCnLEyIgpeFkG45XvqeEgNke0N1OUxyAaDl 4Z5XfLbplO7yME0BJAzI+JjQTEVMX/pqQJjxBuLXOs5Qpn7trAT8PgS0bv/+9fXNMsrO KATQ== X-Gm-Message-State: AOAM530IorugyHbH5VHT83jpma/Dg8DaNTeIW9pbMfD2nclQ02UxADyT cIYY3T4BA7akdVX1PXEMtgL5wB6lCByF0A== X-Google-Smtp-Source: ABdhPJyxUOaE1hZO7g/0GyImXH4KDRZRZqKFMpnDSP0RpLmtTpaAOXBMq1hU61cOUSANb6jooAtUsw== X-Received: by 2002:a05:620a:854:: with SMTP id u20mr465157qku.716.1644394799753; Wed, 09 Feb 2022 00:19:59 -0800 (PST) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id x18sm8837717qta.57.2022.02.09.00.19.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 00:19:59 -0800 (PST) From: Xin Long To: network dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Ziyang Xuan Subject: [PATCH net 2/2] vlan: move dev_put into vlan_dev_uninit Date: Wed, 9 Feb 2022 03:19:56 -0500 Message-Id: <76c52badfdccaa7f094d959eaf24f422ae09dec6.1644394642.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Shuang Li reported an QinQ issue by simply doing: # ip link add dummy0 type dummy # ip link add link dummy0 name dummy0.1 type vlan id 1 # ip link add link dummy0.1 name dummy0.1.2 type vlan id 2 # rmmod 8021q unregister_netdevice: waiting for dummy0.1 to become free. Usage count = 1 When rmmods 8021q, all vlan devs are deleted from their real_dev's vlan grp and added into list_kill by unregister_vlan_dev(). dummy0.1 is unregistered before dummy0.1.2, as it's using for_each_netdev() in __rtnl_kill_links(). When unregisters dummy0.1, dummy0.1.2 is not unregistered in the event of NETDEV_UNREGISTER, as it's been deleted from dummy0.1's vlan grp. However, due to dummy0.1.2 still holding dummy0.1, dummy0.1 will keep waiting in netdev_wait_allrefs(), while dummy0.1.2 will never get unregistered and release dummy0.1, as it delays dev_put until calling dev->priv_destructor, vlan_dev_free(). This issue was introduced by Commit 563bcbae3ba2 ("net: vlan: fix a UAF in vlan_dev_real_dev()"), and this patch is to fix it by moving dev_put() into vlan_dev_uninit(), which is called after NETDEV_UNREGISTER event but before netdev_wait_allrefs(). Fixes: 563bcbae3ba2 ("net: vlan: fix a UAF in vlan_dev_real_dev()") Reported-by: Shuang Li Signed-off-by: Xin Long --- net/8021q/vlan_dev.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index e5d23e75572a..d1902828a18a 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -638,7 +638,12 @@ void vlan_dev_free_egress_priority(const struct net_device *dev) static void vlan_dev_uninit(struct net_device *dev) { + struct vlan_dev_priv *vlan = vlan_dev_priv(dev); + vlan_dev_free_egress_priority(dev); + + /* Get rid of the vlan's reference to real_dev */ + dev_put_track(vlan->real_dev, &vlan->dev_tracker); } static netdev_features_t vlan_dev_fix_features(struct net_device *dev, @@ -851,9 +856,6 @@ static void vlan_dev_free(struct net_device *dev) free_percpu(vlan->vlan_pcpu_stats); vlan->vlan_pcpu_stats = NULL; - - /* Get rid of the vlan's reference to real_dev */ - dev_put_track(vlan->real_dev, &vlan->dev_tracker); } void vlan_setup(struct net_device *dev)