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 2113931 - fix use-after-free accessing error number after rpc call returns an error
Summary: fix use-after-free accessing error number after rpc call returns an error
Keywords:
Status: CLOSED DUPLICATE of bug 2118157
Alias: None
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: libtirpc
Version: 9.1
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Steve Dickson
QA Contact: Zhi Li
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-08-02 10:57 UTC by Zhi Li
Modified: 2022-08-17 13:21 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-08-16 14:03:05 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-129884 0 None None None 2022-08-02 10:59:29 UTC

Description Zhi Li 2022-08-02 10:57:19 UTC
This bug was initially created as a copy of Bug #2042196

I am copying this bug because: 

It seems this problem exists in rhel9.

Version-Release number of selected component (if applicable):
kernel-5.14.0-138.el9.x86_64
libtirpc-1.3.2-1.el9.x86_64

Beaker jobs:
https://beaker.engineering.redhat.com/jobs/6876111


Description of problem:

When an rpc call returns an error, lirbirpc frees the memory associated with the call before obtaining the error number stored in that memory.


Version-Release number of selected component (if applicable):

libtirpc-1.1.4-6.el8


How reproducible:

easy


Steps to Reproduce:

* add iptables rule to reject udp incoming to port 111:

	# iptables -I INPUT -p udp --dport 111 -j REJECT --reject-with=icmp-host-prohibited

* make rpc call over udp

	# valgrind rpcinfo -T udp localhost


Actual results:

# valgrind rpcinfo -T udp localhost
==2799905== Memcheck, a memory error detector
==2799905== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2799905== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==2799905== Command: rpcinfo -T udp localhost
==2799905== 
==2799905== Invalid read of size 4
==2799905==    at 0x4E4F2B1: ??? (in /usr/lib64/libtirpc.so.3.0.0)
==2799905==    by 0x10B819: rpcbdump (rpcinfo.c:831)
==2799905==    by 0x109EE5: main (rpcinfo.c:302)
==2799905==  Address 0x74287a0 is 16 bytes inside a block of size 296 free'd
==2799905==    at 0x4C34A93: free (vg_replace_malloc.c:872)
==2799905==    by 0x4E4F2A8: ??? (in /usr/lib64/libtirpc.so.3.0.0)
==2799905==    by 0x10B819: rpcbdump (rpcinfo.c:831)
==2799905==    by 0x109EE5: main (rpcinfo.c:302)
==2799905==  Block was alloc'd at
==2799905==    at 0x4C36E4B: calloc (vg_replace_malloc.c:1328)
==2799905==    by 0x4E4F098: ??? (in /usr/lib64/libtirpc.so.3.0.0)
==2799905==    by 0x10B819: rpcbdump (rpcinfo.c:831)
==2799905==    by 0x109EE5: main (rpcinfo.c:302)


Expected results:

no use-after-free


Additional info:


The clnt_dg_call error handling reads the error number after it frees the memory that contains the error:

            for (cmsg = CMSG_FIRSTHDR (&msg); cmsg;
                 cmsg = CMSG_NXTHDR (&msg, cmsg))
              if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_RECVERR)
                {
                  mem_free(cbuf, (outlen + 256));               <<<<<<<< 'cbuf' freed
                  e = (struct sock_extended_err *) CMSG_DATA(cmsg);
                  cu->cu_error.re_errno = e->ee_errno;          <<<<<<<< 'e' is a pointer to a location within 'cbuf' that was just freed
                  release_fd_lock(cu->cu_fd_lock, mask);
                  return (cu->cu_error.re_status = RPC_CANTRECV);
                }

patch sent upstream https://www.spinics.net/lists/linux-nfs/msg88447.html

Comment 1 Steve Dickson 2022-08-04 20:47:43 UTC
commit d0dc59e27263c6b53435d770010dcc6f397d58ee
Author: Frank Sorenson <sorenson>
Date:   Mon Jan 17 13:33:13 2022 -0500

    libtirpc: Fix use-after-free accessing the error number
    
    Free the cbuf after obtaining the error number.
    
    Signed-off-by: Frank Sorenson <sorenson>
    Signed-off-by: Steve Dickson <steved>

Comment 2 Steve Dickson 2022-08-16 14:03:05 UTC

*** This bug has been marked as a duplicate of bug 2118157 ***


Note You need to log in before you can comment on or make changes to this bug.