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: 12812052 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2700AC433F5 for ; Wed, 13 Apr 2022 13:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aD+Ab0piz30rvi2e4fh8TeTzGJnFbuqkEhnIPLSzqaE=; b=IizL9jQD99o3yX vbxzg1TEacZameP8cvxJQO6ZH1QoszCCwqEBIkxQ/p8iihqjrE7tQiyXHknkHF+vvmfJzZnzvFc2z v+si+apBCcR9CofB1pHIylWh7AgZH3SdmZFSkRiNdQBQ0UL4x+p3ars89eM3nz/rYWGcdRlKlt/m/ vkrZxjVRJ65VRKRKpR4a+nnCtr8cHFShrtHCcPNw+qfP5olsMGQ3jYiJSoL4GqQcxUT6AuA2iY2y+ gK2F1/2qobwxum2qwiU1SbQRwePQ7UP+ILwruChfuUx+3mkpuMovtYMLr8rcIq06rvemBKQhmXUrS bhKRycJftTA4vawCFX4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nedOB-001GZm-JB; Wed, 13 Apr 2022 13:50:31 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nedNi-001GPx-TI for linux-arm-kernel@lists.infradead.org; Wed, 13 Apr 2022 13:50:05 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220413_065003_056970_4FE39626 X-CRM114-Status: GOOD ( 13.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 */