Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4955684pxv; Tue, 20 Jul 2021 15:28:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxN+Z9laTazzndPpO3vNcuzJR8gUNO7LYjD+cyk6kWLfyhXfggJScf6GfO4Wn3i/I7NJ1/c X-Received: by 2002:aa7:d809:: with SMTP id v9mr44589283edq.146.1626820089535; Tue, 20 Jul 2021 15:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626820089; cv=none; d=google.com; s=arc-20160816; b=Z3wzYNUtzE8UQd7KoFRkPig/bzFNfFLajRl85M0t7/YTHLzHnQVzq4KUeV8w2jReT3 2tZMaj2W6LxAQaEs9sEOzi1PMzoHXe6nMl+3Ud6m+yqRUuw8FG3bE39t/vFczzi9yVyC g+0M4EFSdw+p4ayEvKgbEuBBWSHdnsMGjZyFTmEdFm/7V6lV2QkYiKElQ2Di9p9Aj53A Y0z1mFdE5kr6IMJpXspRL5ORzNALkO4WwaJ2/sKmuTaJrqd2k5Rm3lK1XR/wu+OT2NzJ U0S1Q+ZW614PCYzW46KnaLQUfQMqlXAJPkggf6QT0tBGZIStHhYxIs0do5ilky0wSlzZ 3ZOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=R2F29apSURu+IG0KtraJ0+rZnz2VLfT3gZPbk7j55ag=; b=gHNp3GzIrUH8vhOjdavujCxbkdW59N6LnjC+CFSB+3Pz/ovw/ZNG3gVFczHsEWIXSX NkR7aA8D5/pVm7knpc7QnvxmurzJh0gjiFm2P+zDKQnCuu3BdgBfRlZ4kdPRwWS3pwuQ 7RWxVB63sh7gp8aGEg32JbBuGA8Z9RVg4tZuUz+PYi0Q1VeXIpXktApdz3K37VCJiH9K 365DnkfUwSklZdzqvNWi5omyG0jJENyzmWIqgEt51VgEqamoGL2Z58ipzJG5ITdK0Ba5 s5VJE9aJaiDn+G2akATdy24tuuJRZGo5D76HG9JJEiIr+O/em8pG3o3pfv7V1DKLTQ7I sw3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kbtASbOP; 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 s20si561092ejb.555.2021.07.20.15.27.43; Tue, 20 Jul 2021 15:28:09 -0700 (PDT) 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=kbtASbOP; 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 S230512AbhGTVpM (ORCPT + 99 others); Tue, 20 Jul 2021 17:45:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229816AbhGTVpI (ORCPT ); Tue, 20 Jul 2021 17:45:08 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 768DDC061574 for ; Tue, 20 Jul 2021 15:25:45 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id e14so406082ljo.7 for ; Tue, 20 Jul 2021 15:25:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=R2F29apSURu+IG0KtraJ0+rZnz2VLfT3gZPbk7j55ag=; b=kbtASbOPWbpzOdYKIDhZY5bN0lT2tbl28NLr943++MghdVByMURwBagN0VTQxwmCfw 7bUEDMCGnX3xw+69j9KigDRrbbopKWd01Mb4Nb6n0Ou5oU77FeiiucaOxdTYF8+9AcQ+ XGaj3X2ZYwOlbR/h1g6H1fzYr6S2FjKrRxje7DHHztIQtstLxZhDC3J2BGp9yERHIml3 OIsQ7b6MFKtoNeR+JOG3iLGLB5R4ahXAtHJdUET/Aai462EE9fTZ8GdnUiwo3afzXUxM GY48Ve1QVcandqBj6CGb02Jxtrmm/XPGUahIU7n0Q3VFRKW5//QlcgFi5g2w+JdIrbH6 ug+w== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=R2F29apSURu+IG0KtraJ0+rZnz2VLfT3gZPbk7j55ag=; b=BzV7O4TDVDSPbBEbBgCSe/MHJ7aAlSp8L0ARwP8F5AKIgW4yNjxWnDm+tm0JADSrYY epgeLF4BYBpBnUWSzFH/oNsJyj2+E85twvwhlJNvmtbVjoRXXkUs5j66qcz3FcWAsuDb w5t/pcolF6dUfeJ2qM7PH7Qs5dYy9BQGfJZXhMSOGmKSWnCXRNTLPFP0E9UM/xSnfeuL pNp2pBeJQiMnVM1POTkAoHzdRgUyz4rGweb2EEE/iKtOl7/XUcz9GM+UAPjnph61UCp5 5hsFJICiKEyA0viyay/2WBTpRBV5v1KTlJRqEzg1f0UfNAbPjb1O92Ga943T/cX13cA9 ejHQ== X-Gm-Message-State: AOAM531Vb3ydQCd0s3BaO+8f2Eoi0+VD8HeB0JB9E9vuCoPyYlz+y2Uz dD2sh2EVeKJImAGXZfKWd54= X-Received: by 2002:a05:651c:1141:: with SMTP id h1mr23398496ljo.224.1626819943852; Tue, 20 Jul 2021 15:25:43 -0700 (PDT) Received: from grain.localdomain ([5.18.255.97]) by smtp.gmail.com with ESMTPSA id v12sm2488496ljv.65.2021.07.20.15.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 15:25:42 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id B439C5A001E; Wed, 21 Jul 2021 01:25:41 +0300 (MSK) Date: Wed, 21 Jul 2021 01:25:41 +0300 From: Cyrill Gorcunov To: Andrew Morton Cc: LKML , Keno Fischer , Dmitry Safonov <0x7f454c46@gmail.com>, Andrey Vagin , Kirill Tkhai , "Eric W. Biederman" Subject: Re: [PATCH] prctl: allow to setup brk for et_dyn executables Message-ID: References: <20210121221207.GB2174@grain> <20210720145148.cdcfa3210e39e88a591af12b@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210720145148.cdcfa3210e39e88a591af12b@linux-foundation.org> User-Agent: Mutt/2.0.7 (2021-05-04) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 20, 2021 at 02:51:48PM -0700, Andrew Morton wrote: > > > > 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. > > So... do you recall why you added that test originally? To be honest, when I added this test in first place I simply forgot about et_dyn executables because we usually run executables via traditional exec call (where brk map sits before end_data VMA), not via loader and that's the reason why I didn't hit this problem before and why this get revealed only after a couple of years. This is simply rarely used. > > This is under prctl(CAP_SET_MM), yes? What capabilities does this > require? Yes, it is for prctl(PR_SET_MM_MAP) and requires no additional caps. The most important thing here is check_data_rlimit() function which called at the end of memory map verification -- we make sure the user won't get more memory than been granted by RLIMIT_DATA limit even if he passes some bad brk value here on a purpose. /* * Neither we should allow to override limits if they set. */ if (check_data_rlimit(rlimit(RLIMIT_DATA), prctl_map->brk, prctl_map->start_brk, prctl_map->end_data, prctl_map->start_data)) goto out; which expands to (I wrapped code to make it a bit more readable) static inline int check_data_rlimit(unsigned long rlim, unsigned long new, unsigned long start, unsigned long end_data, unsigned long start_data) { if (rlimit(RLIMIT_DATA) < RLIM_INFINITY) { if (((prctl_map->brk - prctl_map->start_brk) + (prctl_map->end_data - prctl_map->start_data)) > rlimit(RLIMIT_DATA)) return -ENOSPC; } return 0; }