From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B017C5519F for ; Mon, 30 Nov 2020 06:02:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 95B3D20757 for ; Mon, 30 Nov 2020 06:02:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725933AbgK3GBq (ORCPT ); Mon, 30 Nov 2020 01:01:46 -0500 Received: from atcsqr.andestech.com ([60.248.187.195]:23423 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725860AbgK3GBp (ORCPT ); Mon, 30 Nov 2020 01:01:45 -0500 X-Greylist: delayed 1765 seconds by postgrey-1.27 at vger.kernel.org; Mon, 30 Nov 2020 01:01:45 EST Received: from ATCSQR.andestech.com (localhost [127.0.0.2] (may be forged)) by ATCSQR.andestech.com with ESMTP id 0AU5WjgV040092 for ; Mon, 30 Nov 2020 13:32:45 +0800 (GMT-8) (envelope-from tesheng@andestech.com) Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id 0AU5VqLj039951; Mon, 30 Nov 2020 13:31:52 +0800 (GMT-8) (envelope-from tesheng@andestech.com) Received: from atcfdc88.andestech.com (10.0.15.120) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.487.0; Mon, 30 Nov 2020 13:31:25 +0800 From: Eric Lin To: , , , , , , , , , CC: , Eric Lin , Alan Kao Subject: [PATCH] riscv/mm: Prevent kernel module access user-space memory without uaccess routines Date: Mon, 30 Nov 2020 13:30:37 +0800 Message-ID: <20201130053037.27006-1-tesheng@andestech.com> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.0.15.120] X-DNSRBL: X-MAIL: ATCSQR.andestech.com 0AU5VqLj039951 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the page fault handler, an access to user-space memory without get/put_user() or copy_from/to_user() routines is not resolved properly. Like arm and other architectures, we need to let it die earlier in page fault handler. Signed-off-by: Eric Lin Cc: Alan Kao --- arch/riscv/mm/fault.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c index 3c8b9e433c67..a452cfa266a2 100644 --- a/arch/riscv/mm/fault.c +++ b/arch/riscv/mm/fault.c @@ -232,6 +232,9 @@ asmlinkage void do_page_fault(struct pt_regs *regs) if (user_mode(regs)) flags |= FAULT_FLAG_USER; + if (!user_mode(regs) && addr < TASK_SIZE && unlikely(!(regs->status & SR_SUM))) + die(regs, "Accessing user space memory without uaccess routines\n"); + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr); if (cause == EXC_STORE_PAGE_FAULT) -- 2.17.0