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 1346419

Summary: rpc.gssd segfaults when mounting NFS filesystems with sec=krb5 (nfs-utils-1.2.3-70.el6.x86_64)
Product: Red Hat Enterprise Linux 6 Reporter: Jesse Connell <jesse08>
Component: nfs-utilsAssignee: Steve Dickson <steved>
Status: CLOSED DUPLICATE QA Contact: Filesystem QE <fs-qe>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.8CC: arawat, yoyang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-06-15 07:35:30 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:
Attachments:
Description Flags
Modified version of patch #101 (gssd-uppercase) from nfs-utils 1.2.3-70 none

Description Jesse Connell 2016-06-14 18:41:19 UTC
Created attachment 1167940 [details]
Modified version of patch #101 (gssd-uppercase) from nfs-utils 1.2.3-70

Description of problem:

After allowing our systems to update from nfs-utils-1.2.3-64 to nfs-utils-1.2.3-70, the new rpc.gssd binary crashes when mounting a second NFS filesystems with kerberos enabled via sec=krb5. The first filesystem (specific order/identity doesn't matter) goes fine, but the second triggers a crash.

I've reported this on the CentOS bugzilla as well, since that's what we're running, but since I've traced it to one of the new RHEL-provided patches (see Additional Info below), I thought it was worth reporting here as well.  The corresponding CentOS bug report: https://bugs.centos.org/view.php?id=10996

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

How reproducible: Always

Steps to Reproduce:
1. yum -y install nfs-utils-1.2.3-70.el6.x86_64
2. service rpcgssd restart
3. mount server:/volume /mountpoint -t nfs -o vers=3,sec=krb5
4. mount server:/volume2 /mountpoint2 -t nfs -o vers=3,sec=krb5

Actual results:

The mount hangs indefinitely and rpc.gssd crashes with a segfault.

Expected results:

The mount succeeds and rpc.gssd continues running.

Additional info:

I've traced this problem to a new patch in this version of the nfs-utils package: nfs-utils-1.2.3-gssd-uppercase.patch.  The patch adds a loop to convert a string to uppercase on line 32, but this loop uses the same index variable (i) that's already in use for indexing realmnames[] in the outer while loop in that function.

This has the effect of trying to access the address of a non-existent element of realmnames (line 953 of the patched krb5_util.c file) and assign it to the realm variable.  If the data that happens to sit at that non-existent element of realmnames represents an inaccessible address, then the next time there's an attempted read on the data at that supposed address (line 872, in strcmp(), during a later iteration of the while loop) it triggers the segmentation fault.  So, I edited the patch in the source RPM to have a new index variable for that for loop (attached) and rebuilt the package, and that version of rpc.gssd seems OK.  From the comments in the SRPM the original patch looks to be related to bug #1273166 but I don't have permissions to view that bug here.

Comment 2 Yongcheng Yang 2016-06-15 07:35:30 UTC
(In reply to Jesse Connell from comment #0)
> 
> Additional info:
> 
> I've traced this problem to a new patch in this version of the nfs-utils
> package: nfs-utils-1.2.3-gssd-uppercase.patch.  The patch adds a loop to
> convert a string to uppercase on line 32, but this loop uses the same index
> variable (i) that's already in use for indexing realmnames[] in the outer
> while loop in that function.
> 
> This has the effect of trying to access the address of a non-existent
> element of realmnames (line 953 of the patched krb5_util.c file) and assign
> it to the realm variable.  If the data that happens to sit at that
> non-existent element of realmnames represents an inaccessible address, then
> the next time there's an attempted read on the data at that supposed address
> (line 872, in strcmp(), during a later iteration of the while loop) it
> triggers the segmentation fault.  So, I edited the patch in the source RPM
> to have a new index variable for that for loop (attached) and rebuilt the
> package, and that version of rpc.gssd seems OK.  From the comments in the
> SRPM the original patch looks to be related to bug #1273166 but I don't have
> permissions to view that bug here.

Thanks for the detailed investigation.

Seems bug 1313090 has traced the same issue. Mark this one as DUPLICATE

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

Comment 3 Yongcheng Yang 2016-06-15 07:38:59 UTC
Paste the upstream patch to fix this issue.

commit 55c12c837feaa909de8cbd6d5fe23378b85efeff
Author: Benjamin Coddington <bcodding>
Date:   Wed Mar 16 11:31:40 2016 -0400

    gssd: Fix inner-loop variable reuse
    
    The var "i" is already in use iterating realmnames.
    
    Fixes: "6597e391 gssd:  Don't assume the machine account will be in
    uppercase"
    
    Signed-off-by: Benjamin Coddington <bcodding>
    Signed-off-by: Steve Dickson <steved>

diff --git a/utils/gssd/krb5_util.c b/utils/gssd/krb5_util.c
index 8ef8184..8dc64fe 100644
--- a/utils/gssd/krb5_util.c
+++ b/utils/gssd/krb5_util.c
@@ -796,7 +796,7 @@ find_keytab_entry(krb5_context context, krb5_keytab kt, const char *tgtname,
        char **realmnames = NULL;
        char myhostname[NI_MAXHOST], targethostname[NI_MAXHOST];
        char myhostad[NI_MAXHOST+1];
-       int i, j, retval;
+       int i, j, k, retval;
        char *default_realm = NULL;
        char *realm;
        char *k5err = NULL;
@@ -941,8 +941,8 @@ find_keytab_entry(krb5_context context, krb5_keytab kt, const char *tgtname,
                                 * moving on to the svcname
                                 */
                                if (strcmp(svcnames[j],"$") == 0 && !tried_upper) {
-                                       for (i = 0; myhostad[i] != '$'; ++i) {
-                                               myhostad[i] = toupper(myhostad[i]);
+                                       for (k = 0; myhostad[k] != '$'; ++k) {
+                                               myhostad[k] = toupper(myhostad[k]);
                                        }
                                        j--;
                                        tried_upper = 1;