Whilst working on something, I suddenly found that I wasn't able to use tcpdump
to write into a file
$ tcpdump -i any -s0 -w masto.pcap.%Y-%M-%d_%H.%M.%s port 3000
tcpdump: Couldn't change ownership of savefile
tcpdump
is being invoked as root
and the working directory is a local volume (so we're not trying to write into a NFS share or anything like that).
It was working fine earlier (maybe 30 minutes ago?)
$ tcpdump --version
tcpdump version 4.9.3
libpcap version 1.9.1 (with TPACKET_V3)
OpenSSL 1.1.1f 31 Mar 2020
Activity
07-Jan-23 09:46
assigned to @btasker
07-Jan-23 09:46
moved from project-management-only/staging#5
07-Jan-23 09:46
assigned to @btasker
07-Jan-23 09:48
Checking that it still repros
stracing to see what it's doing
Here's the failure
It's not going to be able to chown that file because it hasn't created it yet
07-Jan-23 09:49
This works (appending a filename extension to the output filename):
I'm guessing there's some logic buried in there somewhere that works out whether to create the file or not?
07-Jan-23 09:51
The chosen extension seems to matter
This also works
07-Jan-23 10:03
Looks like the version of tcpdump I'm running (
4.9.3
) was released in 2019.Looks like it works fine on more recent versions, so options are:
tcpdump
(best option).pcap
as a filename extension (appears to break time based cyclic captures)$PWD
(e.g.tcpdump -i any -s0 -w $PWD/foo port 3000
)07-Jan-23 10:15
Re-opening as this is only a partial answer - using
$PWD
still resulted in issues.Also, there's another failure mode which has (hopefully) pointed me in the right direction: capture works initially but fails at rotate time
07-Jan-23 11:32
So, it can open a file, but when it tries to open another it gets permissions denied?
It's going to be AppArmour screwing things up.
There's a profile in enforce mode for
/usr/sbin/tcpdump
Checking whether AA suggests changes
So, it is the profile.
And we can now see (in
/etc/apparmor.d/usr.sbin.tcpdump
) why having a.pcap
extension workedSwitching to complain
doesn't fix the issue either.
Bizarrely, it continues to work if provided with a path:
So I'm just going to do that, and may come back to this later
07-Jan-23 11:32
mentioned in issue CDN#49