Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3263055rwb; Mon, 7 Aug 2023 10:32:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAUPpBmTa+s+K9Tk3qjudP0hwV45ASUG1/7hGTSha+fHTp/j1RklZ94H8K63AlYXtg0JPT X-Received: by 2002:a17:90a:e605:b0:269:18f5:683e with SMTP id j5-20020a17090ae60500b0026918f5683emr8748266pjy.3.1691429557556; Mon, 07 Aug 2023 10:32:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691429557; cv=none; d=google.com; s=arc-20160816; b=VZYPRgCweUmpHT0KNaXWXUgUwPYBZBRwjt8tjTOY4JqIr/OyRuM+kSJRE7xF99NB0v 0VeXyc8pq+xJLJpIb+KGSwBONtL4KtRz9HNa5ZE4/XBoJfR7biwmOoJAsD7i4+zvnZQc K/i3/ix+qsddIz0zYoPJS+FcsZCd2vBy8bWoN/MSb/7AlPX7yadGw6/xqrU3VawukU9C B+4R5wCE7WcbsTQ1qb14n90uOJgx9ESSMXSeK3rvUahyAkWfs6XoXEnkgptokcIV8sTp u+KI0aIQ317YqFo/nrC5y1gkeR3HvmJ+y64FCeZWucG+4AJdnDJjewApqbb1vI4qaqxP gmDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=t8nMuHzZwKqpQ5hra5dFOZMtKSkVAkVzEJp74n54ePU=; fh=+pu8Up2/Ak8iV/Tt5cK3V8uJqVbTkH9oQDQnq94pF5o=; b=HGeVpOeSOcf8YKMOt7aIrAc7iwv//ONOtBq+mFjAwIDiWggnNtQ2m5KMB6n9/cvcbq xQ7u7bsQg7lS8VX3HQ/o4YOihshZHUwhCOSAcW/fIqiPcMYsiEHrB7CY2BYbXD0wLxPn Eg8ZvZGB3K7WTELVqmfWP3t3sQE/9qgDg03nmBgCW+hzdQhoafH0EKsRNAnzUZq8TPz5 zMZfKvnFzMyReAaipD7DLX3a4WpPNyHzUAGZxRnQSt9ymfW1zso7BL/CK7aW43F0cjrB vmzTTk5LRAF4IES1GPaIXmEEA2K6olgOVoAwotJ0N+OZRkWYVtsNWvuiUjT+35MNaBIJ qYMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MQYtzJaU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p20-20020a17090a931400b002639394cfcdsi6047136pjo.145.2023.08.07.10.32.25; Mon, 07 Aug 2023 10:32:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MQYtzJaU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231630AbjHGRI7 (ORCPT + 99 others); Mon, 7 Aug 2023 13:08:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231351AbjHGRI4 (ORCPT ); Mon, 7 Aug 2023 13:08:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 048051A4 for ; Mon, 7 Aug 2023 10:08:55 -0700 (PDT) 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 841C261FD6 for ; 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.