From patchwork Thu Aug 1 17:08:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13750764 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 4728CC3DA4A for ; Thu, 1 Aug 2024 17:08:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B0F26B0083; Thu, 1 Aug 2024 13:08:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EC126B0085; Thu, 1 Aug 2024 13:08:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73E6F6B0088; Thu, 1 Aug 2024 13:08:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4F62D6B0083 for ; Thu, 1 Aug 2024 13:08:54 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D168F140F82 for ; Thu, 1 Aug 2024 17:08:53 +0000 (UTC) X-FDA: 82404311346.07.D0565A3 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf04.hostedemail.com (Postfix) with ESMTP id EDDD540023 for ; Thu, 1 Aug 2024 17:08:51 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=E4jQU5CT; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf04.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.215.176 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722532068; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gSvjFG11eFXXPisXUSuvwXh3UtwiwX8QldwHUp+YOlQ=; b=6DZ0tT/g5g3ejSOFRN379BIT91izYQCKAuH6klwwK6DzldL+QmLz76c762VSC+WAj6VKKt tg28Upqn4KL51jEbMLe2/UFU3RpDB0PolIWLczEcInlS/S9RWypHXkWXNoNxbKnKpzri7a upbgfBzOKB18/3eyLvWkDAQIfhUCK5M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722532068; a=rsa-sha256; cv=none; b=b8FfVQoRHnawxZZ9IOMYNDO+WVmk6k55GaDrCetVbjh24gxP6g1743KmZyPhx4d34K9d7y bguJXauxwEHhkr7FngazMhOLaSIkSSQA/rD8cMYRrqGAelRTZcCh+X8rlf93TaOaB86BCZ sbNtzZguJsaFmKB1captto3WP3iuvcY= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=E4jQU5CT; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf04.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.215.176 as permitted sender) smtp.mailfrom=jeffxu@chromium.org Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-75a6c290528so4953332a12.1 for ; Thu, 01 Aug 2024 10:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1722532130; x=1723136930; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gSvjFG11eFXXPisXUSuvwXh3UtwiwX8QldwHUp+YOlQ=; b=E4jQU5CTEChBzOx5G+6fADHDemTh9/pPdJLQtkTLtWYHif85232lAV1OzkS93GfS7N Dz39/qaMQrPDdQ9u6bWexROwhOLpkYQFg6rsxMWsUmqQNPExCndxkENKjX3TXdT4a0h9 OBtBtM+9rsEHlIebk8yzSyPmGImlKT6oTxizo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722532130; x=1723136930; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gSvjFG11eFXXPisXUSuvwXh3UtwiwX8QldwHUp+YOlQ=; b=sug8X5ehYYmSM+3EpMvEq5VBxFKR5KwPwAFQu1ErWGQ5wb8pDgjRwdzHtaCm74YYQJ MPXccFVH2zndRq7tdu3Vag6lxMZ4Gr18cc7sh6ShohG+vjutAuKjjwL/1B/MnpcIJqf3 iO4semQUnDibD2OVBmG9dldMlLrps6QSOBJCakgHvgKezsQdy1uHGKEfHdxBNMtHSiHg 7ujT7N6rdr2omY2cIbdwpwBKrr++WPyIF0hE4TM/DL3VcTYvhOy0AAIgpAOYMXysxFOz tzp4fQ8zZA1+3c5qbW0fqcKfKP1AOBPoM68EjXI0R5koXxEq0sjVRRN7QzRGeSHilaJl Mjtg== X-Forwarded-Encrypted: i=1; AJvYcCXIpBthHxoq44H5Vd7OfDW+lYnsMLoGOsTzh2DInLEYkRhLqaGDFbVL0K8E3goZoTtjPPy8rCEmYbmdoW7lAHG+BY8= X-Gm-Message-State: AOJu0Yz5ra4sAj6f4gHqCtomiUK9Vf7IRqm1ouNPsIaikattWuQYBe4O cocZ8Up6vaOI9twfZLFf8iOuNZRI9h20QvhrLYmPPyrXgJx3fj4Q/I+K3wJKVw== X-Google-Smtp-Source: AGHT+IH0NnCLuyb7HngEFKEFyvGr5nBufmB5AXTNrSM7ABBYmr31HM+iM4rvpLqggxwU65VWSqTv+w== X-Received: by 2002:a17:90b:3849:b0:2c9:5f45:5d30 with SMTP id 98e67ed59e1d1-2cff9526d3bmr979842a91.26.1722532130487; Thu, 01 Aug 2024 10:08:50 -0700 (PDT) Received: from localhost (25.11.145.34.bc.googleusercontent.com. [34.145.11.25]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2cfca2a8330sm2588490a91.0.2024.08.01.10.08.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Aug 2024 10:08:50 -0700 (PDT) From: jeffxu@chromium.org To: akpm@linux-foundation.org, keescook@chromium.org, jannh@google.com, sroettger@google.com, adhemerval.zanella@linaro.org, ojeda@kernel.org, adobriyan@gmail.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, jorgelo@chromium.org, Jeff Xu Subject: [RFC PATCH v1 1/1] binfmt_elf: mseal address zero Date: Thu, 1 Aug 2024 17:08:33 +0000 Message-ID: <20240801170838.356177-2-jeffxu@google.com> X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog In-Reply-To: <20240801170838.356177-1-jeffxu@google.com> References: <20240801170838.356177-1-jeffxu@google.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: EDDD540023 X-Stat-Signature: rywup9iwak1giytitdysstnzpchyphwu X-Rspam-User: X-HE-Tag: 1722532131-900566 X-HE-Meta: U2FsdGVkX19pFkuCEGZhhmwfzN9F/GaDvaEh/tQA7pOzEy/5sjNTMvyGhfABwG7YuuNpGPF/tZugs7K4NPwquWsezdML7LRS4y0BQRyewY6fJ9MADWzB1dhj5Hp7Kknbxy4kkAGuqmAFcfLqjSWy0Z9ngjtLWHO2haDtsT3RTM/QvtUeCJ22SuwMiXkXqyzZOz8PtZXuSVh+xUYLkYU7EnD1GGP9JAhE168GL78d4iUh6UFFzEvc/ozTubipjg+DTBIr7J20aykMyEkNFpFOcBWdYJEVwWMnVQihfVlX0HShP3Uhvck8gzuVWlS5DvHNBJvfPZPojImAtm6/PeHbwK8pk7z6QmOwjyWxMSLpwDzRgHesv2Jli4XrJCV8RSbdqzwyMF7nzotYUTfhZIWB84KqaiAeoZGxS5oVXqfzvAewmqhXPcpo6XuhltFYsFsWfHUncaphOdRBOEIDw292gxVtwHWtginNN8UjO5r0nx691yALgv7cgjDXOHHG47fH6ayywnfOdZml0TlgHUyloehqmnBA5GugBoAhNB4g1i6TLEbr7fn5iKSUZUuTJSwaZmsl7J7yHC1jI0bwhPeWEo0RvJNF1r21CmkKFL8o1moGSkFnVTRl0IKz6qm4p9u8ZpJe9obrpDCy52wD1BTBy+RT6WHmfbUza/WFZImVn84dBggFNKfMc4u6iWu0yUPpLNXu+6SKA2G3ULCbut1HKNfTqppeUqW1T1Bhmn3fZkP2Zi5mpsxI7g/4fTVhez9DfYWagdnX03kh9lDoaJXqnbbedZl2AGCQkxMXNdNaPEGYPs0clT2mNLPt6VLGAlBhfXBqZmol3iouXeMUAHNC+6MNuiZoTyn9e+ofIiADeXMTJcOQEVUWLNfqvkReXtiOVLYpXNCO0PlwqqndzLyuHFtUZVaN0jA0uIYYI4702GsSXQxa/pKWPpBa0NyGnloWUjjkQjFSxbL4HrklTyE YzyMzOVc PkF/QzHRxF9W4BgWv3GNIKvWzKMs3CkQi8KZYigY7LsReazlcTBhIwAs0l80P1taZ/ftSf6mVhxc7hRSU3DzRFpWjYeEFr3lxKX9COPiMQ9tZ71FK+AOazUfD2nIo/dPqf2rWzM1Eqxmb0+NNCjDs0fCzf5C3ZEPofPi8Psen/qp7ansQlVDMBK72UBDzzhdrhAsht0p/xUdfz2vecSYzVtvvwTVgGiUpmWPeSQ9IygqAcC8r3YVtryiqh0tUdYh7X+zrn7P5l6ZwepWESzRcZmuEk3gR1IK2vf0TcAMq2+B/yO/TFTUJA98j6Q== 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: List-Subscribe: List-Unsubscribe: From: Jeff Xu Some legacy SVr4 apps might depend on page on address zero to be readable, however I can't find a reason that the page ever becomes writeable, so seal it. If there is a compain, we can make this configurable. Signed-off-by: Jeff Xu --- fs/binfmt_elf.c | 4 ++++ include/linux/mm.h | 4 ++++ mm/mseal.c | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 19fa49cd9907..e4d35d6f5d65 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1314,6 +1314,10 @@ static int load_elf_binary(struct linux_binprm *bprm) emulate the SVr4 behavior. Sigh. */ error = vm_mmap(NULL, 0, PAGE_SIZE, PROT_READ | PROT_EXEC, MAP_FIXED | MAP_PRIVATE, 0); + +#ifdef CONFIG_64BIT + do_mseal(0, PAGE_SIZE, 0); +#endif } regs = current_pt_regs(); diff --git a/include/linux/mm.h b/include/linux/mm.h index c4b238a20b76..b5fed60ddcd9 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -4201,4 +4201,8 @@ void vma_pgtable_walk_end(struct vm_area_struct *vma); int reserve_mem_find_by_name(const char *name, phys_addr_t *start, phys_addr_t *size); +#ifdef CONFIG_64BIT +int do_mseal(unsigned long start, size_t len_in, unsigned long flags); +#endif + #endif /* _LINUX_MM_H */ diff --git a/mm/mseal.c b/mm/mseal.c index bf783bba8ed0..7a40a84569c8 100644 --- a/mm/mseal.c +++ b/mm/mseal.c @@ -248,7 +248,7 @@ static int apply_mm_seal(unsigned long start, unsigned long end) * * unseal() is not supported. */ -static int do_mseal(unsigned long start, size_t len_in, unsigned long flags) +int do_mseal(unsigned long start, size_t len_in, unsigned long flags) { size_t len; int ret = 0;