From patchwork Thu May 26 18:43:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 9137351 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D611A6075C for ; Thu, 26 May 2016 19:13:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2A4D2793B for ; Thu, 26 May 2016 19:13:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95698280B2; Thu, 26 May 2016 19:13:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 401D32793B for ; Thu, 26 May 2016 19:13:14 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b60h3-0002X7-2C; Thu, 26 May 2016 19:11:41 +0000 Received: from mail-pa0-x230.google.com ([2607:f8b0:400e:c03::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b60h0-0002Vi-5t for linux-arm-kernel@lists.infradead.org; Thu, 26 May 2016 19:11:38 +0000 Received: by mail-pa0-x230.google.com with SMTP id eu11so23106731pad.3 for ; Thu, 26 May 2016 12:11:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=GQNYqKQdeD2g0ZhgmXatdbVh+VOHelvnptpdg7dL7PM=; b=a1cpfVUGb6cPTVZb87XSrTCvdWMjQNOpAfsO+W83umAYzyP6iEEqBW6kX/G+P2gnAU UNRdtr/UwXPSvZXVE/QUMY7jKGSncVBYu6mwZX1VUKuUsXseM9x0A6Cai+5kbchhJwXq f7n6vVLxDuX7FjzL72pZglCD/vDjomcfTAMMA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=GQNYqKQdeD2g0ZhgmXatdbVh+VOHelvnptpdg7dL7PM=; b=EVVp+eVqRCyayqGqj1FBIa5/KB1reXMGDgbreL7zvAy4hhPGhR5LtIju6jbI77V3NF VblbmymJx9wpt/oeJVRnbBBXemP7IrrgCZeMfVm2a0T5WZccC9m2NNUw/Z7BMLtW3yse BpcSnRTWvtSd1cgbrv9JSIipVqlXB3L9QRKto51G5Prg8p95PkQy7Mr8OEgzQQtuU9J5 3zxD3lQXkqdkjNfP9OQpNHsHiAZfK8l/i4AfrPpdrwXbbKzDkTd7p43o37wmOH5KFhB5 K/eVGYpbkzM9nzuLD2qpmGmdMGJX1eLmPUgSPwAj0JGYXMR1SaBPuCoMU9VXL+77XeyJ Azxg== X-Gm-Message-State: ALyK8tKMKmStYiN1a2GeglFuWPU94Sp1p9SA2kMlyDDXzCxp4qIOEwSdBGMzUz0kZgS6LCuB X-Received: by 10.67.14.7 with SMTP id fc7mr16428396pad.1.1464289876931; Thu, 26 May 2016 12:11:16 -0700 (PDT) Received: from yshi-Precision-T5600.corp.ad.wrs.com (unknown-216-82.windriver.com. [147.11.216.82]) by smtp.gmail.com with ESMTPSA id f187sm7854421pfb.60.2016.05.26.12.11.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 May 2016 12:11:16 -0700 (PDT) From: Yang Shi To: aryabinin@virtuozzo.com, will.deacon@arm.com, catalin.marinas@arm.com Subject: [PATCH] arm64: kasan: instrument user memory access API Date: Thu, 26 May 2016 11:43:51 -0700 Message-Id: <1464288231-11304-1-git-send-email-yang.shi@linaro.org> X-Mailer: git-send-email 2.0.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160526_121138_262780_3B081497 X-CRM114-Status: GOOD ( 12.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mm@kvack.org, linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, yang.shi@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The upstream commit 1771c6e1a567ea0ba2cccc0a4ffe68a1419fd8ef ("x86/kasan: instrument user memory access API") added KASAN instrument to x86 user memory access API, so added such instrument to ARM64 too. Tested by test_kasan module. Signed-off-by: Yang Shi Acked-by: Mark Rutland Tested-by: Mark Rutland --- arch/arm64/include/asm/uaccess.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 0685d74..ec352fa 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -23,6 +23,7 @@ */ #include #include +#include #include #include @@ -276,6 +277,8 @@ extern unsigned long __must_check __clear_user(void __user *addr, unsigned long static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n) { + kasan_check_write(to, n); + if (access_ok(VERIFY_READ, from, n)) n = __copy_from_user(to, from, n); else /* security hole - plug it */ @@ -285,6 +288,8 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n) { + kasan_check_read(from, n); + if (access_ok(VERIFY_WRITE, to, n)) n = __copy_to_user(to, from, n); return n; @@ -297,8 +302,17 @@ static inline unsigned long __must_check copy_in_user(void __user *to, const voi return n; } -#define __copy_to_user_inatomic __copy_to_user -#define __copy_from_user_inatomic __copy_from_user +static inline unsigned long __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n) +{ + kasan_check_read(from, n); + return __copy_to_user(to, from, n); +} + +static inline unsigned long __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n) +{ + kasan_check_write(to, n); + return __copy_from_user(to, from, n); +} static inline unsigned long __must_check clear_user(void __user *to, unsigned long n) {