Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capsicum-related fixes for tcpdump #687

Merged
merged 1 commit into from Jun 15, 2023

Conversation

hselasky
Copy link
Contributor

No description provided.

@infrastation
Copy link
Member

It would not harm to have some comments in the commit messages or the source code to explain these changes to the folks in future.

@hselasky
Copy link
Contributor Author

Are you referring to both commits?

@infrastation
Copy link
Member

Well, yes.

@hselasky
Copy link
Contributor Author

Better now?

@infrastation
Copy link
Member

Looks much more comprehensible to me now, thank you.

@guyharris
Copy link
Member

So there are no backends that 1) do have a file descriptor but 2) don't support Capsicum?

For example, does the Netmap support in pcap-netmap.c support Capsicum? If not, testing the result of pcap_fileno(), to make sure it's not -1, is not sufficient to eliminate the use of Capsicum on Netmap devices.

Or is it a case of "support Capsicum" really meaning that, to support Capsicum with a given device, you have to enable the particular ioctls used by the device, in which case, to fix this, there will have to be support in libpcap (as that's the only place that knows which ioctls have to be enabled)?

@hselasky
Copy link
Contributor Author

For example libibverbs have a bunch of file descriptors associated with the data transport object. None of these are registered by libpcap, so at the moment we enter sandboxing, these transport objects stop working.

From what I understand, the file handle in question is only used for BPF, Berkeley Packet Filter, compatible file handles. If it is -1 it means BPF is not in use. I'll have to dig a bit deeper in the code to verify this. Basically these bits been tested under FreeBSD and verified. And there is also an identical review pending with some more information:

https://reviews.freebsd.org/D15785

@guyharris
Copy link
Member

For example libibverbs have a bunch of file descriptors associated with the data transport object.

That's one particular example; you need to look at all the backends that will run on OSes that support Capsicum (is it FreeBSD-only, or do any other OSes that support libpcap support it?) to determine whether this change is sufficient.

None of these are registered by libpcap

Are there libibverbs call to fetch the descriptors from the various handles pcap-rdmasniff.c opens? If so, again, perhaps what's needed is a per-backend "Capsicumize" function pointer, which would be null on platforms that don't support Capsicum, and would perform the appropriate operations on platforms that do, combined with "Capsicumize" APIs in libpcap, which tcpdump would use.

From what I understand, the file handle in question is only used for BPF, Berkeley Packet Filter, compatible file handles.

Not true - perhaps, in my previous comment, I should have explicitly indicated that the file handle is set by the Netmap backend, and therefore that pcap_fileno() will not return -1.

If it is -1 it means BPF is not in use.

"The return value of pcap_fileno() is -1" implies "BPF is not in use".

"BPF is not in use", however, does not imply "the return value of pcap_fileno() is -1".

@hselasky
Copy link
Contributor Author

hselasky commented Jul 2, 2018

That's one particular example; you need to look at all the backends that will run on OSes that support Capsicum (is it FreeBSD-only, or do any other OSes that support libpcap support it?) to determine whether this change is sufficient.

This is out of the scope of my patch. Do you believe there is any reason my patch will break anything?

@hselasky
Copy link
Contributor Author

hselasky commented Jul 2, 2018

"BPF is not in use", however, does not imply "the return value of pcap_fileno() is -1".

If you understand the code better than I do, maybe you can help correct my patch.

@hselasky
Copy link
Contributor Author

hselasky commented Jul 2, 2018

Are there libibverbs call to fetch the descriptors from the various handles pcap-rdmasniff.c opens?

This is not possible currently, so capsicum + libibverbs is a no-go.

@hselasky
Copy link
Contributor Author

Ping - can these patches be pushed?

@infrastation
Copy link
Member

Please allow some more time for a more thorough review.

@emaste
Copy link
Contributor

emaste commented Aug 1, 2018

Please allow some more time for a more thorough review.

Do you have a rough guess of the timeline? We're approaching code freeze for FreeBSD 12 and would prefer to include a change identical to upstream, but if it will be a while yet we'll incorporate a local patch and revert to upstream later.

@infrastation infrastation changed the title Fixes for tcpdump Capsicum-related fixes for tcpdump Aug 14, 2018
@infrastation
Copy link
Member

To answer one of the Guy's questions: Capsicum project page says it is supported on FreeBSD, Linux and DragonFlyBSD, if that helps.

@hselasky
Copy link
Contributor Author

Ping - any updates?

@hselasky
Copy link
Contributor Author

FYI: Submitted to FreeBSD:
https://svnweb.freebsd.org/base?view=revision&revision=338613

@mcr
Copy link
Member

mcr commented May 3, 2019

Sorry this is taking so long.
May I ask you to rebase again?

@hselasky
Copy link
Contributor Author

hselasky commented May 3, 2019

Sorry this is taking so long.
May I ask you to rebase again?

Done.

Not all libpcap backends use the BPF compatible set
of IOCTLs. For example the mlx5 backend uses libibverbs
which is currently not capsicum compatible.

Disable sandboxing for such backends.

Completes commit 3e26499

Signed-off-by: Hans Petter Selasky <hps@selasky.org>
@fxlb
Copy link
Member

fxlb commented Jul 10, 2021

Any reason to NOT merge this patch?

@fxlb
Copy link
Member

fxlb commented Jul 10, 2021

Perhaps the test should be explained...

@infrastation
Copy link
Member

@hselasky, a few months ago I made a few Capsicum-related bugfixes in tcpdump (commits 780f86b, ac23514 and 51f9c3b), it would be great if you could confirm these look good to you. Also it would be very useful to add a detailed comment into the proposed change, as it is often difficult to reconstruct the context.

@hselasky
Copy link
Contributor Author

I'll have a look. Thanks for the heads up.

@emaste
Copy link
Contributor

emaste commented May 12, 2023

Is there anything remaining to do here?

@hselasky
Copy link
Contributor Author

@emaste : I have not observed any problems in FreeBSD-14-main as of recently. Are these patches imported into our code-base? If yes, then this issue can be closed.

@emaste
Copy link
Contributor

emaste commented May 12, 2023

It looks like the one change under "Commits" is in FreeBSD, but is not in upstream tcpdump.

@infrastation
Copy link
Member

I had another round at comprehending this change and managed to understand it this time. Excuse us for the delay, there has been a lot of backlog.

@infrastation infrastation merged commit b5a602a into the-tcpdump-group:master Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

6 participants