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 629D1C001DE for ; Mon, 7 Aug 2023 17:08:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFC9F6B0072; Mon, 7 Aug 2023 13:08:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CAD1D6B0074; Mon, 7 Aug 2023 13:08:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B74C16B0075; Mon, 7 Aug 2023 13:08:58 -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 A78496B0072 for ; Mon, 7 Aug 2023 13:08:58 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6D97D8068D for ; Mon, 7 Aug 2023 17:08:58 +0000 (UTC) X-FDA: 81097943556.16.6E190AD Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id 970AC4001B for ; Mon, 7 Aug 2023 17:08:56 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MQYtzJaU; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of pali@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=pali@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691428136; 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:dkim-signature; bh=t8nMuHzZwKqpQ5hra5dFOZMtKSkVAkVzEJp74n54ePU=; b=fSN+gbrhfZPjJe4ZvsywwsTdcXQe6wZD1995oMWx7Jfj+rQ55pvIkK9Ete46LsHGD2u/X2 B1rN886gyv8ARd3Ec1vELpD8/o86SPE3iF0DuNmdJyCc9j56hW7wps24XE+IeYVH8RAYRi KA6ljWrqIeAf2Mw7sxl2y+uK+Agj5AA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MQYtzJaU; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of pali@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=pali@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691428136; a=rsa-sha256; cv=none; b=8LEY6F85Pzltth4RWdAZcyTPN43J4/PLye7y2qjYLDVy6HJpXWtbKOfxk0RE8xPby/lAdi YcBfPYoEbbezRjM6kb2WM9Qc9ZMb4vLphJQ3M9nBeLnmpxubm+r7u6A7c+IALiHZvSXD/l Acq2rarLGw84H3U69jDPYywPK8SXM2w= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7F73561FBB; Mon, 7 Aug 2023 17:08:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAA20C433C7; Mon, 7 Aug 2023 17:08:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691428134; bh=/dradSX2yLZH6YySu9JzmAAMU7c5OndtP3GUWy7HcxE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MQYtzJaUhVlDKiJAUcM1/TvdWybqf979ld58eWe9VivXxuOTBFm2wYowMDfCYCEnV A0Esa0Xuqqom/p3IfotPGySl6yxwbva4OIGKxKU5lPNbsQR6ucc0Xzk9meqaB4ycFR 05nMIHDTIiRTd6XsrpIiaFl8jVn4Obdaz2FohJwKNSRVXBO+OvO6jc3dez4k3IdE05 IWDfr9gKgSrwVK87aTqJrDTJCajGkh+mcSp143BAw/HeJSrXObZFtohKEwW0ONOo2t TwAwFHTEnjXN8riyih8OJU4ZO3ocspNzFPPajuGkrfrl9qeZkk/k+vXHrriiCUdatL Kc4CqUFVBj2ig== Received: by pali.im (Postfix) id 3B93F820; Mon, 7 Aug 2023 19:08:52 +0200 (CEST) Date: Mon, 7 Aug 2023 19:08:52 +0200 From: Pali =?utf-8?B?Um9ow6Fy?= To: Kees Cook Cc: Eric Biederman , Kees Cook , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: binfmt_misc & different PE binaries Message-ID: <20230807170852.yefmkcqwum6gdao6@pali> References: <20230706115550.sqyh3k26e2glz2lu@pali> <20230806162346.v7gjoev2nepxlcox@pali> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 X-Rspamd-Queue-Id: 970AC4001B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dyr6yaf6wzezyzzbfyup1dybn6my7md5 X-HE-Tag: 1691428136-510901 X-HE-Meta: U2FsdGVkX1/fWcm8FSaXCNgCubOAVw5DxlOFl7M2n3O1+Fq2bpQsES9DsKztOekTynqEdymBzxpJnrJTlXjk69lWYFrLFW5DlTuVD1brQ7QJ4GrZpY82bmuthELBR+NiDHd31X2/aJ4n9EJ2UrvX1/46f4AECCFyr+0Xp1V7QxmlyNqFvjNixCRUFXTktpk0BnZvLpVK6mrLcMT3fCffMVKHAzoUFGOeE863ciU7mESw4lH36t9qv0O7INavwCSXK/a7qGHjWQB044+XO1wvZ4IvjcxfbcHcaTkJYzWb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a9QZ3qUD9Zbaxo7ODgPcQEcoVc2BGynftuHxITn3Dr3ZKYBTLdzVyoUNJz44jdjVBL6+5ZrP91qdTigxq+Ks= 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: On Monday 07 August 2023 07:45:08 Kees Cook wrote: > On August 6, 2023 9:23:46 AM PDT, "Pali Rohár" wrote: > >Hello, I would like to remind this email about binfmt_misc for PE. > > > >On Thursday 06 July 2023 13:55:50 Pali Rohár wrote: > >> Hello, > >> > >> I would like to ask how to properly register binfmt_misc for different > >> PE binaries, so kernel could execute the correct loader for them. > >> > >> I mean, how to register support for Win32 (console/gui) PE binaries and > >> also for CLR PE binaries (dotnet). Win32 needs to be executed under wine > >> and CLR ideally under dotnet core (or mono). > >> > >> I have read kernel documentation files admin-guide/binfmt-misc.rst > >> and admin-guide/mono.rst. But seems that they are in conflicts as both > >> wants to registers its own handler for the same magic: > >> > >> echo ':DOSWin:M::MZ::/usr/local/bin/wine:' > register > >> > >> echo ':CLR:M::MZ::/usr/bin/mono:' > /proc/sys/fs/binfmt_misc/register > >> > >> Not mentioning the fact that they register DOS MZ handler, which matches > >> not only all PE binaries (including EFI, libraries, other processors), > >> but also all kind of other NE/LE/LX binaries and different DOS extenders. > >> > >> From documentation it looks like that even registering PE binaries is > >> impossible by binfmt_misc as PE is detected by checking that indirect > >> reference from 0x3C is PE\0\0. And distinguish between Win32 and CLR > >> needs to parse PE COM descriptor directory. > >> > >> Or it is possible to write binfmt_misc pattern match based on indirect > >> offset? > > Normally a single userspace program will be registered and it can do whatever it needs to do to further distinguish the binary and hand it off to the appropriate loader. > > > > -- > Kees Cook Ok, so you are saying that there should be one userspace program which distinguish between DOS, CLR and Win32 and then exec the correct "runtime" loader? Is there such one? Also it would be nice to mention it in the documentation.