netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf, sockops: Enhance the return capability of sockops
@ 2023-07-06 10:02 Xin Liu
  2023-07-06 17:43 ` Stanislav Fomichev
  2023-07-11 16:39 ` Simon Horman
  0 siblings, 2 replies; 3+ messages in thread
From: Xin Liu @ 2023-07-06 10:02 UTC (permalink / raw)
  To: daniel
  Cc: andrii, ast, bpf, davem, edumazet, hsinweih, jakub,
	john.fastabend, kuba, linux-kernel, liuxin350, netdev, pabeni,
	syzbot+49f6cef45247ff249498, syzkaller-bugs, yanan, wuchangye,
	xiesongyang, kongweibin2, zhangmingyi5

Since commit 2585cd62f098 ("bpf: Only reply field should be writeable"),
sockops is not allowd to modify the replylong field except replylong[0].
The reason is that the replylong[1] to replylong[3] field is not used
at that time.

But in actual use, we can call `BPF_CGROUP_RUN_PROG_SOCK_OPS` in the
kernel modules and expect sockops to return some useful data.

The design comment about bpf_sock_ops::replylong in 
include/uapi/linux/bpf.h is described as follows:

```
  struct bpf_sock_ops {
	__u32 op;
	union {
		__u32 args[4];		/* Optionally passed to bpf program */
		__u32 reply;		/* Returned by bpf program	    */
		__u32 replylong[4];	/* Optioznally returned by bpf prog  */
	};
  ...
```

It seems to contradict the purpose for which the field was originally
designed. Let's remove this restriction.

Fixes: 2585cd62f098 ("bpf: Only reply field should be writeable")

Signed-off-by: Xin Liu <liuxin350@huawei.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 06ba0e56e369..4662d2d3a0af 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -9063,7 +9063,7 @@ static bool sock_ops_is_valid_access(int off, int size,
 
 	if (type == BPF_WRITE) {
 		switch (off) {
-		case offsetof(struct bpf_sock_ops, reply):
+		case bpf_ctx_range_till(struct bpf_sock_ops, reply, replylong[3]):
 		case offsetof(struct bpf_sock_ops, sk_txhash):
 			if (size != size_default)
 				return false;
-- 
2.33.0


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

* Re: [PATCH bpf-next] bpf, sockops: Enhance the return capability of sockops
  2023-07-06 10:02 [PATCH bpf-next] bpf, sockops: Enhance the return capability of sockops Xin Liu
@ 2023-07-06 17:43 ` Stanislav Fomichev
  2023-07-11 16:39 ` Simon Horman
  1 sibling, 0 replies; 3+ messages in thread
From: Stanislav Fomichev @ 2023-07-06 17:43 UTC (permalink / raw)
  To: Xin Liu
  Cc: daniel, andrii, ast, bpf, davem, edumazet, hsinweih, jakub,
	john.fastabend, kuba, linux-kernel, netdev, pabeni,
	syzbot+49f6cef45247ff249498, syzkaller-bugs, yanan, wuchangye,
	xiesongyang, kongweibin2, zhangmingyi5

On 07/06, Xin Liu wrote:
> Since commit 2585cd62f098 ("bpf: Only reply field should be writeable"),
> sockops is not allowd to modify the replylong field except replylong[0].
> The reason is that the replylong[1] to replylong[3] field is not used
> at that time.
> 
> But in actual use, we can call `BPF_CGROUP_RUN_PROG_SOCK_OPS` in the
> kernel modules and expect sockops to return some useful data.
> 
> The design comment about bpf_sock_ops::replylong in 
> include/uapi/linux/bpf.h is described as follows:
> 
> ```
>   struct bpf_sock_ops {
> 	__u32 op;
> 	union {
> 		__u32 args[4];		/* Optionally passed to bpf program */
> 		__u32 reply;		/* Returned by bpf program	    */
> 		__u32 replylong[4];	/* Optioznally returned by bpf prog  */
> 	};
>   ...
> ```
> 
> It seems to contradict the purpose for which the field was originally
> designed. Let's remove this restriction.
> 
> Fixes: 2585cd62f098 ("bpf: Only reply field should be writeable")

The commit you reference explicitly says that there is no reason to allow
replylong[1..3] because there is no use for them. Has something changed
since it was added? Any reason to expose those fields?

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

* Re: [PATCH bpf-next] bpf, sockops: Enhance the return capability of sockops
  2023-07-06 10:02 [PATCH bpf-next] bpf, sockops: Enhance the return capability of sockops Xin Liu
  2023-07-06 17:43 ` Stanislav Fomichev
@ 2023-07-11 16:39 ` Simon Horman
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2023-07-11 16:39 UTC (permalink / raw)
  To: Xin Liu
  Cc: daniel, andrii, ast, bpf, davem, edumazet, hsinweih, jakub,
	john.fastabend, kuba, linux-kernel, netdev, pabeni,
	syzbot+49f6cef45247ff249498, syzkaller-bugs, yanan, wuchangye,
	xiesongyang, kongweibin2, zhangmingyi5

On Thu, Jul 06, 2023 at 06:02:43PM +0800, Xin Liu wrote:
> Since commit 2585cd62f098 ("bpf: Only reply field should be writeable"),
> sockops is not allowd to modify the replylong field except replylong[0].

nit: allowd -> allowed

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

end of thread, other threads:[~2023-07-11 16:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-06 10:02 [PATCH bpf-next] bpf, sockops: Enhance the return capability of sockops Xin Liu
2023-07-06 17:43 ` Stanislav Fomichev
2023-07-11 16:39 ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).