From patchwork Thu Feb 6 08:46:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13962623 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52D36163 for ; Thu, 6 Feb 2025 08:47:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=72.21.196.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738831637; cv=none; b=GOS0HLRBWSsIYaoW42fpPc5MxOckq4i2fsv+1GABTqPIPB3NpqvhChrFsMNrgfAJZJZK1OFsO4QjbdvXHWVBqhCSqvfbn4r6vsZiTEETkEmnvgdRHcKMt1LHaFFBIH0IZz/wEDL0tMLyGpQFuuKupVg07oJ00GnbdPavp+3two0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738831637; c=relaxed/simple; bh=8RZzTG8rtcXyr68MzQhT4sPKAo+5B5l4WdGs51d+gUI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MI/I/uvMDAhBKv+4dkBfN7ICuGWII1IIlQdFWsk1rQ0sokFsAKXghZRKVhG7F/vv7gzE4WfDqIpmEh0c5fKgQ0KV03fs3VnFYTKaJY8N4R9GiGd+LLbKuy5UyYYXD3WHDxDVoBAdnW23nIAR0aUwOtumAARiLZWoQw4G2H8Gwpo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=Kqu1yH/3; arc=none smtp.client-ip=72.21.196.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="Kqu1yH/3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1738831635; x=1770367635; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KreelsqqXuYSTBodDgBhJaKjOuVIDvgqCwjcnSlBpP4=; b=Kqu1yH/3/RIJVXsi6XdID7ZCnsF6IcA/cjlOneg0cKdrYILx5toQafL7 sv4Kg+UQARDRa75dH+cF4tuW5eWItoc+J8l55uTkLXtLq0LyLaXVTx9ZM NowP7NFivdzAPS2b5feS0up+Q0t6CRsaG/sMEfRqNmwRwiDcoFCL7FrON o=; X-IronPort-AV: E=Sophos;i="6.13,264,1732579200"; d="scan'208";a="464546071" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2025 08:47:11 +0000 Received: from EX19MTAUWA001.ant.amazon.com [10.0.38.20:7709] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.4.10:2525] with esmtp (Farcaster) id 47bc56bb-968f-47b5-8be9-ddc079c5442e; Thu, 6 Feb 2025 08:47:10 +0000 (UTC) X-Farcaster-Flow-ID: 47bc56bb-968f-47b5-8be9-ddc079c5442e Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWA001.ant.amazon.com (10.250.64.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Thu, 6 Feb 2025 08:47:10 +0000 Received: from 6c7e67bfbae3.amazon.com (10.37.244.8) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Thu, 6 Feb 2025 08:47:07 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 1/6] fib: rules: Don't check net in rule_exists() and rule_find(). Date: Thu, 6 Feb 2025 17:46:24 +0900 Message-ID: <20250206084629.16602-2-kuniyu@amazon.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250206084629.16602-1-kuniyu@amazon.com> References: <20250206084629.16602-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D042UWA001.ant.amazon.com (10.13.139.92) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org fib_nl_newrule() / fib_nl_delrule() looks up struct fib_rules_ops in sock_net(skb->sk) and calls rule_exists() / rule_find() respectively. fib_nl_newrule() creates a new rule and links it to the found ops, so struct fib_rule never belongs to a different netns's ops->rules_list. Let's remove redundant netns check in rule_exists() and rule_find(). Signed-off-by: Kuniyuki Iwashima --- net/core/fib_rules.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c index e684ba3ebb38..02dfb841ab29 100644 --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c @@ -459,9 +459,6 @@ static struct fib_rule *rule_find(struct fib_rules_ops *ops, if (rule->tun_id && r->tun_id != rule->tun_id) continue; - if (r->fr_net != rule->fr_net) - continue; - if (rule->l3mdev && r->l3mdev != rule->l3mdev) continue; @@ -719,9 +716,6 @@ static int rule_exists(struct fib_rules_ops *ops, struct fib_rule_hdr *frh, if (r->tun_id != rule->tun_id) continue; - if (r->fr_net != rule->fr_net) - continue; - if (r->l3mdev != rule->l3mdev) continue; From patchwork Thu Feb 6 08:46:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13962624 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-9106.amazon.com (smtp-fw-9106.amazon.com [207.171.188.206]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 194BD163 for ; Thu, 6 Feb 2025 08:47:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=207.171.188.206 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738831665; cv=none; b=t2zjeeiGREHOZMu8+6jKPb+jKZw9+MAFYyuvmOYl5AIiriVrpYI7eR7OqopjcA6kGRFuQbACkkyRIQ38pIOsvgqosmxXQleEuwzhJT61msWhTxiUXLJWnbqfScARq2Kx94wODmyNu/YgUHnPNulljIAzMwa3F7KtrG12qMGNow4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738831665; c=relaxed/simple; bh=IfatC+cnYm6O6Kx0euS5DVGjzslo5tN+7J0d7efWUpU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YBxEBFSoTcovRv5F6j0vOJWY/XXKlIBzlK6hw0nLYZgcoQdWeDkzFvCSyGEk1sDTHRPiLBovDlONaS9SjzY1T2E58OYRd5I4lFmgb/HcR/tYOeoou7u6NTAeu55uyv7hW0J3JCU+RkYTBc3QFG7VovSOuIwId7UtomKam198K8c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=LFDuH0BQ; arc=none smtp.client-ip=207.171.188.206 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="LFDuH0BQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1738831664; x=1770367664; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0BB+X7h9rYAk+3iBvdoMrEckwnwfjYQpuIrt7H9Wjj0=; b=LFDuH0BQSk8cr2IXOSARGZZE1o1ndcC+TuhWk2HP27hBNFVu8YJmTyRM 6eW+WUMMlsFg3lXDcLPgKJdpGsLQpRmwkpmMd7JeH9Z/zT89IkX0+A3Hv PW5RFw+ebWTcWVY/lEOMZfO1hgFOUqfls8X8VoO+SHfcbmS4EloKhY5Iz M=; X-IronPort-AV: E=Sophos;i="6.13,264,1732579200"; d="scan'208";a="796563169" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-9106.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2025 08:47:38 +0000 Received: from EX19MTAUWA002.ant.amazon.com [10.0.21.151:27876] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.5.183:2525] with esmtp (Farcaster) id 99094cd6-599e-4eb5-9784-a5efc5e848cd; Thu, 6 Feb 2025 08:47:37 +0000 (UTC) X-Farcaster-Flow-ID: 99094cd6-599e-4eb5-9784-a5efc5e848cd Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Thu, 6 Feb 2025 08:47:36 +0000 Received: from 6c7e67bfbae3.amazon.com (10.37.244.8) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Thu, 6 Feb 2025 08:47:33 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 2/6] fib: rules: Pass net to fib_nl2rule() instead of skb. Date: Thu, 6 Feb 2025 17:46:25 +0900 Message-ID: <20250206084629.16602-3-kuniyu@amazon.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250206084629.16602-1-kuniyu@amazon.com> References: <20250206084629.16602-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D037UWB002.ant.amazon.com (10.13.138.121) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org skb is not used in fib_nl2rule() other than sock_net(skb->sk), which is already available in callers, fib_nl_newrule() and fib_nl_delrule(). Let's pass net directly to fib_nl2rule(). Signed-off-by: Kuniyuki Iwashima --- net/core/fib_rules.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c index 02dfb841ab29..87f731199538 100644 --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c @@ -512,14 +512,13 @@ static int fib_nl2rule_l3mdev(struct nlattr *nla, struct fib_rule *nlrule, } #endif -static int fib_nl2rule(struct sk_buff *skb, struct nlmsghdr *nlh, +static int fib_nl2rule(struct net *net, struct nlmsghdr *nlh, struct netlink_ext_ack *extack, struct fib_rules_ops *ops, struct nlattr *tb[], struct fib_rule **rule, bool *user_priority) { - struct net *net = sock_net(skb->sk); struct fib_rule_hdr *frh = nlmsg_data(nlh); struct fib_rule *nlrule = NULL; int err = -EINVAL; @@ -798,7 +797,7 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, goto errout; } - err = fib_nl2rule(skb, nlh, extack, ops, tb, &rule, &user_priority); + err = fib_nl2rule(net, nlh, extack, ops, tb, &rule, &user_priority); if (err) goto errout; @@ -906,7 +905,7 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, goto errout; } - err = fib_nl2rule(skb, nlh, extack, ops, tb, &nlrule, &user_priority); + err = fib_nl2rule(net, nlh, extack, ops, tb, &nlrule, &user_priority); if (err) goto errout; From patchwork Thu Feb 6 08:46:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13962625 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE22822256E for ; Thu, 6 Feb 2025 08:48:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.218 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738831693; cv=none; b=LqLS9zD51ljT7slUdeYZapPXq+aIoDOEAzM+r9n4oTjKoSwrBk/UGMywoWNgfSU8Nu6gwOv7QXV7rKalYPkVtJYXRjPNBYVs384NywpicSJTdOZTHE4R7ccmo1qCgf5sUEO9X4KzzWuELAwFVqdExwodCTLCr0yTtD8ig9vQMzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738831693; c=relaxed/simple; bh=cYhOQ/3UJBOKDoPuU8kvn7DAsDlzarz4iNrYnu1HbUs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c0Ux6KJdAKfXSz6nvlUVW5QICKApDNXyINoox7+QlNHf7M9VDxY9A213afw1pcsW6K6rfV19pIC6kBYEHSw43dSsyx0aOmwn/XFj7AlMndYCH0/kz6P7eGzT5ZFg05jh18nKET9xlH9Tu2O0V83ctE76K+ub5/QqJdV0K1Hvo1U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=NMYMwlww; arc=none smtp.client-ip=99.78.197.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="NMYMwlww" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1738831692; x=1770367692; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=whPzkE4DuMR9tjYvUgzksMF5c7Irk3CnnY+oNpdtivk=; b=NMYMwlww55qdGCYKbFH3hagRjDZ9W8KCI4YCiB208qrzfZAfFxTpZuEe /FXTDmhIXNQ3A8n6w0wcuCKGYVEbf2zVlUlT6vZx1eaT5d2ol11ZCvM+2 t/WceQmcalMPEK5PfZoB9DtjYL+rcKqXQmEq1tL6pijkD0w8X13urtQz1 4=; X-IronPort-AV: E=Sophos;i="6.13,264,1732579200"; d="scan'208";a="374963711" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2025 08:48:10 +0000 Received: from EX19MTAUWB001.ant.amazon.com [10.0.38.20:29835] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.19.117:2525] with esmtp (Farcaster) id e0834a60-02e2-4107-9b8e-6e3c30145bb6; Thu, 6 Feb 2025 08:48:09 +0000 (UTC) X-Farcaster-Flow-ID: e0834a60-02e2-4107-9b8e-6e3c30145bb6 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB001.ant.amazon.com (10.250.64.248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Thu, 6 Feb 2025 08:48:03 +0000 Received: from 6c7e67bfbae3.amazon.com (10.37.244.8) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Thu, 6 Feb 2025 08:47:59 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 3/6] fib: rules: Split fib_nl2rule(). Date: Thu, 6 Feb 2025 17:46:26 +0900 Message-ID: <20250206084629.16602-4-kuniyu@amazon.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250206084629.16602-1-kuniyu@amazon.com> References: <20250206084629.16602-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D046UWA004.ant.amazon.com (10.13.139.76) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org We will move RTNL down to fib_nl_newrule() and fib_nl_delrule(). Some operations in fib_nl2rule() require RTNL: fib_default_rule_pref() and __dev_get_by_name(). Let's split the RTNL parts as fib_nl2rule_rtnl(). Signed-off-by: Kuniyuki Iwashima --- net/core/fib_rules.c | 58 +++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c index 87f731199538..694a8c2884a8 100644 --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c @@ -550,30 +550,18 @@ static int fib_nl2rule(struct net *net, struct nlmsghdr *nlh, if (tb[FRA_PRIORITY]) { nlrule->pref = nla_get_u32(tb[FRA_PRIORITY]); *user_priority = true; - } else { - nlrule->pref = fib_default_rule_pref(ops); } nlrule->proto = nla_get_u8_default(tb[FRA_PROTOCOL], RTPROT_UNSPEC); if (tb[FRA_IIFNAME]) { - struct net_device *dev; - nlrule->iifindex = -1; nla_strscpy(nlrule->iifname, tb[FRA_IIFNAME], IFNAMSIZ); - dev = __dev_get_by_name(net, nlrule->iifname); - if (dev) - nlrule->iifindex = dev->ifindex; } if (tb[FRA_OIFNAME]) { - struct net_device *dev; - nlrule->oifindex = -1; nla_strscpy(nlrule->oifname, tb[FRA_OIFNAME], IFNAMSIZ); - dev = __dev_get_by_name(net, nlrule->oifname); - if (dev) - nlrule->oifindex = dev->ifindex; } if (tb[FRA_FWMARK]) { @@ -615,11 +603,6 @@ static int fib_nl2rule(struct net *net, struct nlmsghdr *nlh, } nlrule->target = nla_get_u32(tb[FRA_GOTO]); - /* Backward jumps are prohibited to avoid endless loops */ - if (nlrule->target <= nlrule->pref) { - NL_SET_ERR_MSG(extack, "Backward goto not supported"); - goto errout_free; - } } else if (nlrule->action == FR_ACT_GOTO) { NL_SET_ERR_MSG(extack, "Missing goto target for action goto"); goto errout_free; @@ -679,6 +662,39 @@ static int fib_nl2rule(struct net *net, struct nlmsghdr *nlh, return err; } +static int fib_nl2rule_rtnl(struct fib_rule *nlrule, + struct fib_rules_ops *ops, + struct nlattr *tb[], + struct netlink_ext_ack *extack) +{ + if (!tb[FRA_PRIORITY]) + nlrule->pref = fib_default_rule_pref(ops); + + /* Backward jumps are prohibited to avoid endless loops */ + if (tb[FRA_GOTO] && nlrule->target <= nlrule->pref) { + NL_SET_ERR_MSG(extack, "Backward goto not supported"); + return -EINVAL; + } + + if (tb[FRA_IIFNAME]) { + struct net_device *dev; + + dev = __dev_get_by_name(nlrule->fr_net, nlrule->iifname); + if (dev) + nlrule->iifindex = dev->ifindex; + } + + if (tb[FRA_OIFNAME]) { + struct net_device *dev; + + dev = __dev_get_by_name(nlrule->fr_net, nlrule->oifname); + if (dev) + nlrule->oifindex = dev->ifindex; + } + + return 0; +} + static int rule_exists(struct fib_rules_ops *ops, struct fib_rule_hdr *frh, struct nlattr **tb, struct fib_rule *rule) { @@ -801,6 +817,10 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, if (err) goto errout; + err = fib_nl2rule_rtnl(rule, ops, tb, extack); + if (err) + goto errout_free; + if ((nlh->nlmsg_flags & NLM_F_EXCL) && rule_exists(ops, frh, tb, rule)) { err = -EEXIST; @@ -909,6 +929,10 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, if (err) goto errout; + err = fib_nl2rule_rtnl(nlrule, ops, tb, extack); + if (err) + goto errout; + rule = rule_find(ops, frh, tb, nlrule, user_priority); if (!rule) { err = -ENOENT; From patchwork Thu Feb 6 08:46:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13962626 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80008.amazon.com (smtp-fw-80008.amazon.com [99.78.197.219]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1969163 for ; Thu, 6 Feb 2025 08:48:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738831713; cv=none; b=CNGryMA73MYNxvtxgdXLO7XNGnmj3h7Lg/IYBAuSSMW2Vm3ef/WH11t+MBgA/xZ7c2V4UPxATQpYdjF2uRp6PJsN0b1Zqn6XbfBhZuH87Rrj+u027FzG+Fde0qszVaW7ScRbuCe7D35k3qdG6glxBB3sxzcz2rTVV1aDblD/wm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738831713; c=relaxed/simple; bh=O31ATdtnTQFm2JtGFbgfAcyL+s8ArtGXBNbgdN0NME8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m6bIxEVs8gHTqqIKq/TGAwCC/raun152mhMs5m0QjoozIIKZpRLTXipQgqfRvW9Ss/R/iyWpYjsR6LIl9ATJLS/kDsbS+sYxc+fV3ebAdpYSLdueHAK60gpWvtFEp127BhurDaQUJSYGULnv4HKzM0VNzsgrxHdYl6Pe9jZipoI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=X6P3ayo7; arc=none smtp.client-ip=99.78.197.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="X6P3ayo7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1738831711; x=1770367711; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YjUDPFsIp5DWWJKHjHQWO//JSRngbJ3rbnnht5syDb4=; b=X6P3ayo7F2CrEx+a9Y1HS3RY8ANBlt98KRiZEwH9ulYsJ5a5yqcZzcPC XyCAYX+CT67Ih1+QDhH3W5N2hS4GjuWw/W/BdwvYUX7p0A1eAr9oxki67 D/cYiAHzr6o/KjGw9Aqw4V68cYlnrDspR/0X1SZElWdE5e4lRetLplfCp 0=; X-IronPort-AV: E=Sophos;i="6.13,264,1732579200"; d="scan'208";a="167332938" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80008.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2025 08:48:30 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.38.20:2396] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.32.120:2525] with esmtp (Farcaster) id 01f240bf-72cd-4aeb-a87c-e1fec1a906d9; Thu, 6 Feb 2025 08:48:30 +0000 (UTC) X-Farcaster-Flow-ID: 01f240bf-72cd-4aeb-a87c-e1fec1a906d9 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Thu, 6 Feb 2025 08:48:29 +0000 Received: from 6c7e67bfbae3.amazon.com (10.37.244.8) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Thu, 6 Feb 2025 08:48:26 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 4/6] fib: rules: Convert RTM_NEWRULE to per-netns RTNL. Date: Thu, 6 Feb 2025 17:46:27 +0900 Message-ID: <20250206084629.16602-5-kuniyu@amazon.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250206084629.16602-1-kuniyu@amazon.com> References: <20250206084629.16602-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D031UWC003.ant.amazon.com (10.13.139.252) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org fib_nl_newrule() is the doit() handler for RTM_NEWRULE but also called from vrf_newlink(). In the latter case, RTNL is already held and the 3rd arg extack is NULL. Let's hold per-netns RTNL in fib_nl_newrule() if extack is NULL. Note that we call fib_rule_get() before releasing per-netns RTNL to call notify_rule_change() without RTNL and prevent freeing the new rule. Signed-off-by: Kuniyuki Iwashima --- net/core/fib_rules.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c index 694a8c2884a8..3cdfa3ac8c7c 100644 --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c @@ -786,13 +786,13 @@ static const struct nla_policy fib_rule_policy[FRA_MAX + 1] = { int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { - struct net *net = sock_net(skb->sk); + bool user_priority = false, hold_rtnl = !!extack; struct fib_rule_hdr *frh = nlmsg_data(nlh); + struct fib_rule *rule, *r, *last = NULL; + struct net *net = sock_net(skb->sk); + int err = -EINVAL, unresolved = 0; struct fib_rules_ops *ops = NULL; - struct fib_rule *rule = NULL, *r, *last = NULL; struct nlattr *tb[FRA_MAX + 1]; - int err = -EINVAL, unresolved = 0; - bool user_priority = false; if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*frh))) { NL_SET_ERR_MSG(extack, "Invalid msg length"); @@ -817,6 +817,9 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, if (err) goto errout; + if (hold_rtnl) + rtnl_net_lock(net); + err = fib_nl2rule_rtnl(rule, ops, tb, extack); if (err) goto errout_free; @@ -882,12 +885,20 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, if (rule->tun_id) ip_tunnel_need_metadata(); + fib_rule_get(rule); + + if (hold_rtnl) + rtnl_net_unlock(net); + notify_rule_change(RTM_NEWRULE, rule, ops, nlh, NETLINK_CB(skb).portid); + fib_rule_put(rule); flush_route_cache(ops); rules_ops_put(ops); return 0; errout_free: + if (hold_rtnl) + rtnl_net_unlock(net); kfree(rule); errout: rules_ops_put(ops); @@ -1310,7 +1321,8 @@ static struct pernet_operations fib_rules_net_ops = { }; static const struct rtnl_msg_handler fib_rules_rtnl_msg_handlers[] __initconst = { - {.msgtype = RTM_NEWRULE, .doit = fib_nl_newrule}, + {.msgtype = RTM_NEWRULE, .doit = fib_nl_newrule, + .flags = RTNL_FLAG_DOIT_PERNET}, {.msgtype = RTM_DELRULE, .doit = fib_nl_delrule}, {.msgtype = RTM_GETRULE, .dumpit = fib_nl_dumprule, .flags = RTNL_FLAG_DUMP_UNLOCKED}, From patchwork Thu Feb 6 08:46:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13962627 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-9106.amazon.com (smtp-fw-9106.amazon.com [207.171.188.206]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A431163 for ; Thu, 6 Feb 2025 08:48:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=207.171.188.206 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738831739; cv=none; b=HKnSRwiZmDv6nbTo6v9bhGhM802FE5WEqqW/qTDJjSGSSwrq7sEDakKE2IsXlbSvHK6/hShJjsr7hWNwztZTKUjRX8bl/l4+xys3gKbxcG7ywbVl8lv2tFU/I3J87hVfcE7uSIGw/C0ay44tDBKakxPR02quyOFzz1eF2kmR1IM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738831739; c=relaxed/simple; bh=c4X/OAtQbVtCnB7ILPAhIQyJL6mT5rOCEUnu25IhDJo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MaaJChkBIsyejwwoCxLHUw8/v/uhKoOxF2Ye/ZIcwjxz4RRyI9mE1sM6z90wKLUyxv92zMZ2Eij1RiDh/astHR3L/IPeO4RK4D3y3R+DED9QKYQEpC2BqQ/zBTJnTqSzZAE+EcQxbxm7VABkwJAFMX3X0Nr/FDsXUhN86MLwFdY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=koUFtY7c; arc=none smtp.client-ip=207.171.188.206 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="koUFtY7c" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1738831737; x=1770367737; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hSK1JqFhGXGdPQpD8O4Kk52ddjn8SBe09sRP0F8mEXg=; b=koUFtY7cV5E9exJDU2zdO/QeZaXTlJJdsFqPH9GMB6N+ZNQd1OU/Clqx jxPGEOckTmMuLrXsFzqFUhfgH1mlO9jEwxrY4FAoMUSI7zfdHEuHsAr3B PJ/5w+tbn+oK1iDoLf+4xv+U9oyRQaFrtvlK0KdZM3MSOLngdAao8B6UE 0=; X-IronPort-AV: E=Sophos;i="6.13,264,1732579200"; d="scan'208";a="796563631" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-9106.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2025 08:48:57 +0000 Received: from EX19MTAUWB001.ant.amazon.com [10.0.38.20:1112] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.4.10:2525] with esmtp (Farcaster) id 5b175d36-9845-4029-9b46-e1180f14001f; Thu, 6 Feb 2025 08:48:56 +0000 (UTC) X-Farcaster-Flow-ID: 5b175d36-9845-4029-9b46-e1180f14001f Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB001.ant.amazon.com (10.250.64.248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Thu, 6 Feb 2025 08:48:55 +0000 Received: from 6c7e67bfbae3.amazon.com (10.37.244.8) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Thu, 6 Feb 2025 08:48:52 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 5/6] fib: rules: Add error_free label in fib_nl_delrule(). Date: Thu, 6 Feb 2025 17:46:28 +0900 Message-ID: <20250206084629.16602-6-kuniyu@amazon.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250206084629.16602-1-kuniyu@amazon.com> References: <20250206084629.16602-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D045UWC003.ant.amazon.com (10.13.139.198) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org We will hold RTNL just before calling fib_nl2rule_rtnl() in fib_nl_delrule() and release it before kfree(nlrule). Let's add a new rule to make the following change cleaner. Signed-off-by: Kuniyuki Iwashima --- net/core/fib_rules.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c index 3cdfa3ac8c7c..cc26c762fa9e 100644 --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c @@ -942,23 +942,23 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, err = fib_nl2rule_rtnl(nlrule, ops, tb, extack); if (err) - goto errout; + goto errout_free; rule = rule_find(ops, frh, tb, nlrule, user_priority); if (!rule) { err = -ENOENT; - goto errout; + goto errout_free; } if (rule->flags & FIB_RULE_PERMANENT) { err = -EPERM; - goto errout; + goto errout_free; } if (ops->delete) { err = ops->delete(rule); if (err) - goto errout; + goto errout_free; } if (rule->tun_id) @@ -1004,8 +1004,9 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, kfree(nlrule); return 0; -errout: +errout_free: kfree(nlrule); +errout: rules_ops_put(ops); return err; } From patchwork Thu Feb 6 08:46:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13962641 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5464D22578E for ; Thu, 6 Feb 2025 08:49:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.218 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738831764; cv=none; b=k5ruaBb6+NDCxNjmlmhM6ib/pX9l6KA8qIIf8KjD7sbz4Qci+tgIT6Xcxz9kCTcUcpTLHmLeRPPSmijX+bel9awxPKZOudtnFZ1mUAZmoMG3+SFAS6/9Xlgdc/mxfDyhLWoJXEfC5F9BsF4JjzLd7RoyeSPemrZyBnQwTAkqL9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738831764; c=relaxed/simple; bh=yuQndV53eh6JnDaOL7Dv7tv7gWBKGlFuStTlljBr1a4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RWYytE758Gv134SkMVK0mgAmlAsPxz39ztEh2LpSG2iEexI4kaYCTRob0ip0bLjtbpu3hfQkIr5FYh2+j5ulg5kDtGcWoYgUQkDEH2Am6CJl24vRHwxTmZurojfVskJeDQP7i0HB5NNC76uIJmk8xQbzOjza9e0iwlcaJK3aQGI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=v6Ce1OFC; arc=none smtp.client-ip=99.78.197.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="v6Ce1OFC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1738831763; x=1770367763; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/LyxjULeVQVu51J3sSQ7p8Lmg0R5Trlt+EwKMvHVY4A=; b=v6Ce1OFCqbutRgpYAiZwoFIsqOHZI4YhyhIT1MmyZcF1Vo8vQNvy7BY/ AqcB3OpsX3n81t/IlNbuVxadMYN7PmYns/Kh/ze6I0qYQkg3nkc8f3/oB tkhdj/0IyKIQeM5V+29VxSjh0HyUpq8WVM6YslYcBb3GClsaRCDWCX3gC Q=; X-IronPort-AV: E=Sophos;i="6.13,264,1732579200"; d="scan'208";a="374964194" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2025 08:49:23 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.21.151:47884] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.42.242:2525] with esmtp (Farcaster) id dc3ebe3a-7086-4f78-940b-1cdb748fc108; Thu, 6 Feb 2025 08:49:22 +0000 (UTC) X-Farcaster-Flow-ID: dc3ebe3a-7086-4f78-940b-1cdb748fc108 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Thu, 6 Feb 2025 08:49:22 +0000 Received: from 6c7e67bfbae3.amazon.com (10.37.244.8) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Thu, 6 Feb 2025 08:49:18 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 6/6] fib: rules: Convert RTM_DELRULE to per-netns RTNL. Date: Thu, 6 Feb 2025 17:46:29 +0900 Message-ID: <20250206084629.16602-7-kuniyu@amazon.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250206084629.16602-1-kuniyu@amazon.com> References: <20250206084629.16602-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D043UWA001.ant.amazon.com (10.13.139.45) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org fib_nl_delrule() is the doit() handler for RTM_DELRULE but also called 1;95;0cfrom vrf_newlink() in case something fails in vrf_add_fib_rules(). In the latter case, RTNL is already held and the 3rd arg extack is NULL. Let's hold per-netns RTNL in fib_nl_delrule() if extack is NULL. Now we can place ASSERT_RTNL_NET() in call_fib_rule_notifiers(). While at it, fib_rule r is moved to the suitable scope. Signed-off-by: Kuniyuki Iwashima --- net/core/fib_rules.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c index cc26c762fa9e..3430d026134d 100644 --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c @@ -371,7 +371,8 @@ static int call_fib_rule_notifiers(struct net *net, .rule = rule, }; - ASSERT_RTNL(); + ASSERT_RTNL_NET(net); + /* Paired with READ_ONCE() in fib_rules_seq() */ WRITE_ONCE(ops->fib_rules_seq, ops->fib_rules_seq + 1); return call_fib_notifiers(net, event_type, &info.info); @@ -909,13 +910,13 @@ EXPORT_SYMBOL_GPL(fib_nl_newrule); int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { - struct net *net = sock_net(skb->sk); + bool user_priority = false, hold_rtnl = !!extack; + struct fib_rule *rule = NULL, *nlrule = NULL; struct fib_rule_hdr *frh = nlmsg_data(nlh); + struct net *net = sock_net(skb->sk); struct fib_rules_ops *ops = NULL; - struct fib_rule *rule = NULL, *r, *nlrule = NULL; struct nlattr *tb[FRA_MAX+1]; int err = -EINVAL; - bool user_priority = false; if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*frh))) { NL_SET_ERR_MSG(extack, "Invalid msg length"); @@ -940,6 +941,9 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, if (err) goto errout; + if (hold_rtnl) + rtnl_net_lock(net); + err = fib_nl2rule_rtnl(nlrule, ops, tb, extack); if (err) goto errout_free; @@ -980,7 +984,7 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, * current if it is goto rule, have actually been added. */ if (ops->nr_goto_rules > 0) { - struct fib_rule *n; + struct fib_rule *n, *r; n = list_next_entry(rule, list); if (&n->list == &ops->rules_list || n->pref != rule->pref) @@ -994,10 +998,12 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, } } - call_fib_rule_notifiers(net, FIB_EVENT_RULE_DEL, rule, ops, - NULL); - notify_rule_change(RTM_DELRULE, rule, ops, nlh, - NETLINK_CB(skb).portid); + call_fib_rule_notifiers(net, FIB_EVENT_RULE_DEL, rule, ops, NULL); + + if (hold_rtnl) + rtnl_net_unlock(net); + + notify_rule_change(RTM_DELRULE, rule, ops, nlh, NETLINK_CB(skb).portid); fib_rule_put(rule); flush_route_cache(ops); rules_ops_put(ops); @@ -1005,6 +1011,8 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, return 0; errout_free: + if (hold_rtnl) + rtnl_net_unlock(net); kfree(nlrule); errout: rules_ops_put(ops); @@ -1324,7 +1332,8 @@ static struct pernet_operations fib_rules_net_ops = { static const struct rtnl_msg_handler fib_rules_rtnl_msg_handlers[] __initconst = { {.msgtype = RTM_NEWRULE, .doit = fib_nl_newrule, .flags = RTNL_FLAG_DOIT_PERNET}, - {.msgtype = RTM_DELRULE, .doit = fib_nl_delrule}, + {.msgtype = RTM_DELRULE, .doit = fib_nl_delrule, + .flags = RTNL_FLAG_DOIT_PERNET}, {.msgtype = RTM_GETRULE, .dumpit = fib_nl_dumprule, .flags = RTNL_FLAG_DUMP_UNLOCKED}, };