Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp4048541ybg; Sun, 7 Jun 2020 19:53:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI0BbV/N9I6MXPO3HrCM94kzzmL+3YlhnY5nQeWy9xuiD234UQNSzSWgsVEv3CGsvV161C X-Received: by 2002:a17:906:5e06:: with SMTP id n6mr18299982eju.504.1591584826722; Sun, 07 Jun 2020 19:53:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591584826; cv=none; d=google.com; s=arc-20160816; b=ObSJaEC8fJJaR+zcb0aLUMVum7Ftff5C+QaquhSi7505W+ejxWpf1GrHCJWAuh2nK1 BvxnCfnuP8gvU8GKxXS959Tc9AcSdm36lxaUi/hJero5/3U317iNAM87FJrLI43sH1+7 eu3PK9Te/YPR23wSeJhrYGxghYZ5qRUnXdoFC8ZyJTF3UdWYKtoS+vk7n6bqBLM0Rodt 3vj9gPgSi5ehfgLlenJO5kmorWM318Qnvr1hZRZDuO5qNu/VYSSWwRVCqolPne5ttaAK 5PyL8Wry4eRcjR13v0eiNq6ahRLbA1Raf2bj5NFG8J3xgiBxMFjXskfcdbWE7GXJUpi4 1vyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:mime-version:message-id:date:subject :cc:from; bh=DIHLC3wmrWOQ0VIS044u/FvSfGBtD8aU0nIhxEmJ28o=; b=AqWrRVVJedSL19L9qxsqn2B5yNUk95jmrwH0gHJ5Q1XL8b/HsZhew60yEjk9qAQ68a wqlGMPkbO29FTRIee3b7Ssqnn+UW6SG+hBihy9dEVX6L/uu54wGYKuvHLz3u6L+CWdPV 5lBIyVebgGDb1qYoKnX4vRgU3sv4WdlsEyqimDnQv8tbEErFPHkwcThvlIxiy6XBRLeR Vr7bWzrt1Q6j4/aMcKWhhMDlI8RWsF8UB87+vlN2ETn7MhRUb3OtoKyQK+tAq21bT6AM e46/pESjEYzhzi5yW/0W20s9A7HRfPryb0TNZxMj4Z3grqlOpWcjKK87UZpsr7lxNL1k 8ajA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u9si8197191edp.338.2020.06.07.19.53.24; Sun, 07 Jun 2020 19:53:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728802AbgFHCtn (ORCPT + 99 others); Sun, 7 Jun 2020 22:49:43 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:41322 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728065AbgFHCtm (ORCPT ); Sun, 7 Jun 2020 22:49:42 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id BF2978E29D725983B698; Mon, 8 Jun 2020 10:49:40 +0800 (CST) Received: from huawei.com (10.175.124.27) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Mon, 8 Jun 2020 10:49:31 +0800 From: Wang ShaoBo CC: , , , , , , , , , , , Subject: [RESEND PATCH] sys_personality: Add optional arch hook arch_check_personality Date: Mon, 8 Jun 2020 10:49:25 +0800 Message-ID: <20200608024925.42510-1-bobo.shaobowang@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.27] X-CFilter-Loop: Reflected To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently arm64 personality syscall uses wrapper __arm64_sys_personality to redirect to __arm64_sys_arm64_personality, it's easily confused, Whereas using an normal hook arch_check_personality() can reject additional settings like this for special case of different architectures. This makes code clean and easier for subsequent modification. Signed-off-by: Wang ShaoBo Reviewed-by: Dominik Brodowski --- 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 1815065d52f3..3dbbad498027 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -1393,16 +1393,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..f3682f4bf205 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 err; + unsigned int old; + + err = arch_check_personality(personality); + if (err) + return err; + + old = current->personality; if (personality != 0xffffffff) set_personality(personality); -- 2.17.1