From patchwork Fri Feb 19 00:22:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12094571 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D10F7C433DB for ; Fri, 19 Feb 2021 00:25:01 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7ADFA64EC0 for ; Fri, 19 Feb 2021 00:25:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7ADFA64EC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:Mime-Version:Message-Id:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=1TcyP4ooEr8WB1PbIMty3vxLdxvheJ1N3Y7n+dyrTV8=; b=3DOKC61qjz1LRvVLXDpFzJ0j6W zwznsdszkGX6jkSYvDB6bNismA/Y8qJ8WNFe/0lRPAXjG6ruYzOxtPcG6gUqTc+UZmdneGbpN7Lj7 OejevviObQ05fJqw45CC0457MsOImA7luBOH7VpUogyuTPqAeAK9jLQW84uIC0u2QEegxzDWwkDqQ wAlx+wzOJjOVqccEVffhfMhxJrwtDeVzoLaXru2NqIa1EVtlesSYDpr2xHBZFia5U5OJYjGigOEy0 +Ni1Ejs2el/ayqLqVBgrdAViQ4Ws5naUH8g34RUWEeX5GvtCrctOR2/mnhZO0025d8SF4qXPci/z3 fUsPKLFg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lCtZ9-0005mG-TR; Fri, 19 Feb 2021 00:22:39 +0000 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lCtZ6-0005k8-KQ for linux-arm-kernel@lists.infradead.org; Fri, 19 Feb 2021 00:22:37 +0000 Received: by mail-qt1-x849.google.com with SMTP id r18so2251647qta.19 for ; Thu, 18 Feb 2021 16:22:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=U/iWzYWPjCN+XW1A2BqmtUjlIIZumhGvP/yo+EmOxYg=; b=G7bAXsSfm+ZNftqz1PsApsrrwJT8rMmTOEArec4kk5JfXkHSn5yAxj9DM4umoFPnWp RGmtL7d5uL9H7zRtAjVAbKIkaAF8ufdT94u9akurg8SFStJwtepBldAe7CzJ3uhcaMzp 9WEo3HH6yOSmwI+Lcgdd4NIQ6NS6Js00aG5ddncE4w0J4+Ks2433wNoGqaOZDjsXit0l tdPTVlwbwaNJ+GN5c/McwoIy7K8gu4vVTR2V/16/tycbQ9v2qp4R93lfHwogeNIl0Kjn NzIwqCWwxxy9qLwZ9Mf402aMCg10rkgFlP6McJvh2yH2Fz6dXez8C9TT4sRw8BpZBGe+ MWNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=U/iWzYWPjCN+XW1A2BqmtUjlIIZumhGvP/yo+EmOxYg=; b=PZeEDOueKRQhtx1czqDXcAPBhGkBjN8zXddfTEB1qYG9HWVGk8N64YgcSUhr8sALJH d/0huChZ6vojAViFolwxfBLY0FroXNQ8+evLTOBAwBk6CuGpPHz8NHGCw6DtdnKQLpUU Md81pz8M9tsrqPUdHL1d1ALmMQDNlLvKUxKxDNlfmxJ/A4qOY9huc07cNkRmtPjfW85k ilPVpVwOyoVSjtuDt+8YZfmB566bG8BqAMcBPJ6zyrCLrY9rq0ZkbzpO513HCtCMqeZ5 X+UUMjV+H9oGUt7pwbStj+jNzo3vbFYIRw/ngnPQTTnHwucKEnesTDLLwx+k9hbCxGTi CgWw== X-Gm-Message-State: AOAM530ASFQoDs5XmJtMxUCbR7V/eJN0mGVtjGZodNonxGy7O/EGQOkv kdhABxOvlJDXLJ9TXcWOlI/UG8NJFS71MXUu X-Google-Smtp-Source: ABdhPJyFsVJtAau0Mc2BHt611wI2ENN7q1M05EoS8ziF6kD66XPpoztxHVTEQqqAY5LyC/zaszm81323HxFZMODP X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:2d89:512e:587f:6e72]) (user=andreyknvl job=sendgmr) by 2002:a0c:8b8a:: with SMTP id r10mr6826124qva.52.1613694151028; Thu, 18 Feb 2021 16:22:31 -0800 (PST) Date: Fri, 19 Feb 2021 01:22:23 +0100 Message-Id: Mime-Version: 1.0 X-Mailer: git-send-email 2.30.0.617.g56c4b15f3c-goog Subject: [PATCH v2 1/2] kasan: initialize shadow to TAG_INVALID for SW_TAGS From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210218_192236_679685_ACF15184 X-CRM114-Status: GOOD ( 15.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, Christoph Hellwig , linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Peter Collingbourne , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, KASAN_SW_TAGS uses 0xFF as the default tag value for unallocated memory. The underlying idea is that since that memory hasn't been allocated yet, it's only supposed to be dereferenced through a pointer with the native 0xFF tag. While this is a good idea in terms on consistency, practically it doesn't bring any benefit. Since the 0xFF pointer tag is a match-all tag, it doesn't matter what tag the accessed memory has. No accesses through 0xFF-tagged pointers are considered buggy by KASAN. This patch changes the default tag value for unallocated memory to 0xFE, which is the tag KASAN uses for inaccessible memory. This doesn't affect accesses through 0xFF-tagged pointer to this memory, but this allows KASAN to detect wild and large out-of-bounds invalid memory accesses through otherwise-tagged pointers. This is a prepatory patch for the next one, which changes the tag-based KASAN modes to not poison the boot memory. Signed-off-by: Andrey Konovalov --- include/linux/kasan.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 14f72ec96492..44c147dae7e3 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -30,7 +30,8 @@ struct kunit_kasan_expectation { /* Software KASAN implementations use shadow memory. */ #ifdef CONFIG_KASAN_SW_TAGS -#define KASAN_SHADOW_INIT 0xFF +/* This matches KASAN_TAG_INVALID. */ +#define KASAN_SHADOW_INIT 0xFE #else #define KASAN_SHADOW_INIT 0 #endif