Skip to contentSkip to conversation

tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name()

PATCH Superseded Ajith P V 3 participants 8 messages Aug 13 – Aug 18

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Ajith P V

author
#0 lore raw

PATCH v3 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].

In tipc_bearer_get_name(), the 'name' parameter decays into a pointer, meaning sizeof() cannot capture the underlying array bounds directly. However, all parent callers allocate this buffer using the TIPC_MAX_BEARER_NAME macro.

Replace strcpy() with strscpy() using TIPC_MAX_BEARER_NAME as the explicit destination bound length.

---
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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/tipc/bearer.c +1 -1
index 05dcd2f9e887..951bb474c7d4 100644
@@ -209,7 +209,7 @@ int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id)
 	if (!b)
 		return -EINVAL;
 
-	strcpy(name, b->name);
+	strscpy(name, b->name, TIPC_MAX_BEARER_NAME);
 	return 0;
 }
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 1 line

Subject: [PATCH net-next v3] tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name()

It seems your patch is not based on net-next tree:
"Conflicts with pending/net patches (net-next-2026-08-13--12-00): error: patch failed: net/tipc/bearer.c:209 error: net/tipc/bearer.c: patch does not apply"

Could you please apply your patch to net-next tree and resubmit ?

author
#2 lore raw
Quoted 4 lines

It seems your patch is not based on net-next tree:
"Conflicts with pending/net patches (net-next-2026-08-13--12-00): error: patch failed: net/tipc/bearer.c:209 error: net/tipc/bearer.c: patch does not apply"

Could you please apply your patch to net-next tree and resubmit ?

First time net contributor and I'm a bit confused here. When I cloned the net-next, it applied the same patch without the error as shown below:
<path of the linux tree >net-next$ ls

arch   certs    CREDITS  Documentation  fs       init      ipc     Kconfig  lib       MAINTAINERS  mm   README  samples  security  tools  virt
block  COPYING  crypto   drivers        include  io_uring  Kbuild  kernel   LICENSES  Makefile     net  rust    scripts  sound     usr

<path of the linux tree/net-next$ git remote -v
origin https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git (fetch)
origin https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git (push)
<path of the linux tree/net-next$ git branch
* main
<path of the linux tree/net-next$ git am ../../patches/v3-0001-tipc-replace-deprecated-strcpy-with-strscpy-in-ti.patch
Applying: tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name()
<path of the linux tree/net-next$

May I know the correct way of getting the latest net-next so that I can reproduce the same error and patch on top of it?

author
#4 lore raw
Quoted 2 lines

net tree: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git
net-next tree: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git

Thank you. I tried the correct net-next tree. The same patch applied successfully here also as shown below.

<path of the linux tree>/net-next$ ls

arch   certs    CREDITS  Documentation  fs       init      ipc     Kconfig  lib       MAINTAINERS  mm   README  samples  security  tools  virt
block  COPYING  crypto   drivers        include  io_uring  Kbuild  kernel   LICENSES  Makefile     net  rust    scripts  sound     usr

<path of the linux tree>/net-next$ git remote -v
origin https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git (fetch)
origin https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git (push)
<path of the linux tree>/net-next$ git am ../../patches/v3-0001-tipc-replace-deprecated-strcpy-with-strscpy-in-ti.patch
Applying: tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name()
<path of the linux tree>/net-next$ git branch
* main
<path of the linux tree>/net-next$

Am I missing something?

#5 lore raw
Quoted 28 lines

Subject: Re: [PATCH net-next v3] tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name()

Quoted 4 lines

net tree:
https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git
net-next tree:
https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git

Thank you. I tried the correct net-next tree. The same patch applied successfully here also as shown below.

<path of the linux tree>/net-next$ ls
arch certs CREDITS Documentation fs init ipc Kconfig lib
MAINTAINERS mm README samples security tools virt
block COPYING crypto drivers include io_uring Kbuild kernel LICENSES
Makefile net rust scripts sound usr
<path of the linux tree>/net-next$ git remote -v
origin https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
(fetch)
origin https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
(push)
<path of the linux tree>/net-next$ git am ../../patches/v3-0001-tipc-replace- deprecated-strcpy-with-strscpy-in-ti.patch
Applying: tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name() <path of the linux tree>/net-next$ git branch
* main
<path of the linux tree>/net-next$

Quoted 1 line

Am I missing something?

I see that your patch was applied again successfully after failure. There is one feedback from AI review that I see valid:
[...]

net/tipc/bearer.c int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id) · line 212

Quoted 6 lines
net/tipc/bearer.c +1 -1
@@ -209,7 +209,7 @@ int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id)
 	if (!b)
 		return -EINVAL;
 
-	strcpy(name, b->name);
+	strscpy(name, b->name, TIPC_MAX_BEARER_NAME);

