From patchwork Thu Oct 3 20:57:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13821559 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 0CF6C12EBDB for ; Thu, 3 Oct 2024 20:58:02 +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=1727989085; cv=none; b=NX4uY/quMt7rNy46Tm2LQqXGNerTtXOsoax/G9gLcmli/xfQsEwblhSUo0+ZISgZTVon/z8CHad/liZQJugQ2zU+D/kQAxiqb8DeiXZAa4PgH43oVnRzGahd4RWCkjHJ4CZLBw+JLnKwjj+hXZboHIsvgBN/7pxGoxQOLmIU/vI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727989085; c=relaxed/simple; bh=EOjVh/y4SslOWLXNzHTY7N5QGXsYG3/niD1gPvO43TQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nKyKqodTJLyueUq3bdurPoW7YmpPdhzTuMYe5Kt4PlEB7yHOnFhgU29ELQtQQMiReL6B5nchvQe2G15byPcDJYVIAXjqGWLMMc1Ilf3/AI8doJ5Y9ogcmfaYqcKDvFhYfTehzJGulo2uqE5WwjP0giSUmLb5/8O600Z7UuHOiTI= 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=UkM51d7o; 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="UkM51d7o" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1727989084; x=1759525084; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=seOYwIJkBjxJmZoQqu+ysVQtUocOzwWaMd0oDOzAIrY=; b=UkM51d7oy8w0+dnZHp4zVlKYYFBKjEdV3fC71uxV9EjQDyhABzCzIabf oclM/cos6N2fcJYEziwKAl58WATEhsKYGnT9IoGjpiIR4Ucsdhi3CFY0Q k6xCL7X+vINGj50QT04X87gDHoJGdJ3dPH01ZwKfH9mez36SCrwFTFXLR 4=; X-IronPort-AV: E=Sophos;i="6.11,175,1725321600"; d="scan'208";a="134885993" 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; 03 Oct 2024 20:58:01 +0000 Received: from EX19MTAUWB001.ant.amazon.com [10.0.38.20:48809] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.4.107:2525] with esmtp (Farcaster) id 493d5ea5-81ff-4c78-97fd-9f58cbffc4ad; Thu, 3 Oct 2024 20:58:00 +0000 (UTC) X-Farcaster-Flow-ID: 493d5ea5-81ff-4c78-97fd-9f58cbffc4ad 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.34; Thu, 3 Oct 2024 20:58:00 +0000 Received: from 88665a182662.ant.amazon.com (10.187.171.32) 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.35; Thu, 3 Oct 2024 20:57:58 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net 1/6] rtnetlink: Add bulk registration helpers for rtnetlink message handlers. Date: Thu, 3 Oct 2024 13:57:20 -0700 Message-ID: <20241003205725.5612-2-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241003205725.5612-1-kuniyu@amazon.com> References: <20241003205725.5612-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: EX19D036UWC003.ant.amazon.com (10.13.139.214) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org Before commit addf9b90de22 ("net: rtnetlink: use rcu to free rtnl message handlers"), once rtnl_msg_handlers[protocol] was allocated, the following rtnl_register_module() for the same protocol never failed. However, after the commit, rtnl_msg_handler[protocol][msgtype] needs to be allocated in each rtnl_register_module(), so each call could fail. Many callers of rtnl_register_module() do not handle the returned error, and we need to add many error handlings. To handle that easily, let's add wrapper functions for bulk registration of rtnetlink message handlers. Signed-off-by: Kuniyuki Iwashima --- include/net/rtnetlink.h | 19 +++++++++++++++++++ net/core/rtnetlink.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h index b45d57b5968a..b6b91898dc13 100644 --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -29,6 +29,14 @@ static inline enum rtnl_kinds rtnl_msgtype_kind(int msgtype) return msgtype & RTNL_KIND_MASK; } +struct rtnl_msg_handler { + int protocol; + int msgtype; + rtnl_doit_func doit; + rtnl_dumpit_func dumpit; + int flags; +}; + void rtnl_register(int protocol, int msgtype, rtnl_doit_func, rtnl_dumpit_func, unsigned int flags); int rtnl_register_module(struct module *owner, int protocol, int msgtype, @@ -36,6 +44,17 @@ int rtnl_register_module(struct module *owner, int protocol, int msgtype, int rtnl_unregister(int protocol, int msgtype); void rtnl_unregister_all(int protocol); +int __rtnl_register_many(struct module *owner, + struct rtnl_msg_handler *handlers, int n); +void __rtnl_unregister_many(struct rtnl_msg_handler *handlers, int n); + +#define rtnl_register_many(handlers) \ + __rtnl_register_many(NULL, handlers, ARRAY_SIZE(handlers)) +#define rtnl_register_module_many(handlers) \ + __rtnl_register_many(THIS_MODULE, handlers, ARRAY_SIZE(handlers)) +#define rtnl_unregister_many(handlers) \ + __rtnl_unregister_many(handlers, ARRAY_SIZE(handlers)) + static inline int rtnl_msg_family(const struct nlmsghdr *nlh) { if (nlmsg_len(nlh) >= sizeof(struct rtgenmsg)) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index f0a520987085..1fac9e786315 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -384,6 +384,36 @@ void rtnl_unregister_all(int protocol) } EXPORT_SYMBOL_GPL(rtnl_unregister_all); +int __rtnl_register_many(struct module *owner, + struct rtnl_msg_handler *handlers, int n) +{ + struct rtnl_msg_handler *handler; + int i, err; + + for (i = 0, handler = handlers; i < n; i++, handler++) { + err = rtnl_register_internal(owner, handler->protocol, + handler->msgtype, handler->doit, + handler->dumpit, handler->flags); + if (err) { + __rtnl_unregister_many(handlers, i); + break; + } + } + + return err; +} +EXPORT_SYMBOL_GPL(__rtnl_register_many); + +void __rtnl_unregister_many(struct rtnl_msg_handler *handlers, int n) +{ + struct rtnl_msg_handler *handler; + int i; + + for (i = n - 1, handler = handlers + n - 1; i >= 0; i--, handler--) + rtnl_unregister(handler->protocol, handler->msgtype); +} +EXPORT_SYMBOL_GPL(__rtnl_unregister_many); + static LIST_HEAD(link_ops); static const struct rtnl_link_ops *rtnl_link_ops_get(const char *kind) From patchwork Thu Oct 3 20:57:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13821560 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 BBCDA12EBDB for ; Thu, 3 Oct 2024 20:58:29 +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=1727989111; cv=none; b=c+6sNt7KHa+OFUzWldDd0+ooVt+bZ8ZtUsmNOsavyoWvq1vyRZIFPXj1wjdR1c2VT1MK+d/BuHWu3lzRH3Mn3S7KeI9HYBXAU4xkQsWAhx7BfN8+KYLK38ZlN8SgEQ0s8bITRyjVxRQyaVBRWA0oFBaQkyiZpJf0zPNF4kAqguk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727989111; c=relaxed/simple; bh=JwKD4MLXbYKTlj9hCp3/ztUZGxhsJ0nwhKG/qnKAVmY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m/lDn/bYL84NGuzFFBBbCRph1rVT3CxYc4DIBW8Qx0eau2mecZq5ULgBbcIWC4nF9jwhsFywQHGYHBruaajAUODX+gv+24rvjqTOxcQIsSu9egnBnqVzwdfX6JGz3sHNTuxBaOP51kr75M+0EZ/z4ujuqLfgMxha5URZG+9QpPc= 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=KqWS4gpc; 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="KqWS4gpc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1727989110; x=1759525110; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wCi6pBBHAlrcV1EnvzGFqAN+lzQcVPdN/iQ6c8qeAuo=; b=KqWS4gpcAepL1ZXblGFE54WMddyOeDGiki67Pjdz+UJKaM/oMk9vk6jL B8TAn8OxNiajQ4VWypyUctwcmxzouU76XqdtB71xLZpJYjbTAwryOHxoz LGG1HWN5TSDO1H8a2bbMMIvEEoJNFI/XIR7TZZBxjbBaxvmZJclzIHv6T 8=; X-IronPort-AV: E=Sophos;i="6.11,175,1725321600"; d="scan'208";a="339351753" 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; 03 Oct 2024 20:58:27 +0000 Received: from EX19MTAUWC002.ant.amazon.com [10.0.38.20:2340] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.41.198:2525] with esmtp (Farcaster) id dfd2eb68-ec5c-4b0f-b526-355348e66b5c; Thu, 3 Oct 2024 20:58:26 +0000 (UTC) X-Farcaster-Flow-ID: dfd2eb68-ec5c-4b0f-b526-355348e66b5c Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Thu, 3 Oct 2024 20:58:24 +0000 Received: from 88665a182662.ant.amazon.com (10.187.171.32) 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.35; Thu, 3 Oct 2024 20:58:22 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , , Roopa Prabhu Subject: [PATCH v1 net 2/6] vxlan: Handle error of rtnl_register_module(). Date: Thu, 3 Oct 2024 13:57:21 -0700 Message-ID: <20241003205725.5612-3-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241003205725.5612-1-kuniyu@amazon.com> References: <20241003205725.5612-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: EX19D046UWB002.ant.amazon.com (10.13.139.181) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org Since introduced, vxlan_vnifilter_init() has been ignoring the returned value of rtnl_register_module(), which could fail. Let's handle the errors by rtnl_register_module_many(). Fixes: f9c4bb0b245c ("vxlan: vni filtering support on collect metadata device") Signed-off-by: Kuniyuki Iwashima --- Cc: Roopa Prabhu --- drivers/net/vxlan/vxlan_core.c | 6 +++++- drivers/net/vxlan/vxlan_private.h | 2 +- drivers/net/vxlan/vxlan_vnifilter.c | 19 +++++++++---------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 53dcb9fffc04..6e9a3795846a 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -4913,9 +4913,13 @@ static int __init vxlan_init_module(void) if (rc) goto out4; - vxlan_vnifilter_init(); + rc = vxlan_vnifilter_init(); + if (rc) + goto out5; return 0; +out5: + rtnl_link_unregister(&vxlan_link_ops); out4: unregister_switchdev_notifier(&vxlan_switchdev_notifier_block); out3: diff --git a/drivers/net/vxlan/vxlan_private.h b/drivers/net/vxlan/vxlan_private.h index b35d96b78843..76a351a997d5 100644 --- a/drivers/net/vxlan/vxlan_private.h +++ b/drivers/net/vxlan/vxlan_private.h @@ -202,7 +202,7 @@ int vxlan_vni_in_use(struct net *src_net, struct vxlan_dev *vxlan, int vxlan_vnigroup_init(struct vxlan_dev *vxlan); void vxlan_vnigroup_uninit(struct vxlan_dev *vxlan); -void vxlan_vnifilter_init(void); +int vxlan_vnifilter_init(void); void vxlan_vnifilter_uninit(void); void vxlan_vnifilter_count(struct vxlan_dev *vxlan, __be32 vni, struct vxlan_vni_node *vninode, diff --git a/drivers/net/vxlan/vxlan_vnifilter.c b/drivers/net/vxlan/vxlan_vnifilter.c index 9c59d0bf8c3d..4be5d3060039 100644 --- a/drivers/net/vxlan/vxlan_vnifilter.c +++ b/drivers/net/vxlan/vxlan_vnifilter.c @@ -992,19 +992,18 @@ static int vxlan_vnifilter_process(struct sk_buff *skb, struct nlmsghdr *nlh, return err; } -void vxlan_vnifilter_init(void) +static struct rtnl_msg_handler vxlan_rtnl_msg_handlers[] = { + {PF_BRIDGE, RTM_GETTUNNEL, NULL, vxlan_vnifilter_dump, 0}, + {PF_BRIDGE, RTM_NEWTUNNEL, vxlan_vnifilter_process, NULL, 0}, + {PF_BRIDGE, RTM_DELTUNNEL, vxlan_vnifilter_process, NULL, 0}, +}; + +int vxlan_vnifilter_init(void) { - rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_GETTUNNEL, NULL, - vxlan_vnifilter_dump, 0); - rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_NEWTUNNEL, - vxlan_vnifilter_process, NULL, 0); - rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_DELTUNNEL, - vxlan_vnifilter_process, NULL, 0); + return rtnl_register_module_many(vxlan_rtnl_msg_handlers); } void vxlan_vnifilter_uninit(void) { - rtnl_unregister(PF_BRIDGE, RTM_GETTUNNEL); - rtnl_unregister(PF_BRIDGE, RTM_NEWTUNNEL); - rtnl_unregister(PF_BRIDGE, RTM_DELTUNNEL); + rtnl_unregister_many(vxlan_rtnl_msg_handlers); } From patchwork Thu Oct 3 20:57:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13821561 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) (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 B84C912EBDB for ; Thu, 3 Oct 2024 20:58:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727989135; cv=none; b=T8yCGwWaTzWI3F/grhPSPAaSkxjOE6i9rBSmdleSYmOW4RavV2tLpWF3Z+W837KKO0+boGxZfU2nx+cLOKGxMGgtIHhJXMgMYq7L2pIqGVqw+rO8uioek+PdXhXOVtIxNq+quwwOPC5ypXLe/IOMISL7ibA0NSl6jKDGVsOOcgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727989135; c=relaxed/simple; bh=DoYHM5EB6pZkyhbwuxrVTCMFKPSezGGsWKo7i+noN7w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oBsG8bkTRpiF2f3OppOQFOsejwqR9rJGF2OfhkTu+uoXoauzSsv84yOhb5It2RNAimOoSVbwP2vPq/4MgSj0iK8wlX8W6oxvfZO8hd7jkkM8j6UmFW3/WA1OJad9OlXptN3t8BwW40fU/koCMCDXrjGJ/YNBA0zrE9YS7MC0zH0= 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=CejUEVDA; arc=none smtp.client-ip=52.119.213.154 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="CejUEVDA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1727989134; x=1759525134; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OTB5nJR3EjIJ1YjlFz4A7YqKJObwtjuQmwmzlF/CqxM=; b=CejUEVDAha+f1q63LijDpmHBrfTPL11RBALGkII92oPJ9lwoCuuUcfn7 K4LwEgyM0oddfPXBnUa1KmAPflqUNWEAVguG9CCzNtX/SUSbh33yeg5ic KMxHWhmWPjy8NkGhrfmz6dQ0DbE21z+MHpBxntZg4BWyupcEGEKqGgOvh A=; X-IronPort-AV: E=Sophos;i="6.11,175,1725321600"; d="scan'208";a="236583996" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2024 20:58:51 +0000 Received: from EX19MTAUWC001.ant.amazon.com [10.0.21.151:33522] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.22.18:2525] with esmtp (Farcaster) id 027bc79e-0094-4707-8a05-0d03ff340685; Thu, 3 Oct 2024 20:58:49 +0000 (UTC) X-Farcaster-Flow-ID: 027bc79e-0094-4707-8a05-0d03ff340685 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Thu, 3 Oct 2024 20:58:48 +0000 Received: from 88665a182662.ant.amazon.com (10.187.171.32) 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.35; Thu, 3 Oct 2024 20:58:46 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , , Roopa Prabhu , Nikolay Aleksandrov Subject: [PATCH v1 net 3/6] bridge: Handle error of rtnl_register_module(). Date: Thu, 3 Oct 2024 13:57:22 -0700 Message-ID: <20241003205725.5612-4-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241003205725.5612-1-kuniyu@amazon.com> References: <20241003205725.5612-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: EX19D046UWA003.ant.amazon.com (10.13.139.18) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org Since introduced, br_vlan_rtnl_init() has been ignoring the returned value of rtnl_register_module(), which could fail. Let's handle the errors by rtnl_register_module_many(). Fixes: 8dcea187088b ("net: bridge: vlan: add rtm definitions and dump support") Fixes: f26b296585dc ("net: bridge: vlan: add new rtm message support") Fixes: adb3ce9bcb0f ("net: bridge: vlan: add del rtm message support") Signed-off-by: Kuniyuki Iwashima --- Cc: Roopa Prabhu Cc: Nikolay Aleksandrov --- net/bridge/br_netlink.c | 6 +++++- net/bridge/br_private.h | 5 +++-- net/bridge/br_vlan.c | 19 +++++++++---------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index f17dbac7d828..6b97ae47f855 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -1920,7 +1920,10 @@ int __init br_netlink_init(void) { int err; - br_vlan_rtnl_init(); + err = br_vlan_rtnl_init(); + if (err) + goto out; + rtnl_af_register(&br_af_ops); err = rtnl_link_register(&br_link_ops); @@ -1931,6 +1934,7 @@ int __init br_netlink_init(void) out_af: rtnl_af_unregister(&br_af_ops); +out: return err; } diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index d4bedc87b1d8..041f6e571a20 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -1571,7 +1571,7 @@ void br_vlan_get_stats(const struct net_bridge_vlan *v, void br_vlan_port_event(struct net_bridge_port *p, unsigned long event); int br_vlan_bridge_event(struct net_device *dev, unsigned long event, void *ptr); -void br_vlan_rtnl_init(void); +int br_vlan_rtnl_init(void); void br_vlan_rtnl_uninit(void); void br_vlan_notify(const struct net_bridge *br, const struct net_bridge_port *p, @@ -1802,8 +1802,9 @@ static inline int br_vlan_bridge_event(struct net_device *dev, return 0; } -static inline void br_vlan_rtnl_init(void) +static inline int br_vlan_rtnl_init(void) { + return 0; } static inline void br_vlan_rtnl_uninit(void) diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 9c2fffb827ab..a9f00d72fe18 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -2296,19 +2296,18 @@ static int br_vlan_rtm_process(struct sk_buff *skb, struct nlmsghdr *nlh, return err; } -void br_vlan_rtnl_init(void) +static struct rtnl_msg_handler br_vlan_rtnl_msg_handlers[] = { + {PF_BRIDGE, RTM_NEWVLAN, br_vlan_rtm_process, NULL, 0}, + {PF_BRIDGE, RTM_DELVLAN, br_vlan_rtm_process, NULL, 0}, + {PF_BRIDGE, RTM_GETVLAN, NULL, br_vlan_rtm_dump, 0}, +}; + +int br_vlan_rtnl_init(void) { - rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_GETVLAN, NULL, - br_vlan_rtm_dump, 0); - rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_NEWVLAN, - br_vlan_rtm_process, NULL, 0); - rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_DELVLAN, - br_vlan_rtm_process, NULL, 0); + return rtnl_register_module_many(br_vlan_rtnl_msg_handlers); } void br_vlan_rtnl_uninit(void) { - rtnl_unregister(PF_BRIDGE, RTM_GETVLAN); - rtnl_unregister(PF_BRIDGE, RTM_NEWVLAN); - rtnl_unregister(PF_BRIDGE, RTM_DELVLAN); + rtnl_unregister_many(br_vlan_rtnl_msg_handlers); } From patchwork Thu Oct 3 20:57:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13821562 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) (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 C422F1AC429 for ; Thu, 3 Oct 2024 20:59:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.95.48.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727989162; cv=none; b=FAbEBW0hrILawp8hmUXdNChKIRGzPWRz10ItT2f0nfOynLbzZ4SoPSTPGkY70CGbTGI27WYmSktgZNqnCr8RgXMTQo3wJnoRGcdJXBQJpi9YaR3J+L7u/idAdupBnDbfjOuy9/iGgIAuWrk5AxQ1y3SXXRLyNlpMcteSvilvNYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727989162; c=relaxed/simple; bh=Qu9zRBOtnwRVJJEsiHoN/Iu/t9pJpYvC9pKE9q8YJyM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mLveqk82xkU43LfRQvGod5W0tLzPl+HxhJEeeiJ0NdpWOd8p63Q6yT2RGwPUXLSwmBL+qIoXhL4WwhBVqZoErBTuuE8czQ2G2Ct24wyLRYF3RAVzxpD0oWKNQYxi20d7BrjVNv0KEIa43FC4rwJZ/SvbNdMDwcTeyTB2qOmFbw4= 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=Rx3JIR47; arc=none smtp.client-ip=52.95.48.154 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="Rx3JIR47" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1727989161; x=1759525161; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vPXwzzinDqB7NbJ4oGcDXrMVUaz2wCkAuVWcJTktmH4=; b=Rx3JIR47lD0IyPzwMsAKJ4Z2WO02jE1QJdmwibr+Ez6YOaPVFO+rDz9G 6pkJng4EBqJi3/8mexT3rPV/AosWSLqmXSBYSnzgZfVyj+c/2LwaAVf7I fQrwy9TvMmJQUdccj688Nfbzk5c7Hthrxj3cB26R/IKq8nKoIUuiJuscV o=; X-IronPort-AV: E=Sophos;i="6.11,175,1725321600"; d="scan'208";a="428681691" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-6001.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2024 20:59:17 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.7.35:8650] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.4.107:2525] with esmtp (Farcaster) id 632f0500-25a2-4d4c-bbc6-5af16630b27c; Thu, 3 Oct 2024 20:59:16 +0000 (UTC) X-Farcaster-Flow-ID: 632f0500-25a2-4d4c-bbc6-5af16630b27c 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.34; Thu, 3 Oct 2024 20:59:15 +0000 Received: from 88665a182662.ant.amazon.com (10.187.171.32) 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.35; Thu, 3 Oct 2024 20:59:12 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , , Jeremy Kerr , Matt Johnston Subject: [PATCH v1 net 4/6] mctp: Handle error of rtnl_register_module(). Date: Thu, 3 Oct 2024 13:57:23 -0700 Message-ID: <20241003205725.5612-5-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241003205725.5612-1-kuniyu@amazon.com> References: <20241003205725.5612-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: EX19D046UWA001.ant.amazon.com (10.13.139.112) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org Since introduced, mctp has been ignoring the returned value of rtnl_register_module(), which could fail. Let's handle the errors by rtnl_register_module_many(). Fixes: 583be982d934 ("mctp: Add device handling and netlink interface") Fixes: 831119f88781 ("mctp: Add neighbour netlink interface") Fixes: 06d2f4c583a7 ("mctp: Add netlink route management") Signed-off-by: Kuniyuki Iwashima --- Cc: Jeremy Kerr Cc: Matt Johnston --- include/net/mctp.h | 2 +- net/mctp/af_mctp.c | 6 +++++- net/mctp/device.c | 30 ++++++++++++++++++------------ net/mctp/neigh.c | 29 ++++++++++++++++++----------- net/mctp/route.c | 34 ++++++++++++++++++++++++---------- 5 files changed, 66 insertions(+), 35 deletions(-) diff --git a/include/net/mctp.h b/include/net/mctp.h index 7b17c52e8ce2..28d59ae94ca3 100644 --- a/include/net/mctp.h +++ b/include/net/mctp.h @@ -295,7 +295,7 @@ void mctp_neigh_remove_dev(struct mctp_dev *mdev); int mctp_routes_init(void); void mctp_routes_exit(void); -void mctp_device_init(void); +int mctp_device_init(void); void mctp_device_exit(void); #endif /* __NET_MCTP_H */ diff --git a/net/mctp/af_mctp.c b/net/mctp/af_mctp.c index 43288b408fde..f6de136008f6 100644 --- a/net/mctp/af_mctp.c +++ b/net/mctp/af_mctp.c @@ -756,10 +756,14 @@ static __init int mctp_init(void) if (rc) goto err_unreg_routes; - mctp_device_init(); + rc = mctp_device_init(); + if (rc) + goto err_unreg_neigh; return 0; +err_unreg_neigh: + mctp_neigh_exit(); err_unreg_routes: mctp_routes_exit(); err_unreg_proto: diff --git a/net/mctp/device.c b/net/mctp/device.c index acb97b257428..3e5cfe119519 100644 --- a/net/mctp/device.c +++ b/net/mctp/device.c @@ -524,25 +524,31 @@ static struct notifier_block mctp_dev_nb = { .priority = ADDRCONF_NOTIFY_PRIORITY, }; -void __init mctp_device_init(void) +static struct rtnl_msg_handler mctp_rtnl_addr_msg_handlers[] = { + {PF_MCTP, RTM_NEWADDR, mctp_rtm_newaddr, NULL, 0}, + {PF_MCTP, RTM_DELADDR, mctp_rtm_deladdr, NULL, 0}, + {PF_MCTP, RTM_GETADDR, NULL, mctp_dump_addrinfo, 0}, +}; + +int __init mctp_device_init(void) { - register_netdevice_notifier(&mctp_dev_nb); + int err; - rtnl_register_module(THIS_MODULE, PF_MCTP, RTM_GETADDR, - NULL, mctp_dump_addrinfo, 0); - rtnl_register_module(THIS_MODULE, PF_MCTP, RTM_NEWADDR, - mctp_rtm_newaddr, NULL, 0); - rtnl_register_module(THIS_MODULE, PF_MCTP, RTM_DELADDR, - mctp_rtm_deladdr, NULL, 0); + register_netdevice_notifier(&mctp_dev_nb); rtnl_af_register(&mctp_af_ops); + + err = rtnl_register_module_many(mctp_rtnl_addr_msg_handlers); + if (err) { + rtnl_af_unregister(&mctp_af_ops); + unregister_netdevice_notifier(&mctp_dev_nb); + } + + return err; } void __exit mctp_device_exit(void) { + rtnl_unregister_many(mctp_rtnl_addr_msg_handlers); rtnl_af_unregister(&mctp_af_ops); - rtnl_unregister(PF_MCTP, RTM_DELADDR); - rtnl_unregister(PF_MCTP, RTM_NEWADDR); - rtnl_unregister(PF_MCTP, RTM_GETADDR); - unregister_netdevice_notifier(&mctp_dev_nb); } diff --git a/net/mctp/neigh.c b/net/mctp/neigh.c index ffa0f9e0983f..6bcdae3c53b2 100644 --- a/net/mctp/neigh.c +++ b/net/mctp/neigh.c @@ -322,22 +322,29 @@ static struct pernet_operations mctp_net_ops = { .exit = mctp_neigh_net_exit, }; +static struct rtnl_msg_handler mctp_rtnl_neigh_msg_handlers[] = { + {PF_MCTP, RTM_NEWNEIGH, mctp_rtm_newneigh, NULL, 0}, + {PF_MCTP, RTM_DELNEIGH, mctp_rtm_delneigh, NULL, 0}, + {PF_MCTP, RTM_GETNEIGH, NULL, mctp_rtm_getneigh, 0}, +}; + int __init mctp_neigh_init(void) { - rtnl_register_module(THIS_MODULE, PF_MCTP, RTM_NEWNEIGH, - mctp_rtm_newneigh, NULL, 0); - rtnl_register_module(THIS_MODULE, PF_MCTP, RTM_DELNEIGH, - mctp_rtm_delneigh, NULL, 0); - rtnl_register_module(THIS_MODULE, PF_MCTP, RTM_GETNEIGH, - NULL, mctp_rtm_getneigh, 0); - - return register_pernet_subsys(&mctp_net_ops); + int err; + + err = rtnl_register_module_many(mctp_rtnl_neigh_msg_handlers); + if (err) + return err; + + err = register_pernet_subsys(&mctp_net_ops); + if (err) + rtnl_unregister_many(mctp_rtnl_neigh_msg_handlers); + + return err; } void __exit mctp_neigh_exit(void) { unregister_pernet_subsys(&mctp_net_ops); - rtnl_unregister(PF_MCTP, RTM_GETNEIGH); - rtnl_unregister(PF_MCTP, RTM_DELNEIGH); - rtnl_unregister(PF_MCTP, RTM_NEWNEIGH); + rtnl_unregister_many(mctp_rtnl_neigh_msg_handlers); } diff --git a/net/mctp/route.c b/net/mctp/route.c index eefd7834d9a0..88ac6feb4e22 100644 --- a/net/mctp/route.c +++ b/net/mctp/route.c @@ -1474,26 +1474,40 @@ static struct pernet_operations mctp_net_ops = { .exit = mctp_routes_net_exit, }; +static struct rtnl_msg_handler mctp_rtnl_route_msg_handlers[] = { + {PF_MCTP, RTM_NEWROUTE, mctp_newroute, NULL, 0}, + {PF_MCTP, RTM_DELROUTE, mctp_delroute, NULL, 0}, + {PF_MCTP, RTM_GETROUTE, NULL, mctp_dump_rtinfo, 0}, +}; + int __init mctp_routes_init(void) { + int err; + dev_add_pack(&mctp_packet_type); - rtnl_register_module(THIS_MODULE, PF_MCTP, RTM_GETROUTE, - NULL, mctp_dump_rtinfo, 0); - rtnl_register_module(THIS_MODULE, PF_MCTP, RTM_NEWROUTE, - mctp_newroute, NULL, 0); - rtnl_register_module(THIS_MODULE, PF_MCTP, RTM_DELROUTE, - mctp_delroute, NULL, 0); + err = rtnl_register_module_many(mctp_rtnl_route_msg_handlers); + if (err) + goto fail_rtnl; + + err = register_pernet_subsys(&mctp_net_ops); + if (err) + goto fail_pernet; - return register_pernet_subsys(&mctp_net_ops); +out: + return err; + +fail_pernet: + rtnl_unregister_many(mctp_rtnl_route_msg_handlers); +fail_rtnl: + dev_remove_pack(&mctp_packet_type); + goto out; } void mctp_routes_exit(void) { unregister_pernet_subsys(&mctp_net_ops); - rtnl_unregister(PF_MCTP, RTM_DELROUTE); - rtnl_unregister(PF_MCTP, RTM_NEWROUTE); - rtnl_unregister(PF_MCTP, RTM_GETROUTE); + rtnl_unregister_many(mctp_rtnl_route_msg_handlers); dev_remove_pack(&mctp_packet_type); } From patchwork Thu Oct 3 20:57:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13821564 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 E24C0BA41 for ; Thu, 3 Oct 2024 20:59:41 +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=1727989183; cv=none; b=pL6cOmbRX1MHoVm4gHo5kRcfFo/5+agScYuj5z2MDnXzx5H2LdCN9T2zX3acqFxm7kErQd9iojYn8Tn/FU9qt4OhaxlQRr/AfxtASP0cgfsAu1P1JawU095w3PszGn+oufk5XrJza0nPctG81CooM5fT5b3Fvk+kfk3cfZAtE/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727989183; c=relaxed/simple; bh=NY22pid3HCXxCIj/1IGFv3Tr+qHCbmOKbapuFit7Zrw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q1QiO0V+KBizRuS3KroVpY3fBNRJk56ed6rwRwOBLc27TFTdLxLRXZcbcbFEKFv3DSwOqGreAK5+otKpGF3t8+s4w6+jgILs/vNRYtT1XH6qylLCJTiwmYXEigFTAPB05DH+9bvKVMrP6DrRGe5ZsIPTYGmkp1ETzsaRyOC1IHQ= 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=C/3RdY92; 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="C/3RdY92" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1727989182; x=1759525182; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PLSfPFBVZvMGJqC5yh1/Qa5hnsbwA8Ea18CHwsSjSBQ=; b=C/3RdY92tlHE32Xj0Sge6VZ2fEExfEfRgRgrUubN2O2+QJgY7rKsPQHh gllYMdA/fCBlPdUIQ42D97PG3jGjy4zLvUjoVI51xodui6GXy3ecSWnAE EJHKKnF4+qJwG0xA6UOMQ4XKueXkotmGOYpPUjaDDGCLFiuu5tg7aQVzP 4=; X-IronPort-AV: E=Sophos;i="6.11,175,1725321600"; d="scan'208";a="339352287" 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; 03 Oct 2024 20:59:42 +0000 Received: from EX19MTAUWC002.ant.amazon.com [10.0.38.20:51524] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.57.100:2525] with esmtp (Farcaster) id 360a1209-3e0a-46ce-a143-bc1f963db33d; Thu, 3 Oct 2024 20:59:41 +0000 (UTC) X-Farcaster-Flow-ID: 360a1209-3e0a-46ce-a143-bc1f963db33d Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Thu, 3 Oct 2024 20:59:40 +0000 Received: from 88665a182662.ant.amazon.com (10.187.171.32) 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.35; Thu, 3 Oct 2024 20:59:37 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , , "Eric W. Biederman" Subject: [PATCH v1 net 5/6] mpls: Handle error of rtnl_register_module(). Date: Thu, 3 Oct 2024 13:57:24 -0700 Message-ID: <20241003205725.5612-6-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241003205725.5612-1-kuniyu@amazon.com> References: <20241003205725.5612-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: EX19D038UWC002.ant.amazon.com (10.13.139.238) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org Since introduced, mpls_init() has been ignoring the returned value of rtnl_register_module(), which could fail. Let's handle the errors by rtnl_register_module_many(). Fixes: 03c0566542f4 ("mpls: Netlink commands to add, remove, and dump routes") Signed-off-by: Kuniyuki Iwashima --- Cc: "Eric W. Biederman" --- net/mpls/af_mpls.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c index aba983531ed3..653897327165 100644 --- a/net/mpls/af_mpls.c +++ b/net/mpls/af_mpls.c @@ -2728,6 +2728,15 @@ static struct rtnl_af_ops mpls_af_ops __read_mostly = { .get_stats_af_size = mpls_get_stats_af_size, }; +static struct rtnl_msg_handler mpls_rtnl_msg_handlers[] = { + {PF_MPLS, RTM_NEWROUTE, mpls_rtm_newroute, NULL, 0}, + {PF_MPLS, RTM_DELROUTE, mpls_rtm_delroute, NULL, 0}, + {PF_MPLS, RTM_GETROUTE, mpls_getroute, mpls_dump_routes, 0}, + {PF_MPLS, RTM_GETNETCONF, + mpls_netconf_get_devconf, mpls_netconf_dump_devconf, + RTNL_FLAG_DUMP_UNLOCKED}, +}; + static int __init mpls_init(void) { int err; @@ -2746,24 +2755,25 @@ static int __init mpls_init(void) rtnl_af_register(&mpls_af_ops); - rtnl_register_module(THIS_MODULE, PF_MPLS, RTM_NEWROUTE, - mpls_rtm_newroute, NULL, 0); - rtnl_register_module(THIS_MODULE, PF_MPLS, RTM_DELROUTE, - mpls_rtm_delroute, NULL, 0); - rtnl_register_module(THIS_MODULE, PF_MPLS, RTM_GETROUTE, - mpls_getroute, mpls_dump_routes, 0); - rtnl_register_module(THIS_MODULE, PF_MPLS, RTM_GETNETCONF, - mpls_netconf_get_devconf, - mpls_netconf_dump_devconf, - RTNL_FLAG_DUMP_UNLOCKED); - err = ipgre_tunnel_encap_add_mpls_ops(); + err = rtnl_register_module_many(mpls_rtnl_msg_handlers); if (err) + goto out_unregister_rtnl_af; + + err = ipgre_tunnel_encap_add_mpls_ops(); + if (err) { pr_err("Can't add mpls over gre tunnel ops\n"); + goto out_unregister_rtnl; + } err = 0; out: return err; +out_unregister_rtnl: + rtnl_unregister_many(mpls_rtnl_msg_handlers); +out_unregister_rtnl_af: + rtnl_af_unregister(&mpls_af_ops); + dev_remove_pack(&mpls_packet_type); out_unregister_pernet: unregister_pernet_subsys(&mpls_net_ops); goto out; From patchwork Thu Oct 3 20:57:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13821565 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 56F4B1B85CB for ; Thu, 3 Oct 2024 21:00:07 +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=1727989208; cv=none; b=IJ5LMvOwPW+8zciypxFdCTluz0IEKxY9GP2viG15S6WkxHbMjYlSvv8VfFIGyFuQJaJn2C0CMi/wl/fsgpOTzJZ8RyqsHtKW5aD7my61KtIWGhIaEt5p/7J12PgDEOpY5xdNv+gbFrwzovZndvBK9jgQ3FBSnyQy3Wt3gwdHBww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727989208; c=relaxed/simple; bh=vn2OqySmPduV6bQ8iIhZMkLsGO6m9NSzpa6w4B+acM4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iyvTEcF8qkJ3845mkOFQqtk8co1Y1LbbYneVMHiIV/XCDO7cP7TYnypZQ6lfx6zskslKDOzONa1WVk0VM5TgO5XrKDtRsOfW5wtPMg5uZJnJRsjVIX17jdIsn9U5SYK4XdqmG6udm441XtKBR5fjzd3do31KyqhigBxlyHbZA6k= 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=pBE7Nysg; 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="pBE7Nysg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1727989208; x=1759525208; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fSQDUAF1Kx9sqOJCUiEVjJHxubWxak+52JKbhay6Tos=; b=pBE7NysgayNjxb9zCvuOtiId0N0x/QlxO9QnyhlhBE1ouGx3z9Ala5ls G3c0MG1t2lBsWAk3F9fFlEPKj7eGXjTe7dU7AAS4o6OGMQfYJxjvCrOqP +k+EGi+BExCGE9Xn149RSxym+cfCmmYspmm73FgmcrijbA+EYjQEBpWkL s=; X-IronPort-AV: E=Sophos;i="6.11,175,1725321600"; d="scan'208";a="339352493" 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; 03 Oct 2024 21:00:07 +0000 Received: from EX19MTAUWC001.ant.amazon.com [10.0.21.151:36958] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.25.223:2525] with esmtp (Farcaster) id e5a109a1-ed38-46ca-b3ef-d7955f27125f; Thu, 3 Oct 2024 21:00:06 +0000 (UTC) X-Farcaster-Flow-ID: e5a109a1-ed38-46ca-b3ef-d7955f27125f Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Thu, 3 Oct 2024 21:00:06 +0000 Received: from 88665a182662.ant.amazon.com (10.187.171.32) 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.35; Thu, 3 Oct 2024 21:00:03 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , , Remi Denis-Courmont , Florian Westphal Subject: [PATCH v1 net 6/6] phonet: Handle error of rtnl_register_module(). Date: Thu, 3 Oct 2024 13:57:25 -0700 Message-ID: <20241003205725.5612-7-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241003205725.5612-1-kuniyu@amazon.com> References: <20241003205725.5612-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: EX19D045UWA001.ant.amazon.com (10.13.139.83) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org Before commit addf9b90de22 ("net: rtnetlink: use rcu to free rtnl message handlers"), once the first rtnl_register_module() allocated rtnl_msg_handlers[PF_PHONET], the following calls never failed. However, after the commit, rtnl_register_module() could fail to allocate rtnl_msg_handlers[PF_PHONET][msgtype] and requires error handling for each call. Let's use rtnl_register_module_many() to handle the errors easily. Fixes: addf9b90de22 ("net: rtnetlink: use rcu to free rtnl message handlers") Signed-off-by: Kuniyuki Iwashima Acked-by: RĂ©mi Denis-Courmont --- Cc: Remi Denis-Courmont Cc: Florian Westphal --- net/phonet/pn_netlink.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c index 7008d402499d..d39e6983926b 100644 --- a/net/phonet/pn_netlink.c +++ b/net/phonet/pn_netlink.c @@ -285,23 +285,16 @@ static int route_dumpit(struct sk_buff *skb, struct netlink_callback *cb) return err; } +static struct rtnl_msg_handler phonet_rtnl_msg_handlers[] __initdata_or_module = { + {PF_PHONET, RTM_NEWADDR, addr_doit, NULL, 0}, + {PF_PHONET, RTM_DELADDR, addr_doit, NULL, 0}, + {PF_PHONET, RTM_GETADDR, NULL, getaddr_dumpit, 0}, + {PF_PHONET, RTM_NEWROUTE, route_doit, NULL, 0}, + {PF_PHONET, RTM_DELROUTE, route_doit, NULL, 0}, + {PF_PHONET, RTM_GETROUTE, NULL, route_dumpit, RTNL_FLAG_DUMP_UNLOCKED}, +}; + int __init phonet_netlink_register(void) { - int err = rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_NEWADDR, - addr_doit, NULL, 0); - if (err) - return err; - - /* Further rtnl_register_module() cannot fail */ - rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_DELADDR, - addr_doit, NULL, 0); - rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_GETADDR, - NULL, getaddr_dumpit, 0); - rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_NEWROUTE, - route_doit, NULL, 0); - rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_DELROUTE, - route_doit, NULL, 0); - rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_GETROUTE, - NULL, route_dumpit, RTNL_FLAG_DUMP_UNLOCKED); - return 0; + return rtnl_register_module_many(phonet_rtnl_msg_handlers); }