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 55CEBCDD1BA for ; Fri, 27 Sep 2024 14:56:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA80A6B00F4; Fri, 27 Sep 2024 10:56:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C570A6B00F5; Fri, 27 Sep 2024 10:56:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF7AA6B00F6; Fri, 27 Sep 2024 10:56:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 918946B00F4 for ; Fri, 27 Sep 2024 10:56:29 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 399B5C0A40 for ; Fri, 27 Sep 2024 14:56:29 +0000 (UTC) X-FDA: 82610819298.27.D64022C Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) by imf08.hostedemail.com (Postfix) with ESMTP id 0AC52160015 for ; Fri, 27 Sep 2024 14:56:26 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=tycho.pizza header.s=fm1 header.b=VgdlrTvb; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=iF7I47nA; spf=pass (imf08.hostedemail.com: domain of tycho@tycho.pizza designates 103.168.172.144 as permitted sender) smtp.mailfrom=tycho@tycho.pizza; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727448924; a=rsa-sha256; cv=none; b=ItCS7N0hZRQPJd4bqUsF8yIRGkT8ms8zoS4MRWyn17QubCijw/bAcx9fZqTFikt7Ec+Sp8 Yj5otpIDEtHRHhaiohE9Ymc5AjsOyi/T3rjFYB4zBPXT5swVFuy5+uNLP7KBAcL7vfOqTB 5mQC3naV4ecy3m+zuiG/wEO+ObkoAHw= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=tycho.pizza header.s=fm1 header.b=VgdlrTvb; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=iF7I47nA; spf=pass (imf08.hostedemail.com: domain of tycho@tycho.pizza designates 103.168.172.144 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=1727448924; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lCpfQdkJ67FKoocTx2z3FyOrYGH6Jp6LctLaGMXrtSA=; b=HxMRyRIktIIrRhr8GCgqVwrObooDc/IX6u/EEJKlkPQmJCc/HUL8YjlU/YsuuRyX0CVolp 54JKUVdKYGXepKvRKBUZhcZp4XEjOkQ3s9EpQd4VxwAQSSwURXPVDbMFkyl/cVHapDqo5K Z/HCRo/+c367AUCCzS0n1Pjmq1ndwnw= Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 677CA1380143; Fri, 27 Sep 2024 10:56:26 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Fri, 27 Sep 2024 10:56:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho.pizza; h= cc:cc:content-type: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=1727448986; x=1727535386; bh=lCpfQdkJ67 FKoocTx2z3FyOrYGH6Jp6LctLaGMXrtSA=; b=VgdlrTvbh+92Z+N91GjBhyRVVg op+dQK9nZOurC8zzc00XjCTbVbMSYbzp9nv6OYtywYLLvJIW9JpZgBySIDSonM5b qEfBlt5aVqjyqJIwqQTt5Pvs1o5Y2ZenSr/1t3D4MNrnn9am+ZcFppMZ6bBt2LxR Zhms1yNnfVh65VwHejMrQZ7GFUyAtiYUe6+puZbXUWi5OevULLOysLCRt/s5sIZj Dr+uV/Sm5WVoBboEMtviNSbu1tGhr2gBHdN6VT7aqDKIZ7qSGifk8Z2cTxchlixc /oLCmUhCFBUZLw8Snc1wRybhycad6/c0eukQOcLWL9i+N6Ab6UNJlqU8SRig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type: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=1727448986; x=1727535386; bh=lCpfQdkJ67FKoocTx2z3FyOrYGH6 Jp6LctLaGMXrtSA=; b=iF7I47nAUm+VHeZ0v731v0kbcVwAKvvrhGiDX5WcTLuX cCn+wyryAjXmUIopcug+Lm4WJLrNbeQUwUU3j7vc1aQSEng25aAfuJLvlX3y7zlH TE5WZ52k1LvJgKrnYumwN/7Gh55e5rOcgCqFr/kZOtAFj9mr+7muoGowgiwxbDdX Bj76Y8oZRJBD5RpZM/bdJRek4WLcfekjk0e5mXqH+YZnn9nBMSeV+CjKUJUVrQTX iAwKVG8e0guJYWjbVKGKRPRcFjNw2XLf8KBwf6FS/voMmXWBj8cYpvCVB4JUBSkS 5zkleevjYa7/p1XGmaP3d0zEMeDBuYOW0gLuRG9YCw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtledgkedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomhepvfihtghhohcutehnuggvrhhsvghnuceothihtghhohesthihtghhohdrph hiiiiirgeqnecuggftrfgrthhtvghrnhepueettdetgfejfeffheffffekjeeuveeifedu leegjedutdefffetkeelhfelleetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepthihtghhohesthihtghhohdrphhiiiiirgdpnhgspghrtghp thhtohepudegpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegvsghivgguvghrmh esgihmihhsshhiohhnrdgtohhmpdhrtghpthhtoheptgihphhhrghrsegthihphhgrrhdr tghomhdprhgtphhtthhopehvihhrohesiigvnhhivhdrlhhinhhugidrohhrghdruhhkpd hrtghpthhtohepsghrrghunhgvrheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhgr tghksehsuhhsvgdrtgiipdhrtghpthhtohepkhgvvghssehkvghrnhgvlhdrohhrghdprh gtphhtthhopehjlhgrhihtohhnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegthhhu tghkrdhlvghvvghrsehorhgrtghlvgdrtghomhdprhgtphhtthhopegrlhgvgidrrghrih hnghesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i21f147d5:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Sep 2024 10:56:23 -0400 (EDT) Date: Fri, 27 Sep 2024 08:56:20 -0600 From: Tycho Andersen To: "Eric W. Biederman" Cc: Aleksa Sarai , Alexander Viro , Christian Brauner , Jan Kara , Kees Cook , Jeff Layton , Chuck Lever , Alexander Aring , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Tycho Andersen , Zbigniew =?utf-8?Q?J=C4=99drzejewski-Szmek?= Subject: Re: [RFC] exec: add a flag for "reasonable" execveat() comm Message-ID: References: <20240924141001.116584-1-tycho@tycho.pizza> <87msjx9ciw.fsf@email.froward.int.ebiederm.org> <20240925.152228-private.conflict.frozen.trios-TdUGhuI5Sb4v@cyphar.com> <878qvf17zl.fsf@email.froward.int.ebiederm.org> <87h6a1xilx.fsf@email.froward.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87h6a1xilx.fsf@email.froward.int.ebiederm.org> X-Stat-Signature: 75ohwaqf1yypm7qeyi9dsonfc56t5iaj X-Rspamd-Queue-Id: 0AC52160015 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1727448986-694011 X-HE-Meta: U2FsdGVkX18WGxIQjNfgBVCGX6pV/P+I5DBLPt/YA+k3v/9ZRc0sddpEUcMTaEE9VY6gVl/jBzt8URiSw3C2F2PIqOKy6MlHfLypIZ9i4K9pWAoFb4Q2203IxELxQco3iErQ189zgx6Yqv2leAz0iN+yvCuPkIZqZO5bLROExdsU1rilI1y2alAoG6v5Dshs9DDqSFWJVfzM46Yki20OPNl5s2ZQR2BfYfxyk6RY4lzfbeQkY97koijT9Yj0AsIxw/if+AduhWjuthPe8Zg725NuUcSgKTR9J2OHoyvLzpVB/WhOeIK8GMJyIV7+/OgpM2IIj4W96ziugKeGbeQ+k4Os5+H/pBjS6Awxd5haaXLqRXhKz9CYv5y0MRcD2Jgl92iQrgUL8Jw8P8sRg4GyXglLJz9juB5l5T2qD8ncitMnlEAdHGOc4qDfiHUYGPVnpyyZ4kl5eFZrgF0y5YT62rngw8Q7ZgkE3sq9h+Zu9crBGL4AbptLFxXA0sKihWmJntbh7OfcZwLI9Pa/QJf24JlYXvx4yebKR2vpix0SGy/5Tz+IqXpkmSpLqrOjYDVGFyhCmDT99IDssqCwa4DJ5gAvoFZMp8GlFlld97JresvWDq5XW15w71qVGrdh8+kBBe5Rz/D1z2v2JBOxhMCMcLZROAXdXubXhsQwbXOi1YdU6Ol8M9BG4FPHRkEec+44PtJndRYrhsfUW/x06rrq5TxyGKsJzVRsR9e/jWh4mImnl3G6/IwJX3Niab1HTNrtLHWdR7hUHYhH5Q9ffVa7KlJSJCQE5o+a42lkrxGjoF3lxnrgASm7MjtwjrZYjqDbAh693MCVBWhulnC0RcEgpfAYkOjkPOmwB2XGxxL8sYw3eIw6gp9J3ePsmqRuGEJavj1dBTNioQBOIHqpa77HpmN6ZBUdvz6U0XZMnZW7cqxowN3JV30X/dbyffdtY+CdVObzGJfu7hy72JePUK3 ZPCYQTsd OCbi8FBbsgzFZYOLqQKTWWCN5tcEtbKtWkwlk4AKQ2QDo7Rgx2mCErwDyxSUZd9POD8Ad9iwATbDbKdTvJZB6WseykGSb4ZO1Qp0OZdLa3GS/ZNWF0TOXMUtxKYU1sU/5fhLjI2LXveOTZsmoQrST99hKQQ1DD58G3IPwo65fqRfwtj09emO6QOml5IVUc63z+D2S6CRN65ECkpOsHuiCuLC08ugw4Y7VOe/yCKBwS+xSLSuhYrPkw0h2eC7+7sY2QbMwEzE8/k9Eq5Xvsmv7CxYgd4TtdeI8nZ6lcUk+/GgPjGl478eLg0tg+EMkIuT6hyyJJmjXLFcrozn4stEVA6LmWvGx3dcP3hV/giCXEetax+4cPFPwh/LmUA== 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: On Fri, Sep 27, 2024 at 09:43:22AM -0500, Eric W. Biederman wrote: > Tycho Andersen writes: > > > On Wed, Sep 25, 2024 at 09:09:18PM -0500, Eric W. Biederman wrote: > >> Tycho Andersen writes: > >> > >> > Yep, I did this for the test above, and it worked fine: > >> > > >> > if (bprm->fdpath) { > >> > /* > >> > * 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. > >> > */ > >> > struct path root; > >> > char *path, buf[1024]; > >> > > >> > get_fs_root(current->fs, &root); > >> > path = __d_path(&bprm->file->f_path, &root, buf, sizeof(buf)); > >> > > >> > __set_task_comm(me, kbasename(path), true); > >> > } else { > >> > __set_task_comm(me, kbasename(bprm->filename), true); > >> > } > >> > > >> > obviously we don't want a stack allocated buffer, but triggering on > >> > ->fdpath != NULL seems like the right thing, so we won't need a flag > >> > either. > >> > > >> > The question is: argv[0] or __d_path()? > >> > >> You know. I think we can just do: > >> > >> BUILD_BUG_ON(DNAME_INLINE_LEN >= TASK_COMM_LEN); > >> __set_task_comm(me, bprm->file->f_path.dentry->d_name.name, true); > >> > >> Barring cache misses that should be faster and more reliable than what > >> we currently have and produce the same output in all of the cases we > >> like, and produce better output in all of the cases that are a problem > >> today. > >> > >> Does anyone see any problem with that? > > > > Nice, this works great. We need to drop the BUILD_BUG_ON() since it is > > violated in today's tree, but I think this is safe to do anyway since > > __set_task_comm() does strscpy_pad(tsk->comm, buf, sizeof(tsk->comm)). > > Doh. I simply put the conditional in the wrong order. That should have > been: > BUILD_BUG_ON(TASK_COMM_LEN > DNAME_INLINE_LEN); > > Sorry I was thinking of the invariant that needs to be preserved rather > than the bug that happens. Thanks, I will include that. Just for my own education: this is still *safe* to do, because of _pad, it's just that it is a userspace visible break if TASK_COMM_LEN > DNAME_INLINE_LEN is ever true? Tycho