From patchwork Fri Jun 14 03:07:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 166748 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1505457ilk; Thu, 13 Jun 2019 20:12:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3v6DmL5WRHXaT0078lb2hJyzu28vfOXDR8NBGFMSo2gc0Vb01GYKQfyScBa70xa41dPNG X-Received: by 2002:a17:902:728b:: with SMTP id d11mr61731578pll.78.1560481941802; Thu, 13 Jun 2019 20:12:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560481941; cv=none; d=google.com; s=arc-20160816; b=yTBwTTbGqNqC6mU8YoY+KwflB0Y7r2Gh41HbwAgL2e3T/vxEqjMyUUgy+V3TL2RMaf hg629VL4UMOVt/6SI0zdaanx7fzU7RKytCZZngyocCJIEus3kabBntjN/eMfGykhidj/ JsFd/MlNxfSYZXEMqH+UkgHTAHHvGGJFMgm0aPBgY13cKuk6TZFYyR9jf43/irCxSs9x YvONTIKHTpKPYt861JCwml+juAfvCa5vUaV2ph6BIYpxAZElUVddJxPXDSDGFU2TvmLU EcGTm+jcYgwYwXgRkVNuAynVP60WmCdGCzf5WEg1f4B9zfKDRrW5Ir+n4Em+3ND1wMUQ tl9w== 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=q/AGFfvfHGuDn+dFoAxSTyRFru9zQTVknf0DUmu2KKo=; b=cKIEhobQTZjmHYElbvPUCG3t94wSGGmA08oRBgUmzgytv5bA32tz93IPC2P7ixq/qZ oF7h4xP0prqrBd1DjltcHYtpOb/VO0tGxaG/ghy5g1jCMZauc7zq8Q1MzUMvssEQnY9p 23/9Rkx9TNMz5IZQ7dUUGNannLII+4f6lRnPVP4yD++GgfSuZzGsMa0scOw9sthSu4JC qskDEKpaCzuhmlR4hyUR7vCzGF/fIhYhDRCOMtCloj/XdBIm0ZNy0j9jHrK4wZ7hYRyd Xv3JX2CwmBIupwYAo3UOTsGcNYUx95xDW5a00Zb86TlN6hjY62DOvUgC2K7PvLH5QAaA MkWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EXoJEH53; 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 e8si1073936plb.420.2019.06.13.20.12.21; Thu, 13 Jun 2019 20:12:21 -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=EXoJEH53; 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 S1726252AbfFNDMV (ORCPT + 14 others); Thu, 13 Jun 2019 23:12:21 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:44908 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725819AbfFNDMU (ORCPT ); Thu, 13 Jun 2019 23:12:20 -0400 Received: by mail-pg1-f194.google.com with SMTP id n2so661584pgp.11 for ; Thu, 13 Jun 2019 20:12:20 -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=q/AGFfvfHGuDn+dFoAxSTyRFru9zQTVknf0DUmu2KKo=; b=EXoJEH537ekXX3OvBiXCvmYHnyJHpvoGxXHrkSWsLSUvuohlVgtJEa16Btv4b48dDT WPz9HDGvXX8/nfn9lVM72XeiB9o9Oud6n17yMvo6jFo1TBKW2w7jxU5eKNxnx/qxJwPL AvlDDz8H11flscmdP85UFmYZo0xJOIPPWY194dVFEKTIGoyk/pXK9Gui6nQtoZazb9Fm Kuuxgi5vx34eECek4Lpt0jUWDQb0csa1Q7tO8kDvWPzNqWI1rAfkYQwhqAtu1wm6Dv14 HHIg5YEPsOZ0S8qPY/dHrduCyZN09fRXoq9Za4pf24DYyYETtGvVSyIrAHZzS+KvYQuv rDjQ== 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=q/AGFfvfHGuDn+dFoAxSTyRFru9zQTVknf0DUmu2KKo=; b=FYwC3rPqWmdQsLwM2W7sXs0y/XO1afZRqDlIe1Chg1TAmoprzf96NpSE0Uni3V3ibX 7J5w+bM1Zrmocmwsw0EoDBUuRlQL7I2KJaoUv8gH2AHmZ8okNCd/BChnIcexZZl675iA yJp62iIIzyYNAgBpUEH4SKaKiqu97hDKqegZldC6aUtnC9jvN89nW8iR7B0G42udMfeO ethNUfPUNceScJMgQKl4JUyYK/sbC5xLmk1izF9NyhZZ05EgWI8pk+ZUottzDcGgwaNm dEk+NuMj4LgILy1MkBuC5w0U8fC/6ufm33PxCNNIzHYLuqcdCqZCs4qXOkFeV6c2eEGI tI8Q== X-Gm-Message-State: APjAAAUrWlbQ4s3ohTF4fKgK8JnQjGvN5c+DBm83naS16K4+mC9WPn5+ C3QcnHppUIhc7rnqI1Noy4KKUw== X-Received: by 2002:a17:90a:cf0d:: with SMTP id h13mr8016081pju.63.1560481940227; Thu, 13 Jun 2019 20:12:20 -0700 (PDT) Received: from localhost ([122.172.66.84]) by smtp.gmail.com with ESMTPSA id r4sm1129694pjd.25.2019.06.13.20.12.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2019 20:12:19 -0700 (PDT) From: Viresh Kumar To: linux-arm-kernel@lists.infradead.org, Julien Thierry Cc: Viresh Kumar , stable@vger.kernel.org, Catalin Marinas , Marc Zyngier , Mark Rutland , Will Deacon , Russell King , Vincent Guittot , mark.brown@arm.com Subject: [PATCH v4.4 10/45] mm/kasan: add API to check memory regions Date: Fri, 14 Jun 2019 08:37:53 +0530 Message-Id: <0cedfc51f5941ab2c2e9a09149d34c7451efda56.1560480942.git.viresh.kumar@linaro.org> 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 ] 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 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..3ad31df33e76 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, _RET_IP_); +} +EXPORT_SYMBOL(kasan_check_read); + +void kasan_check_write(const void *p, unsigned int size) +{ + check_memory_region((unsigned long)p, size, true, _RET_IP_); +} +EXPORT_SYMBOL(kasan_check_write); + #undef memset void *memset(void *addr, int c, size_t len) {