Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2184662ybl; Thu, 9 Jan 2020 08:16:59 -0800 (PST) X-Google-Smtp-Source: APXvYqw6Fucw+njzDp8sGIE+2jQRqJrtFENtHLTLXOQ87Cf8BaZUYYhSrdTngm6+8gpywVywrFdd X-Received: by 2002:a9d:367:: with SMTP id 94mr8616260otv.329.1578586619764; Thu, 09 Jan 2020 08:16:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578586619; cv=none; d=google.com; s=arc-20160816; b=d4QRruROyKjXMetK9nCVDkVGghm8ehogugJ3uuhnEsfd2YEuunk9oDYV2VdgugwUet TXAFM0q7OAaBfJ1SRdKiWa+WWhSwHBEhXOmJlehCmVWfRq3I8XuhJhFZKADVbZJ2yhsF +O3NfE8jJECQGVCZqtHoyPisz8dTw1yyjIOSqo03p8y1EiQooPsaji6P1t2V6x28kR9c Rh44jtk3b28tbGfJCdyXQoFKwzbWPuQ9WnSw5XYzoH3HDglWdnFMoG4D0r4XX06qucVx ypB+nf4OSSaWK2Hrvt2IOiBBtT3Z6dxhy+8V/Ih3rePZyndgy+EukU/qMLPOTh8ibgX6 iWRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=TjWp4hsnhHyuxcUJwcysIaMQE5a4k0+1XG9UcxNcIzw=; b=LKzqEQeWue3A19LY054g4POO/44i+yZET7edmjKn/6itGXrMBHG+qID9jRtI5j+ac5 +Nkk4oD+Uu9ZivZi+huhFOQsEnKVIyF09MB8ecI/TmkbkNJ+CNqcVVHVZO6l0cWksxeZ JgjsjBhzPjm3AhAJ35wjK2Onvyvscl+vkEDZtfCgYbRIaqK7JkkMLUMGg2Auu4uPXvWP 50TAlgEyovza+98Ah+kgPD5Dmxi/Z6IjrSNcN6/TuP59YfazDujfCpEFBeQ07aphd1Ya 9jIKdLGVS7lX+wlkcsnayUrdanNYdwshhBV2UYI2q+UCdpPTzxf9qrcnlilZCuPhVjCa Ql+Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8si4150425otq.262.2020.01.09.08.16.46; Thu, 09 Jan 2020 08:16:59 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730258AbgAINk5 (ORCPT + 99 others); Thu, 9 Jan 2020 08:40:57 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8247 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725839AbgAINk5 (ORCPT ); Thu, 9 Jan 2020 08:40:57 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id A5C634568D018053A16A; Thu, 9 Jan 2020 21:40:54 +0800 (CST) Received: from huawei.com (10.175.113.25) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.439.0; Thu, 9 Jan 2020 21:40:47 +0800 From: Wang ShaoBo To: , , CC: , , , , , , , , , Subject: [PATCH v2] sys_personality: Add a optional arch hook arch_check_personality() for common sys_personality() Date: Thu, 9 Jan 2020 21:36:34 +0800 Message-ID: <20200109133634.176483-1-bobo.shaobowang@huawei.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org currently arm64 use __arm64_sys_arm64_personality() as its default syscall. But using a normal hook arch_check_personality() can reject personality settings for special case of different archs. Signed-off-by: Wang ShaoBo --- Changes in v2: - Delete inline ksys_personality() definition. - Update sys_personality() definition. Changes in v1: - Delete macro __arm64_sys_personality. - Add hook arch_check_personality() and update sys_personality(). --- arch/arm64/kernel/sys.c | 7 +++---- include/linux/syscalls.h | 10 ---------- kernel/exec_domain.c | 14 +++++++++++++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kernel/sys.c b/arch/arm64/kernel/sys.c index d5ffaaab31a7..5c01816d7a77 100644 --- a/arch/arm64/kernel/sys.c +++ b/arch/arm64/kernel/sys.c @@ -28,12 +28,13 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); } -SYSCALL_DEFINE1(arm64_personality, unsigned int, personality) +int arch_check_personality(unsigned int personality) { if (personality(personality) == PER_LINUX32 && !system_supports_32bit_el0()) return -EINVAL; - return ksys_personality(personality); + + return 0; } asmlinkage long sys_ni_syscall(void); @@ -46,8 +47,6 @@ asmlinkage long __arm64_sys_ni_syscall(const struct pt_regs *__unused) /* * Wrappers to pass the pt_regs argument. */ -#define __arm64_sys_personality __arm64_sys_arm64_personality - #undef __SYSCALL #define __SYSCALL(nr, sym) asmlinkage long __arm64_##sym(const struct pt_regs *); #include diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 2960dedcfde8..b7ead4c933d5 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -1389,16 +1389,6 @@ static inline long ksys_truncate(const char __user *pathname, loff_t length) return do_sys_truncate(pathname, length); } -static inline unsigned int ksys_personality(unsigned int personality) -{ - unsigned int old = current->personality; - - if (personality != 0xffffffff) - set_personality(personality); - - return old; -} - /* for __ARCH_WANT_SYS_IPC */ long ksys_semtimedop(int semid, struct sembuf __user *tsops, unsigned int nsops, diff --git a/kernel/exec_domain.c b/kernel/exec_domain.c index 33f07c5f2515..1e70b41bf348 100644 --- a/kernel/exec_domain.c +++ b/kernel/exec_domain.c @@ -35,9 +35,21 @@ static int __init proc_execdomains_init(void) module_init(proc_execdomains_init); #endif +int __weak arch_check_personality(unsigned int personality) +{ + return 0; +} + SYSCALL_DEFINE1(personality, unsigned int, personality) { - unsigned int old = current->personality; + int check; + unsigned int old; + + check = arch_check_personality(personality); + if (check) + return check; + + old = current->personality; if (personality != 0xffffffff) set_personality(personality); -- 2.20.1