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 1353311

Summary: Fix resource leaks
Product: Red Hat Enterprise Linux 7 Reporter: Phil Sutter <psutter>
Component: libnftnlAssignee: Phil Sutter <psutter>
Status: CLOSED ERRATA QA Contact: Tomas Dolezal <todoleza>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.3CC: aloughla, atragler, jscotka, mleitner, psutter, sukulkar, todoleza
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libnftnl-1.0.6-6.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-01 16:53: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:

Description Phil Sutter 2016-07-06 18:34:05 UTC
As reported by coverity tool:

 27. libnftnl-1.0.6/src/set.c:564: alloc_fn: Storage is returned from allocation function "nftnl_set_elem_alloc".
28. libnftnl-1.0.6/src/set_elem.c:34:2: alloc_fn: Storage is returned from allocation function "calloc".
29. libnftnl-1.0.6/src/set_elem.c:34:2: var_assign: Assigning: "s" = "calloc(1UL, 216UL)".
32. libnftnl-1.0.6/src/set_elem.c:38:2: return_alloc: Returning allocated memory "s".
33. libnftnl-1.0.6/src/set.c:564: var_assign: Assigning: "elem" = storage returned from "nftnl_set_elem_alloc()".
38. libnftnl-1.0.6/src/set.c:572: noescape: Resource "elem" is not freed or pointed-to in "nftnl_jansson_set_elem_parse".
39. libnftnl-1.0.6/src/jansson.c:247:57: noescape: "nftnl_jansson_set_elem_parse(struct nftnl_set_elem *, json_t *, struct nftnl_parse_err *)" does not free or save its parameter "e".
41. libnftnl-1.0.6/src/set.c:574: leaked_storage: Variable "elem" going out of scope leaks the storage it points to.
#   572|   			if (nftnl_jansson_set_elem_parse(elem,
#   573|   						       json_elem, err) < 0)
#   574|-> 				return -1;
#   575|   
#   576|   			list_add_tail(&elem->head, &s->element_list);


 27. libnftnl-1.0.6/src/set.c:564: alloc_fn: Storage is returned from allocation function "nftnl_set_elem_alloc".
28. libnftnl-1.0.6/src/set_elem.c:34:2: alloc_fn: Storage is returned from allocation function "calloc".
29. libnftnl-1.0.6/src/set_elem.c:34:2: var_assign: Assigning: "s" = "calloc(1UL, 216UL)".
32. libnftnl-1.0.6/src/set_elem.c:38:2: return_alloc: Returning allocated memory "s".
33. libnftnl-1.0.6/src/set.c:564: var_assign: Assigning: "elem" = storage returned from "nftnl_set_elem_alloc()".
37. libnftnl-1.0.6/src/set.c:570: leaked_storage: Variable "elem" going out of scope leaks the storage it points to.
#   568|   			json_elem = json_array_get(array, i);
#   569|   			if (json_elem == NULL)
#   570|-> 				return -1;
#   571|   
#   572|   			if (nftnl_jansson_set_elem_parse(elem,



1. libnftnl-1.0.6/src/ruleset.c:975: alloc_fn: Storage is returned from allocation function "nftnl_rule_list_iter_create".
2. libnftnl-1.0.6/src/rule.c:1140:2: alloc_fn: Storage is returned from allocation function "calloc".
3. libnftnl-1.0.6/src/rule.c:1140:2: var_assign: Assigning: "iter" = "calloc(1UL, 16UL)".
9. libnftnl-1.0.6/src/rule.c:1150:2: return_alloc: Returning allocated memory "iter".
10. libnftnl-1.0.6/src/ruleset.c:975: var_assign: Assigning: "ri" = storage returned from "nftnl_rule_list_iter_create(rs->rule_list)".
13. libnftnl-1.0.6/src/ruleset.c:979: noescape: Resource "ri" is not freed or pointed-to in "nftnl_rule_list_iter_next".
14. libnftnl-1.0.6/src/rule.c:1160:75: noescape: "nftnl_rule_list_iter_next(struct nftnl_rule_list_iter *)" does not free or save its parameter "iter".
17. libnftnl-1.0.6/src/ruleset.c:982: leaked_storage: Variable "ri" going out of scope leaks the storage it points to.
#   980|   	while (r != NULL) {
#   981|   		ret = nftnl_rule_snprintf(buf+offset, len, r, type, flags);
#   982|-> 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
#   983|   
#   984|   		r = nftnl_rule_list_iter_next(ri);



1. libnftnl-1.0.6/src/ruleset.c:946: alloc_fn: Storage is returned from allocation function "nftnl_set_list_iter_create".
2. libnftnl-1.0.6/src/set.c:1142:2: alloc_fn: Storage is returned from allocation function "calloc".
3. libnftnl-1.0.6/src/set.c:1142:2: var_assign: Assigning: "iter" = "calloc(1UL, 16UL)".
9. libnftnl-1.0.6/src/set.c:1152:2: return_alloc: Returning allocated memory "iter".
10. libnftnl-1.0.6/src/ruleset.c:946: var_assign: Assigning: "si" = storage returned from "nftnl_set_list_iter_create(rs->set_list)".
13. libnftnl-1.0.6/src/ruleset.c:950: noescape: Resource "si" is not freed or pointed-to in "nftnl_set_list_iter_next".
14. libnftnl-1.0.6/src/set.c:1162:72: noescape: "nftnl_set_list_iter_next(struct nftnl_set_list_iter *)" does not free or save its parameter "iter".
17. libnftnl-1.0.6/src/ruleset.c:953: leaked_storage: Variable "si" going out of scope leaks the storage it points to.
#   951|   	while (s != NULL) {
#   952|   		ret = nftnl_set_snprintf(buf+offset, len, s, type, flags);
#   953|-> 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
#   954|   
#   955|   		s = nftnl_set_list_iter_next(si);



1. libnftnl-1.0.6/src/ruleset.c:917: alloc_fn: Storage is returned from allocation function "nftnl_chain_list_iter_create".
2. libnftnl-1.0.6/src/chain.c:1032:2: alloc_fn: Storage is returned from allocation function "calloc".
3. libnftnl-1.0.6/src/chain.c:1032:2: var_assign: Assigning: "iter" = "calloc(1UL, 16UL)".
9. libnftnl-1.0.6/src/chain.c:1042:2: return_alloc: Returning allocated memory "iter".
10. libnftnl-1.0.6/src/ruleset.c:917: var_assign: Assigning: "ci" = storage returned from "nftnl_chain_list_iter_create(rs->chain_list)".
13. libnftnl-1.0.6/src/ruleset.c:921: noescape: Resource "ci" is not freed or pointed-to in "nftnl_chain_list_iter_next".
14. libnftnl-1.0.6/src/chain.c:1046:78: noescape: "nftnl_chain_list_iter_next(struct nftnl_chain_list_iter *)" does not free or save its parameter "iter".
17. libnftnl-1.0.6/src/ruleset.c:924: leaked_storage: Variable "ci" going out of scope leaks the storage it points to.
#   922|   	while (c != NULL) {
#   923|   		ret = nftnl_chain_snprintf(buf+offset, len, c, type, flags);
#   924|-> 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
#   925|   
#   926|   		c = nftnl_chain_list_iter_next(ci);



1. libnftnl-1.0.6/src/ruleset.c:888: alloc_fn: Storage is returned from allocation function "nftnl_table_list_iter_create".
2. libnftnl-1.0.6/src/table.c:553:2: alloc_fn: Storage is returned from allocation function "calloc".
3. libnftnl-1.0.6/src/table.c:553:2: var_assign: Assigning: "iter" = "calloc(1UL, 16UL)".
9. libnftnl-1.0.6/src/table.c:563:2: return_alloc: Returning allocated memory "iter".
10. libnftnl-1.0.6/src/ruleset.c:888: var_assign: Assigning: "ti" = storage returned from "nftnl_table_list_iter_create(rs->table_list)".
13. libnftnl-1.0.6/src/ruleset.c:892: noescape: Resource "ti" is not freed or pointed-to in "nftnl_table_list_iter_next".
14. libnftnl-1.0.6/src/table.c:567:78: noescape: "nftnl_table_list_iter_next(struct nftnl_table_list_iter *)" does not free or save its parameter "iter".
17. libnftnl-1.0.6/src/ruleset.c:895: leaked_storage: Variable "ti" going out of scope leaks the storage it points to.
#   893|   	while (t != NULL) {
#   894|   		ret = nftnl_table_snprintf(buf+offset, len, t, type, flags);
#   895|-> 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
#   896|   
#   897|   		t = nftnl_table_list_iter_next(ti);

Comment 2 Phil Sutter 2016-08-12 12:48:17 UTC
The first issue is resolved by the following upstream commit:

commit d29f0825c33af8c53a939b7f0e8d5beb2ed48c83
Author: Phil Sutter <psutter>
Date:   Fri Aug 12 01:33:33 2016 +0200

    set: prevent memleak in nftnl_jansson_parse_set_info()
    
    During list populating, in error case the function returns without
    freeing the newly allocated 'elem' object, thereby losing any references
    to it.
    
    Signed-off-by: Phil Sutter <phil>
    Signed-off-by: Pablo Neira Ayuso <pablo>

A proper fix for the SNPRINTF_BUFFER_SIZE issue is currently under review.

Comment 3 Phil Sutter 2016-08-12 15:16:49 UTC
The second issue's fix was also accepted:

commit 9afae310b019aa497afb94833afc9a936bc38a1f
Author: Phil Sutter <psutter>
Date:   Fri Aug 12 14:39:50 2016 +0200

    utils: Don't return directly from SNPRINTF_BUFFER_SIZE
    
    Apart from being a bad idea in general, the return statement contained
    in that macro in some cases leads to returning from functions without
    properly cleaning up, thereby causing memory leaks.
    
    Instead, just sanitize the value in 'ret' to not harm further calls of
    snprintf() (as 'len' will eventually just become zero).
    
    Cc: Arturo Borrero <arturo.borrero.glez>
    Signed-off-by: Phil Sutter <phil>
    Signed-off-by: Pablo Neira Ayuso <pablo>

Comment 9 errata-xmlrpc 2017-08-01 16:53: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, 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-2017:2007