Page MenuHomeFreeBSD

devfs: add bpf examples
ClosedPublic

Authored by tuexen on Thu, Apr 30, 11:01 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, May 23, 7:53 PM
Unknown Object (File)
Sat, May 23, 12:33 AM
Unknown Object (File)
Sat, May 23, 12:05 AM
Unknown Object (File)
Fri, May 22, 3:28 PM
Unknown Object (File)
Thu, May 21, 4:36 PM
Unknown Object (File)
Thu, May 21, 8:37 AM
Unknown Object (File)
Wed, May 20, 7:37 PM
Unknown Object (File)
Wed, May 20, 2:53 PM
Subscribers

Details

Summary

Add an example for allowing members of the network group to access bpf devices. In particular, this allows members of the network group to monitor traffic without running with root privileges.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

In particular, this allows members of the network group to monitor traffic without running with root privileges.

It also lets those members inject packets... maybe the suggested permissions should be 0640 at least?

Sorry for slightly switching context. This actually links to the recent "regression" that I planted. With a new API to get exact list of possible bpf taps, instead of guessing via getifaddrs(3) + list USB buses, the building of the list requires privileges. Previously you could run tcpdump -D without privileges on FreeBSD, now it can't. The wireshark/tcpdump guys think that it is a regression and should be fixed.

There are two ways to solve:

  1. Change permissions on /dev/bpf and do privileges checking inside the device code. Allow BIOCGETIFLIST for unprivileged user.
  2. In libpcap fallback to getifaddrs(3)+/dev/usb guessing if opening /dev/bpf failed.

Your opinions?

Please take into account Mark's suggestion.

This revision is now accepted and ready to land.Thu, Apr 30, 6:49 PM

Use 0640 as markj@ suggested.

This revision now requires review to proceed.Thu, Apr 30, 7:20 PM

In particular, this allows members of the network group to monitor traffic without running with root privileges.

It also lets those members inject packets... maybe the suggested permissions should be 0640 at least?

Done. I was using the setting 0660 for years since it was suggested in pkg-message.

Sorry for slightly switching context. This actually links to the recent "regression" that I planted. With a new API to get exact list of possible bpf taps, instead of guessing via getifaddrs(3) + list USB buses, the building of the list requires privileges. Previously you could run tcpdump -D without privileges on FreeBSD, now it can't. The wireshark/tcpdump guys think that it is a regression and should be fixed.

I can understand that.

There are two ways to solve:

  1. Change permissions on /dev/bpf and do privileges checking inside the device code. Allow BIOCGETIFLIST for unprivileged user.
  2. In libpcap fallback to getifaddrs(3)+/dev/usb guessing if opening /dev/bpf failed.

Your opinions?

I would tend to 2. I guess most people run at least wireshark with 0660 on bpf devices, since this is what it recommended when the port is installed, they would get the new code with higher quality output. The rest gets what it was getting earlier.

Sorry for slightly switching context. This actually links to the recent "regression" that I planted. With a new API to get exact list of possible bpf taps, instead of guessing via getifaddrs(3) + list USB buses, the building of the list requires privileges. Previously you could run tcpdump -D without privileges on FreeBSD, now it can't. The wireshark/tcpdump guys think that it is a regression and should be fixed.

There are two ways to solve:

  1. Change permissions on /dev/bpf and do privileges checking inside the device code. Allow BIOCGETIFLIST for unprivileged user.

We shouldn't do privilege checking after the /dev/bpf file descriptor has been obtained.

  1. In libpcap fallback to getifaddrs(3)+/dev/usb guessing if opening /dev/bpf failed.

Your opinions?

It must be 2) IMO. Isn't that also required to support running new libpcap on FreeBSD? There are supported releases which do not have BIOCGETIFLIST.

sbin/devfs/devfs.conf
46

It can just be bpf, no? The bpf code only creates /dev/bpf and /dev/bpf0, and they are aliases. Globbing would match any hypothetical device files which start with bpf*.

Use bpf instead of bpf* as suggested by markj@.

tuexen added inline comments.
sbin/devfs/devfs.conf
46

I tested using bpf instead of bpf* and it works as expected. Never tried that. Thanks for the hint.

sbin/devfs/devfs.conf
44

The comment should probably explain that this allows members of the group to snoop all traffic in the system.

Be more explicit in the comment as suggested my markj@ and rscheff@.

tuexen added inline comments.
sbin/devfs/devfs.conf
44

OK. The comment was similar to the other ones for consistency. But rscheff@ also suggested to be more explicit. So do this.

This revision is now accepted and ready to land.Thu, Apr 30, 8:20 PM
This revision was automatically updated to reflect the committed changes.