* [PATCH bpf-next] bpf: use the proper optlen when doing strncpy in bpf_getsockopt()
@ 2019-01-19 6:20 Yafang Shao
2019-01-22 18:04 ` Martin Lau
0 siblings, 1 reply; 4+ messages in thread
From: Yafang Shao @ 2019-01-19 6:20 UTC (permalink / raw)
To: ast, daniel; +Cc: netdev, shaoyafang, Yafang Shao
As the last character of optval will be set with 0, so just copying
(optlen - 1) characters is enough.
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
net/core/filter.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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:
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] bpf: use the proper optlen when doing strncpy in bpf_getsockopt()
2019-01-19 6:20 [PATCH bpf-next] bpf: use the proper optlen when doing strncpy in bpf_getsockopt() Yafang Shao
@ 2019-01-22 18:04 ` Martin Lau
2019-01-22 18:39 ` Lawrence Brakmo
2019-01-23 13:53 ` Daniel Borkmann
0 siblings, 2 replies; 4+ messages in thread
From: Martin Lau @ 2019-01-22 18:04 UTC (permalink / raw)
To: Yafang Shao, Lawrence Brakmo; +Cc: ast, daniel, netdev, shaoyafang
On Sat, Jan 19, 2019 at 02:20:52PM +0800, Yafang Shao wrote:
> As the last character of optval will be set with 0, so just copying
> (optlen - 1) characters is enough.
I am not sure this optimization is needed but I think it will
make it more consistent with the bpf_setsockopt() above.
Acked-by: Martin KaFai Lau <kafai@fb.com>
Cc: 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(-)
>
> 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:
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] bpf: use the proper optlen when doing strncpy in bpf_getsockopt()
2019-01-22 18:04 ` Martin Lau
@ 2019-01-22 18:39 ` Lawrence Brakmo
2019-01-23 13:53 ` Daniel Borkmann
1 sibling, 0 replies; 4+ messages in thread
From: Lawrence Brakmo @ 2019-01-22 18:39 UTC (permalink / raw)
To: Martin Lau, Yafang Shao; +Cc: ast, daniel, netdev, shaoyafang
On 1/22/19, 10:05 AM, "Martin Lau" <kafai@fb.com> wrote:
On Sat, Jan 19, 2019 at 02:20:52PM +0800, Yafang Shao wrote:
> As the last character of optval will be set with 0, so just copying
> (optlen - 1) characters is enough.
I am not sure this optimization is needed but I think it will
make it more consistent with the bpf_setsockopt() above.
Acked-by: Martin KaFai Lau <kafai@fb.com>
Cc: Lawrence Brakmo <brakmo@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(-)
>
> 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:
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] bpf: use the proper optlen when doing strncpy in bpf_getsockopt()
2019-01-22 18:04 ` Martin Lau
2019-01-22 18:39 ` Lawrence Brakmo
@ 2019-01-23 13:53 ` Daniel Borkmann
1 sibling, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2019-01-23 13:53 UTC (permalink / raw)
To: Martin Lau, Yafang Shao, Lawrence Brakmo; +Cc: ast, netdev, shaoyafang
On 01/22/2019 07:04 PM, Martin Lau wrote:
> On Sat, Jan 19, 2019 at 02:20:52PM +0800, Yafang Shao wrote:
>> As the last character of optval will be set with 0, so just copying
>> (optlen - 1) characters is enough.
> I am not sure this optimization is needed but I think it will
Yeah, it's totally fine as is.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-01-23 13:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-19 6:20 [PATCH bpf-next] bpf: use the proper optlen when doing strncpy in bpf_getsockopt() Yafang Shao
2019-01-22 18:04 ` Martin Lau
2019-01-22 18:39 ` Lawrence Brakmo
2019-01-23 13:53 ` Daniel Borkmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.