From patchwork Thu Nov 9 23:48:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 10052129 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 23775601EA for ; Thu, 9 Nov 2017 23:50:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 166752B1E7 for ; Thu, 9 Nov 2017 23:50:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AF5E2B1FE; Thu, 9 Nov 2017 23:50:57 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham 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 74A072B1E7 for ; Thu, 9 Nov 2017 23:50:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755416AbdKIXu4 (ORCPT ); Thu, 9 Nov 2017 18:50:56 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:56981 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755381AbdKIXuq (ORCPT ); Thu, 9 Nov 2017 18:50:46 -0500 Received: by mail-pf0-f194.google.com with SMTP id b85so5416282pfj.13; Thu, 09 Nov 2017 15:50:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BN46O+s3L77gknn0aCxUnu8+0O1IITmhZhbaANaB8vw=; b=vNjYcKWmJyAILH2iBZESL+EaC0SNRBbkUwpKaXnRm74O7loJ53xLLPyPl68GGHYBDn RRQnLEdvv00qTAqA5p4vAo35lY/o8KpBVfdHlA3tZm6L4hzKVbBCTnPHM3Zr0+9/Gz+Q bfbngg8D36jpZ8DIBTbik9LyXd9rot6vCtIMrYVJyhAoBau7AOkIXDbv7xV/u3qqV+Gy md8IWWYqUHd61P/nSZVEUubj3YJaKcYQEsugSD541X4ROLq62rrdeThJn+buhgKS0Pd5 HGJ6uLqBYxB3QBZyX7i1tRyEkQNBIEYfr5M7O/GJBtVKejjjhW2fzo3YoKM7qnW7NMmG pfNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BN46O+s3L77gknn0aCxUnu8+0O1IITmhZhbaANaB8vw=; b=JcfieEET3PXpxvvh7kvPeqwxuDKccVq7mAwxA9M86pUvxl9cPvNj7JjAHNenUc6VGm ACluv+n5tRRWMZZvRJNCuD4M1JiwyILGoRKec83fhcd7SQXI+rxlmwVHNDaHUyNAQCaj U5nKg5Ml9VJtslMcsVkMJ24LxxUUSIXtQ9PzX3DX4EDbgui2UAegaRKYftu7wmsCHJFt TQPLfEfie61DUhGgEBbg/wPaB7RpUrEu1mP5P3RlIxqIZ8LLsWsjwgMLTzGIIr5jAK2v /rxzzcAf4HioIxXDXX24E7l0d5nlqtpZImTWvG072Hz/nUTUzyZHkRGfrdPXdm7yrbtt 6usQ== X-Gm-Message-State: AJaThX6DT5byuXMmHd51Mg0q3zBeIaw3RhnAYgENrNBmHDlN/GRQbq14 n18hBULJi0DqKoeJ1V4xqRc= X-Google-Smtp-Source: ABhQp+QHjY61nAPUYKPvGsxEWgK1hvnW/PM1tCJe40m3lPBs6QLEt9WdIZ1P4wfZlb+1sKVqKB/t2Q== X-Received: by 10.98.166.148 with SMTP id r20mr2187866pfl.80.1510271446157; Thu, 09 Nov 2017 15:50:46 -0800 (PST) Received: from localhost.localdomain ([121.137.63.184]) by smtp.gmail.com with ESMTPSA id t25sm13160477pfh.67.2017.11.09.15.50.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 15:50:45 -0800 (PST) From: Sergey Senozhatsky To: Tony Luck , Fenghua Yu , Helge Deller , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , James Bottomley Cc: Andrew Morton , Jessica Yu , Petr Mladek , Steven Rostedt , linux-ia64@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv4 4/6] parisc64: Add .opd based function descriptor dereference Date: Fri, 10 Nov 2017 08:48:28 +0900 Message-Id: <20171109234830.5067-5-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171109234830.5067-1-sergey.senozhatsky@gmail.com> References: <20171109234830.5067-1-sergey.senozhatsky@gmail.com> Sender: linux-parisc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We are moving towards separate kernel and module function descriptor dereference callbacks. This patch enables it for parisc64. For pointers that belong to the kernel - Added __start_opd and __end_opd pointers, to track the kernel .opd section address range; - Added dereference_kernel_function_descriptor(). Now we will dereference only function pointers that are within [__start_opd, __end_opd); For pointers that belong to a module - Added dereference_module_function_descriptor() to handle module function descriptor dereference. Now we will dereference only pointers that are within [module->opd.start, module->opd.end). Signed-off-by: Sergey Senozhatsky Signed-off-by: Helge Deller --- arch/parisc/boot/compressed/vmlinux.lds.S | 2 ++ arch/parisc/include/asm/sections.h | 6 ++++++ arch/parisc/kernel/module.c | 16 ++++++++++++++++ arch/parisc/kernel/process.c | 9 +++++++++ arch/parisc/kernel/vmlinux.lds.S | 2 ++ 5 files changed, 35 insertions(+) diff --git a/arch/parisc/boot/compressed/vmlinux.lds.S b/arch/parisc/boot/compressed/vmlinux.lds.S index a4ce3314e78e..4ebd4e65524c 100644 --- a/arch/parisc/boot/compressed/vmlinux.lds.S +++ b/arch/parisc/boot/compressed/vmlinux.lds.S @@ -29,7 +29,9 @@ SECTIONS . = ALIGN(16); /* Linkage tables */ .opd : { + __start_opd = .; *(.opd) + __end_opd = .; } PROVIDE (__gp = .); .plt : { *(.plt) diff --git a/arch/parisc/include/asm/sections.h b/arch/parisc/include/asm/sections.h index accdf40aa5b7..5a40b51df80c 100644 --- a/arch/parisc/include/asm/sections.h +++ b/arch/parisc/include/asm/sections.h @@ -6,8 +6,14 @@ #include #ifdef CONFIG_64BIT + +#define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1 + #undef dereference_function_descriptor void *dereference_function_descriptor(void *); + +#undef dereference_kernel_function_descriptor +void *dereference_kernel_function_descriptor(void *); #endif #endif diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c index f1a76935a314..b5b3cb00f1fb 100644 --- a/arch/parisc/kernel/module.c +++ b/arch/parisc/kernel/module.c @@ -66,6 +66,7 @@ #include #include +#include #if 0 #define DEBUGP printk @@ -954,3 +955,18 @@ void module_arch_cleanup(struct module *mod) { deregister_unwind_table(mod); } + +#ifdef CONFIG_64BIT +void *dereference_module_function_descriptor(struct module *mod, void *ptr) +{ + unsigned long start_opd = (Elf64_Addr)mod->core_layout.base + + mod->arch.fdesc_offset; + unsigned long end_opd = start_opd + + mod->arch.fdesc_count * sizeof(Elf64_Fdesc); + + if (ptr < (void *)start_opd || ptr >= (void *)end_opd) + return ptr; + + return dereference_function_descriptor(ptr); +} +#endif diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c index 30f92391a93e..6c4585103a91 100644 --- a/arch/parisc/kernel/process.c +++ b/arch/parisc/kernel/process.c @@ -276,6 +276,15 @@ void *dereference_function_descriptor(void *ptr) ptr = p; return ptr; } + +void *dereference_kernel_function_descriptor(void *ptr) +{ + if (ptr < (void *)__start_opd || + ptr >= (void *)__end_opd) + return ptr; + + return dereference_function_descriptor(ptr); +} #endif static inline unsigned long brk_rnd(void) diff --git a/arch/parisc/kernel/vmlinux.lds.S b/arch/parisc/kernel/vmlinux.lds.S index 159a2ec0b4e0..da2e31190efa 100644 --- a/arch/parisc/kernel/vmlinux.lds.S +++ b/arch/parisc/kernel/vmlinux.lds.S @@ -100,7 +100,9 @@ SECTIONS . = ALIGN(16); /* Linkage tables */ .opd : { + __start_opd = .; *(.opd) + __end_opd = .; } PROVIDE (__gp = .); .plt : { *(.plt)