From patchwork Fri Nov 13 22:20:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11905087 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=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 20961C55ABD for ; Fri, 13 Nov 2020 22:42:37 +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 ADD9F22252 for ; Fri, 13 Nov 2020 22:42:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MXXQNxbR"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="feWIg6qU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ADD9F22252 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:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dX99QjHEyWdiyScGA+ptOPASVeKcICWEb2yK4QSjjcU=; b=MXXQNxbRmaEI7eFrJ0pjoqPzT v8tgG73oTmT6lWSXLwWtg1amUICTW7i1fZA/AW6fzh10dUF20E8WwRTj0xUO/afjLwz8I5FlA8N2S CINezfkBxegfyWRDnvT5WP3WACRFr+ZTtE00/EAFMNF+du9h9HXQscn3PFMk/xllVoWzlhJjF2FDk oo+4EGlpm8iEuxyJaFVOlMvCuH6renoZ/yxBbCAb9D2a51mzbQMWf94tb9DcdakMhpZIpEae1f/RM GSU8JayoaH69zM92mKUXRErJXvIigUImlca/AvHtC5OpJ2vrfVD8gCFXMuRhzvWNwdFC0FUL72+CL /l6jNPyRw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhlX-0002wv-9K; Fri, 13 Nov 2020 22:41:59 +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 1kdhR9-0001hh-Lk for linux-arm-kernel@lists.infradead.org; Fri, 13 Nov 2020 22:21:02 +0000 Received: by mail-qt1-x849.google.com with SMTP id n12so6651309qta.9 for ; Fri, 13 Nov 2020 14:20:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=WUG0j444ZBT4A3BTzNH/LM6507YxULafwrr/Sriwg0c=; b=feWIg6qUi7heyfOTSzsy2DpmrO1Qia8xbqIt8JmH5daMnreAv2krFvZcHiqDVKaKv2 1bTiAzutYZP/XiwiZ9rIvAKvtPkQ7Mc6tpkK9c/r6TsmzWPVn8WIrC7+uJ4GTVzK1zmW TARqSwftqGvkqjdh+M4+ZJqYCDPFDqsDB9jR8vkc90/AV5vWJuhIxDotwDlEkh3jH5qe ZmaI6Rzzwp10/w7Ry/ZUbxCMitP2uLv4cyOpLyoScAlq9lSOFBT/gO1S6XhYs7/32ijH 6yjUGd/6BuFXadoaZ8NaAhKvRf9nKcM6diCCz9JjlSN3ZDQG/jWv6oy7qyJYGVlmyAkl JszA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=WUG0j444ZBT4A3BTzNH/LM6507YxULafwrr/Sriwg0c=; b=NB7lYS7wOOxLGf1zAPIh1qENo0HJLmf439Us1X+qyk0OADVWv3GlteVha5T7LcaTPy 3ncu2r/uxSI96DYJHI4RHIdGqnkWsB6jS+nbyQ+bv1cORkuZ8FKOym9ZqIYqJpL8PPeO SaeDz5GIlIlM14mjPTxWwrfazfLXarUHUptHgMa0m9E1dwIs10dRpCnDBfj/uNv8Zgc9 vdI39bOtJWj8rNkVGL2P7tpFSBLtkx6nd7DE76+AewlFclKwQZVmo9bN6djLNC82ZHH7 uG6kXL4zBA3+HvgaisLBvcIFcQl+lpikn2pPGNMHckOuCt+VDcWIg+aGE4YAy9mblDEK hn3A== X-Gm-Message-State: AOAM532kRCsbuVOd18n63dzmFQCRoz96O38zC8CsCpgZOyBWAW+auCJJ 0chRxp/Z/13Z7n3f8DC4lf+GgQsDCFUbXylD X-Google-Smtp-Source: ABdhPJyDbEDKFY3EfcHLc7j3mQfHgxDyZ09bJBO/2bzJnR89c+WsxkzTNbHHqzArwf4wHZ9mwaSRm4uyurfObZ/0 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:d43:: with SMTP id 3mr4767045qvr.38.1605306048874; Fri, 13 Nov 2020 14:20:48 -0800 (PST) Date: Fri, 13 Nov 2020 23:20:04 +0100 In-Reply-To: Message-Id: <38ed98141f58eb53eb23100caac212b1c1f3bc9f.1605305978.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH mm v3 14/19] kasan: don't round_up too much From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201113_172056_124279_58389F8F X-CRM114-Status: GOOD ( 13.03 ) 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, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For hardware tag-based mode kasan_poison_memory() already rounds up the size. Do the same for software modes and remove round_up() from the common code. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/Ib397128fac6eba874008662b4964d65352db4aa4 --- mm/kasan/common.c | 8 ++------ mm/kasan/shadow.c | 1 + 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 1205faac90bd..1a88e4005181 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -214,9 +214,7 @@ void __kasan_unpoison_object_data(struct kmem_cache *cache, void *object) void __kasan_poison_object_data(struct kmem_cache *cache, void *object) { - poison_range(object, - round_up(cache->object_size, KASAN_GRANULE_SIZE), - KASAN_KMALLOC_REDZONE); + poison_range(object, cache->object_size, KASAN_KMALLOC_REDZONE); } /* @@ -289,7 +287,6 @@ static bool ____kasan_slab_free(struct kmem_cache *cache, void *object, { u8 tag; void *tagged_object; - unsigned long rounded_up_size; tag = get_tag(object); tagged_object = object; @@ -313,8 +310,7 @@ static bool ____kasan_slab_free(struct kmem_cache *cache, void *object, return true; } - rounded_up_size = round_up(cache->object_size, KASAN_GRANULE_SIZE); - poison_range(object, rounded_up_size, KASAN_KMALLOC_FREE); + poison_range(object, cache->object_size, KASAN_KMALLOC_FREE); if (!kasan_stack_collection_enabled()) return false; diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 37153bd1c126..e9efe88f7679 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -83,6 +83,7 @@ void poison_range(const void *address, size_t size, u8 value) * addresses to this function. */ address = kasan_reset_tag(address); + size = round_up(size, KASAN_GRANULE_SIZE); /* Skip KFENCE memory if called explicitly outside of sl*b. */ if (is_kfence_address(address))