libs: [BUG] Timestamp incorrect in event logs, dated in the future by 7 days/1 week
Describe the bug
While analyzing event and debug logs generated by Falco, we discovered that the events were dated in the future.
For example, we saw an debug entry on 1677527444 (around Mon, 27 Feb 2023 19:50:44 GMT), I identified the following entry with the following timestamp 2023-03-06T11:56:34.693685797Z:
{
"hostname": "redacted",
"output": "Falco internal: syscall event drop. 116192 system calls dropped in last second.",
"output_fields": {
"ebpf_enabled": "0",
"n_drops": "116192",
"n_drops_buffer_clone_fork_enter": "0",
"n_drops_buffer_clone_fork_exit": "0",
"n_drops_buffer_connect_enter": "0",
"n_drops_buffer_connect_exit": "0",
"n_drops_buffer_dir_file_enter": "0",
"n_drops_buffer_dir_file_exit": "0",
"n_drops_buffer_execve_enter": "0",
"n_drops_buffer_execve_exit": "0",
"n_drops_buffer_open_enter": "0",
"n_drops_buffer_open_exit": "0",
"n_drops_buffer_other_interest_enter": "0",
"n_drops_buffer_other_interest_exit": "0",
"n_drops_buffer_total": "116192",
"n_drops_bug": "0",
"n_drops_page_faults": "0",
"n_drops_scratch_map": "0",
"n_evts": "430758"
},
"priority": "Debug",
"rule": "Falco internal: syscall event drop",
"time": "2023-03-06T11:56:34.693685797Z"
}
Around an event generated on
date +%s ; date -u
1677527950
Mon 27 Feb 2023 07:59:10 PM UTC
The following event was observed with timestamp 1678109229443642000, 2023-03-06T13:27:09.443642063Z:
{
"hostname": "redacted",
"priority": "Warning",
"rule": "Read sensitive file untrusted",
"source": "syscall",
"tags": [
"T1020",
"T1083",
"T1212",
"T1552",
"T1555",
"container",
"filesystem",
"host",
"mitre_credential_access",
"mitre_discovery"
],
"time": "2023-03-06T13:27:09.443642063Z",
"output_fields": {
"container.id": "host",
"container.image.repository": null,
"evt.time": 1678109229443642000,
"fd.name": "/etc/pam.d/common-session",
"proc.aname[2]": "systemd",
"proc.aname[3]": null,
"proc.aname[4]": null,
"proc.cmdline": "sshd -D -R",
"proc.name": "sshd",
"proc.pid": 3225785,
"proc.pname": "sshd",
"user.loginuid": -1,
"user.name": "root"
}
}
How to reproduce it
Unsure, installation was from HEAD @ 0de9af9 via systemd on-metal.
Generate events and look at log messages?
Expected behaviour
Timestamp should be accurate / not in the future.
Since the epoch times are pretty similar, 1678109229443642000 and 1677527950; perhaps the string generated in the time field is incorrect (~7 days in the future, or 6048000000000 in nanoseconds epoch)?
Environment
- Falco version:
{
"default_driver_version": "e1d0fd9b043f1c7dfd91c9d030c11cfe2c062931",
"driver_api_version": "4.0.0",
"driver_schema_version": "2.0.0",
"engine_version": "16",
"falco_version": "0.34.1-1-da4e36e4",
"libs_version": "e1d0fd9b043f1c7dfd91c9d030c11cfe2c062931",
"plugin_api_version": "2.0.0"
}
- System info:
{
"machine": "x86_64",
"nodename": "redacted",
"release": "5.15.90-custom",
"sysname": "Linux",
"version": "#1 SMP Mon Sep 27 00:00:00 UTC 2010"
}
- OS:
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
- Kernel:
Linux redacted 5.15.90-custom #1 SMP Mon Sep 27 00:00:00 UTC 2010 x86_64 GNU/Linux
- Installation method:
- from source, HEAD @ 0de9af9 via DEB/systemd on-metal
Additional context
Possibly related to https://github.com/falcosecurity/libs/pull/595 ? (Did a search from prior PRs related to time.)
Discussion on Slack community: https://kubernetes.slack.com/archives/CMWH3EH32/p1677517061599169
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 41 (41 by maintainers)
Commits related to this issue
- Resolve falcosecurity/libs#932, use /proc/1/cmdline for boot/procfs creation time See https://github.com/falcosecurity/libs/issues/932 for more context Previous: ```c snprintf(proc_dir, sizeof(proc_... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity/libs#932, use /proc/1/cmdline for boot/procfs creation time See https://github.com/falcosecurity/libs/issues/932 for more context Previous: ```c snprintf(proc_dir, sizeof(proc_... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity/libs#932, use /proc/1/cmdline for boot/procfs creation time See https://github.com/falcosecurity/libs/issues/932 for more context Change occurrences of `/proc/1` to `/proc/1/cm... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity#932, use btime from /proc/stat for boot time Get boot time from btime value in /proc/stat ref: https://github.com/falcosecurity/libs/issues/932 /proc/uptime and btime in /proc... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity/libs#932, use /proc/1/cmdline for boot/procfs creation time See https://github.com/falcosecurity/libs/issues/932 for more context Change occurrences of `/proc/1` to `/proc/1/cm... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity#932, use btime from /proc/stat for boot time Get boot time from btime value in /proc/stat ref: https://github.com/falcosecurity/libs/issues/932 /proc/uptime and btime in /proc... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity/libs#932, use /proc/1/cmdline for boot/procfs creation time See https://github.com/falcosecurity/libs/issues/932 for more context Change occurrences of `/proc/1` to `/proc/1/cm... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity#932, use btime from /proc/stat for boot time Get boot time from btime value in /proc/stat ref: https://github.com/falcosecurity/libs/issues/932 /proc/uptime and btime in /proc... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity#932, use btime from /proc/stat for boot time Get boot time from btime value in /proc/stat ref: https://github.com/falcosecurity/libs/issues/932 /proc/uptime and btime in /proc... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity#932, use btime from /proc/stat for boot time Get boot time from btime value in /proc/stat ref: https://github.com/falcosecurity/libs/issues/932 /proc/uptime and btime in /proc... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity#932, use btime from /proc/stat for boot time Get boot time from btime value in /proc/stat ref: https://github.com/falcosecurity/libs/issues/932 /proc/uptime and btime in /proc... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity#932, use btime from /proc/stat for boot time Get boot time from btime value in /proc/stat ref: https://github.com/falcosecurity/libs/issues/932 /proc/uptime and btime in /proc... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity#932, use btime from /proc/stat for boot time Get boot time from btime value in /proc/stat ref: https://github.com/falcosecurity/libs/issues/932 /proc/uptime and btime in /proc... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity/libs#932, use /proc/1/cmdline for boot/procfs creation time See https://github.com/falcosecurity/libs/issues/932 for more context Change occurrences of `/proc/1` to `/proc/1/cm... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity#932, use btime from /proc/stat for boot time Get boot time from btime value in /proc/stat ref: https://github.com/falcosecurity/libs/issues/932 /proc/uptime and btime in /proc... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity#932, use btime from /proc/stat for boot time Get boot time from btime value in /proc/stat ref: https://github.com/falcosecurity/libs/issues/932 /proc/uptime and btime in /proc... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity#932, use btime from /proc/stat for boot time Get boot time from btime value in /proc/stat ref: https://github.com/falcosecurity/libs/issues/932 /proc/uptime and btime in /proc... — committed to happy-dude/libs by happy-dude a year ago
- Resolve falcosecurity/libs#932, use /proc/1/cmdline for boot/procfs creation time See https://github.com/falcosecurity/libs/issues/932 for more context Change occurrences of `/proc/1` to `/proc/1/cm... — committed to falcosecurity/libs by happy-dude a year ago
- Resolve falcosecurity#932, use btime from /proc/stat for boot time Get boot time from btime value in /proc/stat ref: https://github.com/falcosecurity/libs/issues/932 /proc/uptime and btime in /proc... — committed to falcosecurity/libs by happy-dude a year ago
- Resolve falcosecurity/libs#932, use /proc/1/cmdline for boot/procfs creation time See https://github.com/falcosecurity/libs/issues/932 for more context Change occurrences of `/proc/1` to `/proc/1/cm... — committed to sysflow-telemetry/libs by happy-dude a year ago
Just updated the PR and added a comment, https://github.com/falcosecurity/libs/pull/1003#issuecomment-1483538662
ACK, this would certainly be a super simple refactor …
You know what ahhaah there is no issues here, just that sites like epochconverter automatically switch base depending on number of digits of the number. Therefore, in epochconverter,
12721000000isGMT: Saturday 10 February 2373 19:06:401946299696411786isGMT: Thursday 4 September 2031 14:48:16.411Using another tool, ie: https://www.epoch101.com/, you’ll discover that:
12721(ie: 12721000000 parsed as milliseconds) meansThu, 01 Jan 1970 00:00:12 GMT1946299696(ie: 1946299696411786 parsed as milliseconds) meansFri, 23 Jan 1970 12:38:19 GMTBasically, the even is happening ~22days after you booted up your PC (and that is a validated information from your
uptimeoutput.)The issue here is not about events timestamp, but is all about why your
/proc/1has a very low epoch change time…Unfortunate news:
The change didn’t fix the timestamp on my nodes; it’s possible that
/proc/1/cmdlinechange may be insufficient in producing the right timestamp – confirmed on both a x86-64 host and aarch64 host.Changed the PR to (WIP)
Internally to my org, there may be separate issues affecting
/procmutually exclusive to x86-64 and aarch64 – I’ll investigate further on that front with internal engineers.EDIT: I’m also discussing with my team on if we can patch our builds to use the fall back method w/
clock_gettime()instead 🤔Here is some output from scap_open:
Hey y’all,
Our internal kernel folks are still investigating the
/proc/1epoch time problem, but they have a suggestion for Falco:Instead of
/proc/1, can/proc/1/cmdlinebe used instead? This apparently similar to what Docker is doing (something about the procfs / container creation time?).Yep 😦 A solution could be to fallback to old method if
stat /proc/1leads to weird results (ie: a result like before year 2000). I think the new approach, that was introduced by Melissa if i recall correctly, is more stable therefore i’d avoid to kill it.on your side @Happy-Dude it would be amazing to understand why in all your machines
/prochas this strange change time (~epoch)I’ve updated our test branch removing this proc scan and using the old fallback logic https://github.com/Andreagit97/libs/tree/timestamp_issue. Would you like to give it a try @Happy-Dude?
Hey team,
Did some preliminary investigation:
not a problem with the way my misbehaving systems were configured (timezone, etc.). Confirmed by copying the functions/code used in https://github.com/falcosecurity/falco/blob/93ae6bb6098e7563f94738839715c2d7ee8f5ab5/userspace/falco/logger.cpp into a
test.cppto generate a timestampnot a problem with JSON output. Confirmed by turning
json_output: falseandtime_format_iso_8601: falseand generating a logged alert entryWill do some more digging as time permits. My next “excavation” will be where/how the timestamp is recorded when an event is traced/processed.
I’ve seen this in using the falco libs separately from falco. Tried to reproduced in sinsp-example/scap-example from the head of libs and haven’t been able to replicate currently. Will keep digging.