Bug 30151 - sgetsgent_r does not implement ERANGE protocol compatible with sgetsgent
Summary: sgetsgent_r does not implement ERANGE protocol compatible with sgetsgent
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: nss (show other bugs)
Version: 2.38
: P2 normal
Target Milestone: 2.38
Assignee: Florian Weimer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-21 08:13 UTC by Florian Weimer
Modified: 2024-09-06 14:41 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Weimer 2023-02-21 08:13:08 UTC
The sgetsgent function checks errno for ERANGE, but sgetsgent_r only returns ERANGE, but does not set errno to ERANGE. As a result, sgetsgent does not detect failure at all, and returns indicating success without filling in the struct sgrp result.

This bug is somewhat similar in effect as bug 20338, but the root cause is quite different.
Comment 1 Florian Weimer 2023-02-21 08:13:41 UTC
Not labeling as a security bug because /etc/gshadow contents (to which this data relates) is trusted data.
Comment 2 Florian Weimer 2023-02-21 08:42:02 UTC
Patch posted:

[PATCH] gshadow: Matching sgetsgent, sgetsgent_r ERANGE handling (bug 30151)
<https://sourceware.org/pipermail/libc-alpha/2023-February/145752.html>
Comment 3 Florian Weimer 2024-09-06 14:41:32 UTC
Fixed for 2.38 via:

commit 969e9733c7d17edf1e239a73fa172f357561f440
Author: Florian Weimer <fweimer@redhat.com>
Date:   Tue Feb 21 09:20:28 2023 +0100

    gshadow: Matching sgetsgent, sgetsgent_r ERANGE handling (bug 30151)
    
    Before this change, sgetsgent_r did not set errno to ERANGE, but
    sgetsgent only check errno, not the return value from sgetsgent_r.
    Consequently, sgetsgent did not detect any error, and reported
    success to the caller, without initializing the struct sgrp object
    whose address was returned.
    
    This commit changes sgetsgent_r to set errno as well.  This avoids
    similar issues in applications which only change errno.
    
    Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>