patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Alyssa Ross <hi@alyssa.is>
To: Yureka <yuka@yuka.dev>
Cc: devel@spectrum-os.org
Subject: Re: [DO_NOT_APPLY 1/2] integrate xdp-forwarder into net-vm
Date: Mon, 01 Sep 2025 16:12:48 +0200	[thread overview]
Message-ID: <87iki2p8gv.fsf@alyssa.is> (raw)
In-Reply-To: <199f3fa9-d652-4281-8908-7294ac042434@yuka.dev>

[-- Attachment #1: Type: text/plain, Size: 1773 bytes --]

Yureka <yuka@yuka.dev> writes:

> Pointer arithmetics always work in pointer lengths, so + 1 is adding 
> sizeof(struct ethhdr) bytes.
>
> eth is the beginning of the eth header.
>
> eth + 1 is the first byte after the eth header, or where the next eth 
> header would begin in an array.

I've figured out the source of my confusion.  I mistakenly assumed that
data_end would be a pointer to the last byte of data.  It's actually a
pointer to the byte after the last byte of data.

> On 9/1/25 15:59, Alyssa Ross wrote:
>> Yureka <yuka@yuka.dev> writes:
>>
>>>>> +
>>>>> + /* Byte-count bounds check; check if current pointer + size of header
>>>>> + * is after data_end.
>>>>> + */
>>>>> + if ((void *) (eth + 1) > data_end)
>>>>> + return -1;
>>>> This is checking that there's more data after the header, right? Is
>>>> that something it's important for us to check?
>>> The intent is to check that the entire eth hdr, which we casted a
>>> pointer to, is within the data (length) of the packet before we
>>> de-reference the pointer. So essentially, skipping packets which do not
>>> have a full ethernet header, instead of reading from addresses which we
>>> are not supposed to read from.
>>>
>>> When loading the XDP program, it is tested against an empty or very
>>> small packet, and if it tries to access memory outside of the packet
>>> bounds, it will refuse to load. So the BPF/XDP system ensures that these
>>> kinds of packets are handled properly.
>> Doesn't using > instead of >= check that the entire eth hdr **plus one
>> byte** is within the packet, though? i.e. wouldn't this check fail if
>> the data consisted entirely of an ethernet header? Is that the right
>> thing to do? (Sorry if my maths is just wrong.)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]

  reply	other threads:[~2025-09-01 14:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-23 22:21 [DO_NOT_APPLY 0/2] xdp-forwarder Yureka Lilian
2025-08-23 22:21 ` [DO_NOT_APPLY 1/2] integrate xdp-forwarder into net-vm Yureka Lilian
2025-08-30 10:59   ` Alyssa Ross
2025-08-31 17:10     ` Alyssa Ross
2025-08-31 18:06       ` Yureka
2025-08-31 20:50     ` Yureka
2025-09-01 13:59       ` Alyssa Ross
2025-09-01 14:04         ` Yureka
2025-09-01 14:12           ` Alyssa Ross [this message]
2025-08-23 22:21 ` [DO_NOT_APPLY 2/2] temporary changes for testing Yureka Lilian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87iki2p8gv.fsf@alyssa.is \
    --to=hi@alyssa.is \
    --cc=devel@spectrum-os.org \
    --cc=yuka@yuka.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

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).