2022-12-24 23:59:51

by Artem Chernyshev

[permalink] [raw]
Subject: [PATCH] batman-adv: Check return value

Check, if rtnl_link_register() call in batadv_init() was successful

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: a4ac28c0d06a ("batman-adv: Allow to use rntl_link for device creation/deletion")
Signed-off-by: Artem Chernyshev <[email protected]>
---
net/batman-adv/main.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index e8a449915566..04cd9682bd29 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -113,7 +113,11 @@ static int __init batadv_init(void)
goto err_create_wq;

register_netdevice_notifier(&batadv_hard_if_notifier);
- rtnl_link_register(&batadv_link_ops);
+ ret = rtnl_link_register(&batadv_link_ops);
+ if (ret) {
+ pr_err("Can't register link_ops\n");
+ goto err_create_wq;
+ }
batadv_netlink_register();

pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) loaded\n",
--
2.30.3


2022-12-25 07:03:00

by Sven Eckelmann

[permalink] [raw]
Subject: Re: [PATCH] batman-adv: Check return value

Subject is missing something like ..." after calling rtnl_link_register()" or
..."s during module initialization".

On Sunday, 25 December 2022 00:33:11 CET Artem Chernyshev wrote:
[...]
> diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
> index e8a449915566..04cd9682bd29 100644kwin
> @@ -113,7 +113,11 @@ static int __init batadv_init(void)
> goto err_create_wq;
>
> register_netdevice_notifier(&batadv_hard_if_notifier);
> - rtnl_link_register(&batadv_link_ops);
> + ret = rtnl_link_register(&batadv_link_ops);
> + if (ret) {
> + pr_err("Can't register link_ops\n");
> + goto err_create_wq;
> + }
> batadv_netlink_register();
>
> pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) loaded\n",
>

This looks wrong to me. You missed to destroy the batadv_hard_if_notifier in
this case.

And if you want to start adding the checks, you should also have added it for
batadv_v_init, batadv_iv_init, batadv_nc_init, batadv_tp_meter_init and
register_netdevice_notifier. You can use the unfinished patch from Markus
Pargmann as starting point.

Kind regards,
Sven

[1] https://patchwork.open-mesh.org/project/b.a.t.m.a.n./patch/[email protected]/
https://lists.open-mesh.org/mailman3/hyperkitty/list/[email protected]/thread/QDX46YARWUC4R7OBFHR5OJKWQIXDQWRR/#QDX46YARWUC4R7OBFHR5OJKWQIXDQWRR


Attachments:
signature.asc (849.00 B)
This is a digitally signed message part.

2022-12-25 10:49:01

by Artem Chernyshev

[permalink] [raw]
Subject: Re: [PATCH] batman-adv: Check return value

Hi,
On Sun, Dec 25, 2022 at 07:37:28AM +0100, Sven Eckelmann wrote:
> Subject is missing something like ..." after calling rtnl_link_register()" or
> ..."s during module initialization".
>
> On Sunday, 25 December 2022 00:33:11 CET Artem Chernyshev wrote:
> [...]
> > diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
> > index e8a449915566..04cd9682bd29 100644kwin
> > @@ -113,7 +113,11 @@ static int __init batadv_init(void)
> > goto err_create_wq;
> >
> > register_netdevice_notifier(&batadv_hard_if_notifier);
> > - rtnl_link_register(&batadv_link_ops);
> > + ret = rtnl_link_register(&batadv_link_ops);
> > + if (ret) {
> > + pr_err("Can't register link_ops\n");
> > + goto err_create_wq;
> > + }
> > batadv_netlink_register();
> >
> > pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) loaded\n",
> >
>
> This looks wrong to me. You missed to destroy the batadv_hard_if_notifier in
> this case.
>
> And if you want to start adding the checks, you should also have added it for
> batadv_v_init, batadv_iv_init, batadv_nc_init, batadv_tp_meter_init and
> register_netdevice_notifier. You can use the unfinished patch from Markus
> Pargmann as starting point.
>
> Kind regards,
> Sven
>
> [1] https://patchwork.open-mesh.org/project/b.a.t.m.a.n./patch/[email protected]/
> https://lists.open-mesh.org/mailman3/hyperkitty/list/[email protected]/thread/QDX46YARWUC4R7OBFHR5OJKWQIXDQWRR/#QDX46YARWUC4R7OBFHR5OJKWQIXDQWRR

Thanks for review, I'll try to fix the errors in v2

Best,
Artem