From patchwork Thu Jul 6 22:01:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Hackmann X-Patchwork-Id: 9829089 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 40E4D602F0 for ; Thu, 6 Jul 2017 22:01:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34A4C2842E for ; Thu, 6 Jul 2017 22:01:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28F662852A; Thu, 6 Jul 2017 22:01:55 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B687C2842E for ; Thu, 6 Jul 2017 22:01:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752825AbdGFWBx (ORCPT ); Thu, 6 Jul 2017 18:01:53 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:34098 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752580AbdGFWBv (ORCPT ); Thu, 6 Jul 2017 18:01:51 -0400 Received: by mail-pf0-f170.google.com with SMTP id q85so7202599pfq.1 for ; Thu, 06 Jul 2017 15:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Kmm1Qywy0u93ZgYCHXhJIS26JDoJ76s58y1twqrVVv0=; b=OStZQe69ae09diRUDqUvLkKBt2t3yMfGVdl4j8gLM7j2eK5a9pRIDJ9/zt/FmTnxGC cax/Ggb/733YBy/uYkZ6rV21BhHWW8Eu636Y/86pufaqIqHRU2SJRLQOYn0YsL935mpA +Wwxc3o54WaSk8g3y+5LdchNboZ7Qg0yyfiYyADFFPNYNl5szjfmCTFWHsY6YPsSblcN 0/lGr1gn8vPCQoSUcW5f5/Zy2qRYxzmpTaWK2F47Mi3vmej+HA5QRf6Gtcx0QGV+l+LX LsJOjUIMp52qzQoNsE0J1IithIrzgLmomVTRpXK9KHm7Ez7stKm4vWem8I5j/iPJbNWk 6Xng== 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; bh=Kmm1Qywy0u93ZgYCHXhJIS26JDoJ76s58y1twqrVVv0=; b=qZNGGDNc9SnKyyymubSUALEhgDYDCapsO4zZjq2axnY54hxo/XHK0Un4CzZYVX3b2t NvJAZJUMQsnKnTkd87du3PhnErt25mDRG717+YGc2siXhkORJh23OsD/zycNUTmo8wDj vhDB6N+UA5DVaXxz8gKsQVTon0vQY8GkP7k+cLOSd+5yWFK3siG0xqSTzFMlgHBZM8D4 sOLo+zkrTCQ8EMhRjzCb3YZNN2ZYXN+RL6NJbq58qHPzGJB5J4TbypjNBVFpxIAKctlp 7CWb86NWEh8vFMWTzu/SZGt0TqAqrKDcZSLH69JoYsUrA8EgtuSpPEzLXLQBPWy/uhah EMow== X-Gm-Message-State: AIVw113Mq52teg46Hf78vykFLqWHafZKaSCmKhOv7Gc2WNNf5WurJ23X JVR0OT1gAc4SzOPh X-Received: by 10.99.145.67 with SMTP id l64mr28212437pge.184.1499378500808; Thu, 06 Jul 2017 15:01:40 -0700 (PDT) Received: from hackmann.mtv.corp.google.com ([172.22.122.89]) by smtp.gmail.com with ESMTPSA id w190sm2477691pgb.30.2017.07.06.15.01.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Jul 2017 15:01:40 -0700 (PDT) From: Greg Hackmann To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Masahiro Yamada , Michal Marek Cc: linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kbuild@vger.kernel.org, Matthias Kaehlcke , Michael Davidson , Greg Hackmann Subject: [PATCH 2/4] kasan: added functions for unpoisoning stack variables Date: Thu, 6 Jul 2017 15:01:12 -0700 Message-Id: <20170706220114.142438-3-ghackmann@google.com> X-Mailer: git-send-email 2.13.2.725.g09c95d1e9-goog In-Reply-To: <20170706220114.142438-1-ghackmann@google.com> References: <20170706220114.142438-1-ghackmann@google.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Alexander Potapenko As a code-size optimization, LLVM builds since r279383 may bulk-manipulate the shadow region when (un)poisoning large memory blocks. This requires new callbacks that simply do an uninstrumented memset(). This fixes linking the Clang-built kernel when using KASAN. Signed-off-by: Alexander Potapenko [ghackmann@google.com: fix memset() parameters, and tweak commit message to describe new callbacks] Signed-off-by: Greg Hackmann Reviewed-by: Dmitry Vyukov --- mm/kasan/kasan.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c index 892b626f564b..89911e5c69f9 100644 --- a/mm/kasan/kasan.c +++ b/mm/kasan/kasan.c @@ -828,6 +828,21 @@ void __asan_allocas_unpoison(const void *stack_top, const void *stack_bottom) } EXPORT_SYMBOL(__asan_allocas_unpoison); +/* Emitted by the compiler to [un]poison local variables. */ +#define DEFINE_ASAN_SET_SHADOW(byte) \ + void __asan_set_shadow_##byte(const void *addr, size_t size) \ + { \ + __memset((void *)addr, 0x##byte, size); \ + } \ + EXPORT_SYMBOL(__asan_set_shadow_##byte) + +DEFINE_ASAN_SET_SHADOW(00); +DEFINE_ASAN_SET_SHADOW(f1); +DEFINE_ASAN_SET_SHADOW(f2); +DEFINE_ASAN_SET_SHADOW(f3); +DEFINE_ASAN_SET_SHADOW(f5); +DEFINE_ASAN_SET_SHADOW(f8); + #ifdef CONFIG_MEMORY_HOTPLUG static int kasan_mem_notifier(struct notifier_block *nb, unsigned long action, void *data)