Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A2EC3C76AD for ; Tue, 23 Jun 2026 08:34:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782203678; cv=none; b=PDDI15oyEgaT/S3E90Fzr+qlaayjDn7BCEWyLH99vXdoEnFqA9UUI9f5IPSxYpplUhoEYbgRkSHJ9mxWM8SW+6GukyQU4THfo9H7j6tE4n7u+DiQ1WH4BeTtNi8JGv64Rt1+UnEvHKpyzFEDRO0JxxceopwaCXKw8MuvlV31oKw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782203678; c=relaxed/simple; bh=roiZvRlmW1oPMvNL1hMuMgeHckyYeVBn/hm8eizbnTc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=NpxIdfwPWR/GEChBCF5Bo/vBOGtQhv2Xul/Ds3dgq49cEtvJ7VHt8YKo6qUL1V8Po90bsqPFngyoG+vqfX+7sSDboqPbM4dzz8HCv9Xf0D4/7gfEnQK6kkPbhMJFC8CsXo+Hx/nAS9Bq9G+obW63140TXhTcVWOCb/0rXng7XGE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aru6mgHB; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aru6mgHB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782203676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Bi2iFTaqihl/Pjl2OmXkEpUK4ol3aMmFIEDmjJes594=; b=aru6mgHBsQBktXivOmCEl6Fopu3wlXV23sWO0S+sToD3i3UjRDQNfMoLau/wOtWC0zhhuv gbMBLvxtM6r2HnVfu6p2h9Q+ndvAGGzqZQOBDG7XWFA+HXcm6i9yoMFK1hDNSdxkhlfkr3 pDnNJSl1MhleGe98Uns9CiVbzBbZjc4= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-61-KPI55nZfMBGs0AbeEmS5vg-1; Tue, 23 Jun 2026 04:34:32 -0400 X-MC-Unique: KPI55nZfMBGs0AbeEmS5vg-1 X-Mimecast-MFC-AGG-ID: KPI55nZfMBGs0AbeEmS5vg_1782203671 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BF155180025F; Tue, 23 Jun 2026 08:34:31 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.44.24.9]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6DA3D195608C; Tue, 23 Jun 2026 08:34:29 +0000 (UTC) From: ahajkova@redhat.com To: linux-kernel@vger.kernel.org Cc: kees@kernel.org, akpm@linux-foundation.org Subject: [PATCH] elf: add AT_ARGV and AT_ENVV auxiliary vector entries Date: Tue, 23 Jun 2026 10:22:07 +0200 Message-ID: <20260623082207.835843-1-ahajkova@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 From: Alexandra Hájková Add AT_ARGV (52), which contains the address of the argv pointer array on the initial process stack, and AT_ENVV (53), which contains the address of the envp pointer array. Add a kselftest (tools/testing/selftests/exec/test_auxv) that reads /proc/self/auxv and verifies AT_ARGV and AT_ENVV point to the process's own argv[] and envp[]. The motivation is to allow GDB to find argv and envp in core dumps cleanly. Currently GDB locates them by scanning backwards through stack memory from AT_EXECFN, which is fragile. With AT_ARGV and AT_ENVV it can read the addresses directly from the core dump's auxv note. Signed-off-by: Alexandra Hájková --- fs/binfmt_elf.c | 9 +++++- include/linux/auxvec.h | 2 +- include/uapi/linux/auxvec.h | 2 ++ tools/testing/selftests/exec/Makefile | 1 + tools/testing/selftests/exec/test_auxv.c | 37 ++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/exec/test_auxv.c diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 8e89cc5b2820..6a0830a63335 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -182,6 +182,8 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec, int ei_index; const struct cred *cred = current_cred(); struct vm_area_struct *vma; + elf_addr_t *at_argv_val; + elf_addr_t *at_envv_val; /* * In some cases (e.g. Hyper-Threading), we want to avoid L1 @@ -288,6 +290,10 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec, NEW_AUX_ENT(AT_RSEQ_FEATURE_SIZE, offsetof(struct rseq, end)); NEW_AUX_ENT(AT_RSEQ_ALIGN, __alignof__(struct rseq)); #endif + at_argv_val = elf_info + 1; + NEW_AUX_ENT(AT_ARGV, 0); + at_envv_val = elf_info + 1; + NEW_AUX_ENT(AT_ENVV, 0); #undef NEW_AUX_ENT /* AT_NULL is zero; clear the rest too */ memset(elf_info, 0, (char *)mm->saved_auxv + @@ -309,7 +315,8 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec, #else sp = (elf_addr_t __user *)bprm->p; #endif - + *at_argv_val = (unsigned long)(sp + 1); + *at_envv_val = (unsigned long)(sp + (argc + 2)); /* * Grow the stack manually; some architectures have a limit on how diff --git a/include/linux/auxvec.h b/include/linux/auxvec.h index 8bcb9b726262..7184de95b89d 100644 --- a/include/linux/auxvec.h +++ b/include/linux/auxvec.h @@ -4,6 +4,6 @@ #include -#define AT_VECTOR_SIZE_BASE 24 /* NEW_AUX_ENT entries in auxiliary table */ +#define AT_VECTOR_SIZE_BASE 26 /* NEW_AUX_ENT entries in auxiliary table */ /* number of "#define AT_.*" above, minus {AT_NULL, AT_IGNORE, AT_NOTELF} */ #endif /* _LINUX_AUXVEC_H */ diff --git a/include/uapi/linux/auxvec.h b/include/uapi/linux/auxvec.h index cc61cb9b3e9a..e7af32709aba 100644 --- a/include/uapi/linux/auxvec.h +++ b/include/uapi/linux/auxvec.h @@ -40,5 +40,7 @@ #ifndef AT_MINSIGSTKSZ #define AT_MINSIGSTKSZ 51 /* minimal stack size for signal delivery */ #endif +#define AT_ARGV 52 /* address of argv[] */ +#define AT_ENVV 53 /* address of envp[] */ #endif /* _UAPI_LINUX_AUXVEC_H */ diff --git a/tools/testing/selftests/exec/Makefile b/tools/testing/selftests/exec/Makefile index 45a3cfc435cf..4370a0a65d22 100644 --- a/tools/testing/selftests/exec/Makefile +++ b/tools/testing/selftests/exec/Makefile @@ -20,6 +20,7 @@ TEST_FILES := Makefile TEST_GEN_PROGS += recursion-depth TEST_GEN_PROGS += null-argv TEST_GEN_PROGS += check-exec +TEST_GEN_PROGS += test_auxv EXTRA_CLEAN := $(OUTPUT)/subdir.moved $(OUTPUT)/execveat.moved $(OUTPUT)/xxxxx* \ $(OUTPUT)/S_I*.test diff --git a/tools/testing/selftests/exec/test_auxv.c b/tools/testing/selftests/exec/test_auxv.c new file mode 100644 index 000000000000..5d1215562d40 --- /dev/null +++ b/tools/testing/selftests/exec/test_auxv.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include "kselftest.h" + +int main(int argc, char **argv, char **envp) +{ + FILE *file = fopen("/proc/self/auxv", "rb"); + int argv_found = 0; + int envp_found = 0; + struct { + unsigned long type; + unsigned long val; + } entry; + + if (file == NULL) + return 1; + + ksft_print_header(); + ksft_set_plan(1); + while (fread(&entry, sizeof(entry), 1, file) == 1) { + if (entry.type == 0) + break; + if (entry.type == AT_ARGV && entry.val == (unsigned long)argv) + argv_found++; + if (entry.type == AT_ENVV && entry.val == (unsigned long)envp) + envp_found++; + } + if (argv_found && envp_found) + ksft_test_result_pass("AT_ARGV and AT_ENVV\n"); + else + ksft_test_result_fail("AT_ARGV and AT_ENVV\n"); + + fclose(file); + ksft_finished(); +} -- 2.47.3