From patchwork Fri Oct 4 22:23:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13823059 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 5A1471AE016 for ; Fri, 4 Oct 2024 22:24:36 +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=1728080677; cv=none; b=PIc4knIGJxREDuTN2oG1KRAKs8Uzkro12+YXnXBGV1kUV9KRwZLW8yBzECjFisEQz4WFOWkHw6rlTMB8O3MZasbWQArewsQpBO0cxR9IhmYqDcoKUBMw0yCP+/6UrowHPcyqwXzMHdQ+21PYI7OmoOo5WDmXwLO6cyzH7QfTTNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728080677; c=relaxed/simple; bh=EOjVh/y4SslOWLXNzHTY7N5QGXsYG3/niD1gPvO43TQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e595XlPLrB+0rPJSKi5/K8I2HggmgKbRLcERUkqNBP02aYYCsYW8zHXiRVBkn0Q8leYpvJceRFBJdYNl4HHAWL4SQivMTuAJXGGumS06//WjVX2P0QDXDk2Pnk2SnCKbWhrUQ+dy2SEcREKPwfQ+bnWkYuJp9rSdHc5R71Rf3Ng= 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=U/KL1Tk8; 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="U/KL1Tk8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1728080676; x=1759616676; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=seOYwIJkBjxJmZoQqu+ysVQtUocOzwWaMd0oDOzAIrY=; b=U/KL1Tk8nMZW4mv7i2mB2PD8Qxnew2AECj7RyBkE0RTaa/6mYhw051MJ UeKZNMirQwt0/4ya11mozOimcZKuu7IFK7hg2170Ck4fKPBBN5L2Qnr/U G5oaK3rqu9CtusQqa+larsbZGHsBNNAOL2RDctTPTS0kUusPvIXXyv/74 o=; X-IronPort-AV: E=Sophos;i="6.11,178,1725321600"; d="scan'208";a="339909027" 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; 04 Oct 2024 22:24:34 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.38.20:30475] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.41.198:2525] with esmtp (Farcaster) id d3beda05-1003-467b-899c-1ce44e71cc18; Fri, 4 Oct 2024 22:24:34 +0000 (UTC) X-Farcaster-Flow-ID: d3beda05-1003-467b-899c-1ce44e71cc18 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; Fri, 4 Oct 2024 22:24:33 +0000 Received: from 88665a182662.ant.amazon.com (10.88.184.239) 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; Fri, 4 Oct 2024 22:24:31 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v2 net 1/6] rtnetlink: Add bulk registration helpers for rtnetlink message handlers. Date: Fri, 4 Oct 2024 15:23:53 -0700 Message-ID: <20241004222358.79129-2-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241004222358.79129-1-kuniyu@amazon.com> References: <20241004222358.79129-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: EX19D044UWB001.ant.amazon.com (10.13.139.171) 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 Fri Oct 4 22:23:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13823060 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 17C8F1474B9 for ; Fri, 4 Oct 2024 22:24:58 +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=1728080701; cv=none; b=D0yRpXioM/D3DA7df7pFJcCiyc5e3ET9Bl5v+h9H0dLdcrD/6QUO7/EWwJg8K6cyKwjUmv6fYkTbfI7DQ/OgX2ZjUPowep8+3SUKrPz5+RZw1Pb6nJFPNX4I2A/eqrQp1c7t5YpFY91Ysrf4IY4EdSYTXo/MCn96Jm6JOFFiq5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728080701; c=relaxed/simple; bh=bYWrwZ3KRdxV/MYkDFB9m2JZ3vPtJUXFMpJYUXiWMS8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H2TY2JHgFypyEKzultr3I/bj9qG8JZL77VgnvuSdr/Lcahq2Bxu7YjNVgNBDH+XMgc7xtv4WpfgSH3c9xblRfRJIvZoctgfPc78DxIn+8dT5lbCtT6iCN6LgkJU1AOuVwuHN+z/k+eaS/D5MmwEQEJyFgq5g4ichfTpZnVcyI4Q= 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=Dcx5t5km; 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="Dcx5t5km" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1728080700; x=1759616700; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+jaspAmYjxPpjoDdOyJF57w+i/GYV07UYc6SnYI+f5o=; b=Dcx5t5kmzLqQoE2Z4E0/nWrxWvGC6gj4NmUcVn+H23YyrdObpUPTr/Jy 7qcCK7yqgqNLhmAZbqZWcxoSv/6IJRGINCYRBRvnjPOgl5ht+LTvf44O8 8WcP9Rjn0TnVy2BU8cOSFlqRbAP5A20+jgWajr0hvtgbmZ/1ThY6EJFdU k=; X-IronPort-AV: E=Sophos;i="6.11,178,1725321600"; d="scan'208";a="339909139" 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; 04 Oct 2024 22:24:59 +0000 Received: from EX19MTAUWA002.ant.amazon.com [10.0.38.20:62166] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.6.41:2525] with esmtp (Farcaster) id f2e43582-d156-413e-a40a-f6574638161c; Fri, 4 Oct 2024 22:24:58 +0000 (UTC) X-Farcaster-Flow-ID: f2e43582-d156-413e-a40a-f6574638161c 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.34; Fri, 4 Oct 2024 22:24:58 +0000 Received: from 88665a182662.ant.amazon.com (10.88.184.239) 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; Fri, 4 Oct 2024 22:24:55 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , , Roopa Prabhu Subject: [PATCH v2 net 2/6] vxlan: Handle error of rtnl_register_module(). Date: Fri, 4 Oct 2024 15:23:54 -0700 Message-ID: <20241004222358.79129-3-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241004222358.79129-1-kuniyu@amazon.com> References: <20241004222358.79129-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: EX19D041UWB004.ant.amazon.com (10.13.139.143) 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 Reviewed-by: Nikolay Aleksandrov --- 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..27b4d179a703 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_vnifilter_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_vnifilter_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_vnifilter_rtnl_msg_handlers); } From patchwork Fri Oct 4 22:23:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13823061 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52002.amazon.com (smtp-fw-52002.amazon.com [52.119.213.150]) (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 8A775231C80 for ; Fri, 4 Oct 2024 22:25:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728080726; cv=none; b=metwNA9jIk0y3eYW+s7pfxVInuBCPvWq2aZ8IIvkFvDIzrIVa5DoKL/uDrCNukJkwNfKQ6M7Y66BzXGqw9eedUkauUnpmTTE3dJF+O2nZxH+oKyh18Tap4LhEcK+IoW7xcInBwsO0Tak8lH1usr+8UizSt+yrIhN8N4YMfhiSrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728080726; c=relaxed/simple; bh=DoYHM5EB6pZkyhbwuxrVTCMFKPSezGGsWKo7i+noN7w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BWzUQEOIjafBiczWCSZdVBSnq8pzjUJPUaHzgzYJflwtypX3VTF5ByK9qYLS51sbVBVcP2biQzVBtP21heyYvV8FQns5qYa9pBOux7kWWtG7P2yzQlbGuo/OvKZAIxuiukoqy0e1NUaFSyJGPS6oN25lj7IWyHRxkhM/Wcs9uMM= 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=gIjI48Em; arc=none smtp.client-ip=52.119.213.150 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="gIjI48Em" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1728080725; x=1759616725; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OTB5nJR3EjIJ1YjlFz4A7YqKJObwtjuQmwmzlF/CqxM=; b=gIjI48EmYW8GDxt6MCGeMoeOWmGXzIf4V3TZ/5oq2eWmjI/TkK3zTMqz X5kLNio7vb1KnllV6G8nui0fPrqud/7qIB13NZA7ON4TawrujQqDaTDff oAjk3reBQDDCruEca9CExe3k9wdkT/vDem7gln8wOnnFqSEdZWqduJXhb Q=; X-IronPort-AV: E=Sophos;i="6.11,178,1725321600"; d="scan'208";a="663830981" 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-52002.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2024 22:25:23 +0000 Received: from EX19MTAUWC002.ant.amazon.com [10.0.38.20:33558] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.41.198:2525] with esmtp (Farcaster) id 1ff42ff3-3ec6-4257-8c78-656f1f25115a; Fri, 4 Oct 2024 22:25:22 +0000 (UTC) X-Farcaster-Flow-ID: 1ff42ff3-3ec6-4257-8c78-656f1f25115a 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; Fri, 4 Oct 2024 22:25:21 +0000 Received: from 88665a182662.ant.amazon.com (10.88.184.239) 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; Fri, 4 Oct 2024 22:25:19 +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 v2 net 3/6] bridge: Handle error of rtnl_register_module(). Date: Fri, 4 Oct 2024 15:23:55 -0700 Message-ID: <20241004222358.79129-4-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241004222358.79129-1-kuniyu@amazon.com> References: <20241004222358.79129-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: EX19D039UWB003.ant.amazon.com (10.13.138.93) 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 Acked-by: Nikolay Aleksandrov --- 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 Fri Oct 4 22:23:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13823062 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52002.amazon.com (smtp-fw-52002.amazon.com [52.119.213.150]) (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 7908E1AE016 for ; Fri, 4 Oct 2024 22:25:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728080752; cv=none; b=TtMEcUHPF/oAu6NEFU/3Q6kUk0M3/SQtVWioMZ+b7feTFbKfQ/In4Prol5D9H2+RS5xrP+DUmvpWjYH4bYofgGNuB2HVJM/RQV/NEJbUPRyKle0Z+bqYOWnzYfiLMFlsWJglCarecTLu57t7Hx3+EMiO+NmqPTEahUspG5pHXVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728080752; c=relaxed/simple; bh=xK5EJIXdG1+AkpIH88womkiriYhcbPsU2HBPSRxuDFk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rLxhG99XinJF22bCiuJ1PBFad4ee6h/iJjcIytxnXtyqbPPZn0q0Ps04fyE/qUze/7Qjr6SvF/2/FjLJ8tqg29gbQvEoehMEEy47bv1UlEEyCIJM2yixTcAUr2652Y07uZeY+t+mYWET+wi6pdZEME/PjEKbEa7v5fsj4APi908= 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=G2mnhViZ; arc=none smtp.client-ip=52.119.213.150 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="G2mnhViZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1728080751; x=1759616751; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XkT8Ca7ats+yvzh1zsTnkwh6q4fxqQZOVVnE/iXA4g4=; b=G2mnhViZmfJtyV7kKwlmZXLk5PvA2gjYbD4lPpqlsNgqCZQlxumGhL5D GMmNIE5N/kCfaZd28lZuJvdkD+sJRB6kPzXITT4INOBSDdwrfpaxELok8 xijWzwcS31wLJgXRGHJXsIBZ0D30A9PYaDtf9xhrhpQP4cwF1tNsD+XQF c=; X-IronPort-AV: E=Sophos;i="6.11,178,1725321600"; d="scan'208";a="663831048" 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-52002.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2024 22:25:49 +0000 Received: from EX19MTAUWA001.ant.amazon.com [10.0.38.20:32230] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.6.41:2525] with esmtp (Farcaster) id 4204bda0-e04c-4044-84cb-bd97cf9ec285; Fri, 4 Oct 2024 22:25:48 +0000 (UTC) X-Farcaster-Flow-ID: 4204bda0-e04c-4044-84cb-bd97cf9ec285 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWA001.ant.amazon.com (10.250.64.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Fri, 4 Oct 2024 22:25:46 +0000 Received: from 88665a182662.ant.amazon.com (10.88.184.239) 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; Fri, 4 Oct 2024 22:25:44 +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 v2 net 4/6] mctp: Handle error of rtnl_register_module(). Date: Fri, 4 Oct 2024 15:23:56 -0700 Message-ID: <20241004222358.79129-5-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241004222358.79129-1-kuniyu@amazon.com> References: <20241004222358.79129-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 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 Reviewed-by: Jeremy Kerr --- 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 | 31 +++++++++++++++++++------------ net/mctp/route.c | 34 ++++++++++++++++++++++++---------- 5 files changed, 67 insertions(+), 36 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..d70e688ac886 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_device_rtnl_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_device_rtnl_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_device_rtnl_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..245f8242929b 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_neigh_rtnl_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 = register_pernet_subsys(&mctp_net_ops); + if (err) + return err; + + err = rtnl_register_module_many(mctp_neigh_rtnl_msg_handlers); + if (err) + unregister_pernet_subsys(&mctp_net_ops); + + return err; } -void __exit mctp_neigh_exit(void) +void mctp_neigh_exit(void) { + rtnl_unregister_many(mctp_neigh_rtnl_msg_handlers); unregister_pernet_subsys(&mctp_net_ops); - rtnl_unregister(PF_MCTP, RTM_GETNEIGH); - rtnl_unregister(PF_MCTP, RTM_DELNEIGH); - rtnl_unregister(PF_MCTP, RTM_NEWNEIGH); } diff --git a/net/mctp/route.c b/net/mctp/route.c index eefd7834d9a0..083f9933eb81 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_route_rtnl_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 = register_pernet_subsys(&mctp_net_ops); + if (err) + goto fail_pernet; + + err = rtnl_register_module_many(mctp_route_rtnl_msg_handlers); + if (err) + goto fail_rtnl; - return register_pernet_subsys(&mctp_net_ops); +out: + return err; + +fail_rtnl: + unregister_pernet_subsys(&mctp_net_ops); +fail_pernet: + dev_remove_pack(&mctp_packet_type); + goto out; } void mctp_routes_exit(void) { + rtnl_unregister_many(mctp_route_rtnl_msg_handlers); unregister_pernet_subsys(&mctp_net_ops); - rtnl_unregister(PF_MCTP, RTM_DELROUTE); - rtnl_unregister(PF_MCTP, RTM_NEWROUTE); - rtnl_unregister(PF_MCTP, RTM_GETROUTE); dev_remove_pack(&mctp_packet_type); } From patchwork Fri Oct 4 22:23:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13823063 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52003.amazon.com (smtp-fw-52003.amazon.com [52.119.213.152]) (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 3494D1ADFEE for ; Fri, 4 Oct 2024 22:26:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728080777; cv=none; b=KE7zEoQOVzlNGQc/2x92pA/J/64X/gz426RsN3z9rXa1wcN+TgyxE2kjd5/3QbE8+kcoDvvIH1K/KL9SRo2E7NOtoFStvyfjLxVlWbygGd009rRrM2dXgtnRLa1BhgK+PfF71rqeUKVMxdybHIhxg8XoZC5UmkIrgBfaoAXKZiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728080777; c=relaxed/simple; bh=NY22pid3HCXxCIj/1IGFv3Tr+qHCbmOKbapuFit7Zrw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EsFLojuTiiTwe4iPE1DvIiYS1z4AwGrjYGYjp9YCe7r//5TMzh6rHVnDahqRh3VlP9tieD3PdLXrqG635XQZafc25dZld7UrI0f7FNib43zb1jwivvo/g7quP3O7fF+01cRBDVKunaYECcxrX4gNwyKdDSq3xzmal0wlNZLSqG8= 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=lNbujNFu; arc=none smtp.client-ip=52.119.213.152 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="lNbujNFu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1728080777; x=1759616777; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PLSfPFBVZvMGJqC5yh1/Qa5hnsbwA8Ea18CHwsSjSBQ=; b=lNbujNFuEBfmJM4BFrrzW7YrhFDBrHwrLY8NcXoZX461V5+q0A+steP8 9XYkKm20d0NkOXM5Xts/7QPTnfewTP93B0l2CLSh4Kxid6LTaGsRz5rUy P43j5p4UJgo2CD+AmwvmVVUdYHYtmPG/Y1kP7a906hi0KjnbW+Z8JQwEH A=; X-IronPort-AV: E=Sophos;i="6.11,178,1725321600"; d="scan'208";a="30767100" 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-52003.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2024 22:26:13 +0000 Received: from EX19MTAUWC001.ant.amazon.com [10.0.21.151:27871] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.4.107:2525] with esmtp (Farcaster) id d997f9a8-3e66-49ea-b026-989802031dd8; Fri, 4 Oct 2024 22:26:12 +0000 (UTC) X-Farcaster-Flow-ID: d997f9a8-3e66-49ea-b026-989802031dd8 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; Fri, 4 Oct 2024 22:26:11 +0000 Received: from 88665a182662.ant.amazon.com (10.88.184.239) 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; Fri, 4 Oct 2024 22:26:08 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , , "Eric W. Biederman" Subject: [PATCH v2 net 5/6] mpls: Handle error of rtnl_register_module(). Date: Fri, 4 Oct 2024 15:23:57 -0700 Message-ID: <20241004222358.79129-6-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241004222358.79129-1-kuniyu@amazon.com> References: <20241004222358.79129-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: EX19D044UWA002.ant.amazon.com (10.13.139.11) 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 Fri Oct 4 22:23:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13823064 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52003.amazon.com (smtp-fw-52003.amazon.com [52.119.213.152]) (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 7E77D149C4D for ; Fri, 4 Oct 2024 22:26:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728080799; cv=none; b=iwpagh4MTdab7mWMEmSX9WXreXdcC9jf5bCtJvAZgjHXkDPoPqbEOH+fNyoCX6/glbwWBVEuVn0fLW5wj6Z61C/jDYZwTNWN/MAR6vPPfuUjeuGSvJt4p6ELNZXFQlEM5ahYb6fjwalI1iiwlWctG7aDX+C/8aa7WnhlTT/oLb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728080799; c=relaxed/simple; bh=S2VSOcRVvN3Gsk3/7VdUikD+19l3pRtPYIe3LuVBEp8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I6IAFQqeBQefHDZnYCka3PYGyZKAnIqnTVPE6/pNbk2E4PtP7ns36LYttjzrrI2GR2mzPkYqdigDt62j80yV1Rg5VvqnHTRyp7F+oLaE5Q2Jd26LHpaVxt2F1MfAKpnuxSv1s5kFQAoRHZExAjIIE2hNpE6ZBbCYgBUunBPN4M4= 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=cBZCMeCq; arc=none smtp.client-ip=52.119.213.152 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="cBZCMeCq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1728080798; x=1759616798; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TpJoU38GA8ydQeCYt6xIyPJwSL12KRVtmYq4lB8dal0=; b=cBZCMeCqDLt+V++EKxDuB/n94fBA09p8UKu/SaYNcI0uTFrFcP5G8dIz HV5IMwHGP4Q6Al1OK0a11cEWi3sn/873Tw22kDA6Qs5rHy4eQHzq+JRHP VBNHeJgJ/jfsDDdNK1jPs+31bB/Ontd96as7e70BBr+MwMwW6QLJGQ9rY k=; X-IronPort-AV: E=Sophos;i="6.11,178,1725321600"; d="scan'208";a="30767192" 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-52003.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2024 22:26:36 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.38.20:44002] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.57.100:2525] with esmtp (Farcaster) id b10eee2e-a0ab-4e48-955b-2508dbeadecd; Fri, 4 Oct 2024 22:26:35 +0000 (UTC) X-Farcaster-Flow-ID: b10eee2e-a0ab-4e48-955b-2508dbeadecd 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; Fri, 4 Oct 2024 22:26:35 +0000 Received: from 88665a182662.ant.amazon.com (10.88.184.239) 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; Fri, 4 Oct 2024 22:26:32 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , , =?utf-8?q?R=C3=A9mi_Denis-Courmont?= , "Florian Westphal" Subject: [PATCH v2 net 6/6] phonet: Handle error of rtnl_register_module(). Date: Fri, 4 Oct 2024 15:23:58 -0700 Message-ID: <20241004222358.79129-7-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241004222358.79129-1-kuniyu@amazon.com> References: <20241004222358.79129-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: EX19D042UWA002.ant.amazon.com (10.13.139.17) 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: 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); }