Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp2260487ybg; Fri, 5 Jun 2020 09:24:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpmYjwNF/0R6xTdRgTbihY4DWof/Y6CoqwgSPRw0aYVg1pCAvoIzeYDKvyh8MoUfOOBoSn X-Received: by 2002:a17:906:c7da:: with SMTP id dc26mr10014266ejb.500.1591374264386; Fri, 05 Jun 2020 09:24:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591374264; cv=none; d=google.com; s=arc-20160816; b=pYUfgeRZGY9d95+5LZv6jwFZZHJy0JGTNEX6BtlFlzbgEdbE79X3BMVAr9nYz7z9ZH RcDF+RuXL7KmH5qs2e3L7ZsUWfUt0eRg2RMIiTHj11htFxOItk5fUFJ7uCg3pJTxPLa5 P6qiLFYGSAFkAgC73Ypi4djBJynhjED13O1/jHYhfzK0NQoHZDJEb7B6NupJqNuCDDJb 8oogPKEA2dzMCy+9yRJyb4xMnsZ+soVuEwsiwrkUFrd+gvDRtW81ieutv5L+HVbt0B40 LE+AGLAgJ++tQn0OCYp0Gw0wo52/HhuUbwMldgHYuSKNf2oNblctcW+kHHUp/a3JAg8b 6Dmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:cc:to:subject; bh=eX/oToLZRObYkCtHT3qsXHWfwDMpr8koB+mdtH2FYN0=; b=j0z29X7JWHHmclwO/0RFmZeKbGtmW02hpSBRIPX81bQAJAFSm9KKVswV5y1IdncXsW dbZhfL1LWAuUn4niIxEE7y9/8dFyT6AQ9AxRwMwP8wNM2dltcafApCc7ntS7yu1wi4Dl lKel3NHq5sk/PRA+FHuVcpzPOo5HIdaTafTBlgO8tQY1VWJsCAxm/p6KGC+Am1vOk7g7 W3peEyXtTh2RATgAbeweuX4Pxxu0VtSzryIqXcWoelokzwMqvju9+5jmW1OMT45tSk5x JXXB1L23TYYmhXjE0vTuIZScqcDdSsRmKGDP6pxiJlCRhlK7ogOm/YqhKPKNBjI+zYKG Owfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce13si854642edb.81.2020.06.05.09.24.01; Fri, 05 Jun 2020 09:24:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726639AbgFEQVJ (ORCPT + 99 others); Fri, 5 Jun 2020 12:21:09 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:33235 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726044AbgFEQVI (ORCPT ); Fri, 5 Jun 2020 12:21:08 -0400 Received: from [192.168.100.1] ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue107 [213.165.67.119]) with ESMTPSA (Nemesis) id 1MD9CZ-1jqHcy3E8H-00977A; Fri, 05 Jun 2020 18:20:54 +0200 Subject: Re: [PATCH v3] binfmt_misc: pass binfmt_misc flags to the interpreter To: linux-kernel@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, YunQiang Su , YunQiang Su , Alexander Viro , James Bottomley References: <20200128132539.782286-1-laurent@vivier.eu> From: Laurent Vivier Autocrypt: addr=laurent@vivier.eu; prefer-encrypt=mutual; keydata= mQINBFYFJhkBEAC2me7w2+RizYOKZM+vZCx69GTewOwqzHrrHSG07MUAxJ6AY29/+HYf6EY2 Woe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UC VgUmGQIbDAAKCRDzDDi9Py++PCD3D/9VCtydWDdOyMTJvEMRQGbx0GacqpydMEWbE3kUW0ha US5jz5gyJZHKR3wuf1En/3z+CEAEfP1M3xNGjZvpaKZXrgWaVWfXtGLoWAVTfE231NMQKGoB w2Dzx5ivIqxikXB6AanBSVpRpoaHWb06tPNxDL6SVV9lZpUn03DSR6gZEZvyPheNWkvz7bE6 FcqszV/PNvwm0C5Ju7NlJA8PBAQjkIorGnvN/vonbVh5GsRbhYPOc/JVwNNr63P76rZL8Gk/ hb3xtcIEi5CCzab45+URG/lzc6OV2nTj9Lg0SNcRhFZ2ILE3txrmI+aXmAu26+EkxLLfqCVT ohb2SffQha5KgGlOSBXustQSGH0yzzZVZb+HZPEvx6d/HjQ+t9sO1bCpEgPdZjyMuuMp9N1H ctbwGdQM2Qb5zgXO+8ZSzwC+6rHHIdtcB8PH2j+Nd88dVGYlWFKZ36ELeZxD7iJflsE8E8yg OpKgu3nD0ahBDqANU/ZmNNarBJEwvM2vfusmNnWm3QMIwxNuJghRyuFfx694Im1js0ZY3LEU JGSHFG4ZynA+ZFUPA6Xf0wHeJOxGKCGIyeKORsteIqgnkINW9fnKJw2pgk8qHkwVc3Vu+wGS ZiJK0xFusPQehjWTHn9WjMG1zvQ5TQQHxau/2FkP45+nRPco6vVFQe8JmgtRF8WFJA== Message-ID: <348e8e7a-3a2c-23b7-4a2e-d3f5e8a62173@vivier.eu> Date: Fri, 5 Jun 2020 18:20:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200128132539.782286-1-laurent@vivier.eu> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:CJWnNS6t81j4qzw3g9XQQQW/Krz79nyKBQKdvfN6saD7FitXX9b 2G6HkpgZuWObozbs2/Ob6IN4lAZJijGyWrceUxPADueFeCQ0WC5brR+O6eK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el.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ping? Thanks, Laurent Le 28/01/2020 à 14:25, Laurent Vivier a écrit : > It can be useful to the interpreter to know which flags are in use. > > For instance, knowing if the preserve-argv[0] is in use would > allow to skip the pathname argument. > > This patch uses an unused auxiliary vector, AT_FLAGS, to add a > flag to inform interpreter if the preserve-argv[0] is enabled. > > Signed-off-by: Laurent Vivier > --- > > Notes: > This can be tested with QEMU from my branch: > > https://github.com/vivier/qemu/commits/binfmt-argv0 > > With something like: > > # cp ..../qemu-ppc /chroot/powerpc/jessie > > # qemu-binfmt-conf.sh --qemu-path / --systemd ppc --credential yes \ > --persistent no --preserve-argv0 yes > # systemctl restart systemd-binfmt.service > # cat /proc/sys/fs/binfmt_misc/qemu-ppc > enabled > interpreter //qemu-ppc > flags: POC > offset 0 > magic 7f454c4601020100000000000000000000020014 > mask ffffffffffffff00fffffffffffffffffffeffff > # chroot /chroot/powerpc/jessie sh -c 'echo $0' > sh > > # qemu-binfmt-conf.sh --qemu-path / --systemd ppc --credential yes \ > --persistent no --preserve-argv0 no > # systemctl restart systemd-binfmt.service > # cat /proc/sys/fs/binfmt_misc/qemu-ppc > enabled > interpreter //qemu-ppc > flags: OC > offset 0 > magic 7f454c4601020100000000000000000000020014 > mask ffffffffffffff00fffffffffffffffffffeffff > # chroot /chroot/powerpc/jessie sh -c 'echo $0' > /bin/sh > > v3: mix my patch with one from YunQiang Su and my comments on it > introduce a new flag in the uabi for the AT_FLAGS > v2: only pass special flags (remove Magic and Enabled flags) > > fs/binfmt_elf.c | 5 ++++- > fs/binfmt_elf_fdpic.c | 5 ++++- > fs/binfmt_misc.c | 4 +++- > include/linux/binfmts.h | 4 ++++ > include/uapi/linux/binfmts.h | 4 ++++ > 5 files changed, 19 insertions(+), 3 deletions(-) > > diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c > index ecd8d2698515..ff918042ceed 100644 > --- a/fs/binfmt_elf.c > +++ b/fs/binfmt_elf.c > @@ -176,6 +176,7 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec, > unsigned char k_rand_bytes[16]; > int items; > elf_addr_t *elf_info; > + elf_addr_t flags = 0; > int ei_index = 0; > const struct cred *cred = current_cred(); > struct vm_area_struct *vma; > @@ -250,7 +251,9 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec, > NEW_AUX_ENT(AT_PHENT, sizeof(struct elf_phdr)); > NEW_AUX_ENT(AT_PHNUM, exec->e_phnum); > NEW_AUX_ENT(AT_BASE, interp_load_addr); > - NEW_AUX_ENT(AT_FLAGS, 0); > + if (bprm->interp_flags & BINPRM_FLAGS_PRESERVE_ARGV0) > + flags |= AT_FLAGS_PRESERVE_ARGV0; > + NEW_AUX_ENT(AT_FLAGS, flags); > NEW_AUX_ENT(AT_ENTRY, exec->e_entry); > NEW_AUX_ENT(AT_UID, from_kuid_munged(cred->user_ns, cred->uid)); > NEW_AUX_ENT(AT_EUID, from_kuid_munged(cred->user_ns, cred->euid)); > diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c > index 240f66663543..abb90d82aa58 100644 > --- a/fs/binfmt_elf_fdpic.c > +++ b/fs/binfmt_elf_fdpic.c > @@ -507,6 +507,7 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm, > char __user *u_platform, *u_base_platform, *p; > int loop; > int nr; /* reset for each csp adjustment */ > + unsigned long flags = 0; > > #ifdef CONFIG_MMU > /* In some cases (e.g. Hyper-Threading), we want to avoid L1 evictions > @@ -647,7 +648,9 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm, > NEW_AUX_ENT(AT_PHENT, sizeof(struct elf_phdr)); > NEW_AUX_ENT(AT_PHNUM, exec_params->hdr.e_phnum); > NEW_AUX_ENT(AT_BASE, interp_params->elfhdr_addr); > - NEW_AUX_ENT(AT_FLAGS, 0); > + if (bprm->interp_flags & BINPRM_FLAGS_PRESERVE_ARGV0) > + flags |= AT_FLAGS_PRESERVE_ARGV0; > + NEW_AUX_ENT(AT_FLAGS, flags); > NEW_AUX_ENT(AT_ENTRY, exec_params->entry_addr); > NEW_AUX_ENT(AT_UID, (elf_addr_t) from_kuid_munged(cred->user_ns, cred->uid)); > NEW_AUX_ENT(AT_EUID, (elf_addr_t) from_kuid_munged(cred->user_ns, cred->euid)); > diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c > index cdb45829354d..b9acdd26a654 100644 > --- a/fs/binfmt_misc.c > +++ b/fs/binfmt_misc.c > @@ -154,7 +154,9 @@ static int load_misc_binary(struct linux_binprm *bprm) > if (bprm->interp_flags & BINPRM_FLAGS_PATH_INACCESSIBLE) > goto ret; > > - if (!(fmt->flags & MISC_FMT_PRESERVE_ARGV0)) { > + if (fmt->flags & MISC_FMT_PRESERVE_ARGV0) { > + bprm->interp_flags |= BINPRM_FLAGS_PRESERVE_ARGV0; > + } else { > retval = remove_arg_zero(bprm); > if (retval) > goto ret; > diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h > index b40fc633f3be..265b80d5fd6f 100644 > --- a/include/linux/binfmts.h > +++ b/include/linux/binfmts.h > @@ -78,6 +78,10 @@ struct linux_binprm { > #define BINPRM_FLAGS_PATH_INACCESSIBLE_BIT 2 > #define BINPRM_FLAGS_PATH_INACCESSIBLE (1 << BINPRM_FLAGS_PATH_INACCESSIBLE_BIT) > > +/* if preserve the argv0 for the interpreter */ > +#define BINPRM_FLAGS_PRESERVE_ARGV0_BIT 3 > +#define BINPRM_FLAGS_PRESERVE_ARGV0 (1 << BINPRM_FLAGS_PRESERVE_ARGV0_BIT) > + > /* Function parameter for binfmt->coredump */ > struct coredump_params { > const kernel_siginfo_t *siginfo; > diff --git a/include/uapi/linux/binfmts.h b/include/uapi/linux/binfmts.h > index 689025d9c185..a70747416130 100644 > --- a/include/uapi/linux/binfmts.h > +++ b/include/uapi/linux/binfmts.h > @@ -18,4 +18,8 @@ struct pt_regs; > /* sizeof(linux_binprm->buf) */ > #define BINPRM_BUF_SIZE 256 > > +/* if preserve the argv0 for the interpreter */ > +#define AT_FLAGS_PRESERVE_ARGV0_BIT 0 > +#define AT_FLAGS_PRESERVE_ARGV0 (1 << AT_FLAGS_PRESERVE_ARGV0_BIT) > + > #endif /* _UAPI_LINUX_BINFMTS_H */ >