From patchwork Fri Oct 10 05:45:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineeth Vijayan X-Patchwork-Id: 398453 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E58B01400EA for ; Fri, 10 Oct 2014 16:46:36 +1100 (EST) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id CF3981A1831 for ; Fri, 10 Oct 2014 16:46:36 +1100 (EST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com [209.85.220.53]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 7D8D91A060A for ; Fri, 10 Oct 2014 16:45:54 +1100 (EST) Received: by mail-pa0-f53.google.com with SMTP id kq14so1070732pab.40 for ; Thu, 09 Oct 2014 22:45:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BcJw0i+Uog8H/8hb3K25F5oRlW0HXVeP9rLz8qDTdU4=; b=cCMk/Si5gq962Xc44P+2JJ/KbBe2aO6pUv1AHbBXWDSvAML0pGjZl4GeNiwWU3lls6 le//nj3jexcjaSTRf7FjF+xpSMvEzW58mdYLXFnYPYHycuf90ZpELOTwXvR4XBLPTqKq 8mAg+EhSCiLCC5MMjQhshsCz6DM9pSZtg6tXkUxXH4vcneRr0ZuvaJ84JqzEGoAyP7SQ 3dULuBm+AgJoeCRgFfkm1YGmpLVTgQjGZMAwvG8JMM9UqGIDRqbwEGiKlKyP+bjOyDnf yJjjI4cmDvwXPih5Uinjiyk8GEkF0NK+eS2wS9t5lKo7+6COSdPSTSLn9LyZTg3B4ThY djLQ== X-Gm-Message-State: ALoCoQmSSe4JmBWOYhuoLyi5j2uHGnm3ePqadDBt48PVI9DAZC7XmDEddymn6CTK2hKPTTKieEok X-Received: by 10.66.232.65 with SMTP id tm1mr2953333pac.2.1412919951362; Thu, 09 Oct 2014 22:45:51 -0700 (PDT) Received: from vineeth-OptiPlex-9020.mvista.com ([111.93.218.67]) by mx.google.com with ESMTPSA id wi6sm2276317pac.47.2014.10.09.22.45.48 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 Oct 2014 22:45:50 -0700 (PDT) From: Vineeth Vijayan To: benh@kernel.crashing.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH] powerpc: Fix Text randomization Date: Fri, 10 Oct 2014 11:15:26 +0530 Message-Id: <1412919926-13123-1-git-send-email-vvijayan@mvista.com> X-Mailer: git-send-email 1.7.9.5 Cc: Vineeth Vijayan X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Right now there is no way to disable TEXT randomization on a PPC32 machine. text randomization happens even in the case of "echo 0 > /proc/sys/kernel/randomize_va_space" This happens due to the incorrect definition of ELF_ET_DYN_BASE at arch/powerpc/include/asm/elf.h Signed-off-by: Vineeth Vijayan --- Test details: #include int main(int argc,char *argv) { printf("main = %p\n",main); return 0; } Compile the same as position-independent executable Results without Patch: p5040ds:~# gcc test.c -o test -fPIE -pie p5040ds:~# echo 2 > /proc/sys/kernel/randomize_va_space p5040ds:~# ./test main = 0xb7e9681c p5040ds:~# ./test main = 0xb7aba81c p5040ds:~# ./test main = 0xb7fac81c p5040ds:~# ./test main = 0xb7f4c81c p5040ds:~# echo 0 > /proc/sys/kernel/randomize_va_space p5040ds:~# ./test main = 0x2010281c p5040ds:~# ./test main = 0x2018d81c p5040ds:~# ./test main = 0x206a981c p5040ds:~# ./test main = 0x2036681c Results with Patch: p5040ds:~# gcc test.c -o test -fPIE -pie p5040ds:~# p5040ds:~# echo 2 > /proc/sys/kernel/randomize_va_space p5040ds:~# p5040ds:~# ./test main = 0xb78a581c p5040ds:~# ./test main = 0xb792c81c p5040ds:~# ./test main = 0xb79de81c p5040ds:~# ./test main = 0xb78ae81c p5040ds:~# echo 0 > /proc/sys/kernel/randomize_va_space p5040ds:~# p5040ds:~# ./test main = 0x2000081c p5040ds:~# ./test main = 0x2000081c p5040ds:~# ./test main = 0x2000081c p5040ds:~# ./test main = 0x2000081c arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/elf.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 4bc7b62..f99ddae 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -88,6 +88,7 @@ config PPC select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO select BINFMT_ELF + select ARCH_BINFMT_ELF_RANDOMIZE_PIE select OF select OF_EARLY_FLATTREE select OF_RESERVED_MEM diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h index 888d8f3..162813b 100644 --- a/arch/powerpc/include/asm/elf.h +++ b/arch/powerpc/include/asm/elf.h @@ -29,7 +29,7 @@ that it will "exec", and that there is sufficient room for the brk. */ extern unsigned long randomize_et_dyn(unsigned long base); -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000)) +#define ELF_ET_DYN_BASE (0x20000000) #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)