Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp11931880ybl; Sat, 28 Dec 2019 01:50:06 -0800 (PST) X-Google-Smtp-Source: APXvYqw69uRpLfGqBC5l3oNfPKtCpBlkkO26ojphDLaFgP3pe2M/bpNrF30YZjeUU6Ypec2jQklG X-Received: by 2002:a05:6830:22e6:: with SMTP id t6mr64572012otc.244.1577526605925; Sat, 28 Dec 2019 01:50:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577526605; cv=none; d=google.com; s=arc-20160816; b=VXUIDx+dGxrmFHTFm0LbKtYaWe2QBewI1mrewmO70DZRPkUct7cY+6ei6rxFY+tSau lYV/z3Dg9A5Ylj1tZlwknaqmkeOxRT96Hcr9nMXwGaguT/heAPGCZ5YGcGZOD/AAXROc El1RGtJ4f7bfQ4fSUPlai7o3Ncel+TvVWuYOaW9kpr8D+P0WYWlmQAFOu5oKDMjOEg6e O9n3XVzWCYcebzY+6iVAHL/f82/A9mFRXbiI4idNVH+jp2/OKqHsQNQQ/TmU/ABwZWe7 DS87hMVEemz03pMgX8bkFcMNZvZeeeCN8eN9iZsup7Gpk1gPh4hTOmW8JQ5W2Go+ixgn hx0g== 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=iArYZD1PqcGBbW7VUY0bMa963B7uQJftn6HXPbtbSBo=; b=HHcK84AZiCUHM3bSu2XNjnDbnT3fyKpwbBdzNNrEtItNG6+LZPkx9DSKR7LZts6E4r /dDaWr+qLAsPO+/vs7FDKXk7GNlMxvQD2S08nd2wy1KO7X9S8VftnFtzr9cOu52qLAkY fI7zNsReYsT+Uq/x/3o3hNgL0N22hfkxpd5JcfRfW7/aP81HsnGOrE4ZymD5Jc8GeLnY PNX3wTmXh6z5bW40xk2ViI6RvhAaj4IqoXsByVaB3aTtu9PLfHVbKMA825ICQ3Aw+hNh cz+7QYmQLGkEM3ReDFPCCJjPn4awrpi9cobI8yJ4tifG1C/uoTwvBA/j/+TUqpU2uzAI 7mbA== 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 v5si14063778oix.197.2019.12.28.01.49.43; Sat, 28 Dec 2019 01:50:05 -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 S1726418AbfL1JsF (ORCPT + 99 others); Sat, 28 Dec 2019 04:48:05 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:58002 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726362AbfL1JsF (ORCPT ); Sat, 28 Dec 2019 04:48:05 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id D70F7DAA41F9E5264ECC; Sat, 28 Dec 2019 17:48:02 +0800 (CST) Received: from huawei.com (10.175.113.25) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Sat, 28 Dec 2019 17:47:53 +0800 From: Wang ShaoBo To: , CC: , , , , , , , , , Subject: [PATCH v3] sys_personality: Add a optional arch hook arch_check_personality() Date: Sat, 28 Dec 2019 17:44:07 +0800 Message-ID: <20191228094407.53031-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. Now using a normal hook arch_check_personality() can reject personality settings for special case of different archs. Signed-off-by: Wang ShaoBo --- arch/arm64/kernel/sys.c | 7 +++---- kernel/exec_domain.c | 14 ++++++++++---- 2 files changed, 13 insertions(+), 8 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/kernel/exec_domain.c b/kernel/exec_domain.c index 33f07c5f2515..d1d5d14441e2 100644 --- a/kernel/exec_domain.c +++ b/kernel/exec_domain.c @@ -35,12 +35,18 @@ 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; - if (personality != 0xffffffff) - set_personality(personality); + check = arch_check_personality(personality); + if (check) + return check; - return old; + return ksys_personality(personality); } -- 2.20.1