From patchwork Wed Apr 13 13:49:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 12812047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC4ECC433EF for ; Wed, 13 Apr 2022 13:50:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 717106B0075; Wed, 13 Apr 2022 09:50:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 69F4F6B0078; Wed, 13 Apr 2022 09:50:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CBF66B007B; Wed, 13 Apr 2022 09:50:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0129.hostedemail.com [216.40.44.129]) by kanga.kvack.org (Postfix) with ESMTP id 3AFD96B0075 for ; Wed, 13 Apr 2022 09:50:04 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EE930A5D4E for ; Wed, 13 Apr 2022 13:50:03 +0000 (UTC) X-FDA: 79351989486.26.41FF184 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf17.hostedemail.com (Postfix) with ESMTP id 5FD3C40006 for ; Wed, 13 Apr 2022 13:50:03 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4391A61943; Wed, 13 Apr 2022 13:50:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCBB5C385AF; Wed, 13 Apr 2022 13:49:58 +0000 (UTC) From: Catalin Marinas To: Andrew Morton , Christoph Hellwig , Lennart Poettering , =?utf-8?q?Zbigniew_J=C4=99drze?= =?utf-8?q?jewski-Szmek?= Cc: Will Deacon , Alexander Viro , Eric Biederman , Kees Cook , Szabolcs Nagy , Mark Brown , Jeremy Linton , Topi Miettinen , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-abi-devel@lists.sourceforge.net Subject: [PATCH RFC 3/4] fs/binfmt_elf: Tell user-space about the DENY_WRITE_EXEC personality flag Date: Wed, 13 Apr 2022 14:49:45 +0100 Message-Id: <20220413134946.2732468-4-catalin.marinas@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220413134946.2732468-1-catalin.marinas@arm.com> References: <20220413134946.2732468-1-catalin.marinas@arm.com> MIME-Version: 1.0 X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5FD3C40006 X-Stat-Signature: m7r51c195gbd5yas4qgk51f5w7qisysc X-HE-Tag: 1649857803-668383 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Since personality() accepts any flags and does not mask out any unknown bits, inform user space that such personality flag is supported via an AT_FLAGS_DENY_WRITE_EXEC flag. Signed-off-by: Catalin Marinas Cc: Alexander Viro Cc: Eric Biederman Cc: Kees Cook Cc: Christoph Hellwig --- fs/binfmt_elf.c | 2 ++ include/uapi/linux/binfmts.h | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 6556e13ed95f..4e6cba1f67ee 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -265,6 +265,8 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec, NEW_AUX_ENT(AT_BASE, interp_load_addr); if (bprm->interp_flags & BINPRM_FLAGS_PRESERVE_ARGV0) flags |= AT_FLAGS_PRESERVE_ARGV0; + if (IS_ENABLED(CONFIG_ARCH_ENABLE_DENY_WRITE_EXEC)) + flags |= AT_FLAGS_DENY_WRITE_EXEC; 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)); diff --git a/include/uapi/linux/binfmts.h b/include/uapi/linux/binfmts.h index c6f9450efc12..304bbb30264c 100644 --- a/include/uapi/linux/binfmts.h +++ b/include/uapi/linux/binfmts.h @@ -22,4 +22,8 @@ struct pt_regs; #define AT_FLAGS_PRESERVE_ARGV0_BIT 0 #define AT_FLAGS_PRESERVE_ARGV0 (1 << AT_FLAGS_PRESERVE_ARGV0_BIT) +/* support for DENY_WRITE_EXEC personality flag */ +#define AT_FLAGS_DENY_WRITE_EXEC_BIT 1 +#define AT_FLAGS_DENY_WRITE_EXEC (1 << AT_FLAGS_DENY_WRITE_EXEC_BIT) + #endif /* _UAPI_LINUX_BINFMTS_H */