From nobody Mon Apr 28 12:23:34 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ZmN071ZWvz5vJPY; Mon, 28 Apr 2025 12:23:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZmN063VMHz3g3w; Mon, 28 Apr 2025 12:23:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745843014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DuhZCWuNyEQGYxZRZL9/xZE89Xj8gc1k4ROKl7k1bVA=; b=gm6lS8y//IujAe6A/ulGCHUyVwQj8IF9/wEDPxbOshy+wPTdkZIRYttTxs2j+C4nEdNjtv 55fmIUpfQmvbKJmgjCkNfTmzvMtt4iKh6GkSXB+cxxNOx7w/g+75hbYL6Qc0ta8m5DXv0D FDTjb6Pct1vTfBtnPy583cT9JNOUfufhEpxn4iKEtXHSRPHR4CKOL7HStrRmuN7H9K9HvN F1mZI75b+qrMgFq33eCN8L9rEuTMu9Xw2U27/sTPtczJXTeHKxYAhdWvHe+cTlxeMoqle/ zWbWE0EY2XJzSJW0Hzb8ozjX8McomdMei88MrFNXXfM43gVFvmBj1ssFFGxoDg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1745843014; a=rsa-sha256; cv=none; b=nh1ZDEjdrTFAMymIBl3WnynL0F5PwDXb8YmowDv8VGrxx5TMnYJTRltZeNZRM+qzeBprpQ ZDj9vwSpoyv5+WHk26TNAZaMLrsBU211dyBELeV8a6mOOydUqSiZIld/Iv+ZBGwsS9wLoC LT/gBG1X562uZVLrJnFoncn8gWX1fIZcuWiICqCcBp+VVD36o0uCSmp7qwXQDU0IvuDfMj VJOkY15QoVtMECQk8JhAEEg4+RPdxRJmdLfPcLp1ZP98+RVdbSN8/uf7MEf8EJkRuvFZQx cdROXH3JkD4W4bGB0OioAkZdu8wWzYpqEkOjNOojEYzl8H5Eup+52sbvzM7KfA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745843014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DuhZCWuNyEQGYxZRZL9/xZE89Xj8gc1k4ROKl7k1bVA=; b=F24bz7pjBCwmGQWMXXC8zbGzOvk7T183QKwHY9ryuzIHEAt5ly8PDzp9Jgy6uECYx5q3m2 FFPsXjwIXT+tRp3JrqJxK4bUdVwlwaI1fHNCBoEzw4AJDld8CjjV7utNM54i5oazxKKXTC /9fh1ZQ2h3enWo+IExYHxfd5LebKXZMZrFTuiFR1LoHjCm8YfMSrAdOONLepCN1bwc2TVy a7gmUVgqMWhm9oP69YQHoteAbB8Fijg7/SPsjnCTAAtOPSZMk+J9KHnch3luJzJobHBJ/a YHgg1WoAELgpZzMzV8So7aKimTE4Eq4We+7KgajZIY5s1x0DdX3Y1G0X8OCQ7A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ZmN0630n6zbSn; Mon, 28 Apr 2025 12:23:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53SCNYZQ025578; Mon, 28 Apr 2025 12:23:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53SCNYfm025575; Mon, 28 Apr 2025 12:23:34 GMT (envelope-from git) Date: Mon, 28 Apr 2025 12:23:34 GMT Message-Id: <202504281223.53SCNYfm025575@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: 1aabbb25c9f9 - main - ps(1): Match current user's processes using ps' effective UID List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1aabbb25c9f9c4372fd68621f8cabdc10b665527 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=1aabbb25c9f9c4372fd68621f8cabdc10b665527 commit 1aabbb25c9f9c4372fd68621f8cabdc10b665527 Author: Olivier Certner AuthorDate: 2025-04-01 09:47:25 +0000 Commit: Olivier Certner CommitDate: 2025-04-28 11:59:15 +0000 ps(1): Match current user's processes using ps' effective UID This puts our ps(1) in conformance with POSIX. While here, replace ad-hoc initialization of 'uidlist' with a call to expand_list(). *** Review of the ps(1) implementations in other BSDs, illumos, and Linux's procps shows they already behave as prescribed by POSIX. Previously, we would match processes with their effective user ID but using our real user ID. While the real user ID is meant as the real identity of a process, and is used, e.g., to perform accounting or be permitted to send signals to specific targets, selecting processes to display is arguably more akin to a kind of (advisory) access control. ps(1) is not installed setuid, so normally the real and effective user IDs of ps processes are the same. This may however not be the case when ps(1) is launched by another setuid executable, and the launching process may then logically expect that ps(1) lists the processes corresponding to its effective UID. MFC after: 3 days Relnotes: yes Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D49619 (code) Differential Revision: https://reviews.freebsd.org/D49620 (manual page) --- bin/ps/ps.1 | 26 +------------------------- bin/ps/ps.c | 13 +++++++------ 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index 532e920d1cdd..174f18a2f2d9 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -68,7 +68,7 @@ Other output styles can be requested via .Fl -libxo . .Pp By default, only the processes of the calling user, determined by matching their -effective user ID with the real user ID of the +effective user ID with that of the .Nm process, that have controlling terminals are shown. A different set of processes can be selected for display by using combinations @@ -980,14 +980,6 @@ However, other UNIX systems that provide this functionality do so via option instead, reserving .Fl g to query by group leaders. -.Pp -.Nm -currently determines the processes of the current user by matching their -effective user IDs with its own real user ID, whereas -.St -p1003.1-2024 -mandates the traditional UNIX practice of using the effective user ID as the -current user. -This is expected to be changed soon. .Sh HISTORY The .Nm @@ -1000,22 +992,6 @@ Since cannot run faster than the system and is run as any other scheduled process, the information it displays can never be exact. .Pp -.Nm -currently uses its real user ID as the current user when determining default -processes to show. -Besides being inconsistent with POSIX, using the real user ID essentially makes -sense for programs installed as setuid executables, which -.Nm -is not. -It also complicates the use of -.Nm -from other setuid executables, which cannot rely on its default process listing. -Finally, no other -.Nm -implementation (for other BSDs, illumos or Linux) behaves like this. -For all these reasons, the behavior is expected to be changed soon to using the -effective user ID instead. -.Pp .Nm ps currently does not correctly limit the ouput width, and in most cases does not limit it at all when it should. diff --git a/bin/ps/ps.c b/bin/ps/ps.c index f40f6160672d..bb79c6c9af84 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -510,13 +510,14 @@ main(int argc, char *argv[]) */ nselectors = 0; else if (nselectors == 0) { - /* Default is to request our processes only. */ - uidlist.l.ptr = malloc(sizeof(uid_t)); - if (uidlist.l.ptr == NULL) - xo_errx(1, "malloc failed"); + /* + * Default is to request our processes only. As per POSIX, we + * match processes by their effective user IDs and we use our + * effective user ID as our own identity. + */ + expand_list(&uidlist); + uidlist.l.uids[uidlist.count++] = geteuid(); nselectors = 1; - uidlist.count = uidlist.maxcount = 1; - *uidlist.l.uids = getuid(); } /*