BPF List
 help / color / mirror / Atom feed
* [Question]: BPF_CGROUP_{GET,SET}SOCKOPT handling when optlen > PAGE_SIZE
@ 2022-10-27  1:14 Martin KaFai Lau
  2022-10-27  2:03 ` Stanislav Fomichev
  2022-10-27 20:46 ` Andrii Nakryiko
  0 siblings, 2 replies; 12+ messages in thread
From: Martin KaFai Lau @ 2022-10-27  1:14 UTC (permalink / raw)
  To: Stanislav Fomichev, bpf

The cgroup-bpf {get,set}sockopt prog is useful to change the optname behavior. 
The bpf prog usually just handles a few specific optnames and ignores most 
others.  For the optnames that it ignores, it usually does not need to change 
the optlen.  The exception is when optlen > PAGE_SIZE (or optval_end - optval). 
The bpf prog needs to set the optlen to 0 for this case or else the kernel will 
return -EFAULT to the userspace.  It is usually not what the bpf prog wants 
because the bpf prog only expects error returning to userspace when it has 
explicitly 'return 0;' or used bpf_set_retval().  If a bpf prog always changes 
optlen for optnames that it does not care to 0,  it may risk if the latter bpf 
prog in the same cgroup may want to change/look-at it.

Would like to explore if there is an easier way for the bpf prog to handle it. 
eg. does it make sense to track if the bpf prog has changed the ctx->optlen 
before returning -EFAULT to the user space when ctx.optlen > max_optlen?

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

end of thread, other threads:[~2022-10-27 23:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-27  1:14 [Question]: BPF_CGROUP_{GET,SET}SOCKOPT handling when optlen > PAGE_SIZE Martin KaFai Lau
2022-10-27  2:03 ` Stanislav Fomichev
2022-10-27  6:15   ` Martin KaFai Lau
2022-10-27 16:23     ` Stanislav Fomichev
2022-10-27 17:28       ` Martin KaFai Lau
2022-10-27 17:40         ` Stanislav Fomichev
2022-10-27 18:48           ` Martin KaFai Lau
2022-10-27 19:11             ` Stanislav Fomichev
2022-10-27 20:04               ` Martin KaFai Lau
2022-10-27 20:14                 ` Stanislav Fomichev
2022-10-27 20:46 ` Andrii Nakryiko
2022-10-27 23:46   ` Martin KaFai Lau

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