Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp67155pxb; Thu, 12 Aug 2021 10:54:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuIkMuUQuB2+uphsTIuuUxxOx5UaEZ+7UmzsSrZfADtqXhpBsY25wNjww7rmcvuEN/xE7z X-Received: by 2002:a17:906:b0d1:: with SMTP id bk17mr4897873ejb.59.1628790899749; Thu, 12 Aug 2021 10:54:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628790899; cv=none; d=google.com; s=arc-20160816; b=QhEW2IHqJ4gS8UQt3L5Ao08hCoyHL7ipKHgjWBF9Ev/EVvIl3KrKkV+/SjM9HwgPFH 2RTt1q12DKxC+QtoG+eeTM7DMH7aMzRLckZODXttu0/ZaWL3QqMHbkKj0ilGVIf2x6MX Uqc2gBv5Dawg000XxZBNlK6UutveUnBGHsh2zEdhw07E32qVi65dQb3UWF3WW0s9qsG4 ZiW9g1Hkh21xU7nuCcrk23Fis6glQ1+dbSs5dJClKifBzWquTzP9R59G2pM9nqiiKl3m CF5f1D+6W+UMaz09ShsDl87zW0uITtvnaaivvuNZ4TjwworlnqknbLbRpvcl2Rf6DEQ4 dOdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:mime-version:user-agent:message-id :in-reply-to:date:references:cc:to:from; bh=IO8d/RrHzFXb27qBiu4BnSdXx6cWwpv9SWXS9Y6N+ag=; b=lBbKiLNlPaflMlOsZfAS5rMvGEG2mDYIN98Y71uXwKz0+ZLKwMXNSi3gNaF1HQOlBm Loqf5MR7cukYa9XC/mxbJCNFFhoKKm5rkPHact0ry1wGdHCSqzXF+fvn4f/tQLiUjl2+ q4S3qElyzqKGmDTPu43ChW6vILByXgw1w341wNuSkHpczrAaPl2upY7cJKGjKUM/Yx/p QHIS42EakR1b8U3LXWga+VlZmMjup90cp+6K0B9a1/ulBgOX1/OLkLX8MbRjKMuezhja 2laI5E18gxGe5toexJgVWTEaNPjC7So7RwOF+rZ/Lxz+s2MpVnW3PnKUNBI1fKTnRlAB mGAg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p16si1884194eju.155.2021.08.12.10.54.34; Thu, 12 Aug 2021 10:54:59 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231823AbhHLQSy (ORCPT + 99 others); Thu, 12 Aug 2021 12:18:54 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:34132 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbhHLQSx (ORCPT ); Thu, 12 Aug 2021 12:18:53 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]:43426) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mEDPR-00CQHg-B6; Thu, 12 Aug 2021 10:18:21 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95]:42228 helo=email.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mEDPQ-00EqWu-5G; Thu, 12 Aug 2021 10:18:20 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Florian Weimer Cc: David Hildenbrand , 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 , Greg Ungerer , Geert Uytterhoeven , Mike Rapoport , Vlastimil Babka , Vincenzo Frascino , Chinwen Chang , Michel Lespinasse , 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 , Collin Fijalkovich , Michal Hocko , Miklos Szeredi , Chengguang Xu , Christian =?utf-8?Q?K=C3=B6nig?= , linux-unionfs@vger.kernel.org, linux-api@vger.kernel.org, x86@kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org References: <20210812084348.6521-1-david@redhat.com> <87r1eyg8h6.fsf@oldenburg.str.redhat.com> Date: Thu, 12 Aug 2021 11:17:24 -0500 In-Reply-To: <87r1eyg8h6.fsf@oldenburg.str.redhat.com> (Florian Weimer's message of "Thu, 12 Aug 2021 14:20:37 +0200") Message-ID: <877dgqfxij.fsf@disp2133> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1mEDPQ-00EqWu-5G;;;mid=<877dgqfxij.fsf@disp2133>;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+fUaUYby0ovoa4j4axcDNjRQxbnPUhyZI= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on sa07.xmission.com X-Spam-Level: X-Spam-Status: No, score=-0.2 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01, T_TooManySym_02 autolearn=disabled version=3.4.2 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4999] * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_02 5+ unique symbols in subject * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Florian Weimer X-Spam-Relay-Country: X-Spam-Timing: total 564 ms - load_scoreonly_sql: 0.06 (0.0%), signal_user_changed: 10 (1.8%), b_tie_ro: 9 (1.5%), parse: 1.10 (0.2%), extract_message_metadata: 3.8 (0.7%), get_uri_detail_list: 1.92 (0.3%), tests_pri_-1000: 15 (2.6%), tests_pri_-950: 1.26 (0.2%), tests_pri_-900: 1.15 (0.2%), tests_pri_-90: 85 (15.1%), check_bayes: 84 (14.8%), b_tokenize: 22 (3.9%), b_tok_get_all: 13 (2.3%), b_comp_prob: 3.6 (0.6%), b_tok_touch_all: 41 (7.3%), b_finish: 0.85 (0.2%), tests_pri_0: 424 (75.1%), check_dkim_signature: 0.59 (0.1%), check_dkim_adsp: 2.6 (0.5%), poll_dns_idle: 0.96 (0.2%), tests_pri_10: 2.4 (0.4%), tests_pri_500: 13 (2.2%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH v1 0/7] Remove in-tree usage of MAP_DENYWRITE X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Florian Weimer writes: > * David Hildenbrand: > >> There are some (minor) user-visible changes with this series: >> 1. We no longer deny write access to shared libaries loaded via legacy >> uselib(); this behavior matches modern user space e.g., via dlopen(). >> 2. We no longer deny write access to the elf interpreter after exec >> completed, treating it just like shared libraries (which it often is). > > We have a persistent issue with people using cp (or similar tools) to > replace system libraries. Since the file is truncated first, all > relocations and global data are replaced by file contents, result in > difficult-to-diagnose crashes. It would be nice if we had a way to > prevent this mistake. It doesn't have to be MAP_DENYWRITE or MAP_COPY. > It could be something completely new, like an option that turns every > future access beyond the truncation point into a signal (rather than > getting bad data or bad code and crashing much later). > > I don't know how many invalid copy operations are currently thwarted by > the current program interpreter restriction. I doubt that lifting the > restriction matters. I suspect that what should happen is that we should make shared libraries and executables read-only on disk. We could potentially take this a step farther and introduce a new sysctl that causes "mmap(adr, len, PROT_EXEC, MAP_SHARED, fd, off)" but not PROT_WRITE to fail if the file can be written by anyone. That sysctl could even deny chown adding write access to the file if there are mappings open. Given that there hasn't been enough pain for people to install shared libraries read-only yet I suspect just installing executables and shared libraries without write-permissions on disk is enough to prevent the hard to track down bugs you have been talking about. >> 3. We always deny write access to the file linked via /proc/pid/exe: >> sys_prctl(PR_SET_MM_EXE_FILE) will fail if write access to the file >> cannot be denied, and write access to the file will remain denied >> until the link is effectivel gone (exec, termination, >> PR_SET_MM_EXE_FILE) -- just as if exec'ing the file. >> >> I was wondering if we really care about permanently disabling write access >> to the executable, or if it would be good enough to just disable write >> access while loading the new executable during exec; but I don't know >> the history of that -- and it somewhat makes sense to deny write access >> at least to the main executable. With modern user space -- dlopen() -- we >> can effectively modify the content of shared libraries while being used. > > Is there a difference between ET_DYN and ET_EXEC executables? What is being changed is how we track which files to denying write access on. Instead of denying write-access based on a per mapping (aka mmap) basis, the new code is only denying access to /proc/self/exe. Because the method of tracking is much coarser is why the interper stops being protected. The code doesn't care how the mappings happen, only if the file is /proc/self/exe or not. Eric