daemon/cgrulesengd: check the bytes read in cgre_receive_unix_domain_msg()
Fix ignoring the number of bytes read, warning reported by Coverity
tool:
CID 258286 (#2 of 2): Ignoring number of bytes read (CHECKED_RETURN).
check_return: read(int, void *, size_t) returns the number of bytes
read, but it is ignored.
In cgre_receive_unix_domain_msg(), the number of bytes read() is
ignored, while reading from the flag value from the socket. Coverity
warns on not checking the number of bytes read, fix it.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api.c: check the bytes read in cgroup_register_unchanged_process()
Fix ignoring the number of bytes read, warning reported by Coverity
tool:
CID 258288 (#1 of 1): Ignoring number of bytes read (CHECKED_RETURN).
check_return: read(int, void *, size_t) returns the number of bytes
read, but it is ignored.
In cgroup_register_unchanged_process(), the number of byte read/written
using read()/write() are ignored but coverity it warns about the read()
only, let's fix it.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api.c: fix null deference in is_cgrp_ctrl_shared_mnt()
Fix explicit null dereferenced warning, reported by Coverity tool:
CID 258306 (#1 of 1): Explicit null dereferenced (FORWARD_NULL).
var_deref_model: Passing null pointer controller_name to
cgroup_find_parent, which dereferences it.
the code path which leads to the null dereference:
cgroup_delete_cgroup_ext()
- cgroup_find_parent()
- is_cgrp_ctrl_shared_mnt()
is_cgrp_ctrl_shared_mnt(), assumes that the controller_name is non-NULL
but there are changes that, this static function might be called with
NULL controller_name, let's fix it with a check.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
tools/cgsnapshot: fix out-of-bounds write in parse_controllers()
Fix Out-of-bounds write warning, reported by Coverity tool:
CID 258289 (#2 of 2): Out-of-bounds write (OVERRUN)16. overrun-local:
Overrunning array controllers of 100 4096-byte elements at element index
100 (byte offset 413695) using index max (which evaluates to 100).
there are chances, that the index variable max dereferences controller
array might be over the array size of 100. Add upper bound checks
to index variable max, so that it doesn't overrun the controller array.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api.c: check for invalid error code in cgroup_strerror()
Fix array overflow warning, reported by the Coverity tool:
CID 258309 (#1 of 1): Out-of-bounds read (OVERRUN). overrun-local:
Overrunning array cgroup_strerror_codes of 32 8-byte elements at element
index 49999 (byte offset 399999) using index code % ECGROUPNOTCOMPILED
(which evaluates to 49999).
there are chances of users passing error codes, resulting in crossing
the upper bound of the cgroup_strerror_codes[], fix it by introducing
bound checks.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
tools/cgxget: fix the resource leak in convert_cgroup()
Fix a resource leak warning reported by the Coverity tool:
CID 258272 (#1-2 of 2): Resource leak (RESOURCE_LEAK). leaked_storage:
Variable cg_converted_list going out of scope leaks the storage it
points to.
while free'ing() the cg_converted_list() via cgroup_free(), wrong array
index variable was passed, causing the resource leak. Fix it by passing
the right index variable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix a resource leak, reported by the Coverity tool:
CID 258291 (#1 of 1): Resource leak (RESOURCE_LEAK)8. leaked_storage:
Variable handle going out of scope leaks the storage it points to.
In get_cv_value(), currently, we goto end label, on the failure of
strdup() before closing the handle, leaking the resource. Fix it by
removing the goto, that allows the code flow to close the handle and
execute the code under the end label.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix a resource leak, reported by the Coverity tool:
CID 258291 (#1 of 1): Resource leak (RESOURCE_LEAK)8. leaked_storage:
Variable handle going out of scope leaks the storage it points to.
In get_cv_value(), currently, we goto end label, on the failure of
strdup() before closing the handle, leaking the resource. Fix it by
removing the goto, that allows the code flow to close the handle and
execute the code under the end label.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api: null terminate readlink buffer in cgroup_get_procname_from_procfs()
Fix readlink buffer null termination warning, reported by Coverity tool:
CID 258273 (#2 of 2): String not null terminated (STRING_NULL).
string_null: Passing unterminated string buf to strdup, which expects a
null-terminated string.
As per the man pages (man 2 readlink):
"readlink() does not append a null byte to buf. It will (silently)
truncate the contents (to a length of bufsiz characters), in case the
buffer is too small to hold all of the contents."
Explicitly null terminate the buffer passed to readlink() in
cgroup_get_procname_from_procfs()
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api: null terminate readlink buffer in cg_get_procname_from_proc_cmdline()
Fix readlink buffer null termination warning, reported by Coverity tool:
CID 258276 (#1 of 1): String not null terminated (STRING_NULL).
string_null: Passing unterminated string buf_cwd to strcat, which
expects a null-terminated string.
As per the man pages (man 2 readlink):
"readlink() does not append a null byte to buf. It will (silently)
truncate the contents (to a length of bufsiz characters), in case the
buffer is too small to hold all of the contents."
Explicitly null terminate the buffer passed to readlink() in
cg_get_procname_from_proc_cmdline().
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api.c: fix string termination in cgroup_get_procname_from_procfs()
Fix non-terminated string warning, reported by Coverity tool:
CID 258273 (#2 of 2): String not null terminated (STRING_NULL)6.
string_null: Passing unterminated string buf to strdup, which expects a
null-terminated string.
use snprintf() instead of sprintf(), to string terminate
cgroup_get_procname_from_procfs().
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
wrapper.c: null terminate string in cgroup_new_cgroup()
Fix non-terminated string warning, reported by Coverity tool:
CID 258290 (#1 of 1): String not null terminated (STRING_NULL)46.
string_null: Passing unterminated string aux_cgroup->name to
cgroup_create_cgroup, which expects a null-terminated string.
The call patch leading to this warning:
config.c::cgroup_config_create_template_group()
- wrapper.c::cgroup_new_cgroup()
fix it by null terminating the string.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
abstraction-cpu: fix resource leak in read_setting()
Fix a resource leak, reported by Coverity tool:
CID 258274 (#1 of 1): Resource leak (RESOURCE_LEAK)6. leaked_storage:
Variable handle going out of scope leaks the storage it points to
In read_setting(), currently, we goto end label, on the failure of
strdup() before closing the handle, leaking the resource. Fix it by
removing the goto, that allows the code flow to close the handle and
execute the code under the end label.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
tools/cgsnapshot: add ret value fix in parse_controllers()
Fix the unused ret value warning, reported by Coverity:
CID 258275 (#1 of 1): Unused value (UNUSED_VALUE)returned_value:
Assigning value from display_controller_data(controllers, program_name)
to ret here, but that stored value is overwritten before it can be used.
The parse_controllers(), doesn't check for errors in the value returned
by display_controller_data(). The return value might very well contain
an error, that might go unnoticed. Fix it by adding a check for the
return value.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api.c: add ret value fix in cgroup_change_cgroup_flags()
Fix the unused ret value warning, reported by Coverity:
CID 258304 (#1 of 1): Unused value (UNUSED_VALUE)returned_value:
Assigning value from cgroup_create_template_group(newdest, tmp, flags)
to ret here, but that stored value is overwritten before it can be used.
It turns out that cgroup_change_cgroup_flags(), calls the function
cgroup_create_template_group() to a cgroup based on a template, which
may fail and we don't check the return value for the error. This fix
adds the check and bails out on error.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix copy into fixed size buffer warning, reported by Coverity tool:
CID 258284 (#4 of 4): Copy into fixed size buffer (STRING_OVERFLOW)1.
fixed_size_dest: You might overrun the 4096-character fixed-size string
tmp_val by copying tok without checking the length.
In indent_multiline_value(), warned about the usage of strcat(), that
might overwrite the string. Fix it by replacing strcat() -> strncat()
in the function.
Signed-off-by: Kamalesh Babulal kamalesh.babulal@oracle.com Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix copy into fixed size buffer warning, reported by Coverity tool:
CID 258284 (#4 of 4): Copy into fixed size buffer (STRING_OVERFLOW)1.
fixed_size_dest: You might overrun the 4096-character fixed-size string
tmp_val by copying tok without checking the length.
In indent_multiline_value(), warned about the usage of strcat(), that
might overwrite the string. Fix it by replacing strcat() -> strncat()
in the function.
Signed-off-by: Kamalesh Babulal kamalesh.babulal@oracle.com Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 14:38:54 +0000 (20:08 +0530)]
tools/tools-common.h: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 14:36:17 +0000 (20:06 +0530)]
tools/tools-common.c: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 14:32:44 +0000 (20:02 +0530)]
tools/lssubsys: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 14:30:18 +0000 (20:00 +0530)]
tools/lscgroup: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 14:27:41 +0000 (19:57 +0530)]
tools/cgxget: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 14:22:42 +0000 (19:52 +0530)]
tools/cgxset: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 14:21:09 +0000 (19:51 +0530)]
tools/cgsnapshot: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 14:16:13 +0000 (19:46 +0530)]
tools/cgset: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 14:14:25 +0000 (19:44 +0530)]
tools/cgget: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 14:08:53 +0000 (19:38 +0530)]
tools/cgexec: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 14:02:56 +0000 (19:32 +0530)]
tools/cgcreate: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 08:30:09 +0000 (14:00 +0530)]
tools/cgconfig: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 08:29:11 +0000 (13:59 +0530)]
tools/cgdelete: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 08:26:34 +0000 (13:56 +0530)]
tools/cgclassify: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 08:23:38 +0000 (13:53 +0530)]
pam/pam_cgroup.c: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 08:22:11 +0000 (13:52 +0530)]
daemon/Makefile.am: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 08:21:22 +0000 (13:51 +0530)]
daemon/cgruleseng.h: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 08:18:46 +0000 (13:48 +0530)]
daemon/cgruleseng.c: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)]
Makefile.am: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)]
parse.y: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)]
libcgroup-internal.h: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)]
abstraction-map.h: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)]
abstraction-map.c: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)]
abstraction-cpuset.c: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)]
abstraction-cpu.c: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)]
abstraction-common.c: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across
the file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)]
abstraction-common.c: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across the
file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)]
api.c: increase the column width to 100
100 column width is more comfortable to read over 80 columns, lets
increase it. This patch, also introduced/removes empty lines across the
file, making it more readable.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
wrapper.c: return on failure in cgroup_add_all_controllers()
Add missing goto statement, to return on failure, reported by Coverity
tool:
CID 258281 (#1 of 1): Unused value (UNUSED_VALUE)assigned_value:
Assigning value ECGINVAL to ret here, but that stored value is
overwritten before it can be used.
the tool reported about unused ret value, but it turned out that the
NULL ret value is for failed attempt to add a controller to the desired
cgroup and needs bailing out after losing the handle. Fix it by
introducing the goto statement in cgroup_add_all_controllers()
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Also fix unrelated grammar error near this change.
Fix non-terminated string warnings, reported by the Coverity tool:
CID 258293 (#2 of 2): Copy into fixed size buffer (STRING_OVERFLOW).
fixed_size_dest: You might overrun the 32-character fixed-size string
config_namespace_table[namespace_table_index].name by copying name
without checking the length.
fix one another similar string
config_namespace_table[namespace_table_index].mount.path in the same
function cgroup_config_insert_into_namespace_table() by explicitly
terminating by appending '\0';
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix non-terminated string warning, reported by Coverity tool:
CID 258266 (#1 of 1): String not null-terminated (STRING_NULL).
string_null: Passing unterminated string con to strtok, which expects a
null-terminated string.
Fix the warning in create_cgroup_from_name_value_pairs(), by adding
'\0'.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
config: cgroup_config_insert_into_mount_table() use strncpy()
Fix copy into fixed size buffer warning, reported by Coverity tool:
CID 258282 (#2 of 2): Copy into fixed size buffer (STRING_OVERFLOW)9.
fixed_size_dest: You might overrun the 4096-character fixed-size string
config_mount_table[config_table_index].mount.path by copying mount_point
without checking the length.
parameter_as_source: Note: This defect has an elevated risk because the
source argument is a parameter of the current function
Also, convert config_mount_table[config_table_index].name strcpy to
strncpy.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
calling "hasmntopt" to determine if the controller name exists in
"mntopt", may cause errors because of "hasmntopt" only match substring.
cpu controller may incorrectly match to cpuset when cpuset mount info
appeared before cpu,cpuacct in "/proc/mounts", so we need to validate
the last character to make sure the controller name matches exactly.
Tom Hromatka [Thu, 9 Jun 2022 18:45:29 +0000 (12:45 -0600)]
api.c: Fix handling of full cg_mount_table[]
Commit 9ce90c7edd28 ("api.c: fix segfault in cgroup_populate_mount_points()")
added logic to handle the case when there are 100+ cgroup mounts and
not overflow the cg_mount_table[]. But elsewhere in the libcgroup
code, it's expected that the last entry in the cg_mount_table[] has
a null name entry.
When the cg_mount_table[] is full, make the name of the last entry
null so that loops know to exit. Also, add a couple bail out points
in cgroup_populate_mount_points() to ensure that we don't write
beyond the end of the table.
Depending upon the order in which the tests are run, this failure can
manifest itself as follows:
$ cat tests/ftests/ftests-nocontainer.sh.log
free(): invalid pointer
./ftests-nocontainer.sh: line 18: 199390 Aborted
(core dumped) ./ftests.py -l 10 -L "$START_DIR/ftests-nocontainer.py.log" --no-container -n Libcg"$RANDOM"
FAIL ftests-nocontainer.sh (exit status: 134)
Fixes: 9ce90c7edd28 ("api.c: fix segfault in cgroup_populate_mount_points()") Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Fix copy into fixed size buffer warning, reported by Coverity tool:
CID 258279 (#1 of 1): Copy into fixed size buffer (STRING_OVERFLOW).
fixed_size_dest: You might overrun the 4096-character fixed-size string
mnt_point->path by copying path without checking the length.
10. parameter_as_source: Note: This defect has an elevated risk
because the source argument is a parameter of the current function.
fix this issue by using strnpy(), in place of strcpy().
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
wrapper: null terminated string in cgroup_add_controller()
Fix non-terminated string warning, reported by Coverity tool:
CID 258271 (#1 of 1): String not null terminated (STRING_NULL).
string_null: Passing unterminated string cgc->name to strcmp, which
expects a null-terminated string.
This issue was reported following the path src/abstraction-common.c:
- cgroup_convert_cgroup()
- cgroup_add_controller()
Also, use CONTROL_NAMELEN_MAX macro, in place of calculating the size of
controller->name twice.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Tue, 31 May 2022 22:54:28 +0000 (16:54 -0600)]
api: null terminated string in cgroup_get_controller_next()
Fix non-terminated string warnings, reported by Coverity tool:
CID 258299 (#1-2 of 2): String not null terminated (STRING_NULL).
string_null: Passing unterminated string controller.path to strcmp,
which expects a null-terminated string
This issue was reported following the path src/tools/cgsnapshot.c:
- parse_controllers()
- cgroup_get_controller_begin()
- cgroup_get_controller_next()
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Tue, 31 May 2022 22:51:21 +0000 (16:51 -0600)]
config: add missing ret value check from getgrnam_r()
Fix Unchecked return values from library, reported by Coverity tool:
CID 258287 (#1 of 1): Unchecked return value from library
(CHECKED_RETURN).
check_return: Calling getgrnam_r(value, group, buffer, 20480UL,
&group_buffer) without checking return value. This library function may
fail and return an error code.
CID 258303 (#1 of 1): Unchecked return value from library
(CHECKED_RETURN).
check_return: Calling getgrnam_r(value, group, buffer, 20480UL,
&group_buffer) without checking return value. This library function may
fail and return an error code.
Coverity expects us to check for return value from getgrnam_r(), instead
of the current for group_buffer != NULL. Which is right, let's make
Coverity happy by moving the check to return value.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Fri, 27 May 2022 20:56:42 +0000 (14:56 -0600)]
api: fix coverity warning about uninitialized variable
Fix Uninitialized scalar variable, reported by Coverity tool:
CID 258269 (#1 of 1): Uninitialized scalar variable (UNINIT).
uninit_use: Using uninitialized value version.
In _cgroup_create_cgroup(), the (cg_version_t)version is uninitialized
and might be read the version in false path. It worked until now
because the version is assigned in the true path and given that its enum
the checks are not bounded by range, but rather specific.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 26 May 2022 14:12:30 +0000 (08:12 -0600)]
api.c: add cgroup error string for ECGNOVERSIONCONVERT
Add the missing error string for the error code ECGNOVERSIONCONVERT to
cgroup_strerror_codes[], that is looked upon to print string version of
the error encountered.
Reproducer:
-----------
$ cat cgrp-strerr.c
int main(void)
{
int err = ECGNOVERSIONCONVERT;
fprintf(stderr, "%s\n", cgroup_strerror(err));
return 0;
}
without the patch:
-----------------
$ ./cgrp-stderr
(null)
with the patch:
---------------
$ ./cgrp-stderr
Failed to convert from cgroup v1 to/from cgroup v2
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 25 May 2022 13:47:48 +0000 (07:47 -0600)]
tools/cgget: fix coverity warning about double free
Fix double free warning, reported by Coverity tool:
CID 258297 (#1 of 1): Double free (USE_AFTER_FREE). double_free:
Calling closedir frees pointer dir which has already been freed.
As per the man page, the closedir(), closes the directory stream
associated with the dirp, but is ambiguous about if dirp is set to NULL
or not. Coverity answers that with the above report, that dirp is not
NULL and hence the double free.
Fixes: fea1ab8b45d7 ("tools/cgget: fix coverity warning about resource leak") Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 25 May 2022 13:40:10 +0000 (07:40 -0600)]
api.c: fix coverity out of bounds read warning
Fix out of bounds read, reported by Coverity tool:
CID 1412156 (#1 of 1): Out-of-bounds read (OVERRUN).
overrun-local: Overrunning array cgroup_strerror_codes of 30 8-byte
elements at element index 49999 (byte offset 399999) using index
code % ECGROUPNOTCOMPILED (which evaluates to 49999).
Reproducer:
-----------
$ cat cgrp-strerr.c
int main(void)
{
int err = ECGNONEMPTY;
fprintf(stderr, "%s\n", cgroup_strerror(err));
return 0;
}
without the patch:
-----------------
$ ./cgrp-stderr
(null)
with the patch:
---------------
$ ./cgrp-stderr
Failed to remove a non-empty group
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
There are scenarios where running tests as part of the make check is
not desirable, like rpmbuild. The build systems might not have the
environment to run the tests and might fail to build the packages.
This patch introduces, --enable-tests as a configure option, which
is set by default and can be disabled using the --disable-tests flag.
When disabled, the configure will skip creating the Makefiles for the
tests/* directories and in the top-level Makefile the SUBDIRS omits
tests. For example, consider the rpmbuild case to build rpm with
--disable-tests passed:
1. ./bootstrap.sh
2. ./configure ./configure --enable-opaque-hierarchy="name=systemd"
--disable-tests
3. make check
4. make dist
5. cp libcgroup-3.0.0.tar.gz ~/rpmbuild/SOURCES
6. append --disable-tests to configure in libcgroup.spec
7. rpmbuild -ba libcgroup.spec
this will skip running the test/*, during the build, avoiding unexpected
failures
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Originally this issue got reported on tools/cgset and since tools/cgxset
borrows most of the code from cgset, fix the issue here too. The
original warning (cgset):
CID 1488715 (#1 of 1): Uninitialized scalar variable (UNINIT).
uninit_use_in_call: Using uninitialized value *src_cg_path as
argument to %s when calling fprintf.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix uninitialized scalar variable, reported by Coverity tool:
CID 1412125 (#1 of 1): Uninitialized scalar variable (UNINIT).
uninit_use_in_call: Using uninitialized element of array *controllers
when calling is_ctlr_on_list.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix uninitialized scalar variable, reported by Coverity tool:
CID 1488715 (#1 of 1): Uninitialized scalar variable (UNINIT).
uninit_use_in_call: Using uninitialized value *src_cg_path as argument
to %s when calling fprintf.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix uninitialized scalar variable, reported by Coverity tool:
CID 1488707 (#1 of 1): Uninitialized scalar variable (UNINIT).
uninit_use_in_call: Using uninitialized value *cont_names when calling
print_controller_mount.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix a wrong argument size, reported by Coverity tool:
CID 1412122 (#1 of 1): Wrong sizeof argument (SIZEOF_MISMATCH)
suspicious_sizeof: Passing argument 8UL
/* sizeof (struct ext_cgroup_record *) */ to function calloc and then
casting the return value to struct ext_cgroup_record * is suspicious.
Also, fix the typo in the variable name, that's being allocated memory.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Mon, 16 May 2022 22:05:39 +0000 (16:05 -0600)]
workflows/CI: upgrade CodeQL actions used to v2
CodeQL warns about deprecating v1 by Dec 2022. Upgrade the CodeQL
actions, as per the recommendation made in the upgrade guide at:
https://github.blog/changelog/2022-04-27-code-scanning-deprecation-of-codeql-action-v1/
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api.c: resize controller name to 32 from 4096 bytes
Linux kernel warns on the cgroup controller name length greater than
32 bytes during the cgroup initialization in cgroup_init_early(). Adopt
the same size of 32 bytes (including the null byte) for controller name
in the struct cg_controller and struct cg_mount_table_s. This resize
from FILENAME_MAX (4096 bytes) to a mere 32 bytes, reduces the
libcgroup.so library:
Without the patch:
------------------
$ size -d src/.libs/libcgroup.so
text data bss dec hex filename
123841 3600 24765322603973 27bbc5 src/.libs/libcgroup.so
With the patch:
---------------
$ size -d src/.libs/libcgroup.so
text data bss dec hex filename
123569 3600 12573321384501 152035 src/.libs/libcgroup.so
also replace the index FILENAME_MAX with CONTROL_NAMELEN_MAX at the
struct cg_controller::name and struct cg_mount_table_s::name references.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api.c: fix segfault in cgroup_populate_mount_points()
In cgroup_populate_mount_points(), cgroup v1/v2 mount points get read
from /proc/mounts and populated into cg_mount_table[]. The size of
cg_mount_table[] is set to CG_CONTROLLER_MAX, that's defined as 100 and
if the system has more than CG_CONTROLLER_MAX, unique mount points, it
will segfault while processing them. Fix this by checking, the mount
point count after processing every mount entry and bailout in case it
reaches CG_CONTROLLER_MAX.
The issue can be reproduced using, following simple bash commands on
cgroup v1:
1. sudo for i in $(seq 0 100); do sudo mkdir /name$i; done
2. sudo for i in $(seq 0 86); do sudo mount -t cgroup -o none,name=named$i
none /name$i; done
3. sudo cgget -g <controller>:<existing cgroup name>
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api.c: fix deleting cgroup created on shared mnt point
cgroup v1 allows mounting of two or more controllers on a single
mount point. This fails currently when trying to delete the cgroup
recursively for all the mounted controllers because the cgroup is
already deleted by the first controller of the share mount point and
the next controllers sharing the mount point complain about
missing cgroup path.
Fix this issue by introducing shared_mnt flag to cg_mount_table_s
struct and setting it during cgroup_init() on finding a mount point
shared by controllers and repeats the check in cgroup_find_parent()
on the error to check its share mount point and ignore the error if the
file doesn't exist, similar to ignoring if the file exists during
creation.
api.c: add support to attach tid to an empty cgroup v2
Currently, cgroup_attach_task_pid() checks for enabled
controllers before attaching the given tid to it, but in the case of
empty cgroup, it simply ignores the attaching due to no controllers
available, a.k.a. cgroup->index is 0. Add support to recognize empty
controller cgroups.
Fixes: https://github.com/libcgroup/libcgroup/issues/129 Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
There can be cgroup v2 cgroup with no controllers attached to it and
while checking for enabled controllers always return true in
cgroupv2_controller_enabled() for such cgroups.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api.c: In function ‘cgroup_populate_controllers.constprop’:
api.c:1386:5: warning: ‘buf’ may be used uninitialized in this function [-Wmaybe-uninitialized]
1386 | if (buf)
| ^
api.c: In function ‘cgroup_populate_mount_points.constprop’:
api.c:1461:5: warning: ‘temp_ent’ may be used uninitialized in this function [-Wmaybe-uninitialized]
1461 | if (temp_ent)
| ^
this patch, initializes them to NULL.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 31 Mar 2022 12:21:55 +0000 (17:51 +0530)]
api.c: add support for empty cgroup v2 deletion
Add support to recognize empty cgroup v2 with no controllers attached to
it in cgroup_delete_cgroup_ext(), that gets called to remove a cgroup.
In the deletion path, cgroup_build_tasks_procs_path() builds the path
of the cgroup for re-assignment/movement of tasks from the cgroup that's
getting deleted, teach it to recognize the empty controller as cgroup
V2.
Fixes: https://github.com/libcgroup/libcgroup/issues/125 Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Fix a couple small typos in commit message
Kamalesh Babulal [Wed, 30 Mar 2022 06:19:03 +0000 (11:49 +0530)]
api.c: API to list mount points of a cgroup type
Currently, there is no easy way for a user to list cgroup mount points,
one way to acquire required information is by manually reading the
/proc/mounts and parsing the information they are interested in.
Add a new API:
cgroup_list_mount_points(cg_version_t version, char ***mnts),
where the first argument is either CGROUP_V1 or CGROUP_V2, that
specifies the mount point types and the second argument is a char**,
that will hold the mount point paths of the cgroup version specified in
the first agrument. Note that the mnts pointers are supposed to free'd.
mnts pointers.
$ cat get_mount.c
int main(void)
{
enum cg_version_t t = CGROUP_V2;
char **mount_paths = NULL;
int i = 0;
int ret;
cgroup_init();
ret = cgroup_list_mount_points(t, &mount_paths);
if (ret != 0) {
fprintf(stderr, "Failed to get mount points\n");
return ret;
}
while (mount_paths[i]) {
fprintf(stderr, "%s\n", mount_paths[i]);
free(mount_paths[i]);
i++;
}
free(mount_paths);
return 0;
}
$ gcc -o get_mount get_mount.c -lcgroup
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Sat, 26 Mar 2022 13:40:50 +0000 (19:10 +0530)]
api.c: refactor cgroup_process_*_mnt()
Abstract appending new mount point to the cg_mount_table[] into new
function, reducing the duplication in both cgroup_process_v1_mnt()
and cgroup_process_v2_mnt().
Kamalesh Babulal [Sat, 26 Mar 2022 13:40:43 +0000 (19:10 +0530)]
api.c: refactor cgroup_init()
Refactor cgroup_init() by abstracting freeing of previous cg_mount_table,
populating controller by reading /proc/cgroups file and populating
mount points into its own function.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Fix minor typo in commit message