Skip to content

[WIP] ping: set random ident also for ICMP datagram socket - #490

Draft
pevik wants to merge 2 commits into
iputils:masterfrom
pevik:ping/fix-print-default-ident
Draft

pevik wants to merge 2 commits into
iputils:masterfrom
pevik:ping/fix-print-default-ident

Conversation

@pevik

@pevik pevik commented Sep 21, 2023 •

Copy link
Copy Markdown
Contributor
  • ping: Set random ident also for ICMP datagram socket

Before 87dbb3a both raw socket and ICMP datagram socket used
random ident (PID of ping at the time). 87dbb3a stop setting
random ident for ICMP datagram socket, instead the default value max
value 65535 (via htons(-1)) was used.

This commit removed the need of root privileges for running ping and
maybe that was needed at the time (2015-05-29: kernel v4.0 or maybe
3.16.x which already had ICMP datagram socket support and was still
used) ICMP datagram socket really required root for setting ident. But
that's not true any more now.

Tested on kernel 6.4.x, 5.10.x. Kernel v4.14.x is still LTS, but these
are used on distros which will not update iputils.

Fixes: 87dbb3a

  • ping: Remove check for invalid ident

When the ident is -1 the ident for the group of requests is chosen by
the kernel and most likely it's not 65535. That's why it was not printed
in 43e38f2. But since previous commit random ident was set even for ICMP
datagram socket and we don't allow to set ident < 0. Thus it should be
safe to always print ident.

#489 (comment)

@pevik

pevik commented Sep 21, 2023

Copy link
Copy Markdown
Contributor Author

@rumvadim Could you please review?
@milo FYI

@rumvadim

Copy link
Copy Markdown
Contributor

Hi!
This will not print the right ident, though. When the ident is -1 the ident for the group of requests is chosen by the kernel and most likely it's not 65535.

Before 87dbb3a both raw socket and ICMP datagram socket used
random ident (PID of ping at the time). 87dbb3a stop setting
random ident for ICMP datagram socket, instead the default value max
value 65535 (via htons(-1)) was used.

This commit removed the need of root privileges for running ping and
maybe that was needed at the time (2015-05-29: kernel v4.0 or maybe
3.16.x which already had ICMP datagram socket support and was still
used) ICMP datagram socket really required root for setting ident. But
that's not true any more now.

Tested on kernel 6.4.x, 5.10.x. Kernel v4.14.x is still LTS, but these
are used on distros which will not update iputils.

Fixes: 87dbb3a ("This patch allows running ping and ping6 without root privileges on kernels that support it. Almost identical to Lorenzo Colitti's original patch except:")
Signed-off-by: Petr Vorel <[email protected]>
@pevik

pevik commented Sep 21, 2023 •

Copy link
Copy Markdown
Contributor Author

@rumvadim Thanks for a hint (could you quote kernel code?), I removed that code and update docs, but I need to verify that with tcpdump.

I also set a random ident also for ICMP datagram socket, thus there should be always ident != -1, so maybe I'll remove that -1 check (and we don't allow -e -1 input). And if there is a way to set ident -1, we should print ident=unknow instead). WDYT?

@pevik
pevik force-pushed the ping/fix-print-default-ident branch from 3d103e0 to f2e9f55 Compare September 21, 2023 22:09
pevik added a commit to pevik/iputils that referenced this pull request Sep 21, 2023
Document the reason why ident -1 is not printed: When the ident is -1,
the ident for the group of requests is chosen by the kernel and most
likely it's not 65535 (htons(-1)).

Link: iputils#490 (comment)
Suggested-by: Vadim Rumyantsev <[email protected]>
Signed-off-by: Petr Vorel <[email protected]>
@pevik
pevik force-pushed the ping/fix-print-default-ident branch from f2e9f55 to 59da996 Compare September 21, 2023 22:11
When the ident is -1 the ident for the group of requests is chosen by
the kernel and most likely it's not 65535. That's why it was not printed
in 43e38f2. But since previous commit random ident was set even for ICMP
datagram socket and we don't allow to set ident < 0. Thus it should be
safe to always print ident.

Link: iputils#490 (comment)
Link: iputils#489 (comment)
Reported-by: Miloslav Hůla
Signed-off-by: Petr Vorel <[email protected]>
@pevik
pevik force-pushed the ping/fix-print-default-ident branch from 59da996 to 286707b Compare September 21, 2023 22:18
@pevik

pevik commented Sep 21, 2023

Copy link
Copy Markdown
Contributor Author

@nmav Could you please also have look?

@pevik pevik changed the title ping: Print also the default ident ping: set random ident also for ICMP datagram socket Sep 21, 2023
@rumvadim

rumvadim commented Sep 21, 2023 •

Copy link
Copy Markdown
Contributor

The kernel code is here: https://elixir.bootlin.com/linux/latest/source/net/ipv4/ping.c#L78 (ping_get_port)
ident=unknown seems fine to me, but I'm no expert in good interfaces though 😅

@pevik
pevik marked this pull request as draft September 22, 2023 16:45
@pevik pevik changed the title ping: set random ident also for ICMP datagram socket [WIP] ping: set random ident also for ICMP datagram socket Sep 27, 2023
@pevik pevik removed this from the 20231222 milestone Dec 22, 2023
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

Successfully merging this pull request may close these issues.

2 participants