Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp625893pxx; Wed, 28 Oct 2020 12:44:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPyPYj5de2RKXnz14Y0PWY76AgGtRKNk265A1YKe7pGtba9ePCr6b8sOmFJL8ttcPT+WJj X-Received: by 2002:a05:6402:142a:: with SMTP id c10mr507092edx.261.1603914264068; Wed, 28 Oct 2020 12:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603914264; cv=none; d=google.com; s=arc-20160816; b=cQByMO6/M08ixBI6WB2mN06HbwJM8aXKhLQTbxNlErR4C/RuDNHUjOoY2JXoff+z21 kbhfi/bcJ/B7pfO/j9shKaNW8n4Ijhj27vp/zOC0WlsLzSQACfPsfWwGTNA2l3fLG9nu lkLCyiSeg2/MGKRNiJU64XLOCp0i1pdXTkcqeP+oUJQfY4LkBZT3LASOM0IxghjKidug U1O/2t/BSrOktuiX0/UnFIk1VI63Ctpne/wSLY992qB6Ga8IHwA8C6PC0Dibv0/wzKzz zCsEDd5N8iPeQPVSSca25YB5z5s+glg/e4ZYcPA3IwZUSzzy3BUQWcOq5JBpmIc1rbTH Z46A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9/VDxQRHTfOeyaTlo/J4zWSzvMYUb7/DHTagCxAW7PQ=; b=BizIbDR+UzT3oSFOiysvrI3gN4fcJuGvXamOBNxUtUedY7nGK1qiQDWRSh8X2lWXKW B+uzIQ9dV/H148mWceD0eDyz4igRO3lgqM7x28y7GJdX4hOZ58Q+852tUClhe4t/Gl82 agDDyXlEJ4PO5dkKnVlNVjq62H4gnfpr4ojPP+UA9qzeVAEwVSw9tILRC9gN/AjlbdUk VWIufmI6bl7I4WZ4V7Jv2IAmxZG+HnbRInyrR/2YB/8TEaQk5QTZa+K1MoOj4UU3j8eM okqRThCVB7yhzhdGRjCjDqWuasSJocjUKp7WpL3wvYXaO381k8y8V23QbI0meSVqG+cT G6IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C0NA3bKr; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 8si179023edx.375.2020.10.28.12.44.01; Wed, 28 Oct 2020 12:44:24 -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; dkim=pass header.i=@kernel.org header.s=default header.b=C0NA3bKr; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1827779AbgJ0S1y (ORCPT + 99 others); Tue, 27 Oct 2020 14:27:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:44810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2504140AbgJ0N5p (ORCPT ); Tue, 27 Oct 2020 09:57:45 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A164C2072E; Tue, 27 Oct 2020 13:57:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807064; bh=I6ItegFF5/0mB3bA4/y65+UrSzJEeBIb/GuBLhWEBSs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C0NA3bKroKFAMb4PkEuOjcxFY95CCvHYQyc2lENqyOTCV16zJXix3uPzPgz+zQORZ JH8YlL3k2NSUZ0T9hl63blOj8X1m6rKzErGrHvbJwaVntCm/JtvTCWjmxawYxGvl8s pD+ydR8g1wOgmjCOCPDQsdri16PFpY7b6hyl5WZQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Andrew Morton , Linus Torvalds , Ben Hutchings Subject: [PATCH 4.4 007/112] mm/kasan: add API to check memory regions Date: Tue, 27 Oct 2020 14:48:37 +0100 Message-Id: <20201027134900.893996677@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134900.532249571@linuxfoundation.org> References: <20201027134900.532249571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 [bwh: Backported to 4.4: drop change in MAINTAINERS] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- include/linux/kasan-checks.h | 12 ++++++++++++ mm/kasan/kasan.c | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 include/linux/kasan-checks.h --- /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 --- a/mm/kasan/kasan.c +++ b/mm/kasan/kasan.c @@ -278,6 +278,18 @@ static void check_memory_region(unsigned check_memory_region_inline(addr, size, write, ret_ip); } +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) {