From patchwork Fri Sep 27 15:17:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tycho Andersen X-Patchwork-Id: 13814410 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 54DAFCDD1BA for ; Fri, 27 Sep 2024 15:18:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2B556B00FE; Fri, 27 Sep 2024 11:18:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB2746B00FF; Fri, 27 Sep 2024 11:18:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B06356B0100; Fri, 27 Sep 2024 11:18:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8F6026B00FE for ; Fri, 27 Sep 2024 11:18:17 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3C648120CDA for ; Fri, 27 Sep 2024 15:18:17 +0000 (UTC) X-FDA: 82610874234.06.7ABF312 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) by imf13.hostedemail.com (Postfix) with ESMTP id 35CC520005 for ; Fri, 27 Sep 2024 15:18:14 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=tycho.pizza header.s=fm1 header.b=Nb7KPdXZ; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=X9fjwLSM; spf=pass (imf13.hostedemail.com: domain of tycho@tycho.pizza designates 103.168.172.159 as permitted sender) smtp.mailfrom=tycho@tycho.pizza; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727450171; 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: references:dkim-signature; bh=1MJeUQz3swau3AVK/0+TWO5a/QWf2ulbE3IH6vSxBJI=; b=PMNKD3CwNiIoT3vYZ419f/8sGXylY7f2BBuN279oU/S1/sWVMu6GGg12K4pkiOygIowYMO ooP1pxMkBcjIZzMsSfrTGhdl5PeV7zqwU3ahKwsOkqjV/kS1Ok26sucb0hvcRqiM6wZo4/ G59W4Ur2a//sz5Ft/ES2wKlfDR9zIR4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727450171; a=rsa-sha256; cv=none; b=XYEOm3fUdlvltvxhNMBwrQdMg0ROuZRVMbu6Zea8wK7GxwRedlMhv3OzXN5gFtYUQHPzDr uVSDoknVNeD2QHfOtr/nZz3TlpUvOwc7E2+OH6baxgFUO9dQYaU5wF9+LRXX48eawL6KAa /vqDbok9XIkK5NFaQVy9k0AzzWUkhNw= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=tycho.pizza header.s=fm1 header.b=Nb7KPdXZ; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=X9fjwLSM; spf=pass (imf13.hostedemail.com: domain of tycho@tycho.pizza designates 103.168.172.159 as permitted sender) smtp.mailfrom=tycho@tycho.pizza; dmarc=none Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 8A4C911401BF; Fri, 27 Sep 2024 11:18:13 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Fri, 27 Sep 2024 11:18:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho.pizza; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:message-id:mime-version:reply-to :subject:subject:to:to; s=fm1; t=1727450293; x=1727536693; bh=1M JeUQz3swau3AVK/0+TWO5a/QWf2ulbE3IH6vSxBJI=; b=Nb7KPdXZFSjhJ8Anh1 SnJYc1wgl4ONE3Bmff2Ln0JZ7/YdBmmJYG0Wb4/dAqCb47tl8OwJ3Xkcu2SDK0H/ imzCNbvglV4mmZxEvSVTG1dD2Gq6Bv9Txgsg0LP++zA49c5bR7jc1WsywbQ0C3dg jDMII71P92IPRmX7UICFCgZ5DPlYnvCWC/lLisk243eLJ1IpHW5S6fgrv22pVBjA Q0ISIMJwKPPYpEy0mgzXQrPJIqjRxYrZ+iHPKMNkNldNxWfxed0fy1z1n9FW9d7/ LQh62B6yUsLY+AHGVutq0FIHq2Ia6cq9Zhnwew5Ihdpxz+tfy+Nr1d5S7K4HU9kr /ikw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:message-id:mime-version:reply-to:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1727450293; x=1727536693; bh=1MJeUQz3swau3 AVK/0+TWO5a/QWf2ulbE3IH6vSxBJI=; b=X9fjwLSM4GotMVLhkIxg+GhurN2z0 Wh2y4OX/kg+W+c0mi7bz3XEDivZ496Otb7n3ooZUfatfZVOIMWV4BIWOH77FLkpl pGJK7lGi+uRhsGCU0dYqOgX933SzS0838T7lfnSRiENLXhfaK/iF9VWjbmaDc/ui Uk4Ye8MbrhDeKw+Lh6V6Rm7+u5/UIYBfcL8fA9SI59Ct6kR/batutbOZ2QRIEFfb lkBo7RJeC6KK+5SMpQN9sxuz4XePW//21H5uRyGBcBqhAiREGhmAPHyTj8Gvj8XX vatNHLYNn65CDcP6qY2WPMi8waXkZdInVR2aQPtLwIoDFFKBzsXh2/jtw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtledgkeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofggtgfgsehtkeertdertdejnecu hfhrohhmpefvhigthhhoucetnhguvghrshgvnhcuoehthigthhhosehthigthhhordhpih iiiigrqeenucggtffrrghtthgvrhhnpeeuueeujeffffekheevvdeiudffgfdtteevuddv tefhgeduffehuddvjeffhffgueenucffohhmrghinhepghhithhhuhgsrdgtohhmnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthihtghhohes thihtghhohdrphhiiiiirgdpnhgspghrtghpthhtohepudefpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehvihhrohesiigvnhhivhdrlhhinhhugidrohhrghdruhhkpdhr tghpthhtohepsghrrghunhgvrheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhgrtg hksehsuhhsvgdrtgiipdhrtghpthhtohepvggsihgvuggvrhhmseigmhhishhsihhonhdr tghomhdprhgtphhtthhopehkvggvsheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplh hinhhugidqfhhsuggvvhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthho pehlihhnuhigqdhmmheskhhvrggtkhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvg hrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhk shgvlhhfthgvshhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i21f147d5:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Sep 2024 11:18:10 -0400 (EDT) From: Tycho Andersen To: Alexander Viro , Christian Brauner , Jan Kara , Eric Biederman , Kees Cook Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Tycho Andersen , Tycho Andersen , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , Aleksa Sarai Subject: [PATCH v2 1/2] exec: add a flag for "reasonable" execveat() comm Date: Fri, 27 Sep 2024 09:17:45 -0600 Message-Id: <20240927151746.391931-1-tycho@tycho.pizza> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Stat-Signature: 17f1t459hd3wgp3pi49sxiwwc46j4gf1 X-Rspamd-Queue-Id: 35CC520005 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1727450294-635540 X-HE-Meta: U2FsdGVkX1/uSWTOvdueepaY0Ay4tO6mBql9PzMUbreF1Smblv8yboO1otd2MpJbDSZp5d66/5kKYDgIpoZ+V4E1nRXlStv34lqi2wAHWodToABrR5rw25Rkq18StXdqz3LYU//YXnNseru0tDkdQNYU/5kIFho7ef0Or2tuxnP3lSvVxZVLcQkUEQDXHjHhDspQ+jeoRJiolWRH4LTgID6Q1cgs2m61ncUMaihRH4OtG9//kiO0MmE7j27whDAk02l6ROu1W82e/nFOa4ftCVTK7V6izZ7NCckmQQjumQwKhm9uvUPQfz+oJs57xaMQumTefIgiNrECNFLwhbipqhIFm4Xu4eKHjsgeNwd6fHKwARoPP1aGauvKfHcyQI6gqJxsHzXd0obRaNpK4BqpWcvrjdZ/wafPwISUTgsRnGLpqM7dnijlYm5RUAa3b4a9twOdByhGpf5JtS2qURVuD2W3GXt9P+Hv7CP5RFyWpYcrUQvpyS3PM5Bd+MPaEezl++W5w/OFS0Oiuozk/A9s9r6JpuqpV6OTnJbzS5PV9eGIcTyAK8zM+l+BqYoFBTKKdqhT4ZwLeYDukF2cJ/8MJNcpXJgNtdlUje6q0y4MO/fMMXn7eRcd9BWOWCsFX5OYn23ESrKEurMSaLrd1jjLt72Fbwbsx+kfKMo5vZGXgBDTLrLEFsjZZbGmCAG/jN+PSdWFtYSzZ/8RK8FuUb9X9OsA6+7Q1c4A9aRr7SmsB46RmkeP8qZTaeZ65rkKeVP7W/S9iFhJnT/iBte7+o2GJQ09ODk3EXJHp0F5jHK7OSk3MTLxUshB9D+5COQb2xOEqtIu8lM6eRVtBqOTPXxPe13ARUOPQDORdWvboHLZugNC8XuGQij1Sb72Qw8WYYOB1ni04Dmt9CwCpZSIp440aLZUCgTiAb8Siw1a1gT+JgT7z5vX24bZ99OjAD+cs1EQWc6AYIEqlMblhSBhXSE 8Wdt5XKq FY43XNrNnwOinSAnbpsNTUupPoP7RAYO66ruiVoHBsiNqY35amgypxQ9UpaN77fI44J4AdLBsTGehH6znhrxwlOIeblk9PYXQKOsn90e7gnVxYHphsBKx7vu9kaSX1SX7V31rX5dQBkGvhdcyrXCk122P5P0e9buEYMfx/bmTRx/6d6K8h03lhs/VDY4zX62tfn6EPfai1sPVhhEcYKsH2Kj9GD25TbWsb4SBIKqWdj6YlG7SOBaF/P5OpfK0ZuxYSHnGwzskG9URQuwpIsOFzLE2LAu+z79/LysFzF7FVHxZtGl8AbbDZpCQvC2sJeRfkv+qMuYP5kDWQeYvpKOjqrXbe67j/4pgPgQLYjS0zEjptSEAhvQe4QA+uswxIBkvR+/w8GOaavmVBYo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. Signed-off-by: Tycho Andersen Suggested-by: Zbigniew Jędrzejewski-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(-) base-commit: baeb9a7d8b60b021d907127509c44507539c15e5 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); 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); + } else { + __set_task_comm(me, kbasename(bprm->filename), true); + } /* An exec changes our domain. We are no longer part of the thread group */ From patchwork Fri Sep 27 15:17:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tycho Andersen X-Patchwork-Id: 13814411 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 7CF90CDD1B8 for ; Fri, 27 Sep 2024 15:18:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2566F6B00FF; Fri, 27 Sep 2024 11:18:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B6376B0100; Fri, 27 Sep 2024 11:18:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED74F6B0101; Fri, 27 Sep 2024 11:18:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C615F6B00FF for ; Fri, 27 Sep 2024 11:18:18 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6AB0240F43 for ; Fri, 27 Sep 2024 15:18:18 +0000 (UTC) X-FDA: 82610874276.29.5FA6251 Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) by imf26.hostedemail.com (Postfix) with ESMTP id 6C6C6140017 for ; Fri, 27 Sep 2024 15:18:16 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=tycho.pizza header.s=fm1 header.b="O aGgv9n"; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="A jUy+z7"; dmarc=none; spf=pass (imf26.hostedemail.com: domain of tycho@tycho.pizza designates 103.168.172.145 as permitted sender) smtp.mailfrom=tycho@tycho.pizza ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727450259; a=rsa-sha256; cv=none; b=cXbHM+JdJDVygABDhYG0BE1jNElSfCsJDHHqGaJ23bSZfA5NupySm/4H6iO1BUdn2xtbCU 209avZ7NWFtkUpGDiDT8mYTyF0lMU3/bdOSmea6i4hqWVbrZ1jNfNqSXcHS//xn5nwn0wa Q4EHFFP+55Ekla6OlkJMFVSV3NugcE4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=tycho.pizza header.s=fm1 header.b="O aGgv9n"; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="A jUy+z7"; dmarc=none; spf=pass (imf26.hostedemail.com: domain of tycho@tycho.pizza designates 103.168.172.145 as permitted sender) smtp.mailfrom=tycho@tycho.pizza ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727450259; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jcSby7W+5uYeteUvGb/mYaE5eneel7efJMsI4xZNg/Q=; b=o+hWwOYxLQojES27kwbAEc0acYZGSn5qUzXjOm0eJpD/E+/4Xy10VV/y78uTkjMyZouzpJ NwIhslrpxqFBtv31k8iP5DXAWXh4VGxwr/misA5g0FtGpJAfG13wrjP7b5ePFB76nM968h 5R7dnny8B4b3QZ9LT2KBd2AyBHabknU= Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfout.phl.internal (Postfix) with ESMTP id BF56813802B2; Fri, 27 Sep 2024 11:18:15 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Fri, 27 Sep 2024 11:18:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho.pizza; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1727450295; x= 1727536695; bh=jcSby7W+5uYeteUvGb/mYaE5eneel7efJMsI4xZNg/Q=; b=O aGgv9nY/gvXmka7uEIvUyI2bcReYcLIrGXiC2EXnWt+6t/+3/pSz2aOwRahK5NGN S4w1LpVVLX0+T9WDe2cmujPbqbp7OfhaW9cZKw6wolwdr0KLQCU2J8X6l74GP3zP b71pzfbKjFsjrH0HS8yg/Buznwjlxmdg/d1W5IIHCXyjR9OgOBHq25HjgGtauHzG SbhTRjnAvrw8GMzHNAqjlCjcIkVu0U/+dSnoMbD1yILpYlZ6xaAJR5vu68+1Pklm iF2sJLkKIzeBZ37xp2MTlzV7Fwfg9GMIrAEq/t/WHbSsOkDjC25tReJRJPLMjeyf FqnT2H6YnE0aHR9ZPM11A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727450295; x= 1727536695; bh=jcSby7W+5uYeteUvGb/mYaE5eneel7efJMsI4xZNg/Q=; b=A jUy+z71oFyvq3G7NnTwpUPU9yVnmsM+V82bXRSyZUmqLXVa06AI4PYxNoge9NSFv MLrGAGndjUbPvblZBY6zscQfYm1qMXdPet6kSlYanG7OAvsIMUlfBkkuVixdkbl3 tgkNxetvMtqk/LqG/NL0kmW62+voaWY0ZvZ6bP/bH80rZ+ASXo2WXGWhyHg4IgFU jKlIjoBkz6TJmPTZRFetKfZB6oVn6YGlzbxUvVOAnesgTGcOV7xq+MEILp+xBiVH qwNTNCiQGeer/Pq5C4t6sPLL0m2l/jRGdHoPNTcG9OLXOsFyUCaBj7k/Upg36h1j zsYSMyvxT3PUF0n0z3IyA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtledgkeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomhepvfihtghhohcutehnuggvrhhsvghnuceothihtghhohesthihtghhohdrph hiiiiirgeqnecuggftrfgrthhtvghrnhepvdegffehledvleejvdethffgieefveevhfei gefffffgheeguedtieektdeigeeunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepthihtghhohesthihtghhohdrphhiiiiirgdpnhgspghrtghp thhtohepuddupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehvihhrohesiigvnh hivhdrlhhinhhugidrohhrghdruhhkpdhrtghpthhtohepsghrrghunhgvrheskhgvrhhn vghlrdhorhhgpdhrtghpthhtohepjhgrtghksehsuhhsvgdrtgiipdhrtghpthhtohepvg gsihgvuggvrhhmseigmhhishhsihhonhdrtghomhdprhgtphhtthhopehkvggvsheskhgv rhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqfhhsuggvvhgvlhesvhhgvghrrd hkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhmmheskhhvrggtkhdrohhr ghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdroh hrghdprhgtphhtthhopehlihhnuhigqdhkshgvlhhfthgvshhtsehvghgvrhdrkhgvrhhn vghlrdhorhhg X-ME-Proxy: Feedback-ID: i21f147d5:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Sep 2024 11:18:13 -0400 (EDT) From: Tycho Andersen To: Alexander Viro , Christian Brauner , Jan Kara , Eric Biederman , Kees Cook Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Tycho Andersen , Tycho Andersen Subject: [PATCH v2 2/2] selftests/exec: add a test to enforce execveat()'s comm Date: Fri, 27 Sep 2024 09:17:46 -0600 Message-Id: <20240927151746.391931-2-tycho@tycho.pizza> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240927151746.391931-1-tycho@tycho.pizza> References: <20240927151746.391931-1-tycho@tycho.pizza> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 6C6C6140017 X-Rspamd-Server: rspam01 X-Stat-Signature: 4ff8jai86i7xies8su34w5dzaei47j3t X-HE-Tag: 1727450296-363974 X-HE-Meta: U2FsdGVkX1+g6MAW5P1uVEFloOESflIHktXCEe/3godMwerwMWF83kVcdrZtIBHkqr71cGlmd2+zMnL/dM6ze6pv5eIOy+w5LG780GAFVlnPzT6lTwLCBlbZ9kmkwwjpTSZ0xL0VzlI9iPJ70YRia1+AiwZcqchW+8CMlzNdzNEn18PmQ5ICXzwrDfClDltzgqX/QDjNYXk/o1LSwfngG7llRD7oHfSxRM8P1rDizJtHlJcm1mfD2nFnm7dTh3+/i2A1rHKpnd4E9c3VCUA0GHjIH20u7TUM4tonFZp0TPW9wbLoL2JUimfH5B6V8DYVGf7EIuzbkDMrBTNAe+Ou1W6ghUE7AGkSLQK+/Z0jrcho3IUz+2V6qrpApoKAkhT4bLBpsvepDtypyc0KtyKMmSNiGafjwtI1Tekaj6GpSOB/sbpzAOnduuP/0wA6r34c3dKymbjV9i9LK5Xk1+csE+jq+0JhTT3gsM4kMWMVZnm/Rn1k49P/XX0run+Us2BO0QMlbnRzlT4JUWGiwi0hlb9GZpxv/7JE5DM8K7ZQgKpUA5PkYDKdh1nl+cHWCZ41zvZmNlv54jNUVP4Yf5c5iXrOI9v5107obJW/I/7WztEpMZ2KY2aU+EmP7oFnrdCXmezM6EoNT+4FfEMHcKd5GqcZMPYYUuNmm74pNOxl2X0i+/lJEhJs3ok+oUyo1nmfDDjjEbpU099nW0f+fS9jP8XwtceUANpQcqYycySX/4kpC2PYYRKD3EUej+jJZICkUmscsCNEMLwYW4bfCwaAvrNnv2T8XbXdPa1oEF+pZ+PTzBiEUf+VCjZWPjb3dsKMMzGQ5yHgpU02DxA3d0ZwdNZ9CoromoMBdc10OWtc0PMxCXfZH7eS9EBOTmB9MHVGD0HbZnI70Bp284aF5mbxO5icReZmJT8CVjlmZuXyfcVLdDgOk+CLkgEx66mqX5lS43TJXhOsplf9zov+4ac MT1gqAUt 8xqz7f7ab8xXN0qbPXPyVw6QCkbLmwQPhM3WFSxZxojPT5ydd8earWD4sXr2U6AGaWSjgDcZFEO2DJUul5L77keiSALnP+kdgHqU6q7wAGa6lTLpgQDhVg6jO9/9/SnbDLgu25MGX3E4y9pzAepMxT3TFqRlgc5DHDX8681rSTZs3Tk5KgIqGg/k7FcPfkogkKPFt+4qpDa4P21lCOHZ2L8nKV/eVJTxNrEPc0hkICYGnkEUGX4rs93I7lhrOAsUOTOeJnUbND7DPL/6BINB5E5tatQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Tycho Andersen We want to ensure that /proc/self/comm stays useful for execveat() callers. Signed-off-by: Tycho Andersen --- tools/testing/selftests/exec/execveat.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/testing/selftests/exec/execveat.c b/tools/testing/selftests/exec/execveat.c index 071e03532cba..091029f4ca9b 100644 --- a/tools/testing/selftests/exec/execveat.c +++ b/tools/testing/selftests/exec/execveat.c @@ -419,6 +419,9 @@ int main(int argc, char **argv) if (argc >= 2) { /* If we are invoked with an argument, don't run tests. */ const char *in_test = getenv("IN_TEST"); + /* TASK_COMM_LEN == 16 */ + char buf[32]; + int fd; if (verbose) { ksft_print_msg("invoked with:\n"); @@ -432,6 +435,28 @@ int main(int argc, char **argv) return 1; } + fd = open("/proc/self/comm", O_RDONLY); + if (fd < 0) { + perror("open comm"); + return 1; + } + + if (read(fd, buf, sizeof(buf)) < 0) { + close(fd); + perror("read comm"); + return 1; + } + close(fd); + + /* + * /proc/self/comm should fail to convert to an integer, i.e. + * atoi() should return 0. + */ + if (atoi(buf) != 0) { + ksft_print_msg("bad /proc/self/comm: %s", buf); + return 1; + } + /* Use the final argument as an exit code. */ rc = atoi(argv[argc - 1]); exit(rc);