From patchwork Wed Aug 16 20:55:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 9904601 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 664E1600CA for ; Wed, 16 Aug 2017 20:55:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59A38289A7 for ; Wed, 16 Aug 2017 20:55:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E841289C1; Wed, 16 Aug 2017 20:55:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD18F289A7 for ; Wed, 16 Aug 2017 20:55:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752535AbdHPUzM (ORCPT ); Wed, 16 Aug 2017 16:55:12 -0400 Received: from mail-it0-f54.google.com ([209.85.214.54]:35501 "EHLO mail-it0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752262AbdHPUzK (ORCPT ); Wed, 16 Aug 2017 16:55:10 -0400 Received: by mail-it0-f54.google.com with SMTP id 76so23017773ith.0 for ; Wed, 16 Aug 2017 13:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=oew+gFfHtY3Fe5mj0f/MEwtARSh3nbUEwQLL88nzC4Y=; b=bK+cixIFuTCA64U2EjXLU3HDMSFkULTVHwkK9Qy8+t7fXRsXgEHjwhNJXPPWmzs8Dd y10Tn3NxlfBrXjD2gMoar63m7mnJRMYGwXa+R0N13FLW+yD+ZgKZOcnP0WQi+RPVZYAn A8+mW3pg8U4RHhywCWvXOgUAUbNC2bkcks5C0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=oew+gFfHtY3Fe5mj0f/MEwtARSh3nbUEwQLL88nzC4Y=; b=akY0opTUvn7Hd/EJ7I+Yq/igJhrj1Qf/l0abns4WZYSvEbGbm9CCWGHsuGGVt4ymil O/mqZh75WmUQVokQx29PZcS6Px/fw9WjTsRdsAjaTPYcyfqSQoUoloV5eqRftvd3Qq7J VVmZ+AprQinB3LiOF8OnWvd3GC0Wl83BobFTRRXW1W+8SWWB3MXo7OBANedmRkPmyDz4 yHAyGwNVmGl5XnugeyHlnvk90iB0tvMS3m22OKK2SFBHjGJwZyabstM+s25oppQO0ygK Iq8PREZ8vmau0Ae986HtbZM/F7BYG6mP3jxjEH0o5KaxubKR+4t3vq6k/Q1Hu8sze2cr Qegg== X-Gm-Message-State: AHYfb5htBKkozBeyMxcTzRj4lihTOo7s/a5ASjWn4Fb6FH28i5qaGFzb rDcWe59tvdKzsJ79FFutGA== X-Received: by 10.36.41.143 with SMTP id p137mr302536itp.98.1502916910291; Wed, 16 Aug 2017 13:55:10 -0700 (PDT) Received: from xanadu.home (modemcable199.200-80-70.mc.videotron.ca. [70.80.200.199]) by smtp.gmail.com with ESMTPSA id 67sm744706iob.7.2017.08.16.13.55.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Aug 2017 13:55:09 -0700 (PDT) Date: Wed, 16 Aug 2017 16:55:08 -0400 (EDT) From: Nicolas Pitre To: Alexander Viro cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] binfmt_elf: don't attempt to load FDPIC binaries Message-ID: User-Agent: Alpine 2.20 (LFD 67 2015-01-07) MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On platforms where both ELF and ELF-FDPIC variants are available, the regular ELF loader will happily identify FDPIC binaries as proper ELF and load them without the necessary FDPIC fixups, resulting in an immediate user space crash. Let's prevent binflt_elf from loading those binaries so binfmt_elf_fdpic has a chance to pick them up. For those architectures that don't define elf_check_fdpic(), a default version returning false is provided. Signed-off-by: Nicolas Pitre --- fs/binfmt_elf.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 879ff9c7ff..84d64afaea 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -51,6 +51,11 @@ #define user_siginfo_t siginfo_t #endif +/* That's for binfmt_elf_fdpic to deal with */ +#ifndef elf_check_fdpic +#define elf_check_fdpic(ex) false +#endif + static int load_elf_binary(struct linux_binprm *bprm); static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *, int, int, unsigned long); @@ -541,7 +546,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex, if (interp_elf_ex->e_type != ET_EXEC && interp_elf_ex->e_type != ET_DYN) goto out; - if (!elf_check_arch(interp_elf_ex)) + if (!elf_check_arch(interp_elf_ex) || + elf_check_fdpic(interp_elf_ex)) goto out; if (!interpreter->f_op->mmap) goto out; @@ -718,6 +724,8 @@ static int load_elf_binary(struct linux_binprm *bprm) goto out; if (!elf_check_arch(&loc->elf_ex)) goto out; + if (elf_check_fdpic(&loc->elf_ex)) + goto out; if (!bprm->file->f_op->mmap) goto out; @@ -817,7 +825,8 @@ static int load_elf_binary(struct linux_binprm *bprm) if (memcmp(loc->interp_elf_ex.e_ident, ELFMAG, SELFMAG) != 0) goto out_free_dentry; /* Verify the interpreter has a valid arch */ - if (!elf_check_arch(&loc->interp_elf_ex)) + if (!elf_check_arch(&loc->interp_elf_ex) || + elf_check_fdpic(&loc->interp_elf_ex)) goto out_free_dentry; /* Load the interpreter program headers */ @@ -1189,6 +1198,8 @@ static int load_elf_library(struct file *file) if (elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 || !elf_check_arch(&elf_ex) || !file->f_op->mmap) goto out; + if (elf_check_fdpic(&elf_ex)) + goto out; /* Now read in all of the header information */