Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v4] tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name()
@ 2026-09-02  5:30 Ajith P V
  2026-09-03 11:54 ` Tung Quang Nguyen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ajith P V @ 2026-09-02  5:30 UTC (permalink / raw)
  To: tung.quang.nguyen, jmaloy, davem, edumazet, kuba, pabeni, horms
  Cc: netdev, tipc-discussion, linux-kernel, Ajith P V

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.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
Link: https://github.com/KSPP/linux/issues/88 [2]

Signed-off-by: Ajith P V <ajithpv.linux@gmail.com>
---
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  | 8 ++++++--
 net/tipc/bearer.h  | 2 +-
 net/tipc/monitor.c | 2 +-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 05dcd2f9e887..abd90e6bde09 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -195,12 +195,14 @@ 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;
+	int ret;
 
 	if (bearer_id >= MAX_BEARERS)
 		return -EINVAL;
@@ -209,7 +211,9 @@ int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id)
 	if (!b)
 		return -EINVAL;
 
-	strcpy(name, b->name);
+	ret = strscpy(name, b->name, len);
+	if (ret < 0)
+		return ret; /* Returns -E2BIG if destination buffer is too small */
 	return 0;
 }
 
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h
index 41eac1ee0c09..12a322642de1 100644
--- a/net/tipc/bearer.h
+++ b/net/tipc/bearer.h
@@ -226,7 +226,7 @@ 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);
diff --git a/net/tipc/monitor.c b/net/tipc/monitor.c
index a94b9b36a700..8af49000a07c 100644
--- a/net/tipc/monitor.c
+++ b/net/tipc/monitor.c
@@ -833,7 +833,7 @@ int __tipc_nl_add_monitor(struct net *net, struct tipc_nl_msg *msg,
 	void *hdr;
 	int ret;
 
-	ret = tipc_bearer_get_name(net, bearer_name, bearer_id);
+	ret = tipc_bearer_get_name(net, bearer_name, sizeof(bearer_name), bearer_id);
 	if (ret || !mon)
 		return 0;
 
-- 
2.43.0


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

* RE: [PATCH net-next v4] tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name()
  2026-09-02  5:30 [PATCH net-next v4] tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name() Ajith P V
@ 2026-09-03 11:54 ` Tung Quang Nguyen
  2026-09-03 12:20 ` Ratheesh Kannoth
  2026-09-03 21:44 ` David Laight
  2 siblings, 0 replies; 4+ messages in thread
From: Tung Quang Nguyen @ 2026-09-03 11:54 UTC (permalink / raw)
  To: Ajith P V
  Cc: netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, jmaloy@redhat.com,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org

>Subject: [PATCH net-next v4] 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.
>
>Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
>[1]
>Link: https://github.com/KSPP/linux/issues/88 [2]
>
>Signed-off-by: Ajith P V <ajithpv.linux@gmail.com>
>---
>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  | 8 ++++++--
> net/tipc/bearer.h  | 2 +-
> net/tipc/monitor.c | 2 +-
> 3 files changed, 8 insertions(+), 4 deletions(-)
>
>diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index
>05dcd2f9e887..abd90e6bde09 100644
>--- a/net/tipc/bearer.c
>+++ b/net/tipc/bearer.c
>@@ -195,12 +195,14 @@ 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;
>+	int ret;
>
> 	if (bearer_id >= MAX_BEARERS)
> 		return -EINVAL;
>@@ -209,7 +211,9 @@ int tipc_bearer_get_name(struct net *net, char *name,
>u32 bearer_id)
> 	if (!b)
> 		return -EINVAL;
>
>-	strcpy(name, b->name);
>+	ret = strscpy(name, b->name, len);
>+	if (ret < 0)
>+		return ret; /* Returns -E2BIG if destination buffer is too small
>*/
Line length exceeds 80 columns as reported at:
https://netdev-ctrl.bots.linux.dev/logview.html?f=/logs/build/1155826/14783036/checkpatch/stdout

Also, the changes can be made simpler as follows (I help you fix all warnings):

---
 net/tipc/bearer.c  | 6 ++++--
 net/tipc/bearer.h  | 3 ++-
 net/tipc/monitor.c | 3 ++-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 05dcd2f9e887..65fa18928fe3 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -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;
 }

diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h
index 41eac1ee0c09..9ccc9ffa925a 100644
--- a/net/tipc/bearer.h
+++ b/net/tipc/bearer.h
@@ -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);
diff --git a/net/tipc/monitor.c b/net/tipc/monitor.c
index a94b9b36a700..a8a088fc2a2c 100644
--- a/net/tipc/monitor.c
+++ b/net/tipc/monitor.c
@@ -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;

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

