From patchwork Thu Aug 29 11:33:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 172586 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp2091285ily; Thu, 29 Aug 2019 04:35:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzh+aIrWBEnzkD8uUuQ+eooMZ/+w7HzqCFyFvqxJsbbsj2CHh9E3yc6RofyRpxzN1eshYmG X-Received: by 2002:a63:e213:: with SMTP id q19mr7820654pgh.180.1567078517898; Thu, 29 Aug 2019 04:35:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567078517; cv=none; d=google.com; s=arc-20160816; b=WScoDR7WFpv6x3YTH7BS310TRSSMw1x1rvHuecLAJbS5N4TM+lr+NolLiixsrm3/1/ VP9vLWQMqYsjL892W49WbF04r6zgRL14i+bxEIuP7tRncYWFu42utRM0HLOsKQzFjsO4 w3RVAPPVdHTtNioC5oW3lhnALEE4IMzaOrxIDTuPlRo8RQZC5YQh2niZ2bWQkUFghbJf xBlmnqILMh7CU65q5nd2osewKKa03dPnWgiBQTIoSf/BRdbfKKSdWe+wZKOInY2q9PWI AdX1/hdUSXmAIzd4KO7isyhP7ALeTxw1OOI6KR4FptYMGyxXWhtzY2jHOzbX9vBxeJR9 f0QQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+i1PP70VM4gp+yGXoK79tVzWNeTCN5YHgyu+1fomQgA=; b=d3JU21bxexJsCzYBfiAR+rx+GXHalNUBHwuSh0M9YIOEXDOTH79a2MpN2IW84HWUIk SM5ealrzXw2Ak2Z9AIV781eRP8lSx9ZuBBNAjJ7v4+rjZU5Bc0Wh3LFI4cxEfZUIp4Rg MOve/WTpUulIR7H49yc4wSLBHCQPkKnNcA+ir+XTwenTT10nLLa66Q+0kbbq99086qH1 +zKYbAMNm4pJz0B4O3DiG426e8JSZ8TmTKWzeFzOtCTx4t5AMgOD99oLRMrImY11H7c8 9y5ZoyGnpivjr0HGon4wyik9W/iR9Nw4JcLGy6EMUQMmZWPradAZbpOlGlHv4S97mrpk od5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VUGv1GtX; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h13si1698624plr.12.2019.08.29.04.35.17; Thu, 29 Aug 2019 04:35:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VUGv1GtX; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727034AbfH2LfR (ORCPT + 14 others); Thu, 29 Aug 2019 07:35:17 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40957 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727174AbfH2LfR (ORCPT ); Thu, 29 Aug 2019 07:35:17 -0400 Received: by mail-pg1-f194.google.com with SMTP id w10so1447320pgj.7 for ; Thu, 29 Aug 2019 04:35:16 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=+i1PP70VM4gp+yGXoK79tVzWNeTCN5YHgyu+1fomQgA=; b=VUGv1GtX697HgH14HXO402w5rt/hVrHKuxPDrzMYrHA9MNrwKcBeVp5QmFZ0Yn2bIe 8wm3Gp/vNV/ttw6PDnQWJFwtjUuU7B9ReAuSsbzGHUNGuIB2f5QtbRHwEQ+AMqq/Flyw yFaYeLpOJ7nVVGHUDfoh2DV4TWHaKHT43C2xbhddaZgP3nk65dlOe3PMRz9dzfoVlYaK j7gyfJzh095YjY0vpih0lyQ75vA9+CzVnxR4U6CUyt7b6Y80gckwZnDAIzSsvP6v8//f Rv9wcWgH7Pcrh/MtZItqr3LmAOxBd/IVCOc1edVYJ5ouX+L8qxo0AQAkO7tP2yOagYMJ /5bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+i1PP70VM4gp+yGXoK79tVzWNeTCN5YHgyu+1fomQgA=; b=ZwKIaXSGbVbyUDJ0Z1v7T7Vo7Zg5hTvoK/SeHBfEdkM1SCyiH9XN+vY7EegWi1iWI4 2hcqfSAoN8bXv35atj+QbcbgjWtiJOP/EprZV+M5qwXdeWdccTeLt+hTZ0wy05nhsWA6 IAq6x/4Kjc1Z+EYMNg/XYOZ//z3C3RDbp1GDCID7pOAnwpXPGzwlmgxyjMODoEoVRxn3 xGWkxa6qv6cAsIvwlAg2MzwBGzmO0/VZniVGBys920GD+Whs73VhpkC+iHJP7OcrgP7x BFcZwQ1evGZIY3ZhW6Qu5+Cq12jf8oi9yxFcA/oJi+cufQUlR+2/2uqXZ1yAf3/uP4BN IW8w== X-Gm-Message-State: APjAAAX+15EHroog4x7UA5cIIqgN40Li4xo6hc20gyPfSFHRvHKwkr/3 g0StxZwsLDuwAQPpZ1Z6w1XyR4Wr58o= X-Received: by 2002:aa7:8d42:: with SMTP id s2mr10851725pfe.185.1567078516102; Thu, 29 Aug 2019 04:35:16 -0700 (PDT) Received: from localhost ([122.167.132.221]) by smtp.gmail.com with ESMTPSA id f12sm2154596pgo.85.2019.08.29.04.35.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 04:35:15 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org, Julien Thierry , Mark Rutland Cc: Viresh Kumar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Marc Zyngier , Will Deacon , Russell King , Vincent Guittot , mark.brown@arm.com Subject: [PATCH ARM64 v4.4 V3 09/44] mm/kasan: add API to check memory regions Date: Thu, 29 Aug 2019 17:03:54 +0530 Message-Id: X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Andrey Ryabinin commit 64f8ebaf115bcddc4aaa902f981c57ba6506bc42 upstream. Memory access coded in an assembly won't be seen by KASAN as a compiler can instrument only C code. Add kasan_check_[read,write]() API which is going to be used to check a certain memory range. Link: http://lkml.kernel.org/r/1462538722-1574-3-git-send-email-aryabinin@virtuozzo.com Signed-off-by: Andrey Ryabinin Acked-by: Alexander Potapenko Cc: Dmitry Vyukov Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Thomas Gleixner Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds [ v4.4: Fixed MAINTAINERS conflict and added whole kasan entry. Drop 4th argument to check_memory_region(). ] Signed-off-by: Viresh Kumar --- MAINTAINERS | 14 ++++++++++++++ include/linux/kasan-checks.h | 12 ++++++++++++ mm/kasan/kasan.c | 12 ++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 include/linux/kasan-checks.h -- 2.21.0.rc0.269.g1a574e7a288b Reviewed-by: Mark Rutland [v4.4 backport] diff --git a/MAINTAINERS b/MAINTAINERS index f4d4a5544dc1..2a8826732967 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5982,6 +5982,20 @@ S: Maintained F: Documentation/hwmon/k8temp F: drivers/hwmon/k8temp.c +KASAN +M: Andrey Ryabinin +R: Alexander Potapenko +R: Dmitry Vyukov +L: kasan-dev@googlegroups.com +S: Maintained +F: arch/*/include/asm/kasan.h +F: arch/*/mm/kasan_init* +F: Documentation/kasan.txt +F: include/linux/kasan*.h +F: lib/test_kasan.c +F: mm/kasan/ +F: scripts/Makefile.kasan + KCONFIG M: "Yann E. MORIN" L: linux-kbuild@vger.kernel.org diff --git a/include/linux/kasan-checks.h b/include/linux/kasan-checks.h new file mode 100644 index 000000000000..b7f8aced7870 --- /dev/null +++ b/include/linux/kasan-checks.h @@ -0,0 +1,12 @@ +#ifndef _LINUX_KASAN_CHECKS_H +#define _LINUX_KASAN_CHECKS_H + +#ifdef CONFIG_KASAN +void kasan_check_read(const void *p, unsigned int size); +void kasan_check_write(const void *p, unsigned int size); +#else +static inline void kasan_check_read(const void *p, unsigned int size) { } +static inline void kasan_check_write(const void *p, unsigned int size) { } +#endif + +#endif diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c index b7397b459960..1cdcab0c976a 100644 --- a/mm/kasan/kasan.c +++ b/mm/kasan/kasan.c @@ -274,6 +274,18 @@ static __always_inline void check_memory_region(unsigned long addr, void __asan_loadN(unsigned long addr, size_t size); void __asan_storeN(unsigned long addr, size_t size); +void kasan_check_read(const void *p, unsigned int size) +{ + check_memory_region((unsigned long)p, size, false); +} +EXPORT_SYMBOL(kasan_check_read); + +void kasan_check_write(const void *p, unsigned int size) +{ + check_memory_region((unsigned long)p, size, true); +} +EXPORT_SYMBOL(kasan_check_write); + #undef memset void *memset(void *addr, int c, size_t len) {