telemetrics-client installation starts when the package is installed,
this change makes sure that to start telemetry the first time two steps
are needed: 1- telemctl opt-in and 2- telemctl start
Signed-off-by: Alex Jaramillo <alex.jch@gmail.com>
Remove all references to python probe. The python exceptions
are handled entirely in Python code. This telemetrics-client
package does not need to be aware of the Python code exception handling
and does not need to make any provisions for it (such as creating
services and directories).
It is the responsibility of Python exception handling to properly
interface with the telemetry library.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Add support for ramoops files in pstore probe, get the crash information
from "/sys/fs/pstore/dmesg-ramoops-x" files.
Add the "-f" cmd option support to input runtime config file when
running the probe.
Change-Id: Id7f26d6e07a7c215027b9be039356b2633d4869f
Signed-off-by: Tian Baofeng <baofeng.tian@intel.com>
handle_client: added a reasonable sanity check for record size.
Currently it is not possible to get max size of headers, so
the assumption is each line in header will be at most 80 chars.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Split a fairly convoluted loop in "handle_client" into
two distinct steps:
1. Read the record size by reading the first 4 bytes.
2. Once the record size is known, read the rest of the record
into a buffer.
All the buffer for the record allocation/deallocations are handled
in this routine as well. The new code does not need to know any datails
about the record buffer layout. This needed a minor modification of the
record itself, the first 4 bytes of the record now contain the length of
the entire record (including the 4 bytes). This required a minor change
in "telemtry.c" the routine tm_send_record. The previous "total_size"
in the 4 bytes did not include the terminator and header_size, so
"handle_client" needed to adjust for those to get the real expected
record size.
Also declared "terminate_client" and "process_record" as static.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Upon (error) exit the field buf.st_blocks may contain garbage.
Make sure buf.st_blocks is deterministic.
While in there, also removed some redundant round brackets.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Simplified the code for telemctl_opt_out and telemctl_opt_in.
There is no real need to call "access" to determine if opted_out
file exists, we get the same info by scrutinizing the errno.
This fixes any potential TOCTOU problems between access/create and access/unlink.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
When telemetry is opt-out, telem-record-gen is unable to print a
telemetry record. This change enables printing a record to stdout
without allowing the record to be submitted.
Signed-off-by: Alex Jaramillo <alex.jch@gmail.com>
open_journal: Fix leaked file pointer on error exits.
print_journal: Make sure we always call free_journal_entry(entry),
regardless if we print the entry or not.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
1. Return a known (NULL) value of "*entry" if the function fails.
2. Remove some dead code. Since the loop index ranges 0..4, it is
pointless to have a switch statement outsized of this range.
3. Ensure all pointers within the allocated structure JournalEntry
are defined. (They are initialized as NULL courtesy of calloc),
otherwise we may end up freeing some random pointers in
"free_journal_entry"
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Don't use fscanf in order to avoid a potential string overflow.
Use code that is aware of allocated buffer sizes.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Folders owned by "telemetry" may contain files that are not
owned by "telemetry". Allow deleting those.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Remove a test for a valid pointer. The test hase been done
already. Also the pointer has been dereferenced already.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Add pattern for kernel panic. The new pattern can be tested with:
$ sudo sh -c "echo 'c' > /proc/sysrq-trigger"
The above command will crash the system immediately, however upon reboot
the pstoreprobe will send the crah report.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Prevent time of check to time of use exploit.
Don't use "stat" to get the file size. The "stat" and "fopen"
could refer to two different files.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
tm_set_event_id: if a record exists, then the record headers
array exists as well as it is a part of the record itself.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
In the routine "machine_id_replace" replace "strcpy" with
a safer "strncpy".
Also declare the routine as static as it is not used outside
of this file.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Remove a useless test.
Routine "stack_frame_append": don't test again if a pointer
is NULL. It has been done already. Also, the pointer was
already dereferenced before the test.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
If mkstemp fails, it returns a negative value (-1).
So adjust the test accordingly. Also don't attempt to close
an invalid file descriptor. Don't unlink a file that failed
to be created.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
It is allowed to enter the same command line argument more than once,
the later value overriding the previous one.
Make sure any previous value is properly de-allocated.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
In the routine "instanciate_record":
If the user passed event_id on the command line and it was incorrect,
any returned error from tm_set_event was ignored and "instanciate_record"
could return success (0).
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
"fscanf" assumes an arbitrarily long string, so limit the scan to
32 characters to avoid a potential buffer overflow.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Even if errors were encounterd parsing the header we used to
return success ("true") by a mistake.
Fix this by correcting the test.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Causing double free case when an empty line has been
passed to deserialize_journal_entry() from print_journal()
to print the report, This case double free can be occured
at print_journal() and deserialize_journal_entry().
Signed-off-by: Mohammed Khajapasha <mohammed.khajapasha@intel.com>
Create a binary executable "telemctl" that is equivalent
to the shell script "telemctl".
Main reason is to make (future) localization easier.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
"telemd" was replaced by "telemprobd" a long time
ago, however several man pages still contain refererences
to "telemd".
This patch replaces all references accordingly.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Build is broken for multiple binaries when configured for logging
to systemd journal:
$ ./configure --enable-logtype=systemd
$ make
All binaries that use the routine "telem_log" must link to additional
libraries when logging to systemd journal.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
A simple program that is highly recursive (or very deeply nested)
and causes stack overflow or segmentation fault can take hours
for crash_probe to process.
This patch fixes this by limiting the size of the stacktrace to 64.
(64 is also the size of the stack trace used by systemd).
64 lines of 80 characters == 5120 bytes. Enough to leave room for
telemetry headers and have a reasonable chance of making the 8k payload
limit.
If the stack trace is truncated, the payload will contain a message:
"Too many frames. Backtrace truncated".
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
No functional changes.
Provide additional info in the usage message, based on user feedback.
While in there, some additional minor changes..
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Modify code to avoid generating compiler warning such as:
warning: ‘__builtin_strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Replace strncpy with memcpy to avoid GCC9 warning:
warning: ‘__builtin___strncpy_chk’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
There is no danger of overflow. The destination buffer is guaranteed to
be of MAX_PAYLOAD_LENGTH.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Replaced strncpy with memcpy and added some buffer overflow checks in
order to avoid GCC9 compiler warning:
warning: ‘__builtin___strncpy_chk’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
While in there, removed one unused global variable and declared the remaining
global variables as static.
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
The default configuration for telemetry is to not store records that
were successfully sent. This would result in a multitude of errors when
calling the journal program with --include_record, as the records no
longer existed to open.
Signed-off-by: California Sullivan <california.l.sullivan@intel.com>
Compiler optimization can remove certain security checks for undefined
behavior. Add compiler flags that restrict arbitrary decisions when
handling undefined behaviors.
* fno-strict-overflow, do not assume signed overflow does not occur.
* fno-delete-null-pointer-checks, do not assume null pointer deference
does not exists.
* fwrapv, always wrap signed overflow.
Signed-off-by: Alex Jaramillo <alex.jch@gmail.com>
Use the telem_log, telem_debug, and telem_perror macros to print
messages instead of printf and fprintf where appropriate. These macros
may be configured to print to many standard locations at compile time,
such as the syslog, the journal, or stderr. The remaining uses of
fprintf in printing errors is only for command line utilities.
When using telem_debug, we don't need to surround it with #ifdef DEBUG
statements, as the macro does that itself.
Finally, stop hiding real errors behind #ifdef DEBUGs. If an error
occurs, it should be logged.
Signed-off-by: California Sullivan <california.l.sullivan@intel.com>