lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Thu, 3 Mar 2022 15:42:01 -0800
From:   Martin KaFai Lau <kafai@...com>
To:     Daniel Borkmann <daniel@...earbox.net>
Cc:     bpf@...r.kernel.org, netdev@...r.kernel.org,
        Alexei Starovoitov <ast@...nel.org>,
        Andrii Nakryiko <andrii@...nel.org>,
        David Miller <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Jakub Kicinski <kuba@...nel.org>, kernel-team@...com,
        Willem de Bruijn <willemb@...gle.com>
Subject: Re: [PATCH v6 net-next 11/13] bpf: Keep the (rcv) timestamp behavior
 for the existing tc-bpf@...ress

On Thu, Mar 03, 2022 at 11:55:55PM +0100, Daniel Borkmann wrote:
> On 3/3/22 9:43 PM, Martin KaFai Lau wrote:
> > On Thu, Mar 03, 2022 at 02:00:37PM +0100, Daniel Borkmann wrote:
> > > On 3/2/22 8:56 PM, Martin KaFai Lau wrote:

> > > > +static struct bpf_insn *bpf_convert_tstamp_write(const struct bpf_insn *si,
> > > > +						 struct bpf_insn *insn)
> > > > +{
> > > > +	__u8 value_reg = si->src_reg;
> > > > +	__u8 skb_reg = si->dst_reg;
> > > > +
> > > > +#ifdef CONFIG_NET_CLS_ACT
> > > > +	__u8 tmp_reg = BPF_REG_AX;
> > > > +
> > > > +	*insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, TC_AT_INGRESS_OFFSET);
> > > > +	*insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, TC_AT_INGRESS_MASK);
> > > 
> > > Can't we get rid of tcf_bpf_act() and cls_bpf_classify() changes altogether by just doing:
> > > 
> > >    /* BPF_WRITE: __sk_buff->tstamp = a */
> > >    skb->mono_delivery_time = !skb->tc_at_ingress && a;
> > >    skb->tstamp = a;
> > It will then assume the bpf prog is writing a mono time.
> > Although mono should always be the case now,  this assumption will be
> > an issue in the future if we need to support non-mono.
> 
> Right, for that we should probably instrument verifier to track base based
> on ktime helper call once we get to that point.
The bpf prog does not necessary write a value which is obtained from a
bpf ktime helper.  It could be a value based on the previous skb sent
from a cgroup.

> 
> > > (Untested) pseudo code:
> > > 
> > >    // or see comment on common SKB_FLAGS_OFFSET define or such
> > >    BUILD_BUG_ON(TC_AT_INGRESS_OFFSET != SKB_MONO_DELIVERY_TIME_OFFSET)
> > > 
> > >    BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, SKB_MONO_DELIVERY_TIME_OFFSET)
> > >    BPF_ALU32_IMM(BPF_OR, tmp_reg, SKB_MONO_DELIVERY_TIME_MASK)
> > >    BPF_JMP32_IMM(BPF_JSET, tmp_reg, TC_AT_INGRESS_MASK, <clear>)
> > This can save a BPF_ALU32_IMM(BPF_AND).  I will do that
> > together in the follow up. Thanks for the idea !
> 
> Yeah the JSET comes in handy here.
> 
> > >    BPF_JMP32_REG(BPF_JGE, value_reg, tmp_reg, <store>)
> > > <clear>:
> > >    BPF_ALU32_IMM(BPF_AND, tmp_reg, ~SKB_MONO_DELIVERY_TIME_MASK)
> > > <store>:
> > >    BPF_STX_MEM(BPF_B, skb_reg, tmp_reg, SKB_MONO_DELIVERY_TIME_OFFSET)
> > >    BPF_STX_MEM(BPF_DW, skb_reg, value_reg, offsetof(struct sk_buff, tstamp))
> > > 
> > > (There's a small hack with the BPF_JGE for tmp_reg, so constant blinding for AX doesn't
> > > get into our way.)
> > > 
> > > > +	*insn++ = BPF_JMP32_IMM(BPF_JEQ, tmp_reg, 0, 3);
> > > > +	/* Writing __sk_buff->tstamp at ingress as the (rcv) timestamp.
> > > > +	 * Clear the skb->mono_delivery_time.
> > > > +	 */
> > > > +	*insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg,
> > > > +			      SKB_MONO_DELIVERY_TIME_OFFSET);
> > > > +	*insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg,
> > > > +				~SKB_MONO_DELIVERY_TIME_MASK);
> > > > +	*insn++ = BPF_STX_MEM(BPF_B, skb_reg, tmp_reg,
> > > > +			      SKB_MONO_DELIVERY_TIME_OFFSET);
> > > > +#endif
> > > > +
> > > > +	/* skb->tstamp = tstamp */
> > > > +	*insn++ = BPF_STX_MEM(BPF_DW, skb_reg, value_reg,
> > > > +			      offsetof(struct sk_buff, tstamp));
> > > > +	return insn;
> > > > +}
> > > > +
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