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 86453C04A6A for ; Fri, 11 Aug 2023 19:05:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FAC66B0078; Fri, 11 Aug 2023 15:05:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1AA116B007B; Fri, 11 Aug 2023 15:05:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 072856B007D; Fri, 11 Aug 2023 15:05:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EB2816B0078 for ; Fri, 11 Aug 2023 15:05:34 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C0563C08C3 for ; Fri, 11 Aug 2023 19:05:34 +0000 (UTC) X-FDA: 81112752588.14.AD70679 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id 66DD840015 for ; Fri, 11 Aug 2023 19:05:30 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bnF9oyE6; 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=1691780730; a=rsa-sha256; cv=none; b=1ZdjBl3USJN/jtzx6wi0avhNUaPFbNEQ+GR2eMa03Q1yr3DecchnAj26gAAZIeeDs5dibw b1jlDNtYqqcnmHvgKmbdRglbmf00wre1HWTLHjU+3twjGjXjlgTjrxQfazn67amWiTaFXH tC3wAV7XvOTiTpHFXoyu5KmHUd1XpA8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bnF9oyE6; 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=1691780730; 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=UaEIoEPyIbrzcTu0e9mWV6KwjArPvWMZJhSaISbAzwg=; b=DxFn5TBo9Azs0gfYliX53FjiFiKa00+tYAGaLoWuRv25OGv2mya9WgxPqlNkXW2s+ZCrXE l9UOS14thbTlrYn+NsEjMmDr6a70Op7Ohpg3gDYemm9s5vYbT9GrtXEh1M+kG8HkXcFakU c+LoL+9GsS6QL+pBSTP2mdsVg3R3SkA= 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 4DC4463308; Fri, 11 Aug 2023 19:05:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5BBC0C433C8; Fri, 11 Aug 2023 19:05:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691780728; bh=Iu/6JyTKZAcWtIyDZiIJjyB72dUpwNi0RC+cpyo64zU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bnF9oyE6bpNSvNl0b4poM+UYLrc6CQNLRSuZlOmg92Ub/+5yzmBgVDItITihXTliP cqkImR+YsyrIa8Iv5IsedovuGIgMTFp7CR9bQ1WJ7ojUmxZYa5hjJ21y5ro6Eo8tiz ZWwttTULYH8YWgFCSTg5AUDwXk+rXkq10TOhFnt9Fj64voegf2MBcaNEf9JQ+40v+p qtVrLeH0XEpUs78SXx8Q5PHFxl8u1qr9tOqPMpaotXXim03Vm01sSPo7RPaYpj6Oyg WZrBG4+BXvPT2Ycm3FzZ3+B+fR8MofRrBTdzMTlv0gGo6UEUQdU7WmKwVugisd0Crr DNz1RanwvSlxw== Received: by pali.im (Postfix) id 557FB677; Fri, 11 Aug 2023 21:05:25 +0200 (CEST) Date: Fri, 11 Aug 2023 21:05:25 +0200 From: Pali =?utf-8?B?Um9ow6Fy?= To: Kees Cook Cc: Kees Cook , Eric Biederman , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: binfmt_misc & different PE binaries Message-ID: <20230811190525.hustdrwlgc232dmx@pali> References: <20230706115550.sqyh3k26e2glz2lu@pali> <20230806162346.v7gjoev2nepxlcox@pali> <20230807170852.yefmkcqwum6gdao6@pali> <202308101323.F17474FEB6@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202308101323.F17474FEB6@keescook> User-Agent: NeoMutt/20180716 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 66DD840015 X-Stat-Signature: iicupbafy641f1efwjozqqikbi61j5i6 X-HE-Tag: 1691780730-2646 X-HE-Meta: U2FsdGVkX18BLR+vhq/psgKp+PQKSxz3T1Qj8+fwJIqT67HgwMcGoivtsVlEm2f1jPt7zJUZ3dGNvLC1mDxXtynt0jQIv97MfwR4WZ8GZx7K+x+j6hjsZAX78QOxAWICm9EfEgCR676xIucc9xSV0uzUJwZaza9HQLEdNFoam2Zf6QZPE5vdRPmuU0h2b6BCsKPg5D9DKkshyzGy7XX5SAbrYMMFZp1oD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4drRRsuzWjz1ROHG2UqIgHaZF/Ks6uiUUBfPqmkwGZP8yr23PfZAi/S881YbREq1gfW/dDymBlEBAAY2/7reUlZfJeLBDRbKzwwvmmpZi+F1zpij4eVGfoOAXFh1Yt6keYAE= 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 Thursday 10 August 2023 13:24:55 Kees Cook wrote: > On Mon, Aug 07, 2023 at 07:08:52PM +0200, Pali Rohár wrote: > > 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. > > > > 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. > > I've not spent much time with it, but I think Wine can be set up to > do this? Hm... I have not figured out how. Quick look into wine source code and it looks like that for dos executables has wine hardcoded spawning of dosbox binary with prepared command line and config file. And for dotnet it executes wine's version of mono which has to be installed separately. Which is not really suitable for CLR/C# applications not dependent on Win32 API and also not very useful for modern dotnet / C# applications which should be run under native Linux dotnet runtime and which mono cannot execute. But I agree that this it is useful for C# applications which use Win32 API (as it is the wine who implements Win32). So I have feeling that there is no ideal solution. I will try to prepare some small deciding program which can act as MZ loader for binfmt_misc and which just exec the correct loader for binary after their MZ and PE headers. > Anyway, I'm happy to apply Documentation patches, if you want to send > changes that would make things more clear. :) Saying something that due to difficulty in parsing of MZ/PE binaries it is not possible distinguish between Win32 and CLR PE application in binfmt_misc module and that current manuals describe how to run all executables with dos header either under wine or mono (not both). I can prepare something. But I'm not sure when was this documentation last time read as it looks like that nobody asked such question. > -Kees > > -- > Kees Cook