Subject: Re: [net] tipc: check attribute length for bearer name

From: Jakub Kicinski <[email-masked]>
Date: Wed, 1 Jun 2022 17:53:18 -0700

On Wed,  1 Jun 2022 08:48:53 +0700 Hoang Le wrote:
> diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
> index 6d39ca05f249..0fd7554c7cde 100644
> --- a/net/tipc/bearer.c
> +++ b/net/tipc/bearer.c
> @@ -258,10 +258,10 @@ static int tipc_enable_bearer(struct net *net, const char *name,
>  	char *errstr = "";
>  	u32 i;
>  
> -	if (!bearer_name_validate(name, &b_names)) {
> -		errstr = "illegal name";
> +	if (strlen(name) > TIPC_MAX_BEARER_NAME ||
> +	    !bearer_name_validate(name, &b_names)) {

The strlen() check looks unnecessary, the first thing
bearer_name_validate() does is:

	/* copy bearer name & ensure length is OK */
	if (strscpy(name_copy, name, TIPC_MAX_BEARER_NAME) < 0)
		return 0;

So it will handle non-terminated or over-sized names correctly already.

>  		NL_SET_ERR_MSG(extack, "Illegal name");
> -		goto rejected;
> +		return res;

Seems like we only need the change of goto to return for the fix.