From patchwork Tue Oct 1 13:49:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tycho Andersen X-Patchwork-Id: 13818043 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 CE901CEACC3 for ; Tue, 1 Oct 2024 13:59:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 190A928008B; Tue, 1 Oct 2024 09:59:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 14128280068; Tue, 1 Oct 2024 09:59:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFC9128008B; Tue, 1 Oct 2024 09:59:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D272E280068 for ; Tue, 1 Oct 2024 09:59:32 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 88F141413EC for ; Tue, 1 Oct 2024 13:59:32 +0000 (UTC) X-FDA: 82625190984.26.6FB1DBD Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) by imf02.hostedemail.com (Postfix) with ESMTP id 85DDB80018 for ; Tue, 1 Oct 2024 13:59:29 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=tycho.pizza header.s=fm1 header.b=pssqwj07; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=QjjWVV9R; dmarc=none; spf=pass (imf02.hostedemail.com: domain of tycho@tycho.pizza designates 103.168.172.153 as permitted sender) smtp.mailfrom=tycho@tycho.pizza ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727791130; a=rsa-sha256; cv=none; b=WewLDgGmYSq8ihZdHOzrwbLh/+6ZNynpgirMFTfp1tjmIQ3yFEGKXZZBQCCbVzrzHoxJqS ngzRtwXgV52jeyIEK6FbXDvnAZBidSgBGXNIoPyAlf8RiIPZX1WUqFjuH4srg0LuvJyjvZ NNxS7POkAuBhQUtGFmLrDzEmmQs/5YA= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=tycho.pizza header.s=fm1 header.b=pssqwj07; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=QjjWVV9R; dmarc=none; spf=pass (imf02.hostedemail.com: domain of tycho@tycho.pizza designates 103.168.172.153 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=1727791130; 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=unWHvxzfAjnkbvBw6nviBvkFZdeAWYaudeSrxpKDykw=; b=HvqFiLvw2IASYV6f2ZUfiycSZF7Ehqu6I4Y1pPBwluGtn9sf/6RuG4/dKxDczSLijLFXdi Gf9VEz2aXQyr4810sxxx1Zu0Zu3HPHykTW9Sg9Cv5JzdAf/XIYnvKj3tFqVl3Stzl6eY/1 bpqo3k64ATjFMfJ/lK0hv4Oqrw9chd8= Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id DFD5C11413D4; Tue, 1 Oct 2024 09:59:28 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Tue, 01 Oct 2024 09:59:28 -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=1727791168; x=1727877568; bh=un WHvxzfAjnkbvBw6nviBvkFZdeAWYaudeSrxpKDykw=; b=pssqwj0736RHy3+h8m 0rW29eeT5N3DbwuJBw1egM7Jjjc8JjdGG8vx1Ms7Xx5MkG1syA6O9bdMbu/Qy0jX YoXPpYjN+3JYkz8KMeorIj7ZoWYCzowGHmHbSPvqjQzUGlzFg6ZFfc08BALSydfd mUrDSvLBkxlMhz3JfZPGnsDAgWjIEFag5S3c4XRoCuY0W8V8T8uywY1ULsUf+enq kjUDG8D62/rDZCa4+RCTfGB19a0RoW457RICZH5hXv5vpbihyFiv5p4kwYWGULFv aSEtHAX6VFjv64CpnrSVnM/Im5rL+Fa50fRFZYn8ejVNPZK7zjnSUa2pef7tFDS2 OXrA== 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=1727791168; x=1727877568; bh=unWHvxzfAjnkb vBw6nviBvkFZdeAWYaudeSrxpKDykw=; b=QjjWVV9RrX987qwDX3uubrLJfXsqg DP4OQoVXPMPQzhVneNE0+/RCGI4dXokMK9466jOOOn7cIT9rm0te+0pFqHQJ1fkF WJQsqt18bSPcVRtTmJ3vWLet3AOXl1uTfvNxi4800LKxThOasWAWqZgMSe42GMt3 LOeJ+8aTU1G5uZxc5ExrkcClBoSTMsaFUVSyO/K5mnkZR6MQybrtdsTwrp6qe1Kg XveebKSycxyaOwqFUoKd+aKvemAZnzWIUoSj3eggaOb2vEF/UX0n9aiTCYJDTsdI 17+41DpSmVpt8nGn0JeNzilo4B50h/gmHPpUxFmKwOTzZI39WERZTe2Lw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddujedgieelucetufdoteggodetrfdotf 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; Tue, 1 Oct 2024 09:59:27 -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 v3 1/2] exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case Date: Tue, 1 Oct 2024 07:49:44 -0600 Message-Id: <20241001134945.798662-1-tycho@tycho.pizza> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 85DDB80018 X-Rspamd-Server: rspam01 X-Stat-Signature: 49hz5pa8ufjg7ab8t9ondiis1rzj8usi X-HE-Tag: 1727791169-624734 X-HE-Meta: U2FsdGVkX18C5Z746e1BtpjnAoB3eeNSJvoplvKGVGXwFMpeUyhA7bHQH65pAcwUie1nocuQZQSYlfm+xvsDetsD8wNsVTMV+2MEcDD4Kg/YUJu1b3Dn91sFsTeMSgODVJ3lugwoPUmlQdUT/oIIqI1KFZto+wEWMp3MfVrBVFNN45eOCNCt7nWg+KSTg/9B1uRWopvi1oxIgbATYYV25kkRhRmYnVSP+57zTMEl1GEezSWyvjHM2FG3v/5yDrHHC2g4DX+xfMp76gHuH2OdQPSusmJ/mrmRkW87JO5vB3pTAD6tG3IaFqtmEU/fLm+XvYLRaohEMazUCVSkCWj6tBDf6L6QXYwVM71J5DqGRKjwEigNoI+hDC/q3o2Bww4i3mueZUyP7RYJotFLjHIYTEfoWPWFng34rrD36WxH5b/o521K5DqzMdoVU38C0M3YJPMWaZ5mqYVUdheLZH9eezOb/uaMLt/g8CFPk0Mkk77D0uAie/OAjs/JRypiA6OQFqw38xRF5WawZADoUJ2neoQ3BDw+MMwAynbtak+dtLWa/095yo5Oi05pK85XmnTva18eB5S7KAow9L4MCqaeAy7ugrfw+kRqh1De1W+EVZ1JHvYLxpAjemkj0OMsbK28CT8N+19TKjOTQvU4IKl4U/sxSULJrUjtvqh3uaGmfSjOwro/nD17n5AVaSey8rXROLchGhSEpcTM0AoJAI4gO18cJ4c6pLlySxT3apCSvvh0hKiBlxklzJILT+HFAzTTyz25ojHnlItWqePpH+M1eluKLZtmjPakSdZ63sGyBAJXVIHSQOSrwyGY8zkH127fMuJpu3cDwOv3zH/D80axH0BZUcKkTOyJP7Lsjtc0mNa5h4jwYTmiyskpNpDJ6iIPp9ZM1mnZKXj++m6u+2UyaXXZV7KWoiQJjV3tiDBhtqbRZ98zaRtvvJ+WOvk4jXb+yoz3wQDGkUrUwVgZ1wM SthtEccT 981iDDD9uK/YSRs3MdxIzbvTirStrUG2jR6WF1D7sa9W2GSdYD7/APP2EGDwIEiKzgnKkxNZnZ3D8kuijxeCn0ba/5bLDOK/KsuSg7vND2fADOwWvP6LTLuPvVaVMQQchmVOlk5M43eE+NBDhu+RYVk/yhHXgVv9VqKBNsaLeJnPvqguS/hUhdhzOu7t+DkizPAAO6sjk+wn2LSR9K+O0Y+2mGywbXzRF3GRemcfrRnmXMouMxiZaqb+hUIzCh43Olgv03ctxijsZkfiw1CxcMW4pBf+d1p2CwSgwUvj7zapd5E10nnhRLy2eXuO9+FT5dYr2yVDWSNJAKt3APQjqb95nQR6iv/JVpGesXbPMKByQup7yxqVZ3a57E0mv+9dp6AU/Vwyv9Fv2xlTfyEOVcCeIcET58B4D25g3z88TaFiS9jCHezjNxoaj9sHdprmsCOMx 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 Reviewed-by: Aleksa Sarai --- v2: * drop the flag, everyone :) * change the rendered value to f_path.dentry->d_name.name instead of argv[0], Eric v3: * fix up subject line, 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 Tue Oct 1 13:49:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tycho Andersen X-Patchwork-Id: 13818044 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 E4126CEACC4 for ; Tue, 1 Oct 2024 13:59:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 736CD28008C; Tue, 1 Oct 2024 09:59:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70C71280068; Tue, 1 Oct 2024 09:59:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AD3F28008C; Tue, 1 Oct 2024 09:59:33 -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 43159280068 for ; Tue, 1 Oct 2024 09:59:33 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D48B2814D3 for ; Tue, 1 Oct 2024 13:59:32 +0000 (UTC) X-FDA: 82625190984.29.A8F0308 Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) by imf26.hostedemail.com (Postfix) with ESMTP id E510214001A for ; Tue, 1 Oct 2024 13:59:30 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=tycho.pizza header.s=fm1 header.b="g N5z/a/"; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="A HVl+I8"; spf=pass (imf26.hostedemail.com: domain of tycho@tycho.pizza designates 103.168.172.153 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=1727791131; 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=CwDcBj94Fql8GH06xBbMs3ch/iqzs1CkrXRqqD84R/HUwrcpCS6cSv6PiQzscdmz0rA5tj LHKxe6YOo0dzY53d5lpb/rB41KAABp4EhwNC8Uq1Kruge8+Njo2jaCMuXicvw4qLa0YDFs 1Yiz2XOO5mtaHeZfa/xJ4316HArXea4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=tycho.pizza header.s=fm1 header.b="g N5z/a/"; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="A HVl+I8"; spf=pass (imf26.hostedemail.com: domain of tycho@tycho.pizza designates 103.168.172.153 as permitted sender) smtp.mailfrom=tycho@tycho.pizza; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727791131; a=rsa-sha256; cv=none; b=UjBOKqXDsnPk8nrQ5WHVCt1QyDpLj8iVadonFQloqtUboLFP9DP8e5PT3E6DlOk4hcAvzh D019mRzK5A0Lxk7ZhuofTorQ2nYOtkJv9vzmh/HaqNUEJ1o0HkxAamp1pGxnnRFlH5eb3L jNTRQbTqlVsOQ5ZrxhB0IVXY0F5eWH4= Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id 60FD011413C3; Tue, 1 Oct 2024 09:59:30 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Tue, 01 Oct 2024 09:59:30 -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=1727791170; x= 1727877570; bh=jcSby7W+5uYeteUvGb/mYaE5eneel7efJMsI4xZNg/Q=; b=g N5z/a/iyRdao1WtZNXNECk6YIAmT7yLSEGJP3YhwYvDJKvJYZ0XhzasPsCbSVXPk 0dD7JBoaOs980RnGLrtTZ/18RTNe29uptwG35eF6lHIrr/EAB09lv9Ydlxr4srNH XSFIusvwFwD6oIPJmniPtL4vY2VRDDGDipfJYyOAKHZcK/aKWg8pQ5GMMB7VuVKx xGzEBetglynBN3Hcppu0M6gzFIv/NXqHQLu3WsWT5VdZRtJkkTpGHMfyw6l8uY0O NV3IohKYhg0U5I0dMfOss7TFczldK/NN5i+UUzzh8jQjt7VfyUVs4m+FPs0oHe1U 7ms9+TEa5R0jRbUyqAOGw== 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=1727791170; x= 1727877570; bh=jcSby7W+5uYeteUvGb/mYaE5eneel7efJMsI4xZNg/Q=; b=A HVl+I89YBj4SHx7zwYhyOy7tAg9w5f5A9DTKUEqiD5WauZOKPX9tMPT9bZ7xx6Zu Aw80Iy3SKIDkaall/OlIQr4ViRM7376x1B0LVXr5DX9BMSMbSsbm2fj6/QbsuV8s LWMIbwc4BF5TGu0ajlUO8CFMw90PWNb8mNQH6wzw5j6moVjf6+kB5qQkHu3g3cus EImZvX4QIZgA/ezV1zhd0LXuxPxvqrtga+WAwLqpYTBM3/h5RQafN5otyLm7N2oQ yrHOoNBRO3OF3pk6tOEM9UXox1hFrahkb16Ll3bW8cbKOCaUB0frDkoz0+Nv2Zgc lKpr/aDbdrOr7/vKTi2Ag== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddujedgieelucetufdoteggodetrfdotf 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; Tue, 1 Oct 2024 09:59:28 -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 v3 2/2] selftests/exec: add a test to enforce execveat()'s comm Date: Tue, 1 Oct 2024 07:49:45 -0600 Message-Id: <20241001134945.798662-2-tycho@tycho.pizza> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001134945.798662-1-tycho@tycho.pizza> References: <20241001134945.798662-1-tycho@tycho.pizza> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: qt73e9huf1yq7cydcwsfnqc91b4bz4yk X-Rspamd-Queue-Id: E510214001A X-Rspamd-Server: rspam11 X-HE-Tag: 1727791170-150379 X-HE-Meta: U2FsdGVkX19ugjDmj5TnRb1H172/MmtSjN9mAsaYwhlw6vxjQU0+NJqAlIAaMmwNy5Tiog+1vkvnMHZ0pqPtOHxV1xc2CSN6nNOCWIaPrpQSUMTUfiDHXGNGCP7UTxnLbbCVjE1dQ5mlhQnFsH56to6OJL46LTE6aOCQd15Y3kmYPfpdWEEnpOblDXO8+w2Fp6taa0NGgXoQx1PwqSBIQOpWRNNYyx3r1H1wfuwQhBEfqKk5j8g4LcEC0HQkEfb7jTvaStofLMC5low74jPYArUIx32HfQCQ1vKaItHbdCAjznHjF9hIHE3OWADCOAACWZhtKj6OZ0dm0bNAHtQ1E6nz/D1GTBN71BsNVueaduXX+uM0jLRLk+ItU5vphT3/8GPoQ6Mi6VDTtQWPvh1F5Ct+b7LPp7tbO6aKdGsPwwun+J3fzK1rhkRFAzFQtpouopK1QDgVoD5aqah8zCFHcrCmuPo9o6rDbRn2uXSawF//ojjK/xTikRcCeqC7zjlw09HOWS2YNRbTjtubPcSKD+Rk/DctNii/92KkPo6y7mJk47LMl/ylBdaAXQ5UKm1NRsTVXVoHt3dzLRfSvC63s3RtEMyY0FcMxlCODoKp7IvAfsAb3b5vGl23J9fcV0o+NA8l1/uqoQGRToXYi00d2s7WRluVyXis9FfrnmrXBNXMYhPrlvmt7mAIk7kce741nvjaqxYb+Oz7Exqe71GaXaaFUFKwezzlpXJlrWAj6r8A6fQJavM8xFRXEW1IQrmU9H1xSJAOdxo+WkJEVZwOiWSTb3+tdXjmLINCZcbH2KC73dew+wlUgMNCZufoWvmfYhs3W25M5KnQT0Tniqw65LD/JOpVn+LZpir4fVowBmiOvh9mbXsnygFaFI9kOTIBUxWnpRBvdGLTqGoIYjUjTBTxJp0tAIs6Ui1mSnsrDERtuuNpCsgRtxk68OcgwJ69jiS/s2OAY9l6LCF+3vn KGHm54/6 jdES3fUdXnS+frd1BR3hAIM/VPmJLUTyXbeW8ePfMoiLfqWZRKQo0ubud/VYA8D5CgzK4uQjXv/tsXlMV0aKdCfOTPhJhk/NnCxegXjuVpp6I4CMAd6QpV8/wwzjXxlB0zH/fGnL0GVUoRaZ/Ftp5teqjmV7RmlSArt+c/KSwHDetklc3RLlw3Nk/TtKWYZE7CV2gsIFurHyICQgX6J38qdPR+blM8OSiMNzu1mloXt8UanZt5GL/UoS1xmDsdRS63D25LFQxhrbTn43N0YhKt3928w== 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);