From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BDC5CDD1BD for ; Fri, 27 Sep 2024 15:46:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 922386B0107; Fri, 27 Sep 2024 11:46:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D1D56B0108; Fri, 27 Sep 2024 11:46:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 772EC6B0109; Fri, 27 Sep 2024 11:46:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 571CB6B0107 for ; Fri, 27 Sep 2024 11:46:34 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 01700A0881 for ; Fri, 27 Sep 2024 15:46:33 +0000 (UTC) X-FDA: 82610945508.18.1252773 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) by imf07.hostedemail.com (Postfix) with ESMTP id 8D0FB40015 for ; Fri, 27 Sep 2024 15:46:31 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of ebiederm@xmission.com designates 166.70.13.232 as permitted sender) smtp.mailfrom=ebiederm@xmission.com; dmarc=pass (policy=none) header.from=xmission.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727451829; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5ko+xZoWIoeBC9Rrt8H3OazZOflpjd2dugI8umGnFTQ=; b=rGXxxmXIjDFiSXJyYcxXIyWf8JWNZa3m1TdQ0nywxrvIlb1THpM2CO4IE9rTWFSVOTkoN9 K81jSsHBLJ0A8MSD+BXOAuhVMR1UDk0aYxq4VHFs2G4ev6u1Pgi1PIcORhRsVvd1S0teAg PkVlktggW3Qe+H8NUk601+yNbxMhSwY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of ebiederm@xmission.com designates 166.70.13.232 as permitted sender) smtp.mailfrom=ebiederm@xmission.com; dmarc=pass (policy=none) header.from=xmission.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727451829; a=rsa-sha256; cv=none; b=wxyMllAfrOwEOlMzoW77gQUXdKvKpi9JKKdxPMzWUfPWChxb4GpOEwbPqBX46GtoK1WYzQ spj08w5jngaIObBChwLXfkYoahW+2lENRNpo27T39aT2wNBwMy5ClNwgup3p9aQkEUg4hc bkLsuDGNqgT12EuHl9j3KiiD5Vux+yU= Received: from in02.mta.xmission.com ([166.70.13.52]:36308) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1suDAr-00AfzR-Hh; Fri, 27 Sep 2024 09:46:29 -0600 Received: from ip68-227-165-127.om.om.cox.net ([68.227.165.127]:50292 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1suDAq-00Chi3-EP; Fri, 27 Sep 2024 09:46:29 -0600 From: "Eric W. Biederman" To: Tycho Andersen Cc: Alexander Viro , Christian Brauner , Jan Kara , Kees Cook , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Tycho Andersen , Zbigniew =?utf-8?Q?J=C4=99drzejewski-S?= =?utf-8?Q?zmek?= , Aleksa Sarai References: <20240927151746.391931-1-tycho@tycho.pizza> Date: Fri, 27 Sep 2024 10:45:58 -0500 In-Reply-To: <20240927151746.391931-1-tycho@tycho.pizza> (Tycho Andersen's message of "Fri, 27 Sep 2024 09:17:45 -0600") Message-ID: <87ikuhw155.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-XM-SPF: eid=1suDAq-00Chi3-EP;;;mid=<87ikuhw155.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.165.127;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX19JXeMpjE5lwEscr8j+IipPi94Su8pZcjo= Subject: Re: [PATCH v2 1/2] exec: add a flag for "reasonable" execveat() comm X-SA-Exim-Connect-IP: 166.70.13.52 X-SA-Exim-Rcpt-To: cyphar@cyphar.com, zbyszek@in.waw.pl, tandersen@netflix.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, kees@kernel.org, jack@suse.cz, brauner@kernel.org, viro@zeniv.linux.org.uk, tycho@tycho.pizza X-SA-Exim-Mail-From: ebiederm@xmission.com X-SA-Exim-Scanned: No (on out02.mta.xmission.com); SAEximRunCond expanded to false X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8D0FB40015 X-Stat-Signature: oqnsddwh84s5s95nm6fz4qx6i8yx9gbm X-Rspam-User: X-HE-Tag: 1727451991-72945 X-HE-Meta: U2FsdGVkX1/J3hQ0NeEZF18YOAChyLzZua9f7Pd9gbugEEDSpkLHEvAY7xJvEdU7JnIXyLnxZyFf6jv4jKKcR+7GThEG3hn06yi054Z4XSo39/DmG5YW+KFKVr+ac3IC6UkAHyXb++yYnz+h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linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Tycho Andersen writes: > From: Tycho Andersen > > Zbigniew mentioned at Linux Plumber's that systemd is interested in > switching to execveat() for service execution, but can't, because the > contents of /proc/pid/comm are the file descriptor which was used, > instead of the path to the binary. This makes the output of tools like > top and ps useless, especially in a world where most fds are opened > CLOEXEC so the number is truly meaningless. > > Change exec path to fix up /proc/pid/comm in the case where we have > allocated one of these synthetic paths in bprm_init(). This way the actual > exec machinery is unchanged, but cosmetically the comm looks reasonable to > admins investigating things. Perhaps change the subject to match the code. > Signed-off-by: Tycho Andersen > Suggested-by: Zbigniew J=C4=99drzejewski-Szmek > CC: Aleksa Sarai > Link: https://github.com/uapi-group/kernel-features#set-comm-field-before= -exec > --- > v2: * drop the flag, everyone :) > * change the rendered value to f_path.dentry->d_name.name instead of > argv[0], Eric > --- > fs/exec.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/fs/exec.c b/fs/exec.c > index dad402d55681..9520359a8dcc 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -1416,7 +1416,18 @@ int begin_new_exec(struct linux_binprm * bprm) > set_dumpable(current->mm, SUID_DUMP_USER); >=20=20 > perf_event_exec(); > - __set_task_comm(me, kbasename(bprm->filename), true); > + > + /* > + * If fdpath was set, execveat() made up a path that will > + * probably not be useful to admins running ps or similar. > + * Let's fix it up to be something reasonable. > + */ > + if (bprm->fdpath) { > + BUILD_BUG_ON(TASK_COMM_LEN > DNAME_INLINE_LEN); > + __set_task_comm(me, bprm->file->f_path.dentry->d_name.name, true); We can just do this regardless of bprm->fdpath. It will be a change of behavior on when executing symlinks and possibly mount points but I don't think we care. If we do then we can add make it conditional with "if (bprm->fdpath)" At the very least using the above version unconditionally ought to flush out any bugs. It should be 99% application invisible as all an application can see is argv0. So it is only ps and friends where the comm value is visible. Eric