Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1696063ybv; Fri, 14 Feb 2020 04:29:58 -0800 (PST) X-Google-Smtp-Source: APXvYqyE9ZZ63QcCq7RRROnDa46TyRwygI9V/GuxwvwdKhn1BzPE/ZGe+hA1VqJc+dq9oa0AyWYi X-Received: by 2002:aca:bb54:: with SMTP id l81mr1595202oif.175.1581683398226; Fri, 14 Feb 2020 04:29:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581683398; cv=none; d=google.com; s=arc-20160816; b=lWAHnX4Sginsd0HnJD6Lzs5a9pXS0kIhrHbr3EO8qlXRvzJPdFrRTz4QKqoF1K9Seo BottI55J05+us4dX0ISipal1hPySIGQJIfFXg/0sQq0IVwP9xB8gNfKMfriQ0Uv/oq+h fc+ZHvq64EB2YzwnSTAXgjTmJwNzT/wGC2xbJCPYMF+xF5fGtQ8RNgV+h1+avxhrEH8V wTw5fRQtW7Wo3CoyqYK8gNJJeoTmy9KoYY666mnnVSnwu7L8QVlKszzV/4XVs35LLqBa HUhaKfp5Xy8MOTFGs4JmhM/HC74lX/TIe3csxwdmHTSB9td8cEEHTPmVVW84XWKsVHoI zp8w== 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=xc4WS516pFX42lxkhoNGq7Crr1Y95o1kxkI3yhFQzMM=; b=QFofZsmQRsyvL1sdHNCtJyCWP0CjqxdjI1HoprA1KTqC8HAgRxggnAvdsX2WjGJ7UI AGeWfEJRzD/sxTSlpZv5YUOBbue1fctE1TjCElxJn4iZ2aH2hGsJ+E5/KNDSqlgysNxy NEgUdPIXpqPyTupL9HX+LfVUF6exRLpzsOxJCVDcmfzYTEkTxXSkQeRsEq+nXGKecmni lJowzIdF8rUNTFBqGdPq2d4+4ZGyb/Zummsz4EHEpE0dsfotZBWt/YEn17Eqx4fxhnQE 0Z97Tq9oNt/ocwxcd/EfZdal/vKURaJgTpb6imSSh098CC01ku+v+efBftgT5PBzPCBX 4a8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s22si3043011otq.100.2020.02.14.04.29.44; Fri, 14 Feb 2020 04:29:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728557AbgBNM3d (ORCPT + 99 others); Fri, 14 Feb 2020 07:29:33 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:34579 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728036AbgBNM3d (ORCPT ); Fri, 14 Feb 2020 07:29:33 -0500 Received: from [192.168.100.1] ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue109 [213.165.67.119]) with ESMTPSA (Nemesis) id 1N9dkB-1jWVY02UVB-015YK0; Fri, 14 Feb 2020 13:29:17 +0100 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/+HYf6EY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AQIACQUC 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: Date: Fri, 14 Feb 2020 13:29:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 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:U8ZVyuF3DsPZA0uzJN5toAoN1DG2ycJGri/DO6oMozoCAcFgTpH UrPLsCw9M4QNqhy7dXo4PYV0aC/GDnQDr8vKoVax+sLo4yIa2ASWjGSyUUnnvlGIA619Nyh Ws5WF6O5GB01SonhIZweJVaMZvXGZ0kmTzbJD5yt82LaX6t/5zyOWosIpIPlUT6/+JD7pz/ TPfttrK7h4xcOOAOOFFFA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:feaoCIt9mAg=:5iteKxbyY/lcCU9a9ty5Uu 3Ob4JXmpgm4VuLFB0m/v96QPBABhd60N0hbUqGBKLqiEUxsuRJQihvlrJO6HyCr1CcIB4z3pS gglj1HcIaIXytW2HPaT5zXe7FLwbH+p3mbEDjNOEx1ZGE9Yu5IVj2SZNL7Nf9Kq42ZJX5lpx/ MAgRlt/OHaSMEzTOsltjGCnKY3MJ0SxrfgkYNHhDrpfRlCr37XlBP5bLKtdsM/gnsgR6MYiDY Q27NRsfH7iK9wn1nmA2cK91k81r9050V4WIVwqep46ZKvHaCpGahzJEOVEeiLowvkz6KslRLq J1m5Vzo9nxCEoiEQXE2huSHxxZlpUTCOij+4IiScYQ7Fdnvl5xqy6oZYmTkfFd1GkYPVhhj5a h1x8t0qTEOpwLUrrUuUS3jVHYgRjV7jQZGETnwd2ab3p6oJOWj3+Jvu0T+1uSBzSVcZsetZz/ KbSeWBtUWLSflt9IlZr9L34IKKJ+jN2I/ctmgrfXrpBjhP8VFT73fqis8iexPG70obLK/zTWm pzcO1ilyOWKnPSqhu6lyfl5IbhZICqyUCrHbQUDV3La5e/euEaLz/B0hh/viuMCo3FstzXu7I TkSlQMshC9RK48hUNL8b9XsPkYTjXI89pZM6ReO8o2ACtcc8M700Exzw/Fk60JXz1XZfE0fo3 +DJa1dRcN/CTWREiPZxjOGddzvS0j+22fo6K9LddkAQZxZbiHSyqHRFi6n8eHHyVg1h6ck3je UBFsqGNNi/GBPP+G2YZQP2kYl1McWJRadNEmP3SYZST77DEAUMdzVrmI79JPYdExTldX2xziT tni5I1DjXkxjO1A15VF66lYFCuF+chPDUpBn6Vq9qQrPyZreBfrutovr6ArGoGYtXOUPNzR Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, any comment? I think I've addressed comments on v2. 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 */ >