Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2398282yba; Thu, 25 Apr 2019 16:03:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXBQn8khSbGX/lJkOQrkowzzXHt54C0j/zavxg8JzK1hlQAnVuhitNpRL1+pWj1gjZswLI X-Received: by 2002:a63:5b4b:: with SMTP id l11mr38512591pgm.95.1556233380853; Thu, 25 Apr 2019 16:03:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556233380; cv=none; d=google.com; s=arc-20160816; b=lOB55qKEBQoRo+I1I8ScYsE6f1P1IAEu1n9MC9Oh/BLh25F6/3zo2vKDMcaw18DD3D PyOvDI3Schg3dczLgZscZIM3n3IDTFJvOl6xEi5lea37ZLcxX+LCDVODCvPBkGPESRLS usoRFuuG6Fi9KKC70ghmPALFldlY9V4qzCcdx/WcQ2asyUJZ5LvnMhZ1rMyOn/bxlNES giQemotu2touai3VM/p6XF356AXk3K5vgVkkwBURAMtY4x1Lbv5zyGlA8g9LAl5jNVQq C0HplweXzgIgdI3FXnHL3wwjFCCTPWWN9aN1dWj8tmoJpXDZGPokJzkoGgVZaoDdSS5F R0+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from; bh=UUXtBSBOzxuFMcQrn8ir4/fAjl8E5MhWLJKi7bnLtb8=; b=FPM6RpfaEl+YnQknX+vJ8/Az7kgYOF5KJEAev1CjLYUEtzDvWAW5475Wkoq7nXMvre Nsv4d4PvpqpIFwBIRQeAWXdwVZbul65XM8LRECwmrB4DEyNcmQht9vcWHv9jSs00SUAB Y1efQyEN+SC4hq/Hc5KhR3P456WTzfPv2uZrrQN9g8dAVoGF9I0cEgUzrUWuGUwucjmU dGs6+LPtiCgLYg8a3okMHFu9tFlLDWV0896UQMShnZY6mP8QNgS/r+kbw89dEd9RSPmY Mx+ZDqe8fImss2zIJTNqP549xu2M8CKadjlsqOnM+VfjCTtBQ5xFS40UQX3yTrC4zsFd IKEA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i66si6726320pfb.154.2019.04.25.16.02.38; Thu, 25 Apr 2019 16:03:00 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388269AbfDYVql (ORCPT + 99 others); Thu, 25 Apr 2019 17:46:41 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43018 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388254AbfDYVqg (ORCPT ); Thu, 25 Apr 2019 17:46:36 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x3PLY9eu187566 for ; Thu, 25 Apr 2019 17:46:34 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0b-001b2d01.pphosted.com with ESMTP id 2s3mqh8ran-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 25 Apr 2019 17:46:34 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 25 Apr 2019 22:46:32 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 25 Apr 2019 22:46:27 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x3PLkQoE46923988 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Apr 2019 21:46:26 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6F4B3AE04D; Thu, 25 Apr 2019 21:46:26 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EECBFAE051; Thu, 25 Apr 2019 21:46:23 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.204.209]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 25 Apr 2019 21:46:23 +0000 (GMT) Received: by rapoport-lnx (sSMTP sendmail emulation); Fri, 26 Apr 2019 00:46:23 +0300 From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Chartre , Andy Lutomirski , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , James Bottomley , Jonathan Adams , Kees Cook , Paul Turner , Peter Zijlstra , Thomas Gleixner , linux-mm@kvack.org, linux-security-module@vger.kernel.org, x86@kernel.org, Mike Rapoport Subject: [RFC PATCH 7/7] sci: add example system calls to exercse SCI Date: Fri, 26 Apr 2019 00:45:54 +0300 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556228754-12996-1-git-send-email-rppt@linux.ibm.com> References: <1556228754-12996-1-git-send-email-rppt@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19042521-0020-0000-0000-000003360C05 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19042521-0021-0000-0000-000021887A43 Message-Id: <1556228754-12996-8-git-send-email-rppt@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-04-25_18:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904250133 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Mike Rapoport --- arch/x86/entry/common.c | 6 +++- arch/x86/entry/syscalls/syscall_64.tbl | 3 ++ kernel/Makefile | 2 +- kernel/sci-examples.c | 52 ++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 kernel/sci-examples.c diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 8f2a6fd..be0e1a7 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -275,7 +275,11 @@ __visible inline void syscall_return_slowpath(struct pt_regs *regs) #ifdef CONFIG_SYSCALL_ISOLATION static inline bool sci_required(unsigned long nr) { - return false; + if (!static_cpu_has(X86_FEATURE_SCI)) + return false; + if (nr < __NR_get_answer) + return false; + return true; } static inline unsigned long sci_syscall_enter(unsigned long nr) diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl index f0b1709..a25e838 100644 --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -343,6 +343,9 @@ 332 common statx __x64_sys_statx 333 common io_pgetevents __x64_sys_io_pgetevents 334 common rseq __x64_sys_rseq +335 64 get_answer __x64_sys_get_answer +336 64 sci_write_dmesg __x64_sys_sci_write_dmesg +337 64 sci_write_dmesg_bad __x64_sys_sci_write_dmesg_bad # # x32-specific system call numbers start at 512 to avoid cache impact diff --git a/kernel/Makefile b/kernel/Makefile index 6aa7543..d6441d0 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -10,7 +10,7 @@ obj-y = fork.o exec_domain.o panic.o \ extable.o params.o \ kthread.o sys_ni.o nsproxy.o \ notifier.o ksysfs.o cred.o reboot.o \ - async.o range.o smpboot.o ucount.o + async.o range.o smpboot.o ucount.o sci-examples.o obj-$(CONFIG_MODULES) += kmod.o obj-$(CONFIG_MULTIUSER) += groups.o diff --git a/kernel/sci-examples.c b/kernel/sci-examples.c new file mode 100644 index 0000000..9bfaad0 --- /dev/null +++ b/kernel/sci-examples.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include + +SYSCALL_DEFINE0(get_answer) +{ + return 42; +} + +#define BUF_SIZE 1024 + +typedef void (*foo)(void); + +SYSCALL_DEFINE2(sci_write_dmesg, const char __user *, ubuf, size_t, count) +{ + char buf[BUF_SIZE]; + + if (!ubuf || count >= BUF_SIZE) + return -EINVAL; + + buf[count] = '\0'; + if (copy_from_user(buf, ubuf, count)) + return -EFAULT; + + printk("%s\n", buf); + + return count; +} + +SYSCALL_DEFINE2(sci_write_dmesg_bad, const char __user *, ubuf, size_t, count) +{ + unsigned long addr = (unsigned long)(void *)hugetlb_reserve_pages; + char buf[BUF_SIZE]; + foo func1; + + addr += 0xc5; + func1 = (foo)(void *)addr; + func1(); + + if (!ubuf || count >= BUF_SIZE) + return -EINVAL; + + buf[count] = '\0'; + if (copy_from_user(buf, ubuf, count)) + return -EFAULT; + + printk("%s\n", buf); + + return count; +} -- 2.7.4