Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp124568lqb; Thu, 23 May 2024 12:45:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVLlsze9oPuBQfOSX8LIW3B1lUMpaY1HvCYOIWxhHnLmyDWO9MUrWZeiz5TOdBJ+KQSqIGg/iiqIctWvYr9U46ryvB7VFyT4Bh0p8e70w== X-Google-Smtp-Source: AGHT+IEqMJad1C62moyX1U4ZnhdQXXaBfbmui/8i2pJKGMAyPdYPWdQ77ZN3aveowgdiRAJHiNxi X-Received: by 2002:aa7:8218:0:b0:6ed:21d5:fbdb with SMTP id d2e1a72fcca58-6f7726f5c79mr3599336b3a.8.1716493535898; Thu, 23 May 2024 12:45:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716493535; cv=pass; d=google.com; s=arc-20160816; b=XsNFk2oJJ243ri9CymNM/zu6avPUidJWyGTp0A4EVUuT/q9NtSv1VJ+MrXoo9BMUuB VaLQtk+PLDlhpL02+Kpf9X+7MylpvyBXonqpGutK+4KY/O94lVIkz1MxqAK1thtZlih3 LCaBcFvnlTQjlG/BDeKHIbp5iEnUVrdVWeGdBuCFg0brAOdztNDABVOpckDVnM9JZprl DYTZ0KV4qLVgmEjW6GnOpzA/Jl5vTeFlITNydpc7xYUd2qU7/1RgnuZKN0047X+RHzNo TRKURctPg7lmAynWazsGuN0Ca5tTlCcVvVaxfkC+WTAYA2kAxGRW1c8smHlbMvuxWsk0 VwCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=QDcJp/zEHrglPUQH3wNiWNx3V6g6GIBkFS/71Dv/MzQ=; fh=8VqDrilezDaAvqWiPL47ftaKBOXCgCo+NCXIZ0S1nNc=; b=i29SlxWYTigWHi7XfsVD5TB8Tji1xHOjUMCPENTSIQRoTvEnzcFs8Yn+ELE1MQWYWb GVF5lF++nb2549E2pTbrrYpymc3aqeJkfCBpa4ZVnJl+8M+kB0uCQU5oVum44Q6HbQhi Mge0/4zLOxudrfzNnao+PccAcU/YFK8hobnw2QAAZI0OUfxqsWzYbLyt7XaumHbwo6WM ZvM5yKW9rdKt50aJ5Y1DaMSahYzieOnVUSOsMsJbr7CFizc2SXmXwBLMOx01vT8Elzu1 SrB9ZstUHouy+cVGlss6tIn3GXrtITLUcycO33DLVO7b2nkFskcigXsHEri630gXfJ9L 3atQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=STAvvTVz; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-187939-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187939-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2b1709esi2105223b3a.261.2024.05.23.12.45.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 12:45:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187939-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=STAvvTVz; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-187939-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187939-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8A870281958 for ; Thu, 23 May 2024 19:45:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6811A84A48; Thu, 23 May 2024 19:45:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="STAvvTVz" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83CCD5FB9C; Thu, 23 May 2024 19:45:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716493522; cv=none; b=NbIoT0Z0w2AwesFKsy+62GTO2NWJ/AUXCx5nN3kDAjd+aRnxasC2gYDDVWbyKGq5yxx0D2RNA+jLbVz3skrBtmucU32aQM3iUsvRwBMFyW5M+HVfkQeXEU+QgFrsgS49RE7AWVs0B7Pt3kA3pQzkZz9mI2aUxyLAof+yAmXhQ4E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716493522; c=relaxed/simple; bh=t0orVRpMQ2TKtiB7VH6XOYM3LYyB2qqnNE9rKqfRp/Y=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=TRjAQe6/zCOZcHrKdPzut4+Tnc38QApULDg4A8EVChKm8CRMY8qe3DZIrRWtk5IhvGh9yQNt+ochhEo81uI04bUze1MXgAPIqGylJ+DsQ6EAqDVZnO3ZLNnBdNLV9nfeFx65As3gnPt0X4Xk3czPsF/T+2yHHcdrjMfzxv6I9h0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=STAvvTVz; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7433C2BD10; Thu, 23 May 2024 19:45:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1716493522; bh=t0orVRpMQ2TKtiB7VH6XOYM3LYyB2qqnNE9rKqfRp/Y=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=STAvvTVzBYeeYtMAR4rcP0Cgi9iM9Rx+w3MaVMYJjlI1iQG2xRjQWByb5+m1YRGu9 W7DZ+g/eSDTYcq4y3JfQ60Ej5nCw+KN20a5eILdppvOw/UNJaiqXvbnIT2j/YqK8Ah y7X1KdxHtJniVxNxiff7jTO0AI57+Bw1xgJo0oAA= Date: Thu, 23 May 2024 12:45:21 -0700 From: Andrew Morton To: Jeff Xu Cc: =?UTF-8?Q?Barnab=C3=A1s_P=C5=91cze?= , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, dmitry.torokhov@gmail.com, dverkamp@chromium.org, hughd@google.com, jorgelo@chromium.org, skhan@linuxfoundation.org, keescook@chromium.org Subject: Re: [PATCH v1] memfd: `MFD_NOEXEC_SEAL` should not imply `MFD_ALLOW_SEALING` Message-Id: <20240523124521.99a798d645b0939d331d70c1@linux-foundation.org> In-Reply-To: References: <20240513191544.94754-1-pobrn@protonmail.com> <20240522162324.0aeba086228eddd8aff4f628@linux-foundation.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 22 May 2024 19:32:35 -0700 Jeff Xu wrote: > > > > It's a change to a userspace API, yes? Please let's have a detailed > > description of why this is OK. Why it won't affect any existing users. > > > Unfortunately, this is a breaking change that might break a > application if they do below: > memfd_create("", MFD_NOEXEC_SEAL) > fcntl(fd, F_ADD_SEALS, F_SEAL_WRITE); <-- this will fail in new > semantics, due to mfd not being sealable. > > However, I still think the new semantics is a better, the reason is > due to the sysctl: memfd_noexec_scope > Currently, when the sysctl is set to MEMFD_NOEXEC_SCOPE_NOEXEC_SEAL > kernel adds MFD_NOEXEC_SEAL to memfd_create, and the memfd becomes sealable. > E.g. > When the sysctl is set to MEMFD_NOEXEC_SCOPE_NOEXEC_SEAL > The app calls memfd_create("",0) > application will get sealable memfd, which might be a surprise to application. > > If the app doesn't want this behavior, they will need one of two below > in current implementation. > 1> > set the sysctl: memfd_noexec_scope to 0. > So the kernel doesn't overwrite the mdmfd_create > > 2> > modify their code to get non-sealable NOEXEC memfd. > memfd_create("", MEMFD_NOEXEC_SCOPE_NOEXEC) > fcntl(fd, F_ADD_SEALS, F_SEAL_SEAL) > > The new semantics works better with the sysctl. > > Since memfd noexec is new, maybe there is no application using the > MFD_NOEXEC_SEAL to create > sealable memfd. They mostly likely use > memfd(MFD_NOEXEC_SEAL|MFD_ALLOW_SEALING) instead. > I think it might benefit in the long term with the new semantics. Yes, it's new so I expect any damage will be small. Please prepare a v2 which fully explains/justifies the thinking for this non-backward-compatible change and which include the cc:stable.