Message ID | b11a591e085f1cd06adb454b1f7cde676d317318.1680585798.git.josh@joshtriplett.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2800394vqo; Mon, 3 Apr 2023 23:03:18 -0700 (PDT) X-Google-Smtp-Source: AKy350Z/x+/kRS2totCLkVSxWEutfJ5+uJ44hkCLV8kW2/f6VK2gcMUJsygooE5Ni8kZq4xbPri5 X-Received: by 2002:a17:902:e0c3:b0:19a:6acc:1de2 with SMTP id e3-20020a170902e0c300b0019a6acc1de2mr1251050pla.35.1680588198512; Mon, 03 Apr 2023 23:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680588198; cv=none; d=google.com; s=arc-20160816; b=eAX7rNRWJcjFF+jO1Tf+GEEf7wR1hGDWFH+w7MfaT9nzBgKY89j+UXR6skiaOTtieW xtEfAbZnHh+tkcM8moHGIsKB2HXRYrj7RZt1Ojv27/vQpvoP639Qnc7u/Ho2cUamCxIw 38f89lsA/UfsDw7DetY1yaUiWV5cPswG+FRv0i6Sj+JD9Z8IJCFrCiEn0srNCegHndyY 9jCQEK/TTYyQAwwEofGCkgrIS4OOgccQumuQS56dQE/UK89gw+UYIJf3ms3sljwLTVwk wap7OoB8Y7jOcsk2XjJLNzwBB4JVwxvUCQdxs3lOn08x3pkZGkD9OIwqgaZbqMIonhXM lGPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date:feedback-id:dkim-signature:dkim-signature; bh=LrTlRnC1PMOEduoHyaDrJIwpQILB4R4Y2q12p1O1Lq4=; b=v0+3DMfuggjrKalwAbAMxIzwN0XlqcWMCRj28Il58WioP4Ves/iYtiSQlTt1imEBoa cPbeRhQf8rjN2PkIYaM0BH7WYXSvdS2mQcgLrTHfNFYju12fAitXn1wPf+HaSZL9xErD E1Gwyjj5SYd/MviPDJVfxe3sYWDcH0+6R2b+24M3auzXJWwNIHR4pAjOvE6c6ZTBGt7H Z3vpCXytDWCd6y5laH5Y8FCmpp08ajvDULso2Wv+Fcpdl8ZKcedHIAs69PbI3Ke1gfcf vQVGSMfJa+lJJ1NkPlusxeJqf7qNblkli0NbVYSp+SipHHgtoXJddBbqwyYpGDxXcK1B phYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joshtriplett.org header.s=fm1 header.b=TVQd44oY; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=trYbBXo4; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c4-20020a170902f30400b001a0492c419csi9194127ple.523.2023.04.03.23.03.06; Mon, 03 Apr 2023 23:03:18 -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=@joshtriplett.org header.s=fm1 header.b=TVQd44oY; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=trYbBXo4; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233557AbjDDGAb (ORCPT <rfc822;zwp10758@gmail.com> + 99 others); Tue, 4 Apr 2023 02:00:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233184AbjDDGA3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 4 Apr 2023 02:00:29 -0400 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 455711992 for <linux-kernel@vger.kernel.org>; Mon, 3 Apr 2023 23:00:27 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id B8082320096F; Tue, 4 Apr 2023 02:00:25 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 04 Apr 2023 02:00:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= joshtriplett.org; h=cc:content-type:content-type:date:date:from :from:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to; s=fm1; t=1680588025; x=1680674425; bh=Lr TlRnC1PMOEduoHyaDrJIwpQILB4R4Y2q12p1O1Lq4=; b=TVQd44oYV/EGE32s1j U2FtduT+QMuANL8y4onAgbmKKMM/FqVE0EImoq9XSjzYsMgl97KwCFjN1tNKNNig cWqI/KOygYxL3q5YAkffb9TL6FDpM58aLSeCiQAW8j2YeDeN/4pD8dZev1OvueCu 6z6eQH9PdG19ABcWHXZNVhvqRl6NN3bRJsO6GCKXq61Hw0t0f+fqg0BWaOmCjhNf TWiNCElsY/dZsI91vE8Fe0rBnANoYdv2EQxoWMUWUtnoT+g2kDNTDtyoJN3TWuXg BlanORl+lotAHUArBd/stRjGPHRBLFpEme6U4xP9nqlb35GkYO+RBPj0LEof8Vnn 7UTw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1680588025; x=1680674425; bh=LrTlRnC1PMOEduoHyaDrJIwpQILB4R4Y2q1 2p1O1Lq4=; b=trYbBXo4nZv9yYGIl660K02BlRjcUspug0z0uEJXchR0X3vVizm CWYp2aspxKTqM9H3SIhFZujUCmPiTQtnw16Ur6xG0fqdcWN9ts+KJViNLM2/c9Qj KHkZNxx0rH7DkboOcSTCxPB7zordka1C1toU/ffxhO0jGDOoq2AQQDRvCGy3mQHd o9GUutruWvP0B2SncJ5QjfMlvHMKlR2s/LQhCK+6ze9IlDFQQmF/a7eg6FguHT4c vaM2d9NaKnP2+OuZLOS9eCkmy18L7pwaXaMby59Mk4IZtnuLFQndsj6VnRkbdWsh FzrkGS0XNPKV/TbNOyiEkfzNRG3LyGN5XBw== X-ME-Sender: <xms:-bwrZGy1tLfxDnxTQBIYYvCZ10GZmE9xohspJO8R0zeaXq7Jc80DJA> <xme:-bwrZCRjdsIq38OHOOEjOvTHiyTrSrGRfnwVnDANG8_fBEM4PpM3FTnj-uQMze8YB NuLT5vyKXCntxByxug> X-ME-Received: <xmr:-bwrZIXmCr5UGlPwlWWhgPOQdCbWFdTV8YifHgJePIC4LRIp_9uyghkSFfsUYVqolqozNBFh9fjeBSUKzWdYifWxmaA3YsX-eUYjUUM> X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeikedgkeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkgggtugesthdtredttd dtvdenucfhrhhomheplfhoshhhucfvrhhiphhlvghtthcuoehjohhshhesjhhoshhhthhr ihhplhgvthhtrdhorhhgqeenucggtffrrghtthgvrhhnpeelleeggedtjeejfeeuvddufe eggfektdefkeehveeuvedvvdfhgeffgfdvgfffkeenucevlhhushhtvghrufhiiigvpedt necurfgrrhgrmhepmhgrihhlfhhrohhmpehjohhshhesjhhoshhhthhrihhplhgvthhtrd horhhg X-ME-Proxy: <xmx:-bwrZMgQP9OLTEQzpTUiTAqbcOh3m0McF8_CRNni9s6PXTJjwFxt9Q> <xmx:-bwrZICZkb-M6xpAxBQdBLOOjTYeV_JYcJy0evq_eORTwSvztBa6MQ> <xmx:-bwrZNL3zWO_H_lNytygtBlO2qPlrRPvTj2ks6JNqCmodX7OhsI5lg> <xmx:-bwrZDpvGlmDZHNW4b3mB_1v2Z4yFxlRibj62BjaTCHaZIuArkPH6g> Feedback-ID: i83e94755:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 4 Apr 2023 02:00:23 -0400 (EDT) Date: Tue, 4 Apr 2023 15:00:19 +0900 From: Josh Triplett <josh@joshtriplett.org> To: Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org Subject: [PATCH] prctl: Add PR_GET_AUXV to copy auxv to userspace Message-ID: <b11a591e085f1cd06adb454b1f7cde676d317318.1680585798.git.josh@joshtriplett.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762224450914062793?= X-GMAIL-MSGID: =?utf-8?q?1762224450914062793?= |
Series |
prctl: Add PR_GET_AUXV to copy auxv to userspace
|
|
Commit Message
Josh Triplett
April 4, 2023, 6 a.m. UTC
If a library wants to get information from auxv (for instance,
AT_HWCAP/AT_HWCAP2), it has a few options, none of them perfectly
reliable or ideal:
- Be main or the pre-main startup code, and grub through the stack above
main. Doesn't work for a library.
- Call libc getauxval. Not ideal for libraries that are trying to be
libc-independent and/or don't otherwise require anything from other
libraries.
- Open and read /proc/self/auxv. Doesn't work for libraries that may run
in arbitrarily constrained environments that may not have /proc
mounted (e.g. libraries that might be used by an init program or a
container setup tool).
- Assume you're on the main thread and still on the original stack, and
try to walk the stack upwards, hoping to find auxv. Extremely bad
idea.
- Ask the caller to pass auxv in for you. Not ideal for a user-friendly
library, and then your caller may have the same problem.
Add a prctl that copies current->mm->saved_auxv to a userspace buffer.
Signed-off-by: Josh Triplett <josh@joshtriplett.org>
---
I've built, booted, and tested this.
man-pages snippet:
.\" prctl PR_GET_AUXV
.TP
.BR PR_GET_AUXV " (since Linux 6.x)"
Get the auxilliary vector (auxv) into the buffer pointed to by
.IR "(void\~*) arg2" ,
whose length is given by \fIarg3\fP.
If the buffer is not long enough for the full auxilliary vector,
the copy will be truncated.
Return (as the function result)
the full length of the auxilliary vector.
\fIarg4\fP and \fIarg5\fP must be 0.
Will send a patch for man-pages once merged.
include/uapi/linux/prctl.h | 2 ++
kernel/sys.c | 15 +++++++++++++++
2 files changed, 17 insertions(+)
Comments
Hi Josh, kernel test robot noticed the following build warnings: [auto build test WARNING on linus/master] [also build test WARNING on v6.3-rc5] [cannot apply to akpm-mm/mm-everything next-20230404] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Josh-Triplett/prctl-Add-PR_GET_AUXV-to-copy-auxv-to-userspace/20230404-140043 patch link: https://lore.kernel.org/r/b11a591e085f1cd06adb454b1f7cde676d317318.1680585798.git.josh%40joshtriplett.org patch subject: [PATCH] prctl: Add PR_GET_AUXV to copy auxv to userspace config: i386-randconfig-a001-20230403 (https://download.01.org/0day-ci/archive/20230404/202304041715.c3b7aJd4-lkp@intel.com/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/4323f9bd6c2ecbfd6be4f8a3830ea47a89558314 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Josh-Triplett/prctl-Add-PR_GET_AUXV-to-copy-auxv-to-userspace/20230404-140043 git checkout 4323f9bd6c2ecbfd6be4f8a3830ea47a89558314 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Link: https://lore.kernel.org/oe-kbuild-all/202304041715.c3b7aJd4-lkp@intel.com/ All warnings (new ones prefixed by >>): >> kernel/sys.c:2383:23: warning: comparison of distinct pointer types ('typeof (sizeof (mm->saved_auxv)) *' (aka 'unsigned int *') and 'typeof (len) *' (aka 'unsigned long *')) [-Wcompare-distinct-pointer-types] unsigned long size = min(sizeof(mm->saved_auxv), len); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:67:19: note: expanded from macro 'min' #define min(x, y) __careful_cmp(x, y, <) ^~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp' __builtin_choose_expr(__safe_cmp(x, y), \ ^~~~~~~~~~~~~~~~ include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp' (__typecheck(x, y) && __no_side_effects(x, y)) ^~~~~~~~~~~~~~~~~ include/linux/minmax.h:20:28: note: expanded from macro '__typecheck' (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~ 1 warning generated. vim +2383 kernel/sys.c 2379 2380 static int prctl_get_auxv(void __user *addr, unsigned long len) 2381 { 2382 struct mm_struct *mm = current->mm; > 2383 unsigned long size = min(sizeof(mm->saved_auxv), len); 2384 2385 if (size && copy_to_user(addr, mm->saved_auxv, size)) 2386 return -EFAULT; 2387 return sizeof(mm->saved_auxv); 2388 } 2389
Hi Josh, kernel test robot noticed the following build warnings: [auto build test WARNING on linus/master] [also build test WARNING on v6.3-rc5] [cannot apply to akpm-mm/mm-everything next-20230404] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Josh-Triplett/prctl-Add-PR_GET_AUXV-to-copy-auxv-to-userspace/20230404-140043 patch link: https://lore.kernel.org/r/b11a591e085f1cd06adb454b1f7cde676d317318.1680585798.git.josh%40joshtriplett.org patch subject: [PATCH] prctl: Add PR_GET_AUXV to copy auxv to userspace config: arm-randconfig-r025-20230403 (https://download.01.org/0day-ci/archive/20230404/202304041710.JYcSAmPL-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 67409911353323ca5edf2049ef0df54132fa1ca7) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install arm cross compiling tool for clang build # apt-get install binutils-arm-linux-gnueabi # https://github.com/intel-lab-lkp/linux/commit/4323f9bd6c2ecbfd6be4f8a3830ea47a89558314 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Josh-Triplett/prctl-Add-PR_GET_AUXV-to-copy-auxv-to-userspace/20230404-140043 git checkout 4323f9bd6c2ecbfd6be4f8a3830ea47a89558314 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Link: https://lore.kernel.org/oe-kbuild-all/202304041710.JYcSAmPL-lkp@intel.com/ All warnings (new ones prefixed by >>): >> kernel/sys.c:2383:23: warning: comparison of distinct pointer types ('typeof (sizeof (mm->saved_auxv)) *' (aka 'unsigned int *') and 'typeof (len) *' (aka 'unsigned long *')) [-Wcompare-distinct-pointer-types] unsigned long size = min(sizeof(mm->saved_auxv), len); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:67:19: note: expanded from macro 'min' #define min(x, y) __careful_cmp(x, y, <) ^~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp' __builtin_choose_expr(__safe_cmp(x, y), \ ^~~~~~~~~~~~~~~~ include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp' (__typecheck(x, y) && __no_side_effects(x, y)) ^~~~~~~~~~~~~~~~~ include/linux/minmax.h:20:28: note: expanded from macro '__typecheck' (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~ 1 warning generated. vim +2383 kernel/sys.c 2379 2380 static int prctl_get_auxv(void __user *addr, unsigned long len) 2381 { 2382 struct mm_struct *mm = current->mm; > 2383 unsigned long size = min(sizeof(mm->saved_auxv), len); 2384 2385 if (size && copy_to_user(addr, mm->saved_auxv, size)) 2386 return -EFAULT; 2387 return sizeof(mm->saved_auxv); 2388 } 2389
On Tue, Apr 04, 2023 at 05:58:51PM +0800, kernel test robot wrote: > reproduce (this is a W=1 build): Right, I *really* need to start doing W=1 builds. (Am I missing something, or did kernel builds once emit warnings about type mismatches on `min` by default?) > >> kernel/sys.c:2383:23: warning: comparison of distinct pointer types ('typeof (sizeof (mm->saved_auxv)) *' (aka 'unsigned int *') and 'typeof (len) *' (aka 'unsigned long *')) [-Wcompare-distinct-pointer-types] Will fix in v2.
On Tue, Apr 04, 2023 at 09:07:59PM +0900, Josh Triplett wrote: > On Tue, Apr 04, 2023 at 05:58:51PM +0800, kernel test robot wrote: > > reproduce (this is a W=1 build): > > Right, I *really* need to start doing W=1 builds. (Am I missing > something, or did kernel builds once emit warnings about type mismatches > on `min` by default?) I see this warning in a normal ARCH=arm allmodconfig build (i.e., without W=1). Perhaps you never did a 32-bit build, since that is the only way this warning would appear? > > >> kernel/sys.c:2383:23: warning: comparison of distinct pointer types ('typeof (sizeof (mm->saved_auxv)) *' (aka 'unsigned int *') and 'typeof (len) *' (aka 'unsigned long *')) [-Wcompare-distinct-pointer-types] > > Will fix in v2. > Cheers, Nathan
diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index 1312a137f7fb..b2b24eaf2427 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -290,4 +290,6 @@ struct prctl_mm_map { #define PR_SET_VMA 0x53564d41 # define PR_SET_VMA_ANON_NAME 0 +#define PR_GET_AUXV 0x41555856 + #endif /* _LINUX_PRCTL_H */ diff --git a/kernel/sys.c b/kernel/sys.c index 495cd87d9bf4..fdd297507d7e 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2377,6 +2377,16 @@ static inline int prctl_get_mdwe(unsigned long arg2, unsigned long arg3, PR_MDWE_REFUSE_EXEC_GAIN : 0; } +static int prctl_get_auxv(void __user *addr, unsigned long len) +{ + struct mm_struct *mm = current->mm; + unsigned long size = min(sizeof(mm->saved_auxv), len); + + if (size && copy_to_user(addr, mm->saved_auxv, size)) + return -EFAULT; + return sizeof(mm->saved_auxv); +} + SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, unsigned long, arg4, unsigned long, arg5) { @@ -2661,6 +2671,11 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, case PR_SET_VMA: error = prctl_set_vma(arg2, arg3, arg4, arg5); break; + case PR_GET_AUXV: + if (arg4 || arg5) + return -EINVAL; + error = prctl_get_auxv((void __user *)arg2, arg3); + break; default: error = -EINVAL; break;