From patchwork Thu Nov 5 00:02:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883379 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=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 C8860C4741F for ; Thu, 5 Nov 2020 06:36:52 +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 35D8E2151B for ; Thu, 5 Nov 2020 06:36:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="hZvwkIKs"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ChWFw5hM"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="sFpQqhhE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 35D8E2151B 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=SaDDqKyQP3rfYwGhaTS0zu8ZIgUu2RhSoGpmEq6sEkg=; b=hZvwkIKsDuSbcYSeE3p20bp2K 3A32TcEXiBGnMmf1faG2Dm++ZXsSzzInSGLN3HzFK6c5QouPxUvK7pySMuue1CvQf+2kNexVqGPvE Tn3cUj8wnlXmYUDQJfPgtmHJmwJbOWAPpMUx/5k3jUke1PWa/2uGxujy8CBiSHaV9tQhxHUQtglEW H+xaP03oOT21sIQ60foWaZrpaezkihNaAvXBLmCKPNO/2IOnNzMMFPpmllXCcxJ+pLhXlOohsmqCq 4mv93124cNLEcaPYa0t4SxCDONu8vak4xleMmjrzpaTPkjFs/FZNBQFiTmLOOS7S7hfA5UDY1LKPe bs5T1tjeA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaYs6-0007IK-Go; Thu, 05 Nov 2020 06:35:46 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW3n-000145-MH for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:35:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=0USIvWPWD+0X5uGT95blxzhIaksN6b9CBpQaBzMOnSY=; b=ChWFw5hMXgRJPz1Q0KIpMEfaB/ ofNL3WXpcpwXO+AnZfRqGFREioE9faJMt892rDGLzEGHmpeeIdMQxVuLJR0J7vLKEBAFlhQyyzAD0 BQRkqHWC+TnDfb0NDtGXJ9+H1WIkb2KZU0SK9PzWSDWNAnRUwWWRhU47gwMrQAqMJUnwqgayNbKDW sx+JR7ogdOojemI3A8RcAlDYST3gU4Jcvqd+ynPuvR+/erGC7cmW8TEZf6g9Z8PI+es8ZdeJ9766u Vsofm5OcFbnN7WZJ9lsCXLlrAbKynFOr5hLbiy2NTV9oZRp57azx1dd3Uzu+P4vsYQiwCCrAC5z2+ mDBUOOjw==; Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaSlB-0000s3-Hm for linux-arm-kernel@lists.infradead.org; Thu, 05 Nov 2020 00:04:16 +0000 Received: by mail-wr1-x449.google.com with SMTP id m4so82758wrq.23 for ; Wed, 04 Nov 2020 16:04:12 -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=0USIvWPWD+0X5uGT95blxzhIaksN6b9CBpQaBzMOnSY=; b=sFpQqhhEG5gmFI9GQ8viL3pqjWr2ET4+vulUOd3uW9uXSre4REhA33qyv+t4dVSEU7 w545R8LNs86kAkwY0TXSEvxLnddxzfkbaplqkm43YTr/brE+bJoOY+C2aatYwHPrKd8V lyF0Dk29ZIFpFIJ1Og+2xmXpbHGti9zQJ89WmkxMG1/0OCal1u616x08x92MgB7fVD/D G69WQShQeI4m/Swv42Hyjt3WeTnoKf7SUs6+1sXJtxjv/UHA5ZAhdSY1gHBAtl08c45b vDih+OYOVaIk+p10CXSYtIivWlmHY49fZ1jflJr3KJySxpjBR7RHRbYJf7/j6E5/VucA 0Etg== 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=0USIvWPWD+0X5uGT95blxzhIaksN6b9CBpQaBzMOnSY=; b=ocAu2YXs/wkW3iHQ0phCv4HVz1X2Z7v3BhZWWL4qNeors5EeynxG1mZEv/u7/anRRN L3SONj6PVpzRw0Xd+1Nxmfum5h1b4vnu4vfIqlU3o9kM4ijyg3gH2Gdi8kYsVEmVUtjo QjoPkpS2YTgVS7PWm7ML8RrhjV9bsiQCbq/Bsb243Lrpm0Gpg53eNEVq5FUTzxf6ulHO ADOuBmPwRNVECGeWUSFKsIF9bN/qxakn2Kjd7fMAgd0YLlj8ogs6AUo3As9BC0tL3sbZ n5yGNC95fs6kpqaLDeJCaMX5GhPATZQ7Bh08baa2/VaDb6YLrasAi84fOgUeMrFtvQPQ ux8w== X-Gm-Message-State: AOAM532noBPqkJ+XdpIR90DmhGAcCcDlY0crUkTnNhZfMYEdjntyBqPU veVU6YgnsU7rV8vQ+ZmJoZq/UMwYbaeQizWs X-Google-Smtp-Source: ABdhPJxw/lGpcSbzl86AC+uSuIK+hwvLKzT3r8ACA6Gr0SlWmsWXhA12+uWjp+hh9NvD3Cd9/idF6XWVIRZbxQIj X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a5d:4c4f:: with SMTP id n15mr475161wrt.137.1604534591024; Wed, 04 Nov 2020 16:03:11 -0800 (PST) Date: Thu, 5 Nov 2020 01:02:25 +0100 In-Reply-To: Message-Id: <3a3e6dfe3ad355bb5ffc3cc34769cb97aec650d2.1604534322.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH 15/20] kasan: don't round_up too much From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Marco Elver X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201105_000413_741466_99989FE0 X-CRM114-Status: GOOD ( 11.99 ) 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: Branislav Rankov , Andrey Konovalov , Kevin Brodsky , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Andrey Ryabinin , Andrew Morton , Evgenii Stepanov 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 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 60793f8695a8..69ab880abacc 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -218,9 +218,7 @@ void __kasan_unpoison_object_data(struct kmem_cache *cache, void *object) void __kasan_poison_object_data(struct kmem_cache *cache, void *object) { - kasan_poison_memory(object, - round_up(cache->object_size, KASAN_GRANULE_SIZE), - KASAN_KMALLOC_REDZONE); + kasan_poison_memory(object, cache->object_size, KASAN_KMALLOC_REDZONE); } /* @@ -293,7 +291,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; @@ -314,8 +311,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); - kasan_poison_memory(object, rounded_up_size, KASAN_KMALLOC_FREE); + kasan_poison_memory(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 8e4fa9157a0b..3f64c9ecbcc0 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -82,6 +82,7 @@ void kasan_poison_memory(const void *address, size_t size, u8 value) * addresses to this function. */ address = kasan_reset_tag(address); + size = round_up(size, KASAN_GRANULE_SIZE); shadow_start = kasan_mem_to_shadow(address); shadow_end = kasan_mem_to_shadow(address + size);