From patchwork Wed Sep 8 03:00:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12480065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 567EDC433F5 for ; Wed, 8 Sep 2021 03:00:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 066146115A for ; Wed, 8 Sep 2021 03:00:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 066146115A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 9DBF294005E; Tue, 7 Sep 2021 23:00:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 98BAE940042; Tue, 7 Sep 2021 23:00:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87ADE94005E; Tue, 7 Sep 2021 23:00:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id 784A8940042 for ; Tue, 7 Sep 2021 23:00:43 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 3B762181C9B94 for ; Wed, 8 Sep 2021 03:00:43 +0000 (UTC) X-FDA: 78562903566.39.5AC871E Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf28.hostedemail.com (Postfix) with ESMTP id ED20C90000A1 for ; Wed, 8 Sep 2021 03:00:42 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id DE9FA6113C; Wed, 8 Sep 2021 03:00:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1631070042; bh=CYyUj0+CwoQHaYQmGh7VQsJnd3mv9wghYzT5kalHb/8=; h=Date:From:To:Subject:In-Reply-To:From; b=njXTQFEdjAKjLa/3nFnYWoTMHbT6sEdoQbtajuxGzpUau37eor6mtND1Fzd5Xo+V8 Yk4fcdFLaN3dIxE/cc0JKOAhDEeWrFe9TfkhEiKUW02tVrPaVdC6OaUemSSlPqoMMv kJYpJl+gqp9Hj8tg9J0/htDpEbRXGc4I+3Kip3hM= Date: Tue, 07 Sep 2021 20:00:41 -0700 From: Andrew Morton To: 0x7f454c46@gmail.com, akpm@linux-foundation.org, alexander.mikhalitsyn@virtuozzo.com, avagin@gmail.com, ebiederm@xmission.com, gorcunov@gmail.com, keno@juliacomputing.com, ktkhai@virtuozzo.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, ptikhomirov@virtuozzo.com, torvalds@linux-foundation.org Subject: [patch 141/147] prctl: allow to setup brk for et_dyn executables Message-ID: <20210908030041.CgEe1pD_s%akpm@linux-foundation.org> In-Reply-To: <20210907195226.14b1d22a07c085b22968b933@linux-foundation.org> User-Agent: s-nail v14.8.16 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=njXTQFEd; dmarc=none; spf=pass (imf28.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: ED20C90000A1 X-Stat-Signature: b4hcr7kr8msuhnppf1pwme1t9d6bfjxk X-HE-Tag: 1631070042-789922 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Cyrill Gorcunov Subject: 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 Reported-by: Keno Fischer Acked-by: Andrey Vagin Tested-by: Andrey Vagin Cc: Dmitry Safonov <0x7f454c46@gmail.com> Cc: Kirill Tkhai Cc: Eric W. Biederman Cc: Pavel Tikhomirov Cc: Alexander Mikhalitsyn Signed-off-by: Andrew Morton --- kernel/sys.c | 7 ------- 1 file changed, 7 deletions(-) --- a/kernel/sys.c~prctl-allow-to-setup-brk-for-et_dyn-executables +++ a/kernel/sys.c @@ -1960,13 +1960,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,