diff mbox series

[v2,bpf-next] bpf: use the proper optlen when doing strncpy in bpf_getsockopt()

Message ID 1548306994-877-1-git-send-email-laoar.shao@gmail.com
State Rejected
Delegated to: BPF Maintainers
Headers show
Series [v2,bpf-next] bpf: use the proper optlen when doing strncpy in bpf_getsockopt() | expand

Commit Message

Yafang Shao Jan. 24, 2019, 5:16 a.m. UTC
As strncpy(..., TCP_CA_NAME_MAX-1) is used in bpf_setsockopt(),
this change  will make it more consistent with the bpf_setsockopt() above.

Acked-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Lawrence Brakmo <brakmo@fb.com>
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 net/core/filter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Daniel Borkmann Jan. 24, 2019, 11:24 a.m. UTC | #1
On 01/24/2019 06:16 AM, Yafang Shao wrote:
> As strncpy(..., TCP_CA_NAME_MAX-1) is used in bpf_setsockopt(),
> this change  will make it more consistent with the bpf_setsockopt() above.
> 
> Acked-by: Martin KaFai Lau <kafai@fb.com>
> Acked-by: Lawrence Brakmo <brakmo@fb.com>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>

While not wrong, I also don't think it improves much either. As mentioned,
that code is totally fine as it currently is.
diff mbox series

Patch

diff --git a/net/core/filter.c b/net/core/filter.c
index 447dd1b..7a4de22 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4262,7 +4262,7 @@  static unsigned long bpf_xdp_copy(void *dst_buff, const void *src_buff,
 
 			if (!icsk->icsk_ca_ops || optlen <= 1)
 				goto err_clear;
-			strncpy(optval, icsk->icsk_ca_ops->name, optlen);
+			strncpy(optval, icsk->icsk_ca_ops->name, optlen - 1);
 			optval[optlen - 1] = 0;
 			break;
 		case TCP_SAVED_SYN: