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 1959003

Summary: network_init: oops due to non-initialized res pointer
Product: Red Hat Enterprise Linux 8 Reporter: Roberto Bergantinos <rbergant>
Component: rpcbindAssignee: Steve Dickson <steved>
Status: CLOSED ERRATA QA Contact: Yongcheng Yang <yoyang>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 8.3CC: dostwal, xzhou, yoyang
Target Milestone: betaKeywords: Patch, Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: rpcbind-1.2.5-9.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-11-08 10:50:49 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 Roberto Bergantinos 2021-05-10 14:47:53 UTC
Description of problem:

If for some reason, i.e. /etc/services is not accesible for daemonized rpcbind "rpc" user
getaddrinfo will return errors and "res" list pointer does not get any value/element, 
we end up causing an oops.

To reproduce :

- RHEL 8.3 
- rpcbind-1.2.5-7.el8.x86_64

# chmod 600 /etc/services
# ls -l /etc/services
-rw-------. 1 root root 692241 Sep 10  2018 /etc/services
# sysctl -w fs.suid_dumpable=2
fs.suid_dumpable = 2
# systemctl stop rpcbind
# systemctl stop rpcbind.socket
# /usr/sbin/rpcbind -d -w -f
...
rpcbind: will start from scratch
can't get local ip4 address: Servname not supported for ai_socktype
can't get local ip6 address: Servname not supported for ai_socktype
socket(AF_INET6) failed: Address family not supported by protocol
Segmentation fault (core dumped)

We get EAI_SERVICE "Servname not supported for ai_socktype" for both ip4 and ip6
sockets due to file permission issue in this case, which is expected, but not oops.

Code :

280 void
281 network_init()
282 {
...
290         struct addrinfo hints, *res;
...
294         if ((ecode = getaddrinfo(NULL, "sunrpc", &hints, &res))) {
...
309         if ((ecode = getaddrinfo(NULL, "sunrpc", &hints, &res))) {
...
363         freeaddrinfo (res);  <<<--- segfault

Coredump :

(gdb) bt
#0  __GI_freeaddrinfo (ai=0x9259ebdbe5549f00) at ../sysdeps/posix/getaddrinfo.c:2521
#1  0x0000555ec5283c29 in network_init () at src/util.c:363
#2  0x0000555ec527db4f in main (argc=<optimized out>, argv=<optimized out>) at src/rpcbind.c:301
(gdb) f 1
#1  0x0000555ec5283c29 in network_init () at src/util.c:363
363		freeaddrinfo (res);
(gdb) info locals
ifap = <optimized out>
ifp = 0x555ec588a780
mreq6 = {ipv6mr_multiaddr = {__in6_u = {__u6_addr8 = "\377\002", '\000' <repeats 12 times>, "\002\002", __u6_addr16 = {767, 0, 0, 0, 0, 0, 0, 514}, __u6_addr32 = {767, 0, 0, 
        33685504}}}, ipv6mr_interface = 0}
ifindex = <optimized out>
s = <optimized out>
ecode = <optimized out>
hints = {ai_flags = 0, ai_family = 10, ai_socktype = 0, ai_protocol = 0, ai_addrlen = 0, ai_addr = 0x0, ai_canonname = 0x0, ai_next = 0x0}
res = 0x9259ebdbe5549f00 <<<--- garbage

This simple patch avoids the segfault :

diff --git a/src/util.c b/src/util.c
index 564e3a2..4af8b9b 100644
--- a/src/util.c
+++ b/src/util.c
@@ -309,7 +309,7 @@ network_init()
        int s;
 #endif
        int ecode;
-       struct addrinfo hints, *res;
+       struct addrinfo hints, *res = NULL;
 
        memset(&hints, 0, sizeof hints);
        hints.ai_family = AF_INET;

just sent upstream for verification

Version-Release number of selected component (if applicable): rpcbind-1.2.5-7.el8.x86_64


How reproducible: 100%


Steps to Reproduce: see above
1.
2.
3.

Actual results: oops, segfault


Expected results: not segfault


Additional info:

Comment 3 Yongcheng Yang 2022-04-18 04:48:13 UTC
We may need to backport this upstream fix:

commit 7fcf2b27097fda927d637835468a83ed1b918001 (tag: rpcbind-1_2_6-rc7)
Author: Roberto Bergantinos Corpas <rbergant>
Date:   Mon May 10 12:53:19 2021 -0400

    network_init: initialize response addrinfo list to NULL

    res pointer is not initialized, if for some reason it does not
    take any value after calling getaddrinfo, we end up causing oops
    when calling freeaddrinfo

Comment 4 Yongcheng Yang 2022-06-01 01:40:58 UTC
Have verified that oops won't occur now with rpcbind-1.2.5-9.el8

~~~~~~~~~~~~~~~~~~~
# Test logs
~~~~~~~~~~~~~~~~~~~
[root@yoyang-rhel-860-updates-202205230 ~]# rpm -q rpcbind
rpcbind-1.2.5-9.el8.x86_64
[root@yoyang-rhel-860-updates-202205230 ~]# ll /etc/services
-rw-------. 1 root root 692252 Apr 15  2020 /etc/services
[root@yoyang-rhel-860-updates-202205230 ~]# sysctl fs.suid_dumpable
fs.suid_dumpable = 2
[root@yoyang-rhel-860-updates-202205230 ~]# systemctl stop rpcbind rpcbind.socket
[root@yoyang-rhel-860-updates-202205230 ~]# rpcbind -d -w -f
libtirpc: debug level 1
rpcbind: local: 0 lookup routines :

rpcbind: rpcbind : my address is (null)

rpcbind: FUNCTION rbllist_add
rpcbind: Add the prog 100000 vers 3 to the rpcbind list
rpcbind: FUNCTION rbllist_add
rpcbind: Add the prog 100000 vers 4 to the rpcbind list
rpcbind: check binding for local

...

rpcbind: debugging enabled.
rpcbind: using '/run/rpcbind/rpcbind.xdr' startup file
rpcbind: using '/run/rpcbind/portmap.xdr' startup file
can't get local ip4 address: Servname not supported for ai_socktype
can't get local ip6 address: Servname not supported for ai_socktype

^C
[root@yoyang-rhel-860-updates-202205230 ~]# chmod 644 /etc/services
[root@yoyang-rhel-860-updates-202205230 ~]# systemctl start rpcbind
[root@yoyang-rhel-860-updates-202205230 ~]# systemctl status rpcbind
* rpcbind.service - RPC Bind
   Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2022-05-31 21:34:21 EDT; 3s ago
     Docs: man:rpcbind(8)
 Main PID: 21433 (rpcbind)
    Tasks: 1 (limit: 7928)
   Memory: 968.0K
   CGroup: /system.slice/rpcbind.service
           `-21433 /usr/bin/rpcbind -w -f

May 31 21:34:21 yoyang-rhel-860-updates-202205230 systemd[1]: Starting RPC Bind...
May 31 21:34:21 yoyang-rhel-860-updates-202205230 systemd[1]: Started RPC Bind.
[root@yoyang-rhel-860-updates-202205230 ~]#

Comment 8 errata-xmlrpc 2022-11-08 10:50:49 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 (rpcbind 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:7734