Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp578408pxb; Thu, 21 Jan 2021 14:30:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwfbCo8KUpnOMml41dawMkNHCj0HsTIrenP9PUsWlra/uNxs0x1kuyF3RcWNMIhjsfzyDR8 X-Received: by 2002:aa7:d1c7:: with SMTP id g7mr1040709edp.128.1611268225135; Thu, 21 Jan 2021 14:30:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611268225; cv=none; d=google.com; s=arc-20160816; b=gAqtw71WJIqm/w/cEdVgP65ctGiSaRxxRZk0voa+UGyff/u1T+GC0DO+pXjemZ4Vhh BbKO67GnfrHskN5iu0mgADmp4lvdQ4MMYC6ywbF1mMJDtuirk3wrPCf+qhho11xzmb61 Im0O5ugaQv9VH47kkCo875yNN4cP2WGhwSttvuC/xpxnzfBZdPvufQy0D/ajh0fNbuCp 1fp7D4NgrROit19YRynCvOSXeE7AYW/X6PtB24XK95813KtcVrorTdnLfLA34K+fSzSY we2yMthJNekoLGoEyRsYZqF7KYSQpyduwtagVRDFVu0HLDDsjVosiAAIaNA8JJYo2ynU ZYpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=KPxlu742QoNGnQZoUKH6S6ca6SSajmjdRBKvsB2jv0M=; b=Qu0RsnCwfftydOPVk4O1WCXuwRiW0zU8HN8X0L+e/u+XKljbwulxVXMbKqaohfgBHt gfeGK5llAwkJloX+Ctl7jec6LyXI18KpvwA4vGJEWOKZGa911LoFi10Tm0OqpZnTZ98D 64u+bISppEZXhU8fgu1kmzPjo3dHICtPyxoFwh+wOMbueU4JYstbqFDy745yTrgAPWsH hm2HQCJbMJYTlfveXTDpdGNHf70Datw0ZpQGJcIok6dxCgYHe8i1VdDWmPUsdEiMZVTv sQPyXxESOcxmeN8DLPQeCkBHXKkv/naXbwxNBoCDpHjFIzVWePIWD4F+JL+qHtHJSaqb cwMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dESmoQhs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf11si2742489edb.381.2021.01.21.14.30.01; Thu, 21 Jan 2021 14:30:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dESmoQhs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727068AbhAUWNF (ORCPT + 99 others); Thu, 21 Jan 2021 17:13:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726963AbhAUWMy (ORCPT ); Thu, 21 Jan 2021 17:12:54 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6E62C06174A for ; Thu, 21 Jan 2021 14:12:13 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id b26so4760669lff.9 for ; Thu, 21 Jan 2021 14:12:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=KPxlu742QoNGnQZoUKH6S6ca6SSajmjdRBKvsB2jv0M=; b=dESmoQhs98S5Ou6yaIItbvtAvGEoEPqdikbXZMH8QGsJssGlFovF04uBay1bRtXIRM 4+aGwoksykql2vSCknaWlEtMPKN5GqI1jbIP3PmKHZwr1tMUjZgDMBzIn6mP21RnPQZ+ zXIS2+3f9aAsVPOeIzgme2afzcTLmPRktVwWJ5HCC7/xMmXqrYLySjEq6vRNOd+DHCe5 pWUZRzIpSyL2FJ0efKDFW8FmnFA5UgvKSUvNhvo5QAlAPuINE+czO1bE51YvdlFOsF1t EJIm6ci1aWbMigCWvTMAQPfcPFedjGP8U35l4sRnRojuRoPbZIVFbphTkmnYXHqrh4i+ /mrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=KPxlu742QoNGnQZoUKH6S6ca6SSajmjdRBKvsB2jv0M=; b=G/qALlvGmb7f8WqXxvtYZffNLekEZ/4sOQNHG1+mATNvC9FBSFgLGivi+2D9HFeq7o pyTQ+ksLprXmN3/HjllOpIWZ79CPGyIaHOhMyIznqu7abyd1MrCTM+9IZM1KEPjsl7jt tZhPKDjxh23X19M4h6Fr0iyMKFCZGUxM3Qulfv1TG7VucUVp4qKJwtCJKNDRwnzfwyka ppxS1Zte4dvjfmayGYPhstHwxISQiQpJTy+NeHHOSUy6WJTKo6P5vqYsyXYLvBosk9RS QcJyiOUhKFBLF9Ln6yTcpwwH48C/C5c4jPjXYT6dkHFFgJQj/13DQ7njTBuREBefogOX Di8A== X-Gm-Message-State: AOAM533oGP4b5sWJjsY2h0t2SxqLMsMADH+BS0MpdCU/srVy+PjTn8cS 5q3Q2qnBb3KQ0DY4lqBw47kw+ryYwDs= X-Received: by 2002:ac2:4c2f:: with SMTP id u15mr615266lfq.163.1611267132091; Thu, 21 Jan 2021 14:12:12 -0800 (PST) Received: from grain.localdomain ([5.18.91.94]) by smtp.gmail.com with ESMTPSA id 187sm682689lfo.20.2021.01.21.14.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 14:12:10 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id 6D8EB560134; Fri, 22 Jan 2021 01:12:07 +0300 (MSK) Date: Fri, 22 Jan 2021 01:12:07 +0300 From: Cyrill Gorcunov To: LKML Cc: Keno Fischer , Andrew Morton , Dmitry Safonov <0x7f454c46@gmail.com>, Andrey Vagin , Kirill Tkhai , "Eric W. Biederman" Subject: [PATCH] prctl: allow to setup brk for et_dyn executables Message-ID: <20210121221207.GB2174@grain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.14.6 (2020-07-11) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Reported-by: Keno Fischer Signed-off-by: Cyrill Gorcunov CC: Andrew Morton CC: Dmitry Safonov <0x7f454c46@gmail.com> CC: Andrey Vagin CC: Kirill Tkhai CC: Eric W. Biederman --- Guys, take a look please once time permit. Hopefully I didn't miss something 'cause made this patch via code reading only. Andrey, do we still have a criu container which tests new kernels, right? Would be great to run criu tests with this patch applied to make sure everything is intact. kernel/sys.c | 7 ------- 1 file changed, 7 deletions(-) Index: linux-tip.git/kernel/sys.c =================================================================== --- linux-tip.git.orig/kernel/sys.c +++ linux-tip.git/kernel/sys.c @@ -1943,13 +1943,6 @@ static int validate_prctl_map_addr(struc 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. */ if (check_data_rlimit(rlimit(RLIMIT_DATA), prctl_map->brk,