Bug 31968 - mremap implementation in C does not handle arguments correctly
Summary: mremap implementation in C does not handle arguments correctly
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: 2.41
Assignee: Florian Weimer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-07-09 13:57 UTC by Florian Weimer
Modified: 2024-09-06 14:33 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
A different patch (793 bytes, patch)
2024-07-11 03:21 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Weimer 2024-07-09 13:57:29 UTC
Conditional varargs processing for system calls is bad.  It causes an ongoing maintenance headache, and weird application issues.  For example, Linux 5.7 added MREMAP_DONTUNMAP, and it can use the address argument just like MREMAP_FIXED.  But the current mremap implementation always passes NULL as a system call argument.

Regression in 2.35 caused by:

commit 5b3e31e3124bf89710e5c25176c70fdf66c2a212
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Jun 17 09:29:07 2020 -0300

    linux: Implement mremap in C
    
    Variadic function calls in syscalls.list does not work for all ABIs
    (for instance where the argument are passed on the stack instead of
    registers) and might have underlying issues depending of the variadic
    type (for instance if a 64-bit argument is used).
    
    Checked on x86_64-linux-gnu.
Comment 1 Florian Weimer 2024-07-09 15:01:51 UTC
Patch posted:

[PATCH] Revert "linux: Implement mremap in C" (bug 31968)
<https://inbox.sourceware.org/libc-alpha/87msmqzk2m.fsf@oldenburg.str.redhat.com/>
Comment 2 H.J. Lu 2024-07-09 22:13:11 UTC
(In reply to Florian Weimer from comment #1)
> Patch posted:
> 
> [PATCH] Revert "linux: Implement mremap in C" (bug 31968)
> <https://inbox.sourceware.org/libc-alpha/87msmqzk2m.fsf@oldenburg.str.redhat.
> com/>

Don't we need a test for MREMAP_DONTUNMAP?
Comment 3 H.J. Lu 2024-07-11 03:21:39 UTC
Created attachment 15615 [details]
A different patch
Comment 4 H.J. Lu 2024-07-12 22:38:12 UTC
A different patch set with tests is at

https://patchwork.sourceware.org/project/glibc/list/?series=36193
Comment 5 Sourceware Commits 2024-08-01 12:10:51 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6c40cb0e9f893d49dc7caee580a055de53562206

commit 6c40cb0e9f893d49dc7caee580a055de53562206
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jul 24 14:05:13 2024 -0700

    linux: Update the mremap C implementation [BZ #31968]
    
    Update the mremap C implementation to support the optional argument for
    MREMAP_DONTUNMAP added in Linux 5.7 since it may not always be correct
    to implement a variadic function as a non-variadic function on all Linux
    targets.  Return MAP_FAILED and set errno to EINVAL for unknown flag bits.
    This fixes BZ #31968.
    
    Note: A test must be added when a new flag bit is introduced.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Comment 6 Sourceware Commits 2024-08-01 12:38:28 UTC
The release/2.39/master branch has been updated by Florian Weimer <fw@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9f349d02c6065f77b485526b3d76a637f6f079dc

commit 9f349d02c6065f77b485526b3d76a637f6f079dc
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jul 24 14:05:13 2024 -0700

    linux: Update the mremap C implementation [BZ #31968]
    
    Update the mremap C implementation to support the optional argument for
    MREMAP_DONTUNMAP added in Linux 5.7 since it may not always be correct
    to implement a variadic function as a non-variadic function on all Linux
    targets.  Return MAP_FAILED and set errno to EINVAL for unknown flag bits.
    This fixes BZ #31968.
    
    Note: A test must be added when a new flag bit is introduced.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
    (cherry picked from commit 6c40cb0e9f893d49dc7caee580a055de53562206)
Comment 7 Sourceware Commits 2024-08-01 12:39:39 UTC
The release/2.40/master branch has been updated by Florian Weimer <fw@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=3433a358428bcec2d203fa408b85f442c9a465ca

commit 3433a358428bcec2d203fa408b85f442c9a465ca
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jul 24 14:05:13 2024 -0700

    linux: Update the mremap C implementation [BZ #31968]
    
    Update the mremap C implementation to support the optional argument for
    MREMAP_DONTUNMAP added in Linux 5.7 since it may not always be correct
    to implement a variadic function as a non-variadic function on all Linux
    targets.  Return MAP_FAILED and set errno to EINVAL for unknown flag bits.
    This fixes BZ #31968.
    
    Note: A test must be added when a new flag bit is introduced.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
    (cherry picked from commit 6c40cb0e9f893d49dc7caee580a055de53562206)
Comment 8 Sourceware Commits 2024-08-01 13:00:37 UTC
The release/2.38/master branch has been updated by Florian Weimer <fw@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0301637b9931766ee389aedf3899cde756b37283

commit 0301637b9931766ee389aedf3899cde756b37283
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jul 24 14:05:13 2024 -0700

    linux: Update the mremap C implementation [BZ #31968]
    
    Update the mremap C implementation to support the optional argument for
    MREMAP_DONTUNMAP added in Linux 5.7 since it may not always be correct
    to implement a variadic function as a non-variadic function on all Linux
    targets.  Return MAP_FAILED and set errno to EINVAL for unknown flag bits.
    This fixes BZ #31968.
    
    Note: A test must be added when a new flag bit is introduced.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
    (cherry picked from commit 6c40cb0e9f893d49dc7caee580a055de53562206)
Comment 9 Sourceware Commits 2024-08-01 15:15:15 UTC
The release/2.37/master branch has been updated by Florian Weimer <fw@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=40fb943e12041190ec38706b1d098fa0ff0910d3

commit 40fb943e12041190ec38706b1d098fa0ff0910d3
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jul 24 14:05:13 2024 -0700

    linux: Update the mremap C implementation [BZ #31968]
    
    Update the mremap C implementation to support the optional argument for
    MREMAP_DONTUNMAP added in Linux 5.7 since it may not always be correct
    to implement a variadic function as a non-variadic function on all Linux
    targets.  Return MAP_FAILED and set errno to EINVAL for unknown flag bits.
    This fixes BZ #31968.
    
    Note: A test must be added when a new flag bit is introduced.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
    (cherry picked from commit 6c40cb0e9f893d49dc7caee580a055de53562206)
Comment 10 Sourceware Commits 2024-08-01 15:16:13 UTC
The release/2.36/master branch has been updated by Florian Weimer <fw@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ab482a557d4a34a913b49fad4b3bd3bf7f1d70bd

commit ab482a557d4a34a913b49fad4b3bd3bf7f1d70bd
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jul 24 14:05:13 2024 -0700

    linux: Update the mremap C implementation [BZ #31968]
    
    Update the mremap C implementation to support the optional argument for
    MREMAP_DONTUNMAP added in Linux 5.7 since it may not always be correct
    to implement a variadic function as a non-variadic function on all Linux
    targets.  Return MAP_FAILED and set errno to EINVAL for unknown flag bits.
    This fixes BZ #31968.
    
    Note: A test must be added when a new flag bit is introduced.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
    (cherry picked from commit 6c40cb0e9f893d49dc7caee580a055de53562206)
Comment 11 Sourceware Commits 2024-08-01 15:30:49 UTC
The release/2.35/master branch has been updated by Florian Weimer <fw@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7459b6fe4773ff36d20e6f0890d6e40fbd803ea2

commit 7459b6fe4773ff36d20e6f0890d6e40fbd803ea2
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jul 24 14:05:13 2024 -0700

    linux: Update the mremap C implementation [BZ #31968]
    
    Update the mremap C implementation to support the optional argument for
    MREMAP_DONTUNMAP added in Linux 5.7 since it may not always be correct
    to implement a variadic function as a non-variadic function on all Linux
    targets.  Return MAP_FAILED and set errno to EINVAL for unknown flag bits.
    This fixes BZ #31968.
    
    Note: A test must be added when a new flag bit is introduced.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
    (cherry picked from commit 6c40cb0e9f893d49dc7caee580a055de53562206)
Comment 12 Florian Weimer 2024-09-06 14:33:58 UTC
Fixed.