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: 110276 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp1296972qge; Wed, 16 Aug 2017 13:55:16 -0700 (PDT) X-Received: by 10.99.168.65 with SMTP id i1mr2708836pgp.305.1502916916618; Wed, 16 Aug 2017 13:55:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502916916; cv=none; d=google.com; s=arc-20160816; b=VgIM0mzNhrXwcAAid0c3dUl259QsjaKAY7+g4RhymcAIimJtSDTM1V1RH3nT62BP/G WK7L676kfYbdOTb8ImZFN7RN8e0sUvs8j1LhkNttLTIL3tbQlwB2oBJiJ+etY/ef90Bp 8TfPDNFQYLkGYdob8nMnMnnByzoajI14XQHAm1F0icnERHn4lNvCVslMDNNwV7KYA+ce m8hgI8ZjbsQhkrL2lwlmnJi+1LlZ3/955nGpnGkfHhoe1DKEEQENaBcIXDyG6CqD2mVk CS/kzf4/8iU93Dz0dG0UfP33EdXGHRUJRAiPTuVeLPsMKez48v5YNHw3F37Ln7GFVkEc 78fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature:arc-authentication-results; bh=oew+gFfHtY3Fe5mj0f/MEwtARSh3nbUEwQLL88nzC4Y=; b=tOVyh2j0uQKcoHkH48phoSKe3YaOdxaQ5OTZuTLcLnVg16mkF0m829GpPuhNTja/7H X/KTbow4WE6kqsPOlRBEBh/IvPNRuUbo4dvILz48TrX+CQWOcv9QZDjsBiyZ2fL+cVXq dpPUSAwMGIKU5M9h2RHoH0MZw9eoSs/w23nNCqC6KyM6d/zzFzSwFEN7hp6FATxPdgy4 RhjleTvXFE1pic+aaCjakUxMIbN8rMSwmfLJu0mJnPMC8JP3TdHNj7lnNmf5ZULi/3J8 wGHo1XYmHEBEjIYCcIZFt5XgYNBwxY4d4ogW43Cn2h+a0sij1dfOzthPGhl8ktGqLDar DzVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bK+cixIF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g34si1048914pld.801.2017.08.16.13.55.16; Wed, 16 Aug 2017 13:55:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bK+cixIF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752570AbdHPUzO (ORCPT + 26 others); Wed, 16 Aug 2017 16:55:14 -0400 Received: from mail-it0-f54.google.com ([209.85.214.54]:37227 "EHLO mail-it0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752233AbdHPUzK (ORCPT ); Wed, 16 Aug 2017 16:55:10 -0400 Received: by mail-it0-f54.google.com with SMTP id 76so22634314ith.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=k1q3YfUYxFjp+3V1htGFnRBay8Bf9y3xzivsIgq02SuL7Fq40wzVcgmifHLEMYVzQV 9PESe+RXZkR+SmO4+iifhkDDNDSqD2n5YGBil6TXcqpN+VvOByp3hOU3uYTyqyITN1TO R9LeN1mJSjXZYhjSimZi/7/jscbeYWXfiFiyE7XbbcW3bHL2VP0LyvmLYaWRpavsY5yw rd+GIxnpyLVyTFreX2gi/VBnW9WX0CN1v75151xgg+bZrSV2sH0syx+jVpx/0ATtGf2p Cwf4qhKjfQJyx861OWUFtFr2miRLZ8DhZlfwxjw7YvU2Cw0B17Tvqt9f4H/Jjb7CssNO VWgQ== X-Gm-Message-State: AHYfb5jL8tgtaoBRqDEQEuv0IrJE4XR6DYWqsefGU9qWxhaeHsY/xLjK VrpT1ZWswB+FAp/j 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */