Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3870822rdg; Wed, 18 Oct 2023 08:18:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcO3yeUqqJ7dweT0jtEVx1euARAJ9XcEPZlnX8Q0XnbVngmxKTl7jolmz7mDPcPINcfRfI X-Received: by 2002:a17:902:eccf:b0:1bd:aeb3:9504 with SMTP id a15-20020a170902eccf00b001bdaeb39504mr7263021plh.15.1697642295734; Wed, 18 Oct 2023 08:18:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697642295; cv=none; d=google.com; s=arc-20160816; b=nPLCF3RmIf2udmekSyTBk+dy7UTQ9/jWRulVO+dmFOnvdANB7b2I+gTR//VIYiVyGH E32kd8HkuyAp+h9jV9J8DaawBz37UEpyUr9hcLGix9OP5S8Aliol2q1KZahIaC0KEsfN bWvt0P3RkRpKb9/pBXTZdF8NmegK03Azp5oTVd396Nj0FOvygF1MYqn36/5pxZNnGkCd NOueUZiJRIfeHPsDiFTaUFD9fPl0+J3cgSj/BroQTX2k1FSXj772Kdvdy3cNlAo7KHQU Yfzrljfb9B0xVEjcGKW+uQlS6SICdOnI0+6An4FyE1RCxOctEPXtmfXvNENEIxIaLAUr Mc1w== 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:dkim-signature; bh=EYJWM82k/mYbNh1hfZQ8KkV147YIzBIZxX71F7kjj3o=; fh=ikUW4pSOYC2ZpjC+tEeDGAUQzaB/M31fRWGZsKrO3Q0=; b=MbfEIQkqlI8sOskkFPDUwa+KiBIwSLX0BPk6Yq0vwzLnxOIFs1Pi3CYdqqvVJcvyHb Zqa2PnSBcPCIl5Vy+lDZ3Uks8Omjj5J0+/g0QMLoLQKSf4+iAyIKA6/ITYFNZn2jFVjF MPxlqKy4f4VRn++tnKSn7F4rZknbToK4mJAj3Ho8SmIqtNqm5YrAyZ6+kqEx4VcPjcJ0 fvLTKOfDkUurKHKTPTIJ/z36ZLNp51AwnWGPC9qM69et1/AE2OpJ43Zd32bitvCLa//Z RcRrpNr2r7/iFBT47OvNzB/SP6uT2FLWcYXTC/WX2F3d0CvN4CkclMQG8EtVkCKsYe0l Eu5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=SP8eWuTh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id z4-20020a170902708400b001b894687ec9si57938plk.462.2023.10.18.08.18.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 08:18:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=SP8eWuTh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 0916980F66B1; Wed, 18 Oct 2023 08:18:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231472AbjJRPSF (ORCPT + 99 others); Wed, 18 Oct 2023 11:18:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230515AbjJRPSE (ORCPT ); Wed, 18 Oct 2023 11:18:04 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D0BB94; Wed, 18 Oct 2023 08:18:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=EYJWM82k/mYbNh1hfZQ8KkV147YIzBIZxX71F7kjj3o=; b=SP8eWuThWrXi0c+GKIfuQmjZth m8/aZFY0nYGaQzDsejHx0z/V6t3NsJjeORp/uGXzhj39+OR2w2/oRsloh++YDaE2cTL3KmaFAfJOn 1abJTfFo5CEZEKuPxBZ0FPFkDnDehbk+hCyRjsxjHUY6NXG0/A+MD2FRrLo2JYgFo8BaKNUaq0SEz /+odCu/MMdB5q5sBf9XxYOBN376/6smqd3AYT/9m7BwfQC9Adp6kQQhqG383BL57eLzLWs8latknJ yTnbdZ1C+yUGO2QdDKTttULIj+JqxIRcKc4PdhojxFG7PgO/UW0fs6OY8VbZXahhYtUOFINnnIjMs tVn/tT0w==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qt8Iq-001bDQ-Mh; Wed, 18 Oct 2023 15:17:44 +0000 Date: Wed, 18 Oct 2023 16:17:44 +0100 From: Matthew Wilcox To: Jeff Xu Cc: Theo de Raadt , Linus Torvalds , jeffxu@chromium.org, akpm@linux-foundation.org, keescook@chromium.org, sroettger@google.com, jorgelo@chromium.org, groeck@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, jannh@google.com, surenb@google.com, alex.sierra@amd.com, apopple@nvidia.com, aneesh.kumar@linux.ibm.com, axelrasmussen@google.com, ben@decadent.org.uk, catalin.marinas@arm.com, david@redhat.com, dwmw@amazon.co.uk, ying.huang@intel.com, hughd@google.com, joey.gouly@arm.com, corbet@lwn.net, wangkefeng.wang@huawei.com, Liam.Howlett@oracle.com, lstoakes@gmail.com, mawupeng1@huawei.com, linmiaohe@huawei.com, namit@vmware.com, peterx@redhat.com, peterz@infradead.org, ryan.roberts@arm.com, shr@devkernel.io, vbabka@suse.cz, xiujianfeng@huawei.com, yu.ma@intel.com, zhangpeng362@huawei.com, dave.hansen@intel.com, luto@kernel.org, linux-hardening@vger.kernel.org Subject: Re: [RFC PATCH v1 0/8] Introduce mseal() syscall Message-ID: References: <20231016143828.647848-1-jeffxu@chromium.org> <55960.1697566804@cvs.openbsd.org> <95482.1697587015@cvs.openbsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 18 Oct 2023 08:18:13 -0700 (PDT) On Tue, Oct 17, 2023 at 08:18:47PM -0700, Jeff Xu wrote: > In practice: libc could do below: > #define MM_IMMUTABLE > (MM_SEAL_MPROTECT|MM_SEAL_MUNMAP|MM_SEAL_MREMAP|MM_SEAL_MMAP) > mseal(add,len, MM_IMMUTABLE) > it will be equivalent to BSD's immutable(). No, it wouldn't, because you've carefully listed the syscalls you're blocking instead of understanding the _concept_ of what you need to block. > In linux cases, I think, eventually, mseal() will have a bigger scope than > BSD's mimmutable(). VMA's metadata(vm_area_struct) contains a lot > of control info, depending on application's needs, mseal() can be > expanded to seal individual control info. > > For example, in madvice(2) case: > As Jann point out in [1] and I quote: > "you'd probably also want to block destructive madvise() operations > that can effectively alter region contents by discarding pages and > such, ..." > > Another example: if an application wants to keep a memory always > present in RAM, for whatever the reason, it can call seal the mlock(). > > To handle those two new cases. mseal() could add two more bits: > MM_SEAL_MADVICE, MM_SEAL_MLOCK. Yes, thank you for demonstrating that you have no idea what you need to block. > It is practical to keep syscall extentable, when the business logic is the same. I concur with Theo & Linus. You don't know what you're doing. I think the underlying idea of mimmutable() is good, but how you've split it up and how you've implemented it is terrible. Let's start with the purpose. The point of mimmutable/mseal/whatever is to fix the mapping of an address range to its underlying object, be it a particular file mapping or anonymous memory. After the call succeeds, it must not be possible to make any address in that virtual range point into any other object. The secondary purpose is to lock down permissions on that range. Possibly to fix them where they are, possibly to allow RW->RO transitions. With those purposes in mind, you should be able to deduce for any syscall or any madvise(), ... whether it should be allowed. Look, I appreciate this is only your second set of patches to Linux and you've taken on a big job. But that's all the more reason you should listen to people who are trying to help you.