skmsg: lose offset info in sk_psock_skb_ingress
Subsystems (4)
PATCH v3 1/1 skmsg: lose offset info in sk_psock_skb_ingress
If sockmap enable strparser, there are lose offset info in sk_psock_skb_ingress. If the length determined by parse_msg function is not skb->len, the skb will be converted to sk_msg multiple times, and userspace app will get the data multiple times.
Fix this by get the offset and length from strp_msg.
And as Cong suggestion, add one bit in skb->_sk_redir to distinguish enable or disable strparser.
---v1->v2: fix build error when disable CONFIG_BPF_STREAM_PARSER v2->v3: Add one bit in skb->_sk_redir to distinguish enable or disable strparser
include/linux/skmsg.h | 18 ++++++++++++++-- net/core/skmsg.c | 48 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 12 deletions(-)
include/linux/skmsg.h +16 -2
@@ -508,8 +508,22 @@ static inline bool sk_psock_strp_enabled(struct sk_psock *psock)#if IS_ENABLED (CONFIG_NET_SOCK_MSG ) -/* We only have one bit so far. */ -#define BPF_F_PTR_MASK ~(BPF_F_INGRESS) +#define BPF_F_STRPARSER (1UL << 1) + +/* We only have two bit so far. */ +#define BPF_F_PTR_MASK ~(BPF_F_INGRESS | BPF_F_STRPARSER) + +static inline bool skb_bpf_strparser (const struct sk_buff *skb) +{ +unsigned long sk_redir = skb->_sk_redir; + +return sk_redir &BPF_F_STRPARSER ; +} + +static inline void skb_bpf_set_strparser (struct sk_buff *skb) +{ + skb->_sk_redir |=BPF_F_STRPARSER ; +}static inline bool skb_bpf_ingress (const struct sk_buff *skb) {
net/core/skmsg.c +38 -10
130 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 12 lines · Liu Jian
static void sk_psock_skb_state(struct
sk_psock*psock,net/core/skmsg.c +3
-0@@ -604,6 +608,9 @@ static void sk_psock_backlog(struct work_struct *work) { struct sk_psock *psock = container_of(work, struct sk_psock, work);struct sk_psock_work_state *state = &psock->work_state; +#if IS_ENABLED (CONFIG_BPF_STREAM_PARSER ) +struct strp_msg *stm =NULL ; +#endif struct sk_buff *skb =NULL ;bool ingress;u32 len, off;
net/core/skmsg.c static void sk_psock_backlog(struct work_struct *work) · line 635
Quoted 5 lines
net/core/skmsg.c +2
-0@@ -624,6 +631,13 @@ static void sk_psock_backlog(struct work_struct *work)while ((skb =skb_dequeue (&psock->ingress_skb))) { len = skb->len; off =0 ; +#if IS_ENABLED (CONFIG_BPF_STREAM_PARSER ) +if (skb_bpf_strparser (skb)) {
If CONFIG_BPF_STREAM_PARSER is disabled, this should always return false, hence you don't need this #ifdef. Or alternatively, you can at least define for nop for skb_bpf_strparser() if !CONFIG_BPF_STREAM_PARSER. And you can move the above "stm" down here too.
(Ditto for the other place below.)
Thanks.
Quoted 35 lines
-----Original Message-----
From: Cong Wang [mailto:[email protected]]
Sent: Tuesday, September 28, 2021 1:52 PM
To: liujian (CE) <[email protected]>
Cc: John Fastabend <[email protected]>; Daniel Borkmann <[email protected]>; Jakub Sitnicki <[email protected]>; Lorenz Bauer <[email protected]>; David Miller <[email protected]>; Jakub Kicinski <[email protected]>; Alexei Starovoitov <[email protected]>; Andrii Nakryiko <[email protected]>; Martin KaFai Lau <[email protected]>; Song Liu <[email protected]>; Yonghong Song <[email protected]>; KP Singh <[email protected]>; Linux Kernel Network Developers <[email protected]>; bpf <[email protected]>
Subject: Re: [PATCH v3] skmsg: lose offset info insk_psock_skb_ingressnet/core/skmsg.c static void sk_psock_backlog(struct work_struct
Quoted 11 lines · Liu Jian
static void sk_psock_skb_state(struct
sk_psock*psock, @@ -604,6+608,9 @@ static void sk_psock_backlog(struct work_struct *work) { struct sk_psock *psock = container_of(work, struct sk_psock, work); struct sk_psock_work_state *state = &psock->work_state;net/core/skmsg.c +3
-0+#if IS_ENABLED (CONFIG_BPF_STREAM_PARSER ) +struct strp_msg *stm =NULL ; +#endif struct sk_buff *skb =NULL ;bool ingress;u32 len, off;@@ -624,6 +631,13 @@ static void sk_psock_backlog(struct work_struct*work)
net/core/skmsg.c static void sk_psock_backlog(struct work_struct *work) · line 635
Quoted 5 lines
net/core/skmsg.c +2
-0while ((skb =skb_dequeue (&psock->ingress_skb))) { len = skb->len; off =0 ; +#if IS_ENABLED (CONFIG_BPF_STREAM_PARSER ) +if (skb_bpf_strparser (skb)) {
Quoted 6 lines
If
CONFIG_BPF_STREAM_PARSERis disabled, this should always return false, hence you don't need this #ifdef.
Or alternatively, you can at least define for nop forskb_bpf_strparser()if !CONFIG_BPF_STREAM_PARSER.
And you can move the above "stm" down here too.
V4 has been sent, thank you~
Quoted 3 lines
(Ditto for the other place below.)
Thanks.