Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp909493lqb; Wed, 29 May 2024 14:31:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwoEurZ8DE+UeE3rYwrrym6d2FyfTDgEQwyA8T6rYHTb/rqrBgLMaqagiFAUIQGOPG2VuiD7UA8yORSco2bFjAJ2hy4VMGVZJuDcr8yw== X-Google-Smtp-Source: AGHT+IHXG2UYugAnNYd1P4g41QOFgv7qsByRVNLw+H1zLQfGfw/VhLPW+0uWELIuKHyBfIsIoLd5 X-Received: by 2002:a19:9101:0:b0:522:3356:3b8 with SMTP id 2adb3069b0e04-52b7d4292c1mr224213e87.27.1717018292769; Wed, 29 May 2024 14:31:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717018292; cv=pass; d=google.com; s=arc-20160816; b=UlwSJSW/gFaZ/Gm8x/ssLY7sZW4hyrarxtprl2WWgMUSEgwYq5VteZsTY+bGViZsan SKL8o/Q1ZgOlutTUFjBJvYPVhERe26RsRdYS/jG4ehrfKY6EN/zgQiP4ah/WQoiTIU1n CQvNwNk0oHKRgAZCvzYRDPA3Fm8PEV24Q3u3ORh8OrtnUvgUzqETLAJ4NFOQqh5KWpxH K2ZzZ+PcF6BH3C2Xbm5waT+esFrR8sRI8o7i8aqI0pCBhGD+0/0dGvRw6bmOaHBdHUEP P8+Y1XyklWXK5nI+t9A2Q0Lr6CxmJfBVgj0I/tGYrvNhSFSLrl+Sva41XJkZNDxDJLq2 Bj+g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=FLiA1NhyieWQfcXd3ARNdY+JpVH2itsFMZIhqt+3Mg4=; fh=AVcMX5eWL1OAMv4f6I/jsg2z4QGnuBGZPUIJVlW8Gds=; b=SOWDcTrabNRQnOzZRqr4PDfluMjS1BcdGsUpMVphPqth+Kn0OR0yFLAm8JpPTkQ878 9hLmcm4zy6XuowKuqIEJFer+mRMS7dKXxXzEcQ1mcK6vg8bjuGw2Rqt/n7jPCk5BA2ud w3oNd4a3o4kZmYq+SRl0uV/z1FEEnM9zh6iz6tF6M3cEwtZA/K1KD/xbdnWkveJArObR scmhcNMu0xOnsB9hwnUgfItFv669dzYrGWlJYK/2AeliyDbu6gslzZx1PJbavpHHa8/8 doMXpEq9CNy+xlRNN96WUO5Sf5UpSxmMe6z39NbbW6HUWdgI7fdlxRdvrV5Ryassr7tZ aHzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jdaPSZFf; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-194708-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194708-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a634d79c08csi210411566b.975.2024.05.29.14.31.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 14:31:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194708-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jdaPSZFf; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-194708-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194708-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5308F1F21E91 for ; Wed, 29 May 2024 21:31:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 722F51C9EB2; Wed, 29 May 2024 21:31:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jdaPSZFf" Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE4E315D5C4 for ; Wed, 29 May 2024 21:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717018285; cv=none; b=YU/ugtAGuEnkRv1Iu0xXwHch2Tvdl1wMyYAj7faDniKzneL0EyJQ6F8NHugMI04Zy+J89a14Ywa/pH7yPzzTUiv64UkxUM9FAwZ7OHrdxqhd6R91iXpYJuEXMZ9sJBkUNbCIC814nO4fSh3MADpywLzBcQaoiOyXs2WenltZf88= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717018285; c=relaxed/simple; bh=W05mNXb0UrG3pIeEAflXGkFgca+10GQzjYeUMQhZlUY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=DRpp3d4A/nz1OeHcx/Xc4pt0X/K2D8qtl4XKVG7jVRPDlhnFBFq8AQ5tmZsRzQrd9rreH3RfITbjgOwFyfYgRAzhN7oFpSEOgbc5YrijiFVvfq+allicoGeDciRfX2O85hcJlhpR2uaVQinNVB2KWpF4Hh34rOENHJwLiXlzK5Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jdaPSZFf; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-57a1b122718so158a12.1 for ; Wed, 29 May 2024 14:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717018282; x=1717623082; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=FLiA1NhyieWQfcXd3ARNdY+JpVH2itsFMZIhqt+3Mg4=; b=jdaPSZFflkE7Q70yFfv9H0YtUbr3npbLsWRAqzwlHMgsuGKY+q/+r6mpOyOMVXSgzN +LeYrfWVnYvm78uxw6i4QStOnoMjxQQazP7pyzooRf0Knx+1Fv9r+tTJCoWe+EGjiVZj LcQYwRgLxQvLJtnhdIBR+rdYBsDG36B1mwZLiNm3wwsKhtBPnxbyuhCUzXJQWSPKYZ5W 4EfOfcZe2uB6p0/154Euy7tiHQXACiYtHs6SO2SfOFSEfUOWB8sTxMoEsS2Zt+gpYTKA LOddoHThnP00yJebbrm1qNCXLNaUYADQYjtazseV1EwUDzkip/qycsqfaIrGlSSSCLEk a3GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717018282; x=1717623082; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FLiA1NhyieWQfcXd3ARNdY+JpVH2itsFMZIhqt+3Mg4=; b=l52evjsFmw3rnZiqpXGHu5SDh1wvPZzMFF+bQHk4VoBamiO1xUYOxKeihUxnm3yPOE KZrJ/DpYZRGi4BUFwwdM2ZDYRfEZP5jkUwHhbsNwHQTE3SWpxAFEXn5y5qEi7l8RWHTg aqfg9fkNl3EwXMr+fc2R7B+P5yuBcDX7iPtvHjfWucHmteWIgf0MsuvcbmgVwboQuYiW bLQ+MpR7Yzy0PHj27GN2cOOXuSXVZafdrKqNb8SA31xlcvFZzZnRzEwnaKgj0QASp+4l H1L2SK5bxjOBTzwOc38LJilf8E/xg5zQVRDdhzEH5mg7PWzt2noaiGUxKA9tCVy47NY6 7mhA== X-Forwarded-Encrypted: i=1; AJvYcCUhlwORRXfYT04qTi3JxYDFtRqyt5nWZrdvtxEolOKVufaW+WgfqKux8FNjP5geLoX4vQtRVykZQHDazNGggb6BJZTFYDZ7z0bkKIh8 X-Gm-Message-State: AOJu0YxX/J2rFgJBNXoKLu5BbLn9L/TzENXyc3nhiDfBKAgV/+f4atNJ v2JE6Ud+txt0TfCSWjBwyZRTEa/Og9urKVbvgbBLiOLzfIySJoaeP2Xw6N7+b+ep4FxNUhhwCvI wfPqGs0i1UgqLfojQ7uJhDG33Zz+h25YFtcBM X-Received: by 2002:aa7:c2ce:0:b0:576:b1a9:2960 with SMTP id 4fb4d7f45d1cf-57a18c8ab10mr22904a12.5.1717018280000; Wed, 29 May 2024 14:31:20 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240524033933.135049-1-jeffxu@google.com> <20240524033933.135049-2-jeffxu@google.com> <79b3aa3e-bc70-410e-9646-0b6880a4a74b@app.fastmail.com> In-Reply-To: <79b3aa3e-bc70-410e-9646-0b6880a4a74b@app.fastmail.com> From: Jeff Xu Date: Wed, 29 May 2024 14:30:41 -0700 Message-ID: Subject: Re: [PATCH v2 1/2] memfd: fix MFD_NOEXEC_SEAL to be non-sealable by default To: David Rheinsberg , =?UTF-8?B?QmFybmFiw6FzIFDFkWN6ZQ==?= Cc: Jeff Xu , Andrew Morton , cyphar@cyphar.com, dmitry.torokhov@gmail.com, Daniel Verkamp , hughd@google.com, jorgelo@chromium.org, Kees Cook , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, skhan@linuxfoundation.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi David and Barnab=C3=A1s On Fri, May 24, 2024 at 7:15=E2=80=AFAM David Rheinsberg wrote: > > Hi > > On Fri, May 24, 2024, at 5:39 AM, jeffxu@chromium.org wrote: > > From: Jeff Xu > > > > By default, memfd_create() creates a non-sealable MFD, unless the > > MFD_ALLOW_SEALING flag is set. > > > > When the MFD_NOEXEC_SEAL flag is initially introduced, the MFD created > > with that flag is sealable, even though MFD_ALLOW_SEALING is not set. > > This patch changes MFD_NOEXEC_SEAL to be non-sealable by default, > > unless MFD_ALLOW_SEALING is explicitly set. > > > > This is a non-backward compatible change. However, as MFD_NOEXEC_SEAL > > is new, we expect not many applications will rely on the nature of > > MFD_NOEXEC_SEAL being sealable. In most cases, the application already > > sets MFD_ALLOW_SEALING if they need a sealable MFD. > > This does not really reflect the effort that went into this. Shouldn't th= is be something along the lines of: > > This is a non-backward compatible change. However, MFD_NOEXEC_SEAL > was only recently introduced and a codesearch revealed no breaking > users apart from dbus-broker unit-tests (which have a patch pending > and explicitly support this change). > Actually, I think we might need to hold on to this change. With debian code search, I found more codes that already use MFD_NOEXEC_SEAL without MFD_ALLOW_SEALING. e.g. systemd [1], [2] [3] I'm not sure if this will break more applications not-knowingly that have started relying on MFD_NOEXEC_SEAL being sealable. The feature has been out for more than a year. Would you consider my augments in [4] to make MFD to be sealable by default= ? At this moment, I'm willing to add a document to clarify that MFD_NOEXEC_SEAL is sealable by default, and that an app that needs non-sealable MFD can set SEAL_SEAL. Because both MFD_NOEXEC_SEAL and vm.memfd_noexec are new, I don't think it breaks the existing ABI, and vm.memfd_noexec=3D0 is there for backward compatibility reasons. Besides, I honestly think there is little reason that MFD needs to be non-sealable by default. There might be few rare cases, but the majority of apps don't need that. On the flip side, the fact that MFD is set up to be sealable by default is a nice bonus for an app - it makes it easier for apps to use the sealing feature. What do you think ? Thanks -Jeff [1] https://codesearch.debian.net/search?q=3DMFD_NOEXEC_SEAL [2] https://codesearch.debian.net/show?file=3Dsystemd_256~rc3-5%2Fsrc%2Fhom= e%2Fhomed-home.c&line=3D1274 [3] https://sources.debian.org/src/elogind/255.5-1debian1/src/shared/serial= ize.c/?hl=3D558#L558 [4] https://lore.kernel.org/lkml/CALmYWFuPBEM2DE97mQvB2eEgSO9Dvt=3DuO9OewMh= GfhGCY66Hbw@mail.gmail.com/ > > Additionally, this enhances the useability of pid namespace sysctl > > vm.memfd_noexec. When vm.memfd_noexec equals 1 or 2, the kernel will > > add MFD_NOEXEC_SEAL if mfd_create does not specify MFD_EXEC or > > MFD_NOEXEC_SEAL, and the addition of MFD_NOEXEC_SEAL enables the MFD > > to be sealable. This means, any application that does not desire this > > behavior will be unable to utilize vm.memfd_noexec =3D 1 or 2 to > > migrate/enforce non-executable MFD. This adjustment ensures that > > applications can anticipate that the sealable characteristic will > > remain unmodified by vm.memfd_noexec. > > > > This patch was initially developed by Barnab=C3=A1s P=C5=91cze, and Bar= nab=C3=A1s > > used Debian Code Search and GitHub to try to find potential breakages > > and could only find a single one. Dbus-broker's memfd_create() wrapper > > is aware of this implicit `MFD_ALLOW_SEALING` behavior, and tries to > > work around it [1]. This workaround will break. Luckily, this only > > affects the test suite, it does not affect > > the normal operations of dbus-broker. There is a PR with a fix[2]. In > > addition, David Rheinsberg also raised similar fix in [3] > > > > [1]: > > https://github.com/bus1/dbus-broker/blob/9eb0b7e5826fc76cad7b025bc46f26= 7d4a8784cb/src/util/misc.c#L114 > > [2]: https://github.com/bus1/dbus-broker/pull/366 > > [3]: > > https://lore.kernel.org/lkml/20230714114753.170814-1-david@readahead.eu= / > > > > Cc: stable@vger.kernel.org > > Fixes: 105ff5339f498a ("mm/memfd: add MFD_NOEXEC_SEAL and MFD_EXEC") > > Signed-off-by: Barnab=C3=A1s P=C5=91cze > > Signed-off-by: Jeff Xu > > Reviewed-by: David Rheinsberg > > Looks good! Thanks! > David