Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1235435pxv; Thu, 1 Jul 2021 21:47:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz03jYhOCghVS7kYKUmUaJU35jtqPO7RvrfJSbINjw2b/LVffmcugRt2bkjkR23YgK5gPqB X-Received: by 2002:a02:cca6:: with SMTP id t6mr2774903jap.36.1625201250663; Thu, 01 Jul 2021 21:47:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625201250; cv=none; d=google.com; s=arc-20160816; b=OhOqYFY7m7e1fN/repfwBoZCpaUuqZm5c9oxDOFHZCd3ZfcfvAMhmNmVWPKZD+ExsB n6F/4hLugLnuP33gCcstrb9fDY7S8DnCyDo3c4zB912qj3xdQI/RhMCyrAIT3xFCnMsN 52VBOYFzOPa1qqoo4Ksd71sFKA0xThL43ooPE2Mq9UxmRwL5Nb30XpQmqm2LCT3klL/L KGH+hPCh/j/JAp88G2f71VrQXBS91YgZZqb4XH70CczfmlyoI9QVGNX51Ry3bCr5ys9t r5Rio+GFeM9+/WRLNJ8KlZ+Xh4bpwJNIYKR1+QumfFPCIkQbqmWLlyFYfi4cbid6qWw5 JTmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=5F6vIgdl+5H/09KMhT18w77/OKOnrWcwyoIVWSOyvyg=; b=Flbm22t7UPDrB9vHsAvAtQBj3Dn3mBOvl5jhVAZPjp9cif3K9VbhS5sAY2ePkirVKc cVaYNzP1d5eoXbTuOr0hjQeBP1VHPHH+PcC9Esd49GsbVxZFXBYyHGa69EtVZFrLxtVl HUGMjG2HiAk0MRU8c6pOPCOtXi4wKlsxj0wXSqsqcR1OJ1bk2KjEjXZQ8cVdnkE1Tgt8 sJf2fGzY6cdx+f7tBF7ItVzr1X9XVeTebSxz7OuBtXM+GUbc/WJ61TEkGCcpRKJI7Qyf lzNGGnDsOQXmjtJ96+0+leX5MCSNxgQJsX3GClkx6BRyuxF158hY+TZjJ5i9PP10I5UT eunQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t10si2078925ilf.122.2021.07.01.21.47.16; Thu, 01 Jul 2021 21:47:30 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231782AbhGBErT (ORCPT + 99 others); Fri, 2 Jul 2021 00:47:19 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:13051 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbhGBErT (ORCPT ); Fri, 2 Jul 2021 00:47:19 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GGMqQ1qS6zZkDR; Fri, 2 Jul 2021 12:41:38 +0800 (CST) Received: from dggpemm000001.china.huawei.com (7.185.36.245) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 2 Jul 2021 12:44:46 +0800 Received: from localhost.localdomain (10.175.112.125) by dggpemm000001.china.huawei.com (7.185.36.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 2 Jul 2021 12:44:45 +0800 From: Tong Tiangen To: , Paul Walmsley , Palmer Dabbelt , Albert Ou CC: , , "Tong Tiangen" Subject: [PATCH -next] riscv: Implement thread_struct whitelist for hardened usercopy Date: Fri, 2 Jul 2021 04:54:21 +0000 Message-ID: <20210702045422.3527469-1-tongtiangen@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm000001.china.huawei.com (7.185.36.245) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This whitelists the FPU register state portion of the thread_struct for copying to userspace, instead of the default entire struct. Signed-off-by: Tong Tiangen --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/processor.h | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 821081bdb8b8..5c26c0726944 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -70,6 +70,7 @@ config RISCV select HAVE_ARCH_MMAP_RND_BITS if MMU select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_TRACEHOOK + select HAVE_ARCH_THREAD_STRUCT_WHITELIST select HAVE_ASM_MODVERSIONS select HAVE_CONTEXT_TRACKING select HAVE_DEBUG_KMEMLEAK diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 021ed64ee608..46b492c78cbb 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -37,6 +37,14 @@ struct thread_struct { unsigned long bad_cause; }; +/* Whitelist the fstate from the task_struct for hardened usercopy */ +static inline void arch_thread_struct_whitelist(unsigned long *offset, + unsigned long *size) +{ + *offset = offsetof(struct thread_struct, fstate); + *size = sizeof_field(struct thread_struct, fstate); +} + #define INIT_THREAD { \ .sp = sizeof(init_stack) + (long)&init_stack, \ } -- 2.25.1