From patchwork Mon Nov 23 20:14:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926709 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=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 980FBC2D0E4 for ; Mon, 23 Nov 2020 20:41:09 +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 1B5A720721 for ; Mon, 23 Nov 2020 20:41:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="A2zPczTF"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="bCnebjZk"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="K9aATwYZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B5A720721 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=lCiIwj8en42n3vC5tiXyFYKsudLI1wHVR9t1V0IHxQ4=; b=A2zPczTFa8NtzxHbYHPbDuhXG BfRYoqA85CxhuVlrUh+BGySUcJwICoQW2JGvo1DFiY6i2pYsO/zHGJFhJQNDFa6t5z8+CIY3IWul9 0eOAWC4iKPC4pR9kU9Co3QpXB0Zx/PPd3IteZtmcPvCTVddbpxFovuQ+LZEy3hdtakiaMVtx6FABP DRyetGwsrvmLSt6g/Y0xsQJwQyGEA/YCyF91rBDtBpaO4AZiWWvdg6RuXVjCRprHHAkNT4Pq4TYjE s7XyReSQYgv+GpHCpOcZm5vv1crD/pH1onbwYW1TG6JUuZD3EApw1vWDFT4J+N05l4Gruawd5WVfW GB9R4tAmw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIdM-00052g-Be; Mon, 23 Nov 2020 20:40:25 +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 1khIO6-0006KM-Fz for linux-arm-kernel@merlin.infradead.org; Mon, 23 Nov 2020 20:24:38 +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=FZtWTAUkAvRQTA+AtFREJR6Qo+0tQ7KPae8j2grwXDU=; b=bCnebjZk8TA+pKbb5a15uxdM4U 5hyuIHm6McJIn2bsKtTw/drfkLpHHC7SdrU2o5AqI/w02vBbQ7aj1aQeh9iqPxBd5Km7OggfpTadw oWtP0ZvQ9++hj/lATb56hxgpBTgaF6KykeUGeeEbb44oBZDz58V2ieGrbP/948Wa1HjrU+lcOzq7i Qz7vmEA4CyZi7qmdH4lGS67r9FhjOXArpmtr07lQHQ7/A+AepldGglLC+AniKN6GbbthD54O12wC2 OYmq2lGAGzM0xisH8tb1Xt1zcPrGoDdwwaITw6fBPKXqY/7+BWzd5SPIhX2uzjVRIelOKikQLbRAr pLBCMSfQ==; 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 1khIFE-0006Mp-RL for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:37 +0000 Received: by mail-wr1-x449.google.com with SMTP id c8so6243016wrh.16 for ; Mon, 23 Nov 2020 12:15:28 -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=FZtWTAUkAvRQTA+AtFREJR6Qo+0tQ7KPae8j2grwXDU=; b=K9aATwYZ9UoO7zi/mRajdIf64nFoB/xPUhE6qD8yIYqaNAhTqY64x7uB+K9m3QJ40A ytw4vCig7iAtvBjCXfs40hqcTLm7Odl0kKeDucZE+W5LxAe8giB5ELA+GiXmWkoyVfTR 8VWXey3Y9t3qeFOVBmJkyXECHO8rV15eIPpddIiFLLU/qlDLV5HqtrwPJh0+UH2Ygph5 Z6/bnnanhSfmK5redsl/WVUEpIGIXuFJacmnkiW+gJbrNQFApiGz7xK8SCrztmwn+Cvh vx+a8m9boaO+qlJC/KyajQBs38ioorzXUmsspg2Z4ytFIwtAzknXZ1YxVcYgrBWWv60L fiZQ== 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=FZtWTAUkAvRQTA+AtFREJR6Qo+0tQ7KPae8j2grwXDU=; b=OmRt+FvjfUFweFwO+2ue27gbTVJYZj2bNBMTC6cDJFb/pKATnmegtMGI+qcfWzOHfc W7A1F8/ctC9n0NKbsaN4vaWw66otMkv4nrQCTGBNrlZV8k+x1kfzeC7tzHRpI8yR4CqA iw7+B7lo04D+eBhVhcjf1zbxa48ZGh0ABh+NKeriAcuuSrPsAeluDkEFn3oJQh16U7SR pJ/jJddFByxCf59OzomDm7t9ziNC/bgPMxqdtV20f/FjKQDWC411+OkUkKU0+AJaAY/j 0vzGeR7x/Us7V6HEnEV2FpRSKIztaDPmDJVDb6IMmK0znJ+T4pSMNvWAdrgW9IwXqnIS iQBg== X-Gm-Message-State: AOAM530AkOstiU0iD9tzot3nZ6G3iMof390+lvKpjMw79CxhsFMMhPDh P1SK233jnL/O6MzGtEzy0oAEJ9X1xxoFzM6N X-Google-Smtp-Source: ABdhPJx1M4yjerM84Av5uMxcUmZm/oWpySCuetBAnvpXA3hwdyiT7m0HNDW+S1RL2PjXZJhTMRp0/KP7cR2W8hs1 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:ed02:: with SMTP id a2mr1480549wro.81.1606162526631; Mon, 23 Nov 2020 12:15:26 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:44 +0100 In-Reply-To: Message-Id: <47b232474f1f89dc072aeda0fa58daa6efade377.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 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-20201123_201529_594195_164E1499 X-CRM114-Status: GOOD ( 12.70 ) 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))