This isn't a bug, but the destination capacity is now hard-coded in the body while the interface says nothing about it. The declaration in net/tipc/bearer.h is still:

	int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id);

and the comment directly above the implementation only says:
* @name: a pointer to the buffer where the name will be stored.
Should the TIPC_MAX_BEARER_NAME requirement be spelled out in the comment or in the prototype, so that the interface and the body agree? In the current tree there is no behavioural change: the only caller is __tipc_nl_add_monitor() in net/tipc/monitor.c, which declares char bearer_name[TIPC_MAX_BEARER_NAME], and the source is
char name[TIPC_MAX_BEARER_NAME] in struct tipc_bearer, so the copy can neither truncate nor overflow.
The strscpy() return value is also discarded, so a future caller passing a smaller buffer would get a silently truncated name plus a return of 0. Would passing a size_t len from the caller (sizeof(bearer_name)) and forwarding strscpy()'s -E2BIG through the existing int return be preferable to a hard-coded bound?
[...]

Please update your patch and send the new version after Aug 31st. (Because net-next is closed now)

#6 lore raw
Quoted 59 lines · On Mon, 17 Aug 2026 07:53:53 +0000 Tung Quang Nguyen…
Quoted 28 lines

Subject: Re: [PATCH net-next v3] tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name()

Quoted 4 lines

net tree:
https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git
net-next tree:
https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git

Thank you. I tried the correct net-next tree. The same patch applied successfully here also as shown below.

<path of the linux tree>/net-next$ ls
arch certs CREDITS Documentation fs init ipc Kconfig lib
MAINTAINERS mm README samples security tools virt
block COPYING crypto drivers include io_uring Kbuild kernel LICENSES
Makefile net rust scripts sound usr
<path of the linux tree>/net-next$ git remote -v
origin https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
(fetch)
origin https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
(push)
<path of the linux tree>/net-next$ git am ../../patches/v3-0001-tipc-replace- deprecated-strcpy-with-strscpy-in-ti.patch
Applying: tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name() <path of the linux tree>/net-next$ git branch
* main
<path of the linux tree>/net-next$

Quoted 1 line

Am I missing something?

I see that your patch was applied again successfully after failure. There is one feedback from AI review that I see valid:
[...]

net/tipc/bearer.c int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id) · line 212

Quoted 6 lines
net/tipc/bearer.c +1 -1
@@ -209,7 +209,7 @@ int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id)
 	if (!b)
 		return -EINVAL;
 
-	strcpy(name, b->name);
+	strscpy(name, b->name, TIPC_MAX_BEARER_NAME);  

This isn't a bug, but the destination capacity is now hard-coded in the body while the interface says nothing about it. The declaration in net/tipc/bearer.h is still:

	int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id);

and the comment directly above the implementation only says:
* @name: a pointer to the buffer where the name will be stored.
Should the TIPC_MAX_BEARER_NAME requirement be spelled out in the comment or in the prototype, so that the interface and the body agree? In the current tree there is no behavioural change: the only caller is __tipc_nl_add_monitor() in net/tipc/monitor.c, which declares char bearer_name[TIPC_MAX_BEARER_NAME], and the source is
char name[TIPC_MAX_BEARER_NAME] in struct tipc_bearer, so the copy can neither truncate nor overflow.
The strscpy() return value is also discarded, so a future caller passing a smaller buffer would get a silently truncated name plus a return of 0. Would passing a size_t len from the caller (sizeof(bearer_name)) and forwarding strscpy()'s -E2BIG through the existing int return be preferable to a hard-coded bound?
[...]

Quoted 2 lines

Please update your patch and send the new version after Aug 31st. (Because net-next is closed now)

One 'solution' to the non-problem is to embed the array in a struct. Although (IIRC) this is a uapi constant so that may not be completely possible.

Otherwise I'd ignore the AI review.

David

author
#7 lore raw

Thank you Tung Quang Nguyen and David Laight for the suggestions.

Quoted 4 lines

Should the TIPC_MAX_BEARER_NAME requirement be spelled out in the comment or in the prototype, so that the interface and the body agree? In the current tree there is no behavioural change: the only caller is __tipc_nl_add_monitor() in net/tipc/monitor.c, which declares

Quoted 8 lines

char bearer_name[TIPC_MAX_BEARER_NAME], and the source is
char name[TIPC_MAX_BEARER_NAME] in struct tipc_bearer, so the copy can neither truncate nor overflow.
The strscpy() return value is also discarded, so a future caller passing a smaller buffer would get a silently truncated name plus a return of 0. Would passing a size_t len from the caller (sizeof(bearer_name)) and forwarding strscpy()'s -E2BIG through the existing int return be preferable to a hard-coded bound?

I will update the patch with the above fixes and send the new version after Aug 31st.

Regards,
Ajith P V