From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 699DFC4338F for ; Thu, 12 Aug 2021 12:39:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0488861059 for ; Thu, 12 Aug 2021 12:39:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0488861059 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 6A9936B0073; Thu, 12 Aug 2021 08:39:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 65A196B0074; Thu, 12 Aug 2021 08:39:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FA018D0002; Thu, 12 Aug 2021 08:39:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id 338FF6B0073 for ; Thu, 12 Aug 2021 08:39:06 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C57651802D4E3 for ; Thu, 12 Aug 2021 12:39:05 +0000 (UTC) X-FDA: 78466383450.40.7401072 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 5F504D00840C for ; Thu, 12 Aug 2021 12:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628771944; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sbqGKseWRRYhbY2LGrYsEOQPjgQ6ehV+W5zF3jgNGfg=; b=ZKdzV/0fJY+qjkzvTK9xQH4nsB8PJ/Wf7lrN5p/tgwNab+vRRxWk/SBtISALjsp24K9icj KS5zQEs8+sPpHK6ysP72djdMfQTWK4nALis3zsfzfU4KRt+bPfEGmLtAHCWkKd897JdHwk CBJBHr61ZXORZDhWDsUm2CuK/avVrEw= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-564-6XH5uSy8OXq8Fos-tH3SeA-1; Thu, 12 Aug 2021 08:39:03 -0400 X-MC-Unique: 6XH5uSy8OXq8Fos-tH3SeA-1 Received: by mail-wm1-f72.google.com with SMTP id z186-20020a1c7ec30000b02902e6a27a9962so3074191wmc.3 for ; Thu, 12 Aug 2021 05:39:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=sbqGKseWRRYhbY2LGrYsEOQPjgQ6ehV+W5zF3jgNGfg=; b=aqFWqIkXfxM+ZQz0FVc8V2e+pmqjV+piqPVBXUuOsdRbT1DPJtuSvEfT2sl0koPHlO pQ05QG/5azrp10gu19t/n53GCYo2pTK3KxJLuCTjssdAf/0Qp8leGtBhfNCTh2L4kY/1 QGzrVaaUXFDTkZ4dHEafNWf1TO5uzcK1oOCWzQ4AXMmu0orsZRCKFH/g7uUGPQ1Hbyk2 OhbYC0B5Z3nSNt4puJKb3mbCZxWVWoV3dxq4daKxehwZXnpn7Ifht190rjFvzkNS+9Ax KglOsbL7M9h1eG/WI8jbD+mF85zwf5kakxad6EmZllvXwkOnQlhqTv4q7i7YAjsREb0C bxLQ== X-Gm-Message-State: AOAM532RmowNu2D3+QoHmUQRufgVQA9q+RhaQb1BTJCfizAbooLFyLqw 8EvcFK7yCHtkrx3HLAbekvSBw4kTW90OUqIlFe2GoscRTQYBSTlRQ1mMcXRcjtjuTVHPAf5DP3p hosgIsjE1NZI= X-Received: by 2002:adf:db83:: with SMTP id u3mr3880809wri.363.1628771942743; Thu, 12 Aug 2021 05:39:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDcYmjDSU043EHzDh1omoow7kdOXdSFpNIKh9fkmzaYfVhQ8MrQo4AHUXle/AZphgQiUXdsA== X-Received: by 2002:adf:db83:: with SMTP id u3mr3880754wri.363.1628771942458; Thu, 12 Aug 2021 05:39:02 -0700 (PDT) Received: from [192.168.3.132] (p4ff23d8b.dip0.t-ipconnect.de. [79.242.61.139]) by smtp.gmail.com with ESMTPSA id d18sm2297940wrb.16.2021.08.12.05.38.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Aug 2021 05:39:01 -0700 (PDT) Subject: Re: [PATCH v1 3/7] kernel/fork: always deny write access to current MM exe_file To: Christian Brauner 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 , Michel Lespinasse , Catalin Marinas , "Matthew Wilcox (Oracle)" , Huang Ying , Jann Horn , Feng Tang , Kevin Brodsky , Michael Ellerman , Shawn Anastasio , Steven Price , Nicholas Piggin , 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 , =?UTF-8?Q?Christian_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, Andrei Vagin References: <20210812084348.6521-1-david@redhat.com> <20210812084348.6521-4-david@redhat.com> <20210812100544.uhsfp75b4jcrv3qx@wittgenstein> <1b6d27cf-2238-0c1c-c563-b38728fbabc2@redhat.com> <20210812123239.trksnm57owzwzokj@wittgenstein> From: David Hildenbrand Organization: Red Hat Message-ID: <59b6be94-c7d0-0535-1348-4e9c7f188d20@redhat.com> Date: Thu, 12 Aug 2021 14:38:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210812123239.trksnm57owzwzokj@wittgenstein> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="ZKdzV/0f"; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf20.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-Stat-Signature: uf75aie3a7995un83uysxr9zg1wqr15i X-Rspamd-Queue-Id: 5F504D00840C X-Rspamd-Server: rspam05 X-HE-Tag: 1628771945-905613 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: On 12.08.21 14:32, Christian Brauner wrote: > On Thu, Aug 12, 2021 at 12:13:44PM +0200, David Hildenbrand wrote: >> On 12.08.21 12:05, Christian Brauner wrote: >>> [+Cc Andrei] >>> >>> On Thu, Aug 12, 2021 at 10:43:44AM +0200, David Hildenbrand wrote: >>>> We want to remove VM_DENYWRITE only currently only used when mapping the >>>> executable during exec. During exec, we already deny_write_access() the >>>> executable, however, after exec completes the VMAs mapped >>>> with VM_DENYWRITE effectively keeps write access denied via >>>> deny_write_access(). >>>> >>>> Let's deny write access when setting the MM exe_file. With this change, we >>>> can remove VM_DENYWRITE for mapping executables. >>>> >>>> This represents a minor user space visible change: >>>> sys_prctl(PR_SET_MM_EXE_FILE) can now fail if the file is already >>>> opened writable. Also, after sys_prctl(PR_SET_MM_EXE_FILE), the file >>> >>> Just for completeness, this also affects PR_SET_MM_MAP when exe_fd is >>> set. >> >> Correct. >> >>> >>>> cannot be opened writable. Note that we can already fail with -EACCES if >>>> the file doesn't have execute permissions. >>>> >>>> Signed-off-by: David Hildenbrand >>>> --- >>> >>> The biggest user I know and that I'm involved in is CRIU which heavily >>> uses PR_SET_MM_MAP (with a fallback to PR_SET_MM_EXE_FILE on older >>> kernels) during restore. Afair, criu opens the exe fd as an O_PATH >>> during dump and thus will use the same flag during restore when >>> opening it. So that should be fine. >> >> Yes. >> >>> >>> However, if I understand the consequences of this change correctly, a >>> problem could be restoring workloads that hold a writable fd open to >>> their exe file at dump time which would mean that during restore that fd >>> would be reopened writable causing CRIU to fail when setting the exe >>> file for the task to be restored. >> >> If it's their exe file, then the existing VM_DENYWRITE handling would have >> forbidden these workloads to open the fd of their exe file writable, right? > > Yes. > >> At least before doing any PR_SET_MM_MAP/PR_SET_MM_EXE_FILE. But that should >> rule out quite a lot of cases we might be worried about, right? > > Yes, it rules out the most obvious cases. The problem is really just > that we don't know how common weirder cases are. But that doesn't mean > we shouldn't try and risk it. This is a nice cleanup and playing > /proc/self/exe games isn't super common. > Right, and having the file your executing opened writable isn't something very common as well. If we really run into problems, we could not protect the new file when issuing PR_SET_MM_MAP/PR_SET_MM_EXE_FILE. But I'd like to avoid that, if possible, because it feels like working around something that never should have worked that way and is quite inconsistent. -- Thanks, David / dhildenb