[Devel] [PATCH RHEL9 COMMIT] ms/prctl: allow to setup brk for et_dyn executables

Konstantin Khorenko khorenko at virtuozzo.com
Wed Oct 27 12:51:52 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.10.18
------>
commit ef55e767180e9fb6530f90cd17aec85e074b3720
Author: Cyrill Gorcunov <gorcunov at gmail.com>
Date:   Wed Oct 27 12:51:51 2021 +0300

    ms/prctl: allow to setup brk for et_dyn executables
    
    Keno Fischer reported that when a binray loaded via ld-linux-x the
    prctl(PR_SET_MM_MAP) doesn't allow to setup brk value because it lays
    before mm:end_data.
    
    For example a test program shows
    
     | # ~/t
     |
     | start_code      401000
     | end_code        401a15
     | start_stack     7ffce4577dd0
     | start_data      403e10
     | end_data        40408c
     | start_brk       b5b000
     | sbrk(0)         b5b000
    
    and when executed via ld-linux
    
     | # /lib64/ld-linux-x86-64.so.2 ~/t
     |
     | start_code      7fc25b0a4000
     | end_code        7fc25b0c4524
     | start_stack     7fffcc6b2400
     | start_data      7fc25b0ce4c0
     | end_data        7fc25b0cff98
     | start_brk       55555710c000
     | sbrk(0)         55555710c000
    
    This of course prevent criu from restoring such programs.  Looking into
    how kernel operates with brk/start_brk inside brk() syscall I don't see
    any problem if we allow to setup brk/start_brk without checking for
    end_data.  Even if someone pass some weird address here on a purpose then
    the worst possible result will be an unexpected unmapping of existing vma
    (own vma, since prctl works with the callers memory) but test for
    RLIMIT_DATA is still valid and a user won't be able to gain more memory in
    case of expanding VMAs via new values shipped with prctl call.
    
    Link: https://lkml.kernel.org/r/20210121221207.GB2174@grain
    Fixes: bbdc6076d2e5 ("binfmt_elf: move brk out of mmap when doing direct loader exec")
    Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
    
    Reported-by: Keno Fischer <keno at juliacomputing.com>
    Acked-by: Andrey Vagin <avagin at gmail.com>
    Tested-by: Andrey Vagin <avagin at gmail.com>
    Cc: Dmitry Safonov <0x7f454c46 at gmail.com>
    Cc: Kirill Tkhai <ktkhai at virtuozzo.com>
    Cc: Eric W. Biederman <ebiederm at xmission.com>
    Cc: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
    Cc: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
    Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
    
    This patch comes from LKML
    https://lore.kernel.org/all/20210121221207.GB2174@grain/T/#u
    ms commit: e1fbbd073137 ("prctl: allow to setup brk for et_dyn executables")
    
    https://jira.sw.ru/browse/PSBM-125448
    Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
    
    https://jira.sw.ru/browse/PSBM-134962
    (cherry picked from vz7 commit d56cdb57dd3ec925d584991b9f3b7acca0066129)
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 kernel/sys.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index fedc4d14b1af..62bfbe1a51bc 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1978,13 +1978,6 @@ static int validate_prctl_map_addr(struct prctl_mm_map *prctl_map)
 
 	error = -EINVAL;
 
-	/*
-	 * @brk should be after @end_data in traditional maps.
-	 */
-	if (prctl_map->start_brk <= prctl_map->end_data ||
-	    prctl_map->brk <= prctl_map->end_data)
-		goto out;
-
 	/*
 	 * Neither we should allow to override limits if they set.
 	 */


More information about the Devel mailing list