tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name()
Subsystems (3)
PATCH v5 1/1 tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name()
The strcpy() function is deprecated and moving towards code-tree elimination. Replacing it with strscpy() fixes potential buffer overflow vectors by ensuring safe NULL-termination based on the destination buffer size limit [1][2].
To make the interface safer and more robust for future callers, refactor tipc_bearer_get_name() to accept a destination buffer length parameter. Replace strcpy() with strscpy() and pass through any potential -E2BIG truncation error code up to the caller. Update the existing caller in net/tipc/monitor.c to pass its array size.
---
v5:
- Cleaned up implementation by removing extra ret variable as suggested.
- Wrapped long lines to fix checkpatch column-limit warning.
v4:
- Avoid hard-coding TIPC_MAX_BEARER_NAME in the function body.
- Pass size_t len from the caller down to strscpy().
- Forward strscpy()'s -E2BIG error up through the existing int return type.
- Updated function documentation comment block.
v3:
- Fix patch title as suggested by Tung Quang Nguyen.
- No code changes from v2.
v2:
- Target net-next tree instead of standard net tree as requested by Tung Quang Nguyen.
- No code changes from v1.
net/tipc/bearer.c | 6 ++++-- net/tipc/bearer.h | 3 ++- net/tipc/monitor.c | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-)
net/tipc/bearer.c +4 -2
@@ -195,9 +195,10 @@ struct tipc_bearer *tipc_bearer_find(struct net *net, const char *name)/* tipc_bearer_get_name - get the bearer name from its id. * @net: network namespace * @name: a pointer to the buffer where the name will be stored. +* @len: size of the destination buffer * @bearer_id: the id to get the name from. */ -int tipc_bearer_get_name (struct net *net,char *name,u32 bearer_id) +int tipc_bearer_get_name (struct net *net,char *name,size_t len,u32 bearer_id) {struct tipc_net *tn =tipc_net (net);struct tipc_bearer *b;
@@ -209,7 +210,8 @@ int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id)if (!b)return -EINVAL ; -strcpy (name, b->name); +if (strscpy (name, b->name, len) <0 ) +return -E2BIG ;return 0 ; }
net/tipc/bearer.h +2 -1
@@ -226,7 +226,8 @@ int tipc_l2_send_msg(struct net *net, struct sk_buff *buf,void tipc_bearer_add_dest (struct net *net,u32 bearer_id,u32 dest);void tipc_bearer_remove_dest (struct net *net,u32 bearer_id,u32 dest);struct tipc_bearer *tipc_bearer_find (struct net *net,const char *name); -int tipc_bearer_get_name (struct net *net,char *name,u32 bearer_id); +int tipc_bearer_get_name (struct net *net,char *name, +size_t len,u32 bearer_id);struct tipc_media *tipc_media_find (const char *name);int tipc_bearer_setup (void );void tipc_bearer_cleanup (void );
net/tipc/monitor.c +2 -1
@@ -829,11 +829,12 @@ int __tipc_nl_add_monitor(struct net *net, struct tipc_nl_msg *msg, {struct tipc_monitor *mon =tipc_monitor (net, bearer_id);char bearer_name[TIPC_MAX_BEARER_NAME ]; +size_t name_len =sizeof (bearer_name);struct nlattr *attrs;void *hdr;int ret; - ret =tipc_bearer_get_name (net, bearer_name, bearer_id); + ret =tipc_bearer_get_name (net, bearer_name, name_len, bearer_id);if (ret || !mon)return 0 ;
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerQuoted 1 line · On Thu, 3 Sep 2026 13:27:18 +0000 Ajith P V wrote:
From: Ajith P V <[email protected]>
Full name needed. Such a damn waste of time, SMH
Quoted 81 lines · On Thu, 3 Sep 2026 13:27:18 +0000 Ajith P V <[email protected]> wrote:
The
strcpy()function is deprecated and moving towards code-tree elimination. Replacing it withstrscpy()fixes potential buffer overflow vectors by ensuring safe NULL-termination based on the destination buffer size limit [1][2].To make the interface safer and more robust for future callers, refactor
tipc_bearer_get_name()to accept a destination buffer length parameter. Replacestrcpy()withstrscpy()and pass through any potential-E2BIGtruncation error code up to the caller. Update the existing caller innet/tipc/monitor.cto pass its array size.Signed-off-by Ajith P V <[email protected]>---
v5:
- Cleaned up implementation by removing extraretvariable as suggested.
- Wrapped long lines to fix checkpatch column-limit warning.
v4:
- Avoid hard-codingTIPC_MAX_BEARER_NAMEin the function body.
- Passsize_tlen from the caller down tostrscpy().
- Forward strscpy()'s-E2BIGerror up through the existing int return type.
- Updated function documentation comment block.
v3:
- Fix patch title as suggested by Tung Quang Nguyen.
- No code changes from v2.
v2:
- Target net-next tree instead of standard net tree as requested by Tung Quang Nguyen.
- No code changes from v1.net/tipc/bearer.c | 6 ++++-- net/tipc/bearer.h | 3 ++- net/tipc/monitor.c | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-)net/tipc/bearer.c +4
-2@@ -195,9 +195,10 @@ struct tipc_bearer *tipc_bearer_find(struct net *net, const char *name)/* tipc_bearer_get_name - get the bearer name from its id. * @net: network namespace * @name: a pointer to the buffer where the name will be stored. +* @len: size of the destination buffer * @bearer_id: the id to get the name from. */ -int tipc_bearer_get_name (struct net *net,char *name,u32 bearer_id) +int tipc_bearer_get_name (struct net *net,char *name,size_t len,u32 bearer_id) {struct tipc_net *tn =tipc_net (net);struct tipc_bearer *b;@@ -209,7 +210,8 @@ int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id)if (!b)return -EINVAL ; -strcpy (name, b->name); +if (strscpy (name, b->name, len) <0 ) +return -E2BIG ;return 0 ; }net/tipc/bearer.h +2
-1@@ -226,7 +226,8 @@ int tipc_l2_send_msg(struct net *net, struct sk_buff *buf,void tipc_bearer_add_dest (struct net *net,u32 bearer_id,u32 dest);void tipc_bearer_remove_dest (struct net *net,u32 bearer_id,u32 dest);struct tipc_bearer *tipc_bearer_find (struct net *net,const char *name); -int tipc_bearer_get_name (struct net *net,char *name,u32 bearer_id); +int tipc_bearer_get_name (struct net *net,char *name, +size_t len,u32 bearer_id);struct tipc_media *tipc_media_find (const char *name);int tipc_bearer_setup (void );void tipc_bearer_cleanup (void );net/tipc/monitor.c +0
-0
net/tipc/monitor.c int __tipc_nl_add_monitor(struct net *net, struct tipc_nl_msg *msg, · line 837
Quoted 10 lines
net/tipc/monitor.c +2
-1@@ -829,11 +829,12 @@ int __tipc_nl_add_monitor(struct net *net, struct tipc_nl_msg *msg, {struct tipc_monitor *mon =tipc_monitor (net, bearer_id);char bearer_name[TIPC_MAX_BEARER_NAME ]; +size_t name_len =sizeof (bearer_name);struct nlattr *attrs;void *hdr;int ret; - ret =tipc_bearer_get_name (net, bearer_name, bearer_id); + ret =tipc_bearer_get_name (net, bearer_name, name_len, bearer_id);
There really is no point in the name_len variable.
Quoted 3 lines
net/tipc/monitor.c +0
-0if (ret || !mon)return 0 ;