Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3112920rwb; Mon, 7 Aug 2023 08:25:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGM2r9igTv0VKRDKVtE5zbRAhDDhxY8CJp4gCuQIZ29jwjFan+41aYgyziG2mZJ7Mt4AD53 X-Received: by 2002:a05:6a20:7d82:b0:129:c38e:cdd7 with SMTP id v2-20020a056a207d8200b00129c38ecdd7mr11009355pzj.38.1691421916426; Mon, 07 Aug 2023 08:25:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691421916; cv=none; d=google.com; s=arc-20160816; b=n3ctkYOlo87Gk+5HnSm4/NoiBLitfNpNFMkdo7qdeQbb7qcHpJ/qjy/n7AwTFzII61 Sl/gzT83xyKtuVFHLOfRfsFi7Jh0xjTPypFnqoTse2+Ne7iRIgNxQZJRtFiFv0LJwYAI gySJiAwa+O8BmyCKpHXF4Qm23CayZB8iTzLjstURHyFxQdsMquNcjVFyLsLgER26Cjlo 8Q4bRPj8Lra5cjomQmLAOA5vypTNhbYp5ByZ06+WjW5kdFmXRrmR+VTwsD+qTB9SoWW8 8s+4TMUEEyCtJg41142k1fCKr1qPIFNyHEOhAM/BmgNTR4nVGRA4bHhdWCxcfukoWzNG zq1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:references:in-reply-to:user-agent:subject:cc:to:from :date:dkim-signature; bh=QjQ3DEyVE9+VN9nFLr+5WI+x8UPWeJhCDao5Es/OMD0=; fh=6/Lj1uADY8KBefypZ4e1wnzmd5BH5eO3qv0NNQI5r0I=; b=cM1YyTH3WkdKk0Gg7l99r5QlbVFJ10SjVSEWzRQEZwxPDGhIeh+ByRph7N7jvm927N w+dt5L+sG4JY9sd7gEpmcLs1Oq0/AyYMCB41IMp/jAnMO5YNlmtzSu8NFQY+qE6xcObU Ko3TQt8zJ6/n97MnayPXFi8j78eEDu14y4gMJ2fzkhlvFMDyxfn1LJgSEjk0C0h+YskP Ets1HXUhJjM6sF28HQrcfnwY/a4nxNJG64jzSqfiKCw3/JNy830f/j2ji6swlnac/An+ alkOdMRIrYXwYa1aPOZ3FvDvvQz15lhgnjWEQs3UkVRVC/pIQ8uIHCWY3q/QK6kzxp0V fVHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YQ2NHZ70; 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 w29-20020a63935d000000b0055337508370si5636910pgm.889.2023.08.07.08.25.04; Mon, 07 Aug 2023 08:25:16 -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=YQ2NHZ70; 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 S234701AbjHGOpN (ORCPT + 99 others); Mon, 7 Aug 2023 10:45:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233922AbjHGOpM (ORCPT ); Mon, 7 Aug 2023 10:45:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5337C10F8 for ; Mon, 7 Aug 2023 07:45:11 -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 DC31361B4B for ; Mon, 7 Aug 2023 14:45:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31F1BC433C7; Mon, 7 Aug 2023 14:45:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691419510; bh=WSFD2bQVy6auzw96zhXrwKZKxc5XrsGkGJntb9ZP/4c=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=YQ2NHZ709ZPBfz767TYgsEfLBlbLGDdaUOcyZ+w4lteLGcMIynJ28+Q9pBzZ4QMou +P9BhMUpAv9wQsEWfUIEUVGA9L8UX4KV1VLayQ0+Ciic7/2vMxXkSc0hajVi0FPTDz n5hfXyaPToTKBhKzf/7/ZX9pCIu+Y0ONe3hVr7OFbZ+9dJdNdZQkmji3v/w0oPtNf8 730acCFilftvcDLViWK0aKMel9T4/q5OsW1XIJCG442nRaNOpjiZgTisytHRAocf4N 9E4TEOdghjBSC11/J7ayXmol8XoPB5bpnzugn6NqiV9jftvoj92KBT2jBEAgRgGMSI jPCI0EpQ3T9vQ== Date: Mon, 07 Aug 2023 07:45:08 -0700 From: Kees Cook To: =?ISO-8859-1?Q?Pali_Roh=E1r?= , Eric Biederman , Kees Cook CC: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: binfmt_misc & different PE binaries User-Agent: K-9 Mail for Android In-Reply-To: <20230806162346.v7gjoev2nepxlcox@pali> References: <20230706115550.sqyh3k26e2glz2lu@pali> <20230806162346.v7gjoev2nepxlcox@pali> Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 August 6, 2023 9:23:46 AM PDT, "Pali Roh=C3=A1r" wro= te: >Hello, I would like to remind this email about binfmt_misc for PE=2E > >On Thursday 06 July 2023 13:55:50 Pali Roh=C3=A1r wrote: >> Hello, >>=20 >> I would like to ask how to properly register binfmt_misc for different >> PE binaries, so kernel could execute the correct loader for them=2E >>=20 >> I mean, how to register support for Win32 (console/gui) PE binaries and >> also for CLR PE binaries (dotnet)=2E Win32 needs to be executed under w= ine >> and CLR ideally under dotnet core (or mono)=2E >>=20 >> I have read kernel documentation files admin-guide/binfmt-misc=2Erst >> and admin-guide/mono=2Erst=2E But seems that they are in conflicts as b= oth >> wants to registers its own handler for the same magic: >>=20 >> echo ':DOSWin:M::MZ::/usr/local/bin/wine:' > register >>=20 >> echo ':CLR:M::MZ::/usr/bin/mono:' > /proc/sys/fs/binfmt_misc/register >>=20 >> Not mentioning the fact that they register DOS MZ handler, which matche= s >> not only all PE binaries (including EFI, libraries, other processors), >> but also all kind of other NE/LE/LX binaries and different DOS extender= s=2E >>=20 >> 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=2E And distinguish between Win32 and CLR >> needs to parse PE COM descriptor directory=2E >>=20 >> 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 whate= ver it needs to do to further distinguish the binary and hand it off to the= appropriate loader=2E --=20 Kees Cook