Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp605893pxb; Mon, 16 Aug 2021 12:51:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGziGkgXE0naoEaMIi6rkSU2tmXdVtHo06HRlWtuZAVxYGPtt4MxyisfBlXEyeQrF6g7Cs X-Received: by 2002:a17:906:a01:: with SMTP id w1mr130148ejf.117.1629143486743; Mon, 16 Aug 2021 12:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629143486; cv=none; d=google.com; s=arc-20160816; b=ZQTDug4CO/V77nLMICDUo6dHEXi5V7Xg5Lp6FEI91RbvKjeHJFG7DYvCFMUhVUOdZw tymrnWdWfzEmocEw+JEeh2CvfNO8j5zY7DhaladYxTfd2XuyTsXur8/JoCOnFSQZXVbM +z+/pGAPay89PY9kG19xfcAdJYQX1P6wp8jcOdWDUWMWT5flrNTpCzn4b773/VHd/26g zVb3vdSGRbfpOzhH7CQJtSrkkXJYo7vAP5q+VNJkC9v/jpwKJ92IoSd1Qd1F7HRRsQBo yhLml4wjbKW+NShXbRT7IVgTJq/Bida40Yu6e+xGIK6lCzp5olMolGsebuKZUjs0mJvH vmeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xeZs2Vbi3LPUYE5L2DmMtSeAlr7D2lLP2ZjOK1a2vac=; b=zjFpdo7ltRXv3uXkmIRTax+9NmJuKZRfbByaUBo1NAqkZhxHQoyGLyMK7TfWMmwJ2m CAyA5c6bYZD+JnMuis2wV6gs+RmopTlltvts1bLgAernlIzdevEMD+NalGlEZgzUbjJC CwUHsvEgoCtw+w9E8T3LnknWwV36crJVnzjL6n44rVMP2DgIbzXaRRrf5urcvTiIzcZi khF2X2jmndhGXM+R0UVD3N3FTwyPpvYH40JL4Myex0EaJfKeqGB5wary3lohM452qRac RIX6x41Dio1e0Jle5aYjEkYcCaSpAQsdrExgb+/NnIrT41CsgYKGC/xki2UedzjnHKEk svlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HcAhnYyP; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id og26si191581ejc.418.2021.08.16.12.51.03; Mon, 16 Aug 2021 12:51:26 -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=@redhat.com header.s=mimecast20190719 header.b=HcAhnYyP; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230148AbhHPTuP (ORCPT + 99 others); Mon, 16 Aug 2021 15:50:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49388 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbhHPTuP (ORCPT ); Mon, 16 Aug 2021 15:50:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629143382; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xeZs2Vbi3LPUYE5L2DmMtSeAlr7D2lLP2ZjOK1a2vac=; b=HcAhnYyP4FbrhXC7An5Q97M9jPie4Get/ygnVW6+OHVecje+5IgNKkKRC9gX+dyt7UJs3b pkcGHZ4rWhqMjOxhov2WhcDVkRp6HnoTPWhaseVu8tsptEuJR+/ySso0Cy40ll/jyoeuIW dOQq+lxm/ghyhq3jt/K7o2+WsIBzr40= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-542-jFjNC1f-ORu85GVvshofLw-1; Mon, 16 Aug 2021 15:49:41 -0400 X-MC-Unique: jFjNC1f-ORu85GVvshofLw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AC71C871807; Mon, 16 Aug 2021 19:49:40 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.192.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 874FF18017; Mon, 16 Aug 2021 19:49:05 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: David Hildenbrand , 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 , =?UTF-8?q?Christian=20K=C3=B6nig?= , 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: [PATCH v2 1/7] binfmt: don't use MAP_DENYWRITE when loading shared libraries via uselib() Date: Mon, 16 Aug 2021 21:48:34 +0200 Message-Id: <20210816194840.42769-2-david@redhat.com> In-Reply-To: <20210816194840.42769-1-david@redhat.com> References: <20210816194840.42769-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)); retval = error; if (error != start_addr) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 439ed81e755a..6d2c79533631 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1384,7 +1384,7 @@ static int load_elf_library(struct file *file) (eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr)), PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_DENYWRITE, + MAP_FIXED_NOREPLACE | MAP_PRIVATE, (eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr))); if (error != ELF_PAGESTART(eppnt->p_vaddr)) -- 2.31.1