Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1697635rdb; Sun, 19 Nov 2023 06:55:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBuVbQElTaevGQjXHyYmm2gLbKViBLQjZLf1NDQUxbjSrf8IyY64gzWGz/q0KReyplw1Sr X-Received: by 2002:a17:90b:38c2:b0:280:22e2:60ea with SMTP id nn2-20020a17090b38c200b0028022e260eamr3028465pjb.3.1700405700223; Sun, 19 Nov 2023 06:55:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700405700; cv=none; d=google.com; s=arc-20160816; b=vvYNa96F6sChVTunNc5PR5isj6no8ijzMJoF+7QzHSXU0rCJKTpBDy1k1Oyf2KFvU4 azsIemviPDYgAUwHKyTZGOB2ZnKYvj1pNTvdLLkkQ/HtRCc/fZKQBLLrTA+ox/Jd/uBU bELvdtB6yH9/7IqYcv6igrHWi3gCCpdUsckA4I5O/8CXb4Yn8tt8sA8pQWNIEn75fAdV hEatsqeO5nwluKyG/5DZTaIM1yQWHU7jeBEzYsMPpvV7JZkiF/4f242kBQpyeLYVWQ02 DqmPCWVYQg+s5YQmQGbDhgsSNdhBNFTxYF0V0reGVo+hXITdC8wfCs8kbp8mvuMGHT+J iC7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=UFViZfi+D4ykbhkIT1nTXXcFAxgIUhFWAUIBpe5r3Wc=; fh=bluLb82746OfbsFnWY2c7xKzn0AyfmTco/hIRATHNp8=; b=w0edZICBFlwGE+4nR2kKTKXbTvGlAyn5c9w8wd7GdEqtii+vK6jVXmHvOQHDv5+jTI gZ9vmcj7My6wEFu7fgCBvw96hwbyjwuN2d5O1dawwpal7FOqWk3HgyKdxd0CWKT2d3w3 CWZ4C01iMu7A/8r7EEZZd4tpnb8xIxQk+tmsJN6gDD7mK2XjFQf8cLx1B/5z01ZpryUX ouGTEfMKos9rbHr9V0advloeb2mbhyZLQYZYJ49lND7Hr3sZXzusxO5GTIrzYjnSG+ki RDRh5MiVkGouRqNTIDj4l6O/Oe440c9tLF294cYqr2Kqjdl5AyxeEh8DWkMQ0sTZ7S/W Va9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZkYRGAZY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id np12-20020a17090b4c4c00b0027408bd8420si9402731pjb.13.2023.11.19.06.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 06:55:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZkYRGAZY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id AA58A80879E6; Sun, 19 Nov 2023 06:54:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229820AbjKSOys (ORCPT + 99 others); Sun, 19 Nov 2023 09:54:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjKSOyr (ORCPT ); Sun, 19 Nov 2023 09:54:47 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBFEAE1; Sun, 19 Nov 2023 06:54:43 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-28035cf6a30so2722483a91.3; Sun, 19 Nov 2023 06:54:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700405683; x=1701010483; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=UFViZfi+D4ykbhkIT1nTXXcFAxgIUhFWAUIBpe5r3Wc=; b=ZkYRGAZY1eqCGhzjf/MmU0AdLwn1Qe9xCD76KdWY3zEnj2KO6KYSjOkYMtgQWfyk84 +g+zHJwGzNUDPjKMYSAG8zO021qd12ZgtRU5Qm7FC1r99+74dckHxwfutRFKEgVqLS2q VjLGJp3kWyzO/X1p4g+xfqBj126TjrGX4SKTV7lQt1khTCiB4MSVrf+APOxS+7Rajnzy 9d2Gnz40RhWIEWpjcvqYKT6f1MYr3SGDRUcaMJTg1a/kdVgq8jk0NxhtwmTvAbsNsZ79 E52eWzxumClV3RdDXH0eZuXtvnNQ/IqwNWdiCisOyiqG1IHAxuKoW84ZIoYwwi+MG9Re SzgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700405683; x=1701010483; h=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=UFViZfi+D4ykbhkIT1nTXXcFAxgIUhFWAUIBpe5r3Wc=; b=myc+Cbwdg8hBQJ1p6BH0ORXZ8rZfV1NHHL5a50Y1r13kjU8PJ8CXaLPamDBQRnXTw7 4uRwVXagJmbHLuPJ7iW0tfNMJgAMETNGuIxKHlbngMTg/d7kZx3/UZhf7l/FXiUpOHgV FfFv6ekPOheDJ7b1OAyFD/3Nki+bzSg8s3NgHw5az7EmsXKi9WyDk+++cBtKdbuO4woH b26S0Tn7g25/7aMVw94IjhUC+KxRi2JCUttHRKoDWeXgSthQNBNvS5zzDPaKgx/sH5Mf JhqAbKK82u6oNKkedI6WiNraDjL0s50+q4eOo/4pd0A2bB4cla3zOyK571x8GHWCQ27N /Puw== X-Gm-Message-State: AOJu0Yxv89WAhACP7udQiFSP5OGR8Z7wIJxyWjTaAKJi95kWOFSD+0ea KIqa5nm+Xoph2U6CngJbYZ/R7cUdzLLzFUSYgSE= X-Received: by 2002:a17:90a:1690:b0:281:416e:1c3f with SMTP id o16-20020a17090a169000b00281416e1c3fmr3470474pja.28.1700405683271; Sun, 19 Nov 2023 06:54:43 -0800 (PST) MIME-Version: 1.0 References: <20231111125126.11665-1-yjnworkstation@gmail.com> <20231111132431.GA3717@1wt.eu> <20231112045217.GA39417@mit.edu> <87fa3d2e-6822-0f24-daec-772dbe717b63@suse.cz> In-Reply-To: <87fa3d2e-6822-0f24-daec-772dbe717b63@suse.cz> From: Jasper Niebuhr Date: Sun, 19 Nov 2023 15:54:31 +0100 Message-ID: Subject: Re: [PATCH] exitz syscall To: Vlastimil Babka Cc: "Theodore Ts'o" , Willy Tarreau , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-security-module@vger.kernel.org, torvalds@linux-foundation.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Sun, 19 Nov 2023 06:54:57 -0800 (PST) I took some time to consider a few options... 1. MLOCK_ZERO_ON_FREE flag for mlock2: This would achieve what I was looking for. On the other hand, this feature could not be used to just ensure the memory is zeroed before reallocation, without locking it to memory. So if you just want a few regions to be protected from other processes, this would not be ideal. Also the VM_* flags are all used otherwise (except for a random hole in the middle). 2. PR_INIT_ON_FREE option for prctl + some cap against DoS: This could, more generally, be used to "replace" other ways of choosing initialization behavior. Systems could run with zeroing in general disabled to improve performance and just use this feature whenever needed. However, it seems counterintuitive to me to have a prctl option to set properties of a range of memory. Is there a system call to set general properties of memory areas? 3. CONFIG_MLOCK_INIT_ON_FREE: Such a config could be used as an alternative to init_on_free (or its DEFAULT_ON config) and would be limited to the much smaller amount of mlocked memory. Again, this could not be used if you didn't want to lock the pages to memory, but would definitely be one of the easiest ways to avoid most of the init_on_free overhead with essentially the same security. 4. PR_INIT_MLOCKED_ON_FREE option for prctl: This would essentially be option 3. but even further limited to only the processes that want it and cannot ensure keys are zeroed before an exit/crash. This prctl option would take no further options except an enable/disable switch. It could be called once, in the beginning, to enable the feature. If the process then crashes, any mlocked memory is cleared and does not make its way to another process. After any key material has been erased, the program could call prctl again to disable the feature so no clearing is done when the process exits. Currently #1, #3 and #4 sound most applicable to me. Options #3 and #4 are probably a lot cleaner to implement, #1 and #4 should be more performant. From your experience, how often would someone want to seriously prevent memory from getting to another process without the option to mlock it? Is there any arguments I am missing? What's your opinion on these? Which, if any, do you think would work best?