[PATCH net-next v1 4/4] net: hsr: reject unresolved interlink ifindex

luka.gejak@linux.dev posted 4 patches 1 week, 2 days ago
There is a newer version of this series
[PATCH net-next v1 4/4] net: hsr: reject unresolved interlink ifindex
Posted by luka.gejak@linux.dev 1 week, 2 days ago
From: Luka Gejak <luka.gejak@linux.dev>

In hsr_newlink(), a provided but invalid IFLA_HSR_INTERLINK attribute
was silently ignored if __dev_get_by_index() returned NULL. This leads
to incorrect RedBox topology creation without notifying the user.

Fix this by returning -EINVAL and an extack message when the
interlink attribute is present but cannot be resolved.

Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
---
 net/hsr/hsr_netlink.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
index db0b0af7a692..f0ca23da3ab9 100644
--- a/net/hsr/hsr_netlink.c
+++ b/net/hsr/hsr_netlink.c
@@ -76,9 +76,14 @@ static int hsr_newlink(struct net_device *dev,
 		return -EINVAL;
 	}
 
-	if (data[IFLA_HSR_INTERLINK])
+	if (data[IFLA_HSR_INTERLINK]) {
 		interlink = __dev_get_by_index(link_net,
 					       nla_get_u32(data[IFLA_HSR_INTERLINK]));
+		if (!interlink) {
+			NL_SET_ERR_MSG_MOD(extack, "Interlink does not exist");
+			return -EINVAL;
+		}
+	}
 
 	if (interlink && interlink == link[0]) {
 		NL_SET_ERR_MSG_MOD(extack, "Interlink and Slave1 are the same");
-- 
2.53.0
Re: [PATCH net-next v1 4/4] net: hsr: reject unresolved interlink ifindex
Posted by Felix Maurer 1 week ago
On Tue, Mar 24, 2026 at 03:35:03PM +0100, luka.gejak@linux.dev wrote:
> From: Luka Gejak <luka.gejak@linux.dev>
>
> In hsr_newlink(), a provided but invalid IFLA_HSR_INTERLINK attribute
> was silently ignored if __dev_get_by_index() returned NULL. This leads
> to incorrect RedBox topology creation without notifying the user.

Not really incorrect, it's just not a RedBox at all.

> Fix this by returning -EINVAL and an extack message when the
> interlink attribute is present but cannot be resolved.
>
> Signed-off-by: Luka Gejak <luka.gejak@linux.dev>

Reviewed-by: Felix Maurer <fmaurer@redhat.com>

> ---
>  net/hsr/hsr_netlink.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
> index db0b0af7a692..f0ca23da3ab9 100644
> --- a/net/hsr/hsr_netlink.c
> +++ b/net/hsr/hsr_netlink.c
> @@ -76,9 +76,14 @@ static int hsr_newlink(struct net_device *dev,
>  		return -EINVAL;
>  	}
>
> -	if (data[IFLA_HSR_INTERLINK])
> +	if (data[IFLA_HSR_INTERLINK]) {
>  		interlink = __dev_get_by_index(link_net,
>  					       nla_get_u32(data[IFLA_HSR_INTERLINK]));
> +		if (!interlink) {
> +			NL_SET_ERR_MSG_MOD(extack, "Interlink does not exist");
> +			return -EINVAL;
> +		}
> +	}
>
>  	if (interlink && interlink == link[0]) {
>  		NL_SET_ERR_MSG_MOD(extack, "Interlink and Slave1 are the same");
> --
> 2.53.0
>