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

Getting "socket: permission denied" when running in UDP mode in linux #25

Open
wsagehorn opened this issue Jun 16, 2016 · 6 comments
Open

Comments

@wsagehorn
Copy link

I've changed the network to udp mode with p.Network("udp") to avoid the need for sudo privileges, but I get socket: permission denied as an error.

When run with debug on, it prints:
2016/06/16 14:52:34 Run(): Start
2016/06/16 14:52:34 Run(): close(p.ctx.done)

Running without p.Network("udp") works fine (but requires sudo).
The error is identical in 32 bit and 64 bit Ubuntu 14.04.
The same code works as intended on mac.

@karasz
Copy link

karasz commented Jul 29, 2016

Most probably you are bit by a kernel change in recent Ubuntus (or maybe even upstream).
You can do a sysctl net.ipv4.ping_group_range if the response is 1 0 then the UDP variant will not work. To enable all users to use that facility you need
sudo sysctl -w net.ipv4.ping_group_range="0 65535".

More explanations you will get here: https://lwn.net/Articles/422330/

HTH

@karasz
Copy link

karasz commented Jul 29, 2016

Another problem with this code is at line:
https://github.com/tatsushid/go-fastping/blob/master/fastping.go#L652
when UDP is enabled pkt.ID == p.id is not true due to the way the kernel handles ID of those packets.
when using UDP one should only rely on the sequences, ,or properly handle the packet IDs.

@seantcanavan
Copy link

@karasz can we just modify the sudoers file to run the command inherently with sudo privileges?

jcooklin added a commit to jcooklin/snap-plugin-collector-pingscan that referenced this issue Dec 9, 2016
Fastping provides a more effective means to timeout requests (MaxRTT).  Note this plugin will require that it be run as root (see tatsushid/go-fastping#25)
@bmon
Copy link

bmon commented Dec 13, 2016

@seantcanavan You could, but then you're taking all the risks and issues associated with running your program as root. Unless there's something specific that's stopping you from using the workaround karasz mentioned, it would be much safer to not run with root.

@seantcanavan
Copy link

@bmon I was referring specifically to adding the ping command to the sudoers file and not the entire fastping process itself. this would technically constitute least-privilege permissions escalation.

@eikenb
Copy link

eikenb commented Sep 23, 2019

Just hit this. Seems like changing the "net.ipv4.ping_group_range" value as a workaround should be documented somewhere other than only in an old issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants