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] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 25 Jan 2021 23:27:22 +0100
From:   Daniel Borkmann <daniel@...earbox.net>
To:     Jesper Dangaard Brouer <brouer@...hat.com>
Cc:     bpf@...r.kernel.org, netdev@...r.kernel.org,
        Daniel Borkmann <borkmann@...earbox.net>,
        Alexei Starovoitov <alexei.starovoitov@...il.com>,
        maze@...gle.com, lmb@...udflare.com, shaun@...era.io,
        Lorenzo Bianconi <lorenzo@...nel.org>, marek@...udflare.com,
        John Fastabend <john.fastabend@...il.com>,
        Jakub Kicinski <kuba@...nel.org>, eyal.birger@...il.com,
        colrack@...il.com
Subject: Re: [PATCH bpf-next V12 4/7] bpf: add BPF-helper for MTU checking

On 1/25/21 9:41 AM, Jesper Dangaard Brouer wrote:
> On Sat, 23 Jan 2021 02:35:41 +0100
> Daniel Borkmann <daniel@...earbox.net> wrote:
> 
>>> + *		The *flags* argument can be a combination of one or more of the
>>> + *		following values:
>>> + *
>>> + *		**BPF_MTU_CHK_SEGS**
>>> + *			This flag will only works for *ctx* **struct sk_buff**.
>>> + *			If packet context contains extra packet segment buffers
>>> + *			(often knows as GSO skb), then MTU check is harder to
>>> + *			check at this point, because in transmit path it is
>>> + *			possible for the skb packet to get re-segmented
>>> + *			(depending on net device features).  This could still be
>>> + *			a MTU violation, so this flag enables performing MTU
>>> + *			check against segments, with a different violation
>>> + *			return code to tell it apart. Check cannot use len_diff.
>>> + *
>>> + *		On return *mtu_len* pointer contains the MTU value of the net
>>> + *		device.  Remember the net device configured MTU is the L3 size,
>>> + *		which is returned here and XDP and TX length operate at L2.
>>> + *		Helper take this into account for you, but remember when using
>>> + *		MTU value in your BPF-code.  On input *mtu_len* must be a valid
>>> + *		pointer and be initialized (to zero), else verifier will reject
>>> + *		BPF program.
>>> + *
>>> + *	Return
>>> + *		* 0 on success, and populate MTU value in *mtu_len* pointer.
>>> + *
>>> + *		* < 0 if any input argument is invalid (*mtu_len* not updated)
>>> + *
>>> + *		MTU violations return positive values, but also populate MTU
>>> + *		value in *mtu_len* pointer, as this can be needed for
>>> + *		implementing PMTU handing:
>>> + *
>>> + *		* **BPF_MTU_CHK_RET_FRAG_NEEDED**
>>> + *		* **BPF_MTU_CHK_RET_SEGS_TOOBIG**
>>> + *
>>>     */
>> [...]
>>> +BPF_CALL_5(bpf_skb_check_mtu, struct sk_buff *, skb,
>>> +	   u32, ifindex, u32 *, mtu_len, s32, len_diff, u64, flags)
>>> +{
>>> +	int ret = BPF_MTU_CHK_RET_FRAG_NEEDED;
>>> +	struct net_device *dev = skb->dev;
>>> +	int skb_len, dev_len;
>>> +	int mtu;
>>> +
>>> +	if (unlikely(flags & ~(BPF_MTU_CHK_SEGS)))
>>> +		return -EINVAL;
>>> +
>>> +	dev = __dev_via_ifindex(dev, ifindex);
>>> +	if (unlikely(!dev))
>>> +		return -ENODEV;
>>> +
>>> +	mtu = READ_ONCE(dev->mtu);
>>> +
>>> +	dev_len = mtu + dev->hard_header_len;
>>> +	skb_len = skb->len + len_diff; /* minus result pass check */
>>> +	if (skb_len <= dev_len) {
>>> +		ret = BPF_MTU_CHK_RET_SUCCESS;
>>> +		goto out;
>>> +	}
>>> +	/* At this point, skb->len exceed MTU, but as it include length of all
>>> +	 * segments, it can still be below MTU.  The SKB can possibly get
>>> +	 * re-segmented in transmit path (see validate_xmit_skb).  Thus, user
>>> +	 * must choose if segs are to be MTU checked.
>>> +	 */
>>> +	if (skb_is_gso(skb)) {
>>> +		ret = BPF_MTU_CHK_RET_SUCCESS;
>>> +
>>> +		if (flags & BPF_MTU_CHK_SEGS &&
>>> +		    !skb_gso_validate_network_len(skb, mtu))
>>> +			ret = BPF_MTU_CHK_RET_SEGS_TOOBIG;
>>
>> I think that looks okay overall now. One thing that will easily slip through
>> is that in the helper description you mentioned 'Check cannot use len_diff.'
>> for BPF_MTU_CHK_SEGS flag. So right now for non-zero len_diff the user
>> will still get BPF_MTU_CHK_RET_SUCCESS if the current length check via
>> skb_gso_validate_network_len(skb, mtu) passes. If it cannot be checked,
>> maybe enforce len_diff == 0 for gso skbs on BPF_MTU_CHK_SEGS?
> 
> Ok. Do you want/think this can be enforced by the verifier or are you
> simply requesting that the helper will return -EINVAL (or another errno)?

Simple -EINVAL should be fine in this case. Generally, we can detect this from
verifier side but I don't think the extra complexity is worth it especially given
this is dependent on BPF_MTU_CHK_SEGS and otherwise can be non-zero.

Thanks,
Daniel

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