Message ID | 20220601014853.4904-1-hoang.h.le@dektech.com.au (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net] tipc: check attribute length for bearer name | expand |
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.
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)) { NL_SET_ERR_MSG(extack, "Illegal name"); - goto rejected; + return res; } if (prio > TIPC_MAX_LINK_PRI && prio != TIPC_MEDIA_LINK_PRI) {