netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tipc: Fix uninit-value access in tipc_nl_node_get_link()
@ 2023-10-13  7:04 Ma Ke
  2023-10-13  8:56 ` Vadim Fedorenko
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ma Ke @ 2023-10-13  7:04 UTC (permalink / raw)
  To: jmaloy, ying.xue, davem, edumazet, kuba, pabeni
  Cc: netdev, tipc-discussion, linux-kernel, Ma Ke

Names must be null-terminated strings. If a name which is not 
null-terminated is passed through netlink, strstr() and similar 
functions can cause buffer overrun. This patch fixes this issue 
by returning -EINVAL if a non-null-terminated name is passed.

Signed-off-by: Ma Ke <make_ruc2021@163.com>
---
 net/tipc/node.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/tipc/node.c b/net/tipc/node.c
index 3105abe97bb9..a02bcd7e07d3 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -2519,6 +2519,9 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info)
 		return -EINVAL;
 
 	name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
+	if (name[strnlen(name,
+			 nla_len(attrs[TIPC_NLA_LINK_NAME]))] != '\0')
+		return -EINVAL;
 
 	msg.skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
 	if (!msg.skb)
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tipc: Fix uninit-value access in tipc_nl_node_get_link()
  2023-10-13  7:04 [PATCH] tipc: Fix uninit-value access in tipc_nl_node_get_link() Ma Ke
@ 2023-10-13  8:56 ` Vadim Fedorenko
  2023-10-13  9:20 ` Florian Westphal
  2023-10-14  0:17 ` Jakub Kicinski
  2 siblings, 0 replies; 4+ messages in thread
From: Vadim Fedorenko @ 2023-10-13  8:56 UTC (permalink / raw)
  To: Ma Ke, jmaloy, ying.xue, davem, edumazet, kuba, pabeni
  Cc: netdev, tipc-discussion, linux-kernel

On 13/10/2023 08:04, Ma Ke wrote:
> Names must be null-terminated strings. If a name which is not
> null-terminated is passed through netlink, strstr() and similar
> functions can cause buffer overrun. This patch fixes this issue
> by returning -EINVAL if a non-null-terminated name is passed.
> 
> Signed-off-by: Ma Ke <make_ruc2021@163.com>
> ---
>   net/tipc/node.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/net/tipc/node.c b/net/tipc/node.c
> index 3105abe97bb9..a02bcd7e07d3 100644
> --- a/net/tipc/node.c
> +++ b/net/tipc/node.c
> @@ -2519,6 +2519,9 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info)
>   		return -EINVAL;
>   
>   	name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
> +	if (name[strnlen(name,
> +			 nla_len(attrs[TIPC_NLA_LINK_NAME]))] != '\0')
> +		return -EINVAL;

The better choice would be to use strncmp() with limit of
TIPC_MAX_LINK_NAME in tipc_node_find_by_name().
This patch fixes tipc_nl_node_get_link(), but the same pattern is used
in tipc_nl_node_set_link() and tipc_nl_node_reset_link_stats(), these
functions also need improvements. Changes to strncmp() and strnstr()
will fix all spots.

>   
>   	msg.skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
>   	if (!msg.skb)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tipc: Fix uninit-value access in tipc_nl_node_get_link()
  2023-10-13  7:04 [PATCH] tipc: Fix uninit-value access in tipc_nl_node_get_link() Ma Ke
  2023-10-13  8:56 ` Vadim Fedorenko
@ 2023-10-13  9:20 ` Florian Westphal
  2023-10-14  0:17 ` Jakub Kicinski
  2 siblings, 0 replies; 4+ messages in thread
From: Florian Westphal @ 2023-10-13  9:20 UTC (permalink / raw)
  To: Ma Ke
  Cc: jmaloy, ying.xue, davem, edumazet, kuba, pabeni, netdev,
	tipc-discussion, linux-kernel

Ma Ke <make_ruc2021@163.com> wrote:
> Names must be null-terminated strings. If a name which is not 
> null-terminated is passed through netlink, strstr() and similar 
> functions can cause buffer overrun. This patch fixes this issue 
> by returning -EINVAL if a non-null-terminated name is passed.
> 
> Signed-off-by: Ma Ke <make_ruc2021@163.com>
> ---
>  net/tipc/node.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/net/tipc/node.c b/net/tipc/node.c
> index 3105abe97bb9..a02bcd7e07d3 100644
> --- a/net/tipc/node.c
> +++ b/net/tipc/node.c
> @@ -2519,6 +2519,9 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info)
>  		return -EINVAL;
>  
>  	name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
> +	if (name[strnlen(name,
> +			 nla_len(attrs[TIPC_NLA_LINK_NAME]))] != '\0')
> +		return -EINVAL;

If the existing userspace is passing 0-terminated strings it would be
better to fix the policy (tipc_nl_link_policy) instead (and set NLA_NUL_STRING).

And if not, above change breaks userspace.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tipc: Fix uninit-value access in tipc_nl_node_get_link()
  2023-10-13  7:04 [PATCH] tipc: Fix uninit-value access in tipc_nl_node_get_link() Ma Ke
  2023-10-13  8:56 ` Vadim Fedorenko
  2023-10-13  9:20 ` Florian Westphal
@ 2023-10-14  0:17 ` Jakub Kicinski
  2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2023-10-14  0:17 UTC (permalink / raw)
  To: Ma Ke
  Cc: jmaloy, ying.xue, davem, edumazet, pabeni, netdev,
	tipc-discussion, linux-kernel

On Fri, 13 Oct 2023 15:04:08 +0800 Ma Ke wrote:
> Names must be null-terminated strings. If a name which is not 
> null-terminated is passed through netlink, strstr() and similar 
> functions can cause buffer overrun. This patch fixes this issue 
> by returning -EINVAL if a non-null-terminated name is passed.
> 
> Signed-off-by: Ma Ke <make_ruc2021@163.com>

You have now sent 14 incorrect fixes to Linux networking. 
And not a single correct one.
I would like to politely ask you to stop.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-14  0:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-13  7:04 [PATCH] tipc: Fix uninit-value access in tipc_nl_node_get_link() Ma Ke
2023-10-13  8:56 ` Vadim Fedorenko
2023-10-13  9:20 ` Florian Westphal
2023-10-14  0:17 ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).