Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1996799

Summary: stalld: "Negative Returns" defects identified by coverity
Product: Red Hat Enterprise Linux 8 Reporter: Fernando Pacheco <fpacheco>
Component: stalldAssignee: Fernando Pacheco <fpacheco>
Status: CLOSED ERRATA QA Contact: Kernel Realtime QE <rt-qe>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.5CC: bhu, daolivei, mstowell, williams
Target Milestone: betaKeywords: Rebase, Triaged
Target Release: 8.6Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: stalld-1.15-1.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-05-10 13:51:17 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2020013    

Description Fernando Pacheco 2021-08-23 17:29:05 UTC
Error: NEGATIVE_RETURNS (CWE-394): [#def3]
stalld-1.14.1/src/stalld.c:253: negative_return_fn: Function "open("/proc/stat", 0)" returns a negative number. [Note: The source code implementation of the function has been overridden by a user model.]
stalld-1.14.1/src/stalld.c:253: assign: Assigning: "fd" = "open("/proc/stat", 0)".
stalld-1.14.1/src/stalld.c:259: negative_returns: "fd" is passed to a parameter that cannot be negative. [Note: The source code implementation of the function has been overridden by a builtin model.]
#  257|   
#  258|   	do {
#  259|-> 		retval = read(fd, &buffer[position], size - position);
#  260|   		if (retval < 0)
#  261|   			goto out_close_fd;

Error: NEGATIVE_RETURNS (CWE-394): [#def8]
stalld-1.14.1/src/stalld.c:436: negative_return_fn: Function "open(config_sched_debug_path, 0)" returns a negative number. [Note: The source code implementation of the function has been overridden by a user model.]
stalld-1.14.1/src/stalld.c:436: assign: Assigning: "fd" = "open(config_sched_debug_path, 0)".
stalld-1.14.1/src/stalld.c:442: negative_returns: "fd" is passed to a parameter that cannot be negative. [Note: The source code implementation of the function has been overridden by a builtin model.]
#  440|   
#  441|   	do {
#  442|-> 		retval = read(fd, &buffer[position], size - position);
#  443|   		if (retval < 0)
#  444|   			goto out_close_fd;

Error: NEGATIVE_RETURNS (CWE-394): [#def12]
stalld-1.14.1/src/stalld.c:753: negative_return_fn: Function "open(stat_path, 0)" returns a negative number. [Note: The source code implementation of the function has been overridden by a user model.]
stalld-1.14.1/src/stalld.c:753: assign: Assigning: "fd" = "open(stat_path, 0)".
stalld-1.14.1/src/stalld.c:759: negative_returns: "fd" is passed to a parameter that cannot be negative. [Note: The source code implementation of the function has been overridden by a builtin model.]
#  757|   	}
#  758|   	flock(fd, LOCK_SH);
#  759|-> 	retval = read(fd, &stat, sizeof(stat));
#  760|   	if (retval < 0) {
#  761|   		warn("error reading stat for task %d\n", pid);

Error: NEGATIVE_RETURNS (CWE-394): [#def27]
stalld-1.14.1/src/utils.c:122: negative_return_fn: Function "sigfillset(&sigset)" returns a negative number.
stalld-1.14.1/src/utils.c:122: assign: Assigning: "status" = "sigfillset(&sigset)".
stalld-1.14.1/src/utils.c:124: negative_returns: "status" is passed to a parameter that cannot be negative.
#  122|   	status = sigfillset(&sigset);
#  123|   	if (status) {
#  124|-> 		warn("setting up full signal set %s\n", strerror(status));
#  125|   		return status;
#  126|   	}

Error: NEGATIVE_RETURNS (CWE-394): [#def28]
stalld-1.14.1/src/utils.c:134: negative_return_fn: Function "sigemptyset(&sigset)" returns a negative number.
stalld-1.14.1/src/utils.c:134: assign: Assigning: "status" = "sigemptyset(&sigset)".
stalld-1.14.1/src/utils.c:136: negative_returns: "status" is passed to a parameter that cannot be negative.
#  134|   	status = sigemptyset(&sigset);
#  135|   	if (status) {
#  136|-> 		warn("creating empty signal set: %s\n", strerror(status));
#  137|   		return status;
#  138|   	}

Error: NEGATIVE_RETURNS (CWE-394): [#def29]
stalld-1.14.1/src/utils.c:139: negative_return_fn: Function "sigaddset(&sigset, 2)" returns a negative number.
stalld-1.14.1/src/utils.c:139: assign: Assigning: "status" = "sigaddset(&sigset, 2)".
stalld-1.14.1/src/utils.c:141: negative_returns: "status" is passed to a parameter that cannot be negative.
#  139|   	status = sigaddset(&sigset, SIGINT);
#  140|   	if (status) {
#  141|-> 		warn("adding SIGINT to signal set: %s\n", strerror(status));
#  142|   		return status;
#  143|   	}

Error: NEGATIVE_RETURNS (CWE-394): [#def30]
stalld-1.14.1/src/utils.c:144: negative_return_fn: Function "sigaddset(&sigset, 15)" returns a negative number.
stalld-1.14.1/src/utils.c:144: assign: Assigning: "status" = "sigaddset(&sigset, 15)".
stalld-1.14.1/src/utils.c:146: negative_returns: "status" is passed to a parameter that cannot be negative.
#  144|   	status = sigaddset(&sigset, SIGTERM);
#  145|   	if (status) {
#  146|-> 		warn("adding SIGTERM to signal set: %s\n", strerror(status));
#  147|   		return status;
#  148|   	}

Error: NEGATIVE_RETURNS (CWE-394): [#def33]
stalld-1.14.1/src/utils.c:251: negative_return_fn: Function "open("/dev/kmsg", 1)" returns a negative number. [Note: The source code implementation of the function has been overridden by a user model.]
stalld-1.14.1/src/utils.c:251: assign: Assigning: "kmesg_fd" = "open("/dev/kmsg", 1)".
stalld-1.14.1/src/utils.c:257: negative_returns: "kmesg_fd" is passed to a parameter that cannot be negative.
#  255|   		 */
#  256|   		if (kmesg_fd) {
#  257|-> 			if (write(kmesg_fd, message, strlen(message)) < 0)
#  258|   				warn("write to klog failed");
#  259|   			close(kmesg_fd);

Error: NEGATIVE_RETURNS (CWE-394): [#def36]
stalld-1.14.1/tests/test01.c:472: negative_return_fn: Function "sigfillset(&sigset)" returns a negative number.
stalld-1.14.1/tests/test01.c:472: assign: Assigning: "status" = "sigfillset(&sigset)".
stalld-1.14.1/tests/test01.c:474: negative_returns: "status" is passed to a parameter that cannot be negative.
#  472|   	status = sigfillset(&sigset);
#  473|   	if (status) {
#  474|-> 		error("setting up full signal set %s\n", strerror(status));
#  475|   		return status;
#  476|   	}

Error: NEGATIVE_RETURNS (CWE-394): [#def37]
stalld-1.14.1/tests/test01.c:484: negative_return_fn: Function "sigemptyset(&sigset)" returns a negative number.
stalld-1.14.1/tests/test01.c:484: assign: Assigning: "status" = "sigemptyset(&sigset)".
stalld-1.14.1/tests/test01.c:486: negative_returns: "status" is passed to a parameter that cannot be negative.
#  484|   	status = sigemptyset(&sigset);
#  485|   	if (status) {
#  486|-> 		error("creating empty signal set: %s\n", strerror(status));
#  487|   		return status;
#  488|   	}

Error: NEGATIVE_RETURNS (CWE-394): [#def38]
stalld-1.14.1/tests/test01.c:489: negative_return_fn: Function "sigaddset(&sigset, signum)" returns a negative number.
stalld-1.14.1/tests/test01.c:489: assign: Assigning: "status" = "sigaddset(&sigset, signum)".
stalld-1.14.1/tests/test01.c:491: negative_returns: "status" is passed to a parameter that cannot be negative.
#  489|   	status = sigaddset(&sigset, signum);
#  490|   	if (status) {
#  491|-> 		error("adding %d to signal set: %s\n", signum, strerror(status));
#  492|   		return status;
#  493|   	}

Comment 3 Fernando Pacheco 2021-08-30 21:02:51 UTC
Fix posted and merged upstream: https://gitlab.com/rt-linux-tools/stalld/-/merge_requests/55

Relevant commits:
stalld: Fix incorrect open() return value checks
stalld: Pass errno to strerror() on sig*set() failures

Comment 4 Fernando Pacheco 2021-11-16 20:57:54 UTC
Will use this bz to rebase stalld to latest upstream which includes this bz and others:

bz1990057
bz1996825

Comment 10 errata-xmlrpc 2022-05-10 13:51:17 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (stalld bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:1853