diff options
| author | Ajith Parappalliyalil Venugopal <ajithpv.linux@gmail.com> | 2026-09-15 14:56:41 +0000 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2026-09-17 19:20:02 -0700 |
| commit | 4bb9710c6a68d35207f123aef55dcd50e7195ec5 (patch) | |
| tree | 933278854667e3e2e7c81ae6a3fdc9d7945d3467 /net | |
| parent | 8b853476197ff9c6a970419ff3f3f15c940df6ea (diff) | |
| download | linux-next-4bb9710c6a68d35207f123aef55dcd50e7195ec5.tar.gz linux-next-4bb9710c6a68d35207f123aef55dcd50e7195ec5.zip | |
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 Parappalliyalil Venugopal <ajithpv.linux@gmail.com>
Reviewed-by: Tung Nguyen <tung.quang.nguyen@est.tech>
Link: https://patch.msgid.link/20260915145641.2434403-1-ajithpv.linux@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net')
| -rw-r--r-- | net/tipc/bearer.c | 6 | ||||
| -rw-r--r-- | net/tipc/bearer.h | 3 | ||||
| -rw-r--r-- | 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..f3e965c48472 100644 --- a/net/tipc/monitor.c +++ b/net/tipc/monitor.c @@ -833,7 +833,8 @@ 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; |
