From patchwork Sat Apr 17 01:10:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12209413 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10E66C433B4 for ; Sat, 17 Apr 2021 01:10:54 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 821A16113D for ; Sat, 17 Apr 2021 01:10:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 821A16113D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=VOaxuGN5zaVwmtxuCFnAgnwJ9VfkiIBHpH7j7vPtrLo=; b=Nbwd4fNkh79N9fx8CKsl3B39I aT2/S1epQ+RinzoYZ7/52Wb65gVzj1XMxv1ebz1rU3AJncacsQnWs0vRRY/oV9j2Kf1xu4+K4E4eC nCB9VVWNEDvfdwUSN46tEDcOICdpdH2+BudIG1Xt/7S4FaXBNv39qCVsJ06EmO0hkVQGhyIap4aZz ayoJxoaex0Dlnd60XxrcbyIR5EOoZzttOWxKQYaZVJCA0dOikLnaA5XKYZByenXhChU/d7k6zjxE5 6fH0Tk1acrKye9C3QBik8B7JOBtwNlD/ntaNlU+ptIlrIiu2jwb9IZ2TFciI4HHnyyaZGLoAMKLOz Rldn/0vtw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lXZTi-003vih-Rx; Sat, 17 Apr 2021 01:10:31 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lXZTc-003vha-3b for linux-riscv@desiato.infradead.org; Sat, 17 Apr 2021 01:10:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=ZR+aG5j1FNcb3RPFeyHK8OGi97A18JTT5VCIVA1ghVs=; b=bNDmx6JZt8FFw/Au2uANQ+5zrB 5/tE/wJGUadgeMtBJlq3ZMtwUG8M9cBvlPDcwrOOHrCkcf43dRg3fbeGkunUOF+xr5BURR4C+ZP8y Qn5s/UXHwMw9i0kcIuSx1lJ+qVvlljJvK52OaKVkYsg908UE2zU2rQ185oWcchqLac4ijO1pr+g2S tDP8M2YaLI5AQ0A+H9295L+I6uU61NNt5ALp+pXI5lMK76A1AjZJ2YEiX8nnLlXF/6GLnGroq3nA0 UAE2n/1tHcsy8aHeSm+TLlDJDgAMuKDAs2RCYR0PpwwAGtBKepuLMj38F6wszzcHtVjIhrPUWKC5t rwf+xXeA==; Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lXZTW-009owP-Vy for linux-riscv@lists.infradead.org; Sat, 17 Apr 2021 01:10:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1618621818; x=1650157818; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ONje5diYFTfuoHw7Q91T2ek/0x57ALfBBrINovIdSps=; b=VUlF9+Q1HO/FLl853hdYrjcl6+ERfeOownElhcDD1c4nlKd3c+zx/K+i Hn0gSrF5vuvMgP4zA/nX3SO70x5X85HYFBM0evuKFLJNcd+3je6QZ2ZKF Lrx0GFJoH4mDa5jlju7qDPMXqlxaQX+dxoL8ioETxTDH5Elg0T91EF5Dv DkfKVqvSqx8c1ogkLrFAwhBK4vKn1uVt6ZN5NTgQqkWIA9VL4GsFGkfz2 LMFULZSZPs+DXO7wkERocyfIaNuKnItWHFmcNqyVPVIwdRuOujpXP1/DQ 3R5/RMMk5LR8RBlRwM+xo7x67Yb6dS2iQPDLA3h4nLuIyvLblZ1Px+DMs g==; IronPort-SDR: 1Ae+oxd1+avgNdGlWCL545nK/GQk0XGXzoO9zk9KAX/kDVPxdA1hYnwLiykA8TXls1EDQhdwp5 X0oLuJYLDqmJvHJ4eSUPbflAyFb3vmmmcfAT9c66Od8242dTl6pqqOG204JPQYWqgTfRYexdDR ANDdtr8kQY6Wdske0PGgiGji6JPDZEjt8vxOUnYCDpV3qluOA/digHnHHvHXfXIfespZyv/YK2 9jUGuUxKnhJtFeubHRLMdRfSqZQBQqBfaxj8mqCoMiGhlNcgAjmxYYUyM0QQX3foYHg/nLlwk/ F6Y= X-IronPort-AV: E=Sophos;i="5.82,228,1613404800"; d="scan'208";a="165185056" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 17 Apr 2021 09:10:17 +0800 IronPort-SDR: 1yWn3QJEtH/HoUqF0sf6hphmow03kpZk5FZ3M4XsO/gpLeBb27XhJXvvSDx6eok5OFjabnzVZT jVeYTIXsUod5U92AAyRCJl1m8V8+p3R8st7zgkykZVW99m0zDoqEtnDdPtjH+RqBCV41cHRhFQ KAxqyv2+d6X7gliVK3Vc8KlJZH3N8InuiDn8H+G5HLEd2zHpB9rvN4vQBI98+nlvBGaNTjRZwg f8KzaK+EzL7flopWdarwK20SpkFGKk6xxWkqnXau/0Nhp8regu+WqfKF8p5x19FtbpM3dC52ee 1RI+9U27RTAv3NEj0Tqi7JLY Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2021 17:49:31 -0700 IronPort-SDR: /Mpcyl00NWrrMVw8jjb+KQQpaXYt2uHMvilpjvH+sh0oGNKNXGXWtcNNdz5nIzOnFpY1ENd+iI um12RaVkSGx8uC/+4QWQG2o/14uHCMNJbfE37OCBdAdYc4cO7YCQhRBHlEbjl8Jivvl5C+4Hqd 008sngSKp6/xskw9zNJsYd2wOOh78pW9QWpzdRIqvqeOZFKWhKurLQ6p3vHAK2C7vNp/4mHDAY LMxqPyoCGgfoY2ZlOTFY3iSMbEGnxnYXIiKkK4qRMj8czsWvffQVF3EEgS8Su+i8xIrv/Iqr/3 T7Q= WDCIronportException: Internal Received: from unknown (HELO twashi.fujisawa.hgst.com) ([10.225.163.5]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Apr 2021 18:10:17 -0700 From: Damien Le Moal To: uclinux-dev@uclinux.org, Greg Ungerer , Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Anup Patel , Christoph Hellwig Subject: [PATCH v4 1/2] binfmt_flat: allow not offsetting data start Date: Sat, 17 Apr 2021 10:10:08 +0900 Message-Id: <20210417011009.54569-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210417011009.54569-1-damien.lemoal@wdc.com> References: <20210417011009.54569-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210416_181019_059180_968FEE5A X-CRM114-Status: GOOD ( 16.54 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Commit 2217b9826246 ("binfmt_flat: revert "binfmt_flat: don't offset the data start"") restored offsetting the start of the data section by a number of words defined by MAX_SHARED_LIBS. As a result, since MAX_SHARED_LIBS is never 0, a gap between the text and data sections always exists. For architectures which cannot support a such gap between the text and data sections (e.g. riscv nommu), flat binary programs cannot be executed. To allow an architecture to request no data start offset to allow for contiguous text and data sections for binaries flagged with FLAT_FLAG_RAM, introduce the new config option CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET. Using this new option, the macro DATA_START_OFFSET_WORDS is conditionally defined in binfmt_flat.c to MAX_SHARED_LIBS for architectures tolerating or needing the data start offset (CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET disabled case) and to 0 when CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET is enabled. DATA_START_OFFSET_WORDS is used in load_flat_file() to calculate the data section length and start position. Signed-off-by: Damien Le Moal Acked-by: Greg Ungerer --- fs/Kconfig.binfmt | 3 +++ fs/binfmt_flat.c | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt index c6f1c8c1934e..06fb7a93a1bd 100644 --- a/fs/Kconfig.binfmt +++ b/fs/Kconfig.binfmt @@ -112,6 +112,9 @@ config BINFMT_FLAT_ARGVP_ENVP_ON_STACK config BINFMT_FLAT_OLD_ALWAYS_RAM bool +config BINFMT_FLAT_NO_DATA_START_OFFSET + bool + config BINFMT_FLAT_OLD bool "Enable support for very old legacy flat binaries" depends on BINFMT_FLAT diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index b9c658e0548e..1dc68dfba3e0 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c @@ -74,6 +74,12 @@ #define MAX_SHARED_LIBS (1) #endif +#ifdef CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET +#define DATA_START_OFFSET_WORDS (0) +#else +#define DATA_START_OFFSET_WORDS (MAX_SHARED_LIBS) +#endif + struct lib_info { struct { unsigned long start_code; /* Start of text segment */ @@ -560,6 +566,7 @@ static int load_flat_file(struct linux_binprm *bprm, * it all together. */ if (!IS_ENABLED(CONFIG_MMU) && !(flags & (FLAT_FLAG_RAM|FLAT_FLAG_GZIP))) { + /* * this should give us a ROM ptr, but if it doesn't we don't * really care @@ -576,7 +583,8 @@ static int load_flat_file(struct linux_binprm *bprm, goto err; } - len = data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long); + len = data_len + extra + + DATA_START_OFFSET_WORDS * sizeof(unsigned long); len = PAGE_ALIGN(len); realdatastart = vm_mmap(NULL, 0, len, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0); @@ -591,7 +599,7 @@ static int load_flat_file(struct linux_binprm *bprm, goto err; } datapos = ALIGN(realdatastart + - MAX_SHARED_LIBS * sizeof(unsigned long), + DATA_START_OFFSET_WORDS * sizeof(unsigned long), FLAT_DATA_ALIGN); pr_debug("Allocated data+bss+stack (%u bytes): %lx\n", @@ -622,7 +630,8 @@ static int load_flat_file(struct linux_binprm *bprm, memp_size = len; } else { - len = text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(u32); + len = text_len + data_len + extra + + DATA_START_OFFSET_WORDS * sizeof(u32); len = PAGE_ALIGN(len); textpos = vm_mmap(NULL, 0, len, PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0); @@ -638,7 +647,7 @@ static int load_flat_file(struct linux_binprm *bprm, realdatastart = textpos + ntohl(hdr->data_start); datapos = ALIGN(realdatastart + - MAX_SHARED_LIBS * sizeof(u32), + DATA_START_OFFSET_WORDS * sizeof(u32), FLAT_DATA_ALIGN); reloc = (__be32 __user *) @@ -714,7 +723,7 @@ static int load_flat_file(struct linux_binprm *bprm, ret = result; pr_err("Unable to read code+data+bss, errno %d\n", ret); vm_munmap(textpos, text_len + data_len + extra + - MAX_SHARED_LIBS * sizeof(u32)); + DATA_START_OFFSET_WORDS * sizeof(u32)); goto err; } } From patchwork Sat Apr 17 01:10:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12209415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0FE8C433ED for ; Sat, 17 Apr 2021 01:10:54 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3A3F6610FC for ; Sat, 17 Apr 2021 01:10:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3A3F6610FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=DAziZJY5EVmc/u1OkSmuta14wWPIxXDsR7tpiAZuWpk=; b=XY/cW7TMov5hLYGB/AdTlolZq tCIpudw7H6pJ2nq3HPN2Iox97gcgTdOq8P886MdFZSTcbEq3tbY4tWBMF4Fv4q1ivFtgRBmgk4iUJ +qmpBqIcWIA1r5Z2C5IBf3bGjlnjEbdL5JuGy3PnnAQntW10QnzdBJc26PMOCuAgkcbZI692zqOqj mW9DVDkMHZdPBDDrelWiQORNL2e/aORSfdJJs3CdolFh2MrXvnkK5OhTj5LSxTrVwhw8/fRpY1PTb XLxRFd3rW6WVPuT4MA36EFQ/fIb+q7E2FHme4Rh0gtYs8pA6wnUOEEPmdJZ50Q/KsqQeMHR7/4riu gHng8chCA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lXZTr-003vkT-DY; Sat, 17 Apr 2021 01:10:39 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lXZTf-003viG-R0 for linux-riscv@desiato.infradead.org; Sat, 17 Apr 2021 01:10:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=2rL5JbH3pZtBpSx4UjgPN/9o8h57zLSwcMHJ5vhnwSQ=; b=aM3TBE3pNtDomXhx6JbpyO6wyt tan8j+r0LwL5JBGnHtNCcI7dhdhXirtrEVL4WYWUgwF1YasWAwycWvtN93CURxwB/VcrovMlLvAtg F14uPYPFxT45930ExkQIVCgTuwrK/Laj5kkZMHmjhI/9aa1cmAvjkEKFa7auUTDFnJ6DU68rimb5W fwLEjcgIuEOjdpqADOblw0QbLCO/4UrvUcAMcBAiV3zIUBGSTlG/bw6YXyTnNSeEpfxc4Yizo9/5o L9ah3Qw3GPox1zWKDhvorvyPR7eq3Sfmrg1z5Thz47csbdpa50bkdAqebn47f/KgiCwejVCDA27Te 6uEh06Sg==; Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lXZTX-009owy-NR for linux-riscv@lists.infradead.org; Sat, 17 Apr 2021 01:10:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1618621819; x=1650157819; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4DgKpWxB0XLKsv65kA39h+j5FEcPc1pXnik7l1I2KYc=; b=H1loPJCd3F41k3Ow2Gin4bC0VAoXWNfLQJxJjmvNO6Y3BmBXUTMdTWsx YCL3i0ei86zg7kPa/yyaDU+ZM+8qisT5YR5EGszAF6i5sssZixjc+5jQo JFCXBznfBHsvziMZQL5w4Z8h0ppYnkW5bvMZxTNHeOrztSgPpSARasudE 775MM1jWI4jOB5Ets/nTMC9lCGocfMDhYQFnsWb3UDR2R6siV71Z45eAS jqR9PTrTyC7NsceqvlCI2W4X4vckbwgW5teGxq9BPcuAHJdzqBgq8AiXQ xgZ+bPU7v47+7n474t8gyKWJHOS9bBLTNn2kcgkWqW+fbIQQIft4tHSLe w==; IronPort-SDR: nqBDSh+eaSrLATahqoQ+SgyRRHzfIdg9YLq5m8xbFoI6HJJWjLgHmH9cToNj1VEQJY8Z59+ksN mLPCMEwAftoJFvkYPcv+rpzwUZ89BkE5Y9PILfFAgGa9ZNPkspYKXoDasCuJpCPQXAjuZe5A8B MSpLmhiL3DiFsGQ+vg04e6DT9K77XOsZjBE5PMrZAHhwT5wD9G97N+KS1JBLanFS3akRS3B4A3 Vaise86GBLDaSOffZo8jDSeWLT3ONWoBfGhIomXl2turipQ23crPCedWSSLQIaHvJePN/RLGdM x/g= X-IronPort-AV: E=Sophos;i="5.82,228,1613404800"; d="scan'208";a="165185060" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 17 Apr 2021 09:10:19 +0800 IronPort-SDR: 3ppweCNY4KrCkRBupHYM6hh1pz/uShTMKnxqsaDYJSGqtsKmfbgYHoLsxuUzanmUCFaHWAeWo+ KVK79YPAw+qSErLC47frTDODQ3JdVAlP+rtTlJnKEGoBAPhWZWKb3nL+KS7owIxyYsN8T3ZiZK LoQcHnLHYCO6ysapF9l6M4vqmUHYsy0SQq9Kd58jVwJuw3q0gX5QqWj7YptZFvGBCmaccRx6/7 C10DcdcGN1oNoxyaBQUeMYXklkFHrkgWiw5GuCw//KL/fi4qCpBpNPusbxg60aC3I7jTn9eKSr Usvl2Oe6XLCDeMf8qxmg7Kue Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2021 17:49:32 -0700 IronPort-SDR: YHPDjhLsFx+LE0qZcYne9xelQgeX9OMP5X2ZphNVvunYaGLHeFJ1mCFHZFOA/iQiLF2zhhcXtU MEAGtd/1IXUQhhFZGoLVY2ThXNO1MzxOiMJScd5bDoDEfzVMxvvrVaNrWmIdMhP3yLGwzOaSOh JjUOY2qcSvRBSUP0dNuwngB8KtonYjb3AgqCKor6so+znxZFYwrDssokH9eqmSVqCnraHD0Tp1 S5MQizOFLgkC6Xt5jU+v1SpBuftnhWhyTAsq0iwzjBdeCH+jUh9mVfA89HbeqlscP9/x+zmNiw JxQ= WDCIronportException: Internal Received: from unknown (HELO twashi.fujisawa.hgst.com) ([10.225.163.5]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Apr 2021 18:10:19 -0700 From: Damien Le Moal To: uclinux-dev@uclinux.org, Greg Ungerer , Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Anup Patel , Christoph Hellwig Subject: [PATCH v4 2/2] riscv: Disable data start offset in flat binaries Date: Sat, 17 Apr 2021 10:10:09 +0900 Message-Id: <20210417011009.54569-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210417011009.54569-1-damien.lemoal@wdc.com> References: <20210417011009.54569-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210416_181019_786013_E14B689C X-CRM114-Status: GOOD ( 11.36 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org uclibc/gcc combined with elf2flt riscv linker file fully resolve the PC relative __global_pointer$ value at compile time and do not generate a relocation entry to set a correct value of the gp register at runtime. As a result, if the flatbin loader offsets the start of the data section, the relative position change between the text and data sections compared to the compile time positions results in an incorrect gp value being used. This causes flatbin executables to crash. Avoid this problem by enabling CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET automatically when CONFIG_RISCV is enabled and CONFIG_MMU is disabled. Signed-off-by: Damien Le Moal Acked-by: Palmer Dabbelt Acked-by: Greg Ungerer --- arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 4515a10c5d22..add528eb9235 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -33,6 +33,7 @@ config RISCV select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_HUGE_PMD_SHARE if 64BIT + select BINFMT_FLAT_NO_DATA_START_OFFSET if !MMU select CLONE_BACKWARDS select CLINT_TIMER if !MMU select COMMON_CLK