Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7648968pxb; Thu, 18 Feb 2021 16:25:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzwC3Plf+UJRoakK0dwJ9qEfjyxB7oKuB6k/I5ShNg+eiZCW0/guGvw4aOX+TjGEZLjuQP X-Received: by 2002:a17:906:1249:: with SMTP id u9mr6534041eja.484.1613694304096; Thu, 18 Feb 2021 16:25:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613694304; cv=none; d=google.com; s=arc-20160816; b=qRId6jWK762h6rFl6a5iXy37NT8JY/iiD6/HnuyIKbPsuMERsqKweqsZtkujLICqBE H6aax1A2cz5K5imFeZ9iJ0zcUxl26lKzSHXmFbO/vIYlTgmrLjHRqAaQ86i2kvI/i8Ah b2E2a9dhlBLh9N8iza4yKTWp7LQs+VAf9GhC7Ij0Iyw/cSYjR+4L+QlFtdKAdchWDN3Y 5pIpYgJBpHEvekV8uaH2RJDRgmcIBnCBGYkya7PFX+UzUSOF9bKjp1INQd43QIVmbv5x UGOPizLuJ+D7PniY9b/WbgQJd2uoFeLOxSv5Z64JbzZHeg/HvcIfy4XLqa9lZSl4CQzl KU5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :sender:dkim-signature; bh=U/iWzYWPjCN+XW1A2BqmtUjlIIZumhGvP/yo+EmOxYg=; b=JI6It6/MaV2LZKNM6wxkfHWC0qSlRlfULLXuRRzHLlrZtQcY3JfdG7EapEImyKyKo+ NsX37GFnUExFhPBoj78qbaKoEZdX3eABm4Y2YKAWLNGotPC017Foj0M5MRLo/tC4imTl MnPBWy43M0LyGoqOnF8jgkEQceWRCixR3xEA78nEQoU7tmY3khlE8MCL6fQTjxGUm6AB p6Hc/8OuROPnMv+IorcfbcmJcmjV++pks9OqqfhH1bqI294vxtnlhB4KO93h+n1w2SoK Jbv81rfzuDoCTRPh8UdTfJxxU5rrSxu6XoM4hnLAa2MpV0OHbBkIR3b4jOgT4OAB8bkH uNAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=G7bAXsSf; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z13si4299408edc.537.2021.02.18.16.24.40; Thu, 18 Feb 2021 16:25:04 -0800 (PST) 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=@google.com header.s=20161025 header.b=G7bAXsSf; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229802AbhBSAXN (ORCPT + 99 others); Thu, 18 Feb 2021 19:23:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbhBSAXM (ORCPT ); Thu, 18 Feb 2021 19:23:12 -0500 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C26FC061574 for ; Thu, 18 Feb 2021 16:22:32 -0800 (PST) Received: by mail-qt1-x849.google.com with SMTP id t5so2274355qti.5 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=GCYU7pmxDTxcwuHQfHAfPoHC03pOdo7nRW2bHlmF4zivW5/KB2MRmgfrvWOdumOhV4 3/8/WgRg3sToquS4yuXJBvSDPEb1fNkFhds73ndn+USuL1CfY3xdFKTeZPugefmlJ2gS n+3+WlqOS9Zoge+wKQ4xuzBoaqJN09qlxomquMLg8JQzKAsnHWsfVbUeMqqIPcO2V51A TkfX7NfULdpvp1c520RUkyE1VJjceMj1mNLetGyCwoET0fRnadwY7ri6RZhbd53okx5b EqJKGpu09BgQS91Ggi3YFgBVO3xFIZm0jyz76t60Hhr2bwl0SnBA4OTjF3EsMiseGx6D hJeQ== X-Gm-Message-State: AOAM533FKtmatmLQAHKrDi0uG6XZ/PCNVvDt3tNtnfDS3F00344PlrsC hEXAFCUxm1gXJknGdxGTK8hD5KtKL491MJZk Sender: "andreyknvl via sendgmr" 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 Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Peter Collingbourne , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , Christoph Hellwig , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 -- 2.30.0.617.g56c4b15f3c-goog