Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7576678ybl; Thu, 16 Jan 2020 01:56:04 -0800 (PST) X-Google-Smtp-Source: APXvYqwicXZw3tj7z5hFRmra68QM0mmjiFgTV8dm9N5Wfj680aGY31lLmkW+xJeahQjukUl8vU8s X-Received: by 2002:a05:6808:197:: with SMTP id w23mr3563665oic.46.1579168564196; Thu, 16 Jan 2020 01:56:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579168564; cv=none; d=google.com; s=arc-20160816; b=BAP3N54UG9sEG2ridrx3Shtbg53kxT6RJMOGEOKDLWdCz1JdCoyvsIfAUWUuBpJTib lwI0c9nLfAftQio774FHTGuUVbb0JcmdInu3BltmzGv7GJ1nVIPRU352bs9YMv7leGZk EyNk9PdQyjW2BD8iZlY4aCJPQAUKtGsydQaudS/RRV/fxc6QtCjRuNgYakYP454RYfro kEhQ34YBvP4bT2gh/69DVmJxt7LQ9gK+M63XSO1lM7TcbWcmpABrwhsduxteVq6AKFNa Dwkh8PMmdcnBdfqgt6nA8Z2bzVXXgcIaOnL42UXu2tZwjbJa7XdcfjP8aGSPp0yk0Axy PmyQ== 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:subject:autocrypt:from:references:cc:to; bh=+hVSkYukoDD4InsMgjmkNtHpc3Zp/XuV6FNIXFfYOaw=; b=pKHWCC7fWW01EuA+ArMtInE7IBX44ekJjVJkmVXTGs6CKzhovT1+YwvP3pgdKWwVAx dQ25rtO9S6M5owCFMT/+fjArwR/bJxSEO1zKuXPCw/6WADGOq2Ii3XK5TVAYuP3Ez1fg /p4f1+ym9qVsGCSE8gU7G2+j/cQ6O4IbUPSGHao4wMvQCrIBMfbogtiO/HFWRK8sTALm lG7G9Y6WcjSEWrLEv+2UB2jGt/3ZM6rxfKmKAU+dlT4dzHMYSsGKx62VxGzErbOeeCzk EIw6mwxs3Rl1OTwBivC+AqI9GddokLaIwvmq8qlShLUIVYof1u4lwXQjCFv5e17XR9NA fizw== 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 g8si11033005oia.262.2020.01.16.01.55.52; Thu, 16 Jan 2020 01:56:04 -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 S1731526AbgAPIwU (ORCPT + 99 others); Thu, 16 Jan 2020 03:52:20 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:59187 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729427AbgAPIwT (ORCPT ); Thu, 16 Jan 2020 03:52:19 -0500 Received: from [192.168.100.1] ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue108 [213.165.67.119]) with ESMTPSA (Nemesis) id 1MVNJ3-1j2lrh3jeR-00SNca; Thu, 16 Jan 2020 09:52:11 +0100 To: YunQiang Su , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, James.Bottomley@hansenpartnership.com, viro@zeniv.linux.org.uk Cc: YunQiang Su References: <20200116083031.174367-1-syq@debian.org> From: Laurent Vivier Autocrypt: addr=laurent@vivier.eu; prefer-encrypt=mutual; keydata= mQINBFYFJhkBEAC2me7w2+RizYOKZM+vZCx69GTewOwqzHrrHSG07MUAxJ6AY29/+HYf6EY2 WoeuLWDmXE7A3oJoIsRecD6BXHTb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++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== Subject: Re: [PATCH v3] binfmt_misc: pass info about P flag by AT_FLAGS Message-ID: <47d06a3c-eb5c-7824-b443-0f0e64fab38b@vivier.eu> Date: Thu, 16 Jan 2020 09:52:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: <20200116083031.174367-1-syq@debian.org> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:s5O2ppCGHU2XOLDKAZsCq6fl3JlKhF5CMFLvjO8GMUj2u9CLTB1 1qmZFKIFPZIe5iXxaTGTAo5/oFH9dRksVOUb5DuQDA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HpecBhENJ6iGOaTLI 1mvsaxrTeAv1LWBblXHwMfzICkWNlcBxBDrbOf+Y4= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 16/01/2020 à 09:30, YunQiang Su a écrit : > From: YunQiang Su > > Currently program invoked by binfmt_misc cannot be aware about whether > P flag, aka preserve path is enabled. > > Some applications like qemu need to know since it has 2 use case: > 1. call by hand, like: qemu-mipsel-static test.app OPTION > so, qemu have to assume that P option is not enabled. > 2. call by binfmt_misc. If qemu cannot know about whether P flag is > enabled, distribution's have to set qemu without P flag, and > binfmt_misc call qemu like: > qemu-mipsel-static /absolute/path/to/test.app OPTION > even test.app is not called by absoulute path, like > ./relative/path/to/test.app > > This patch passes this information by the 0st bits of unused AT_FLAGS. > Then, in qemu, we can get this info by: > getauxval(AT_FLAGS) & (1<<0) > > v2->v3: > define a new AT_FLAGS_PRESERVE_ARGV0 as (1<<0), so now we use 0st bit. > > v1->v2: > not enable kdebug > > See: https://bugs.launchpad.net/qemu/+bug/1818483 > Signed-off-by: YunQiang Su > --- > fs/binfmt_elf.c | 6 +++++- > fs/binfmt_elf_fdpic.c | 6 +++++- > fs/binfmt_misc.c | 2 ++ > include/linux/binfmts.h | 4 ++++ > 4 files changed, 16 insertions(+), 2 deletions(-) > > diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c > index f4713ea76e82..c4efff74223f 100644 > --- a/fs/binfmt_elf.c > +++ b/fs/binfmt_elf.c > @@ -178,6 +178,7 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec, > unsigned char k_rand_bytes[16]; > int items; > elf_addr_t *elf_info; > + elf_addr_t flags = 0; > int ei_index; > const struct cred *cred = current_cred(); > struct vm_area_struct *vma; > @@ -252,7 +253,10 @@ create_elf_tables(struct linux_binprm *bprm, const 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, 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..c89a4630efad 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,10 @@ 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..cb14e9bbf00f 100644 > --- a/fs/binfmt_misc.c > +++ b/fs/binfmt_misc.c > @@ -158,6 +158,8 @@ static int load_misc_binary(struct linux_binprm *bprm) > retval = remove_arg_zero(bprm); > if (retval) > goto ret; > + } else { > + bprm->interp_flags |= AT_FLAGS_PRESERVE_ARGV0; Keep BINPRM_FLAGS_PRESERVE_ARGV0 here. > } > > if (fmt->flags & MISC_FMT_OPEN_BINARY) { > diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h > index b40fc633f3be..380a30a46db1 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 AT_FLAGS_PRESERVE_ARGV0_BIT 0 > +#define AT_FLAGS_PRESERVE_ARGV0 (1 << AT_FLAGS_PRESERVE_ARGV0_BIT) > + I think it should be added in include/uapi/linux/binfmts.h to be shared with user space (external API- Where is defined BINPRM_FLAGS_PRESERVE_ARGV0 now? It should be here (internal ABI) Thanks, Laurent