Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp2098300pxb; Sun, 5 Sep 2021 08:37:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgAP6439GVW0IRLyhYBmNGDtJX9jCoaVOFXH2vosnQUTvqwsrwug1SvZJywd7gaSWTAsu5 X-Received: by 2002:a05:6402:8c6:: with SMTP id d6mr9228623edz.30.1630856272379; Sun, 05 Sep 2021 08:37:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630856272; cv=none; d=google.com; s=arc-20160816; b=U0Hn7WguUNJYkP/LznCkVx9XdwPOMstaiL011oW2euwSa2ncgo7pIP+OAEPdupw1HM DTR1Wre2LrC0B+t4ITmghxxJfIqGUrSZhi2+C5XAdUkIWcgI6lkZpUS7XJKFXm6CSnaW Ka3M4h/Z1wfmLp6vEmvzcI9LFEhCcMIrXhob310ff1IKJwxm7I/AkIztevEWP000TJd7 0SJq7sOSVpsJyiDBr+Ybx/7M4tRc7jpgL8rbBkH7/nkeDFyIcTckvzKgHr4Y0dWdb/Gj QwHHWqu/ExYdmUnw9/TwXeSpdz3mOwdqWfkqfACsRlrSSR5HBnY9ZFxN0IJ+VegTy6uK h0+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=XoAlzqJi3De8B+VzmGNnnTIvew9rejsmVUIc2D4Tpw0=; b=SfG/SlitW3WcClyw2+RRbglxG4i5m6XrlbBBejMX3P5TiFLq4DFGZqgLjp/O+ucKwH fgRojYNqgxdISZQU0+Ck4yhBkk9lAbNLRkmMGG6LK6F9rS54W6POkgOqw2St6Pnh3UAk jFS0KNtL8MHeUC9pzlJRUadc3JJmdMf8TJPVkEAGH7o0l6xcYMaMiijOegbpzPAECGOa rj2XeLvUrEyRQ1cowHSFuPtNWs00F8qb92fmqWniQc9jzGp6UQDKSBwQgknouqea2T7a stAE7Q3GoxzmteYpupIUGd5aO7kJISvw7wAoUnABM9etvmv59qLEJ3VVmUZWlE3UpO59 Uhog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LurNh+xX; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si5284197ejj.422.2021.09.05.08.37.28; Sun, 05 Sep 2021 08:37:52 -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=20210112 header.b=LurNh+xX; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237379AbhIEPdj (ORCPT + 99 others); Sun, 5 Sep 2021 11:33:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbhIEPdh (ORCPT ); Sun, 5 Sep 2021 11:33:37 -0400 Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 008C6C061575; Sun, 5 Sep 2021 08:32:34 -0700 (PDT) Received: by mail-ot1-x332.google.com with SMTP id c19-20020a9d6153000000b0051829acbfc7so5454206otk.9; Sun, 05 Sep 2021 08:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=XoAlzqJi3De8B+VzmGNnnTIvew9rejsmVUIc2D4Tpw0=; b=LurNh+xXN3Seno1v6vKCeczmHg5jkp75T7+rEOTZc9poUVG66GYg/QUXCpVw/gZFaz UrOiFKVGus5FSJFr25SxzrUPwkqmdBOL2RrQ9cqQnQV+zeT6US5zUeogQAglGZ9aQRpu g+f4EQwqe1RumBAG3axpcqPQtpkxvocGhMlE2O7dmqkW0U/qx0C36GKaVq1rhDbNs7Aq d0kmTanGwQiiXk849oEBv1wsz2C3u5LbNaV8lb9H9tcU+UWwtp/6tZUNqAZ+LW9AQmmY /cbJ4ru1mUxJ8CmChZjh79C9VmP5PfoaUWgv6dfo692Lw8w0YblbPX71SpcZgzh3TgZj pi8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=XoAlzqJi3De8B+VzmGNnnTIvew9rejsmVUIc2D4Tpw0=; b=RdLpgm2pEKZXzVPjHyLD4MO8Mx20ZFkjn6KH29aovOh5bnpe4vnxOvEhPNFAodRfUj dWc8w8IZoHkreTKd/nUD7r3jcA3z8G1C2kq+L7hpLHVklmfROz0qSfI1RXT54MyMXlI5 DtEqbhWaFTAu9/fAwlGkrW5qkf66NxZd2no3yMf/m7EQcwMQ72/JaIW+kHkNg+eGf2ue aAXNj1RH5aYjmSEmHvVHFzXzRh9sY8ogSXS2/J3pMsdlwSe8PfkbxAVfSpMFxU09zpis W3zolk0P4G83Zzqvm01Z7/JFrrIih/W8pIKITBBHlXhiArHrXbLxAkRXGqIEULQkaJbT 2Jjg== X-Gm-Message-State: AOAM532nR+HRfvqAnD6c0Oed8K7sNP8K5idjzZw92uF0dwklSgiQP2o0 ds2WVENpqpfaobJvhkpbs43jH7QKL9w= X-Received: by 2002:a9d:6359:: with SMTP id y25mr7629665otk.274.1630855952160; Sun, 05 Sep 2021 08:32:32 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id x12sm999383oie.56.2021.09.05.08.32.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Sep 2021 08:32:31 -0700 (PDT) Sender: Guenter Roeck Date: Sun, 5 Sep 2021 08:32:29 -0700 From: Guenter Roeck To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, Linus Torvalds , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Alexander Viro , Alexey Dobriyan , Steven Rostedt , Peter Zijlstra , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Petr Mladek , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , Kees Cook , "Eric W. Biederman" , Greg Ungerer , Geert Uytterhoeven , Mike Rapoport , Vlastimil Babka , Vincenzo Frascino , Chinwen Chang , Catalin Marinas , "Matthew Wilcox (Oracle)" , Huang Ying , Jann Horn , Feng Tang , Kevin Brodsky , Michael Ellerman , Shawn Anastasio , Steven Price , Nicholas Piggin , Christian Brauner , Jens Axboe , Gabriel Krisman Bertazi , Peter Xu , Suren Baghdasaryan , Shakeel Butt , Marco Elver , Daniel Jordan , Nicolas Viennot , Thomas Cedeno , Michal Hocko , Miklos Szeredi , Chengguang Xu , Christian =?iso-8859-1?Q?K=F6nig?= , Florian Weimer , David Laight , linux-unionfs@vger.kernel.org, linux-api@vger.kernel.org, x86@kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2 1/7] binfmt: don't use MAP_DENYWRITE when loading shared libraries via uselib() Message-ID: <20210905153229.GA3019909@roeck-us.net> References: <20210816194840.42769-1-david@redhat.com> <20210816194840.42769-2-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210816194840.42769-2-david@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 16, 2021 at 09:48:34PM +0200, David Hildenbrand wrote: > uselib() is the legacy systemcall for loading shared libraries. > Nowadays, applications use dlopen() to load shared libraries, completely > implemented in user space via mmap(). > > For example, glibc uses MAP_COPY to mmap shared libraries. While this > maps to MAP_PRIVATE | MAP_DENYWRITE on Linux, Linux ignores any > MAP_DENYWRITE specification from user space in mmap. > > With this change, all remaining in-tree users of MAP_DENYWRITE use it > to map an executable. We will be able to open shared libraries loaded > via uselib() writable, just as we already can via dlopen() from user > space. > > This is one step into the direction of removing MAP_DENYWRITE from the > kernel. This can be considered a minor user space visible change. > > Acked-by: "Eric W. Biederman" > Signed-off-by: David Hildenbrand > --- > arch/x86/ia32/ia32_aout.c | 2 +- > fs/binfmt_aout.c | 2 +- > fs/binfmt_elf.c | 2 +- > 3 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c > index 5e5b9fc2747f..321d7b22ad2d 100644 > --- a/arch/x86/ia32/ia32_aout.c > +++ b/arch/x86/ia32/ia32_aout.c > @@ -293,7 +293,7 @@ static int load_aout_library(struct file *file) > /* Now use mmap to map the library into memory. */ > error = vm_mmap(file, start_addr, ex.a_text + ex.a_data, > PROT_READ | PROT_WRITE | PROT_EXEC, > - MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_32BIT, > + MAP_FIXED | MAP_PRIVATE | MAP_32BIT, > N_TXTOFF(ex)); > retval = error; > if (error != start_addr) > diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c > index 145917f734fe..d29de971d3f3 100644 > --- a/fs/binfmt_aout.c > +++ b/fs/binfmt_aout.c > @@ -309,7 +309,7 @@ static int load_aout_library(struct file *file) > /* Now use mmap to map the library into memory. */ > error = vm_mmap(file, start_addr, ex.a_text + ex.a_data, > PROT_READ | PROT_WRITE | PROT_EXEC, > - MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE, > + MAP_FIXED | MAP_PRIVATE; > N_TXTOFF(ex)); Guess someone didn't care compile testing their code. This is now in mainline. Guenter