* Re: [PATCH net-next v4] tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name()
  2026-09-02  5:30 [PATCH net-next v4] tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name() Ajith P V
  2026-09-03 11:54 ` Tung Quang Nguyen
@ 2026-09-03 12:20 ` Ratheesh Kannoth
  2026-09-03 21:44 ` David Laight
  2 siblings, 0 replies; 4+ messages in thread
From: Ratheesh Kannoth @ 2026-09-03 12:20 UTC (permalink / raw)
  To: Ajith P V
  Cc: tung.quang.nguyen, jmaloy, davem, edumazet, kuba, pabeni, horms,
	netdev, tipc-discussion, linux-kernel

On 2026-09-02 at 11:00:43, Ajith P V (ajithpv.linux@gmail.com) wrote:
> @@ -209,7 +211,9 @@ int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id)
>  	if (!b)
>  		return -EINVAL;
>
> -	strcpy(name, b->name);
> +	ret = strscpy(name, b->name, len);
> +	if (ret < 0)
> +		return ret; /* Returns -E2BIG if destination buffer is too small */
nit: please remove the comment.
>  	return 0;

Reviewed-by: Ratheesh Kannoth <rkannoth@marvell.com>

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

* Re: [PATCH net-next v4] tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name()
  2026-09-02  5:30 [PATCH net-next v4] tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name() Ajith P V
  2026-09-03 11:54 ` Tung Quang Nguyen
  2026-09-03 12:20 ` Ratheesh Kannoth
@ 2026-09-03 21:44 ` David Laight
  2 siblings, 0 replies; 4+ messages in thread
From: David Laight @ 2026-09-03 21:44 UTC (permalink / raw)
  To: Ajith P V
  Cc: tung.quang.nguyen, jmaloy, davem, edumazet, kuba, pabeni, horms,
	netdev, tipc-discussion, linux-kernel

On Wed,  2 Sep 2026 05:30:43 +0000
Ajith P V <ajithpv.linux@gmail.com> wrote:

> 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.

For real safety embed the char[TIPC_MAX_BEARER_NAME] in a struct and
pass the struct through.
Then you can use sizeof() in the function itself.

	David

> 
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
> Link: https://github.com/KSPP/linux/issues/88 [2]
> 
> Signed-off-by: Ajith P V <ajithpv.linux@gmail.com>
> ---
> 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  | 8 ++++++--
>  net/tipc/bearer.h  | 2 +-
>  net/tipc/monitor.c | 2 +-
>  3 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
> index 05dcd2f9e887..abd90e6bde09 100644
> --- a/net/tipc/bearer.c
> +++ b/net/tipc/bearer.c
> @@ -195,12 +195,14 @@ 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;
> +	int ret;
>  
>  	if (bearer_id >= MAX_BEARERS)
>  		return -EINVAL;
> @@ -209,7 +211,9 @@ int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id)
>  	if (!b)
>  		return -EINVAL;
>  
> -	strcpy(name, b->name);
> +	ret = strscpy(name, b->name, len);
> +	if (ret < 0)
> +		return ret; /* Returns -E2BIG if destination buffer is too small */
>  	return 0;
>  }
>  
> diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h
> index 41eac1ee0c09..12a322642de1 100644
> --- a/net/tipc/bearer.h
> +++ b/net/tipc/bearer.h
> @@ -226,7 +226,7 @@ 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);
> diff --git a/net/tipc/monitor.c b/net/tipc/monitor.c
> index a94b9b36a700..8af49000a07c 100644
> --- a/net/tipc/monitor.c
> +++ b/net/tipc/monitor.c
> @@ -833,7 +833,7 @@ int __tipc_nl_add_monitor(struct net *net, struct tipc_nl_msg *msg,
>  	void *hdr;
>  	int ret;
>  
> -	ret = tipc_bearer_get_name(net, bearer_name, bearer_id);
> +	ret = tipc_bearer_get_name(net, bearer_name, sizeof(bearer_name), bearer_id);
>  	if (ret || !mon)
>  		return 0;
>  


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

end of thread, other threads:[~2026-09-03 21:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02  5:30 [PATCH net-next v4] tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name() Ajith P V
2026-09-03 11:54 ` Tung Quang Nguyen
2026-09-03 12:20 ` Ratheesh Kannoth
2026-09-03 21:44 ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox