From patchwork Fri Nov 13 22:20:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11905091 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 E13DAC4742C for ; Fri, 13 Nov 2020 22:43:00 +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 7792022252 for ; Fri, 13 Nov 2020 22:43:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XTLuzS4u"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="gVybcLoF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7792022252 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=qFHU4nztKvNF2W5Z5CrlPhxjwi+mOE8WoKNns0u6DMY=; b=XTLuzS4uo7OlFKZuNKFuiB12K GmMRkdyNdel3Y6uZfaD/mhGr/MP4/OB45PwIP20NRe/OFqZFwchiTbIZRaVJFclDCtSvWhQ48CVwA XYmlzzv3nrP4AmKEK+c5fhRnzzNXa36/dnk7PxBzbtK9sJDkn8TN7vfFq5c8irCtDKdzejyt7YpGx HlZL2IU1m5Itrk7MQxGR7+/G0Hiiwvx4gsrRWk/27IpkYdWJsFJqblz1vyHl9AX5hWOXKc+0ydpC/ +L4I5Bo0MdfDgZKFO9RUcc88duY/O+VGJOBCRreEYQykXOH4Nsp4AT2pC/rdgk22suJeIlREucaWo diomDhWOg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhlx-0003Ag-Cx; Fri, 13 Nov 2020 22:42:25 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhRE-0001iZ-6X for linux-arm-kernel@lists.infradead.org; Fri, 13 Nov 2020 22:21:07 +0000 Received: by mail-wm1-x349.google.com with SMTP id k128so4706998wme.7 for ; Fri, 13 Nov 2020 14:20:54 -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=FjDCd3uZs5tZgyebUG073A1B5l2RXwE8lidjbcRsCvs=; b=gVybcLoFQUNnqi8BvDXIuLxWzyBvmJ9r8YgiuYhT5Vu2C/zCCrI7te3RDmVOXAIc8d jWdwWo5LeuXbMT+aa3nFbTr7pi1D7mqVCTn1+Kr06wbwlyMlEdafbkwCQf+Np9kgAEwq G18BCLYbfNs//MAyXfJCvA4BZPSNOgVNjaxII/tGOSP3J7KzzOpraccZJslROAokEP/w gbpLxCXcb8AwsSYVXkVGO1YkPuVk07OlX1Ri3z5eDOhzP2nxBArhzqAoDZvUib0T7cA6 sxJ2VEfODnX22F93ftmfkG7ItpS54IPEpfsGlbzriQ4c07kVaMvIWMlMtIo0OfVbEEEc TDHw== 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=FjDCd3uZs5tZgyebUG073A1B5l2RXwE8lidjbcRsCvs=; b=pHMROtiJigppOJU4isFW2SHeM2eUUhF2YcrKb4vkz6QQk3d0q2YCIZIjzr4SQo+nIi IyyukGxjFn0VRW580zRawaGs53WR7aVDL2zXqFsLtDuawyIbeKqsZ4ngqnZ6JbIYXgQ9 WphKWFa8Qg+fWtiTc1lSIhpgV3rrp7etal8Gp7SRsMy7afGIY4KK5Vx3jX+0p4w8vK8A hxiVH5XJkoDk4YLshPO6DL0BqT80FazFU5tdkSq+xn7YyiFmjwk13kaj50zaftiozZrN 4MHr+5/Sa6e8qnUc7j/htQFD5u2nlJ/CubHFfLIcTWpo7nzrmOM4W79JVZKRnaNXIq90 POkw== X-Gm-Message-State: AOAM533aPOS/V4C/prsBKLdd4Fonpd8aFMTwEc9+KR4hPvFe+RMQP++J bqNqPyDqA8E6jJzR5tySb/XxM1Nu3NgcQvO5 X-Google-Smtp-Source: ABdhPJyhSXjfAMNZDyab6PZ2QpxILyu3jBNhWgi25Hcu7VUSLE8KCaS2ijL7XZdOMCTm1EGjb1TAJwfcjEDFzQlL X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:e74d:: with SMTP id c13mr6274338wrn.277.1605306051483; Fri, 13 Nov 2020 14:20:51 -0800 (PST) Date: Fri, 13 Nov 2020 23:20:05 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH mm v3 15/19] kasan: simplify assign_tag and set_tag calls From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201113_172100_680049_91BD2C08 X-CRM114-Status: GOOD ( 14.97 ) 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 set_tag() already ignores the tag for the generic mode, so just call it as is. Add a check for the generic mode to assign_tag(), and simplify its call in ____kasan_kmalloc(). Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/I18905ca78fb4a3d60e1a34a4ca00247272480438 --- mm/kasan/common.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 1a88e4005181..821678a58ac6 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -234,6 +234,9 @@ void __kasan_poison_object_data(struct kmem_cache *cache, void *object) static u8 assign_tag(struct kmem_cache *cache, const void *object, bool init, bool keep_tag) { + if (IS_ENABLED(CONFIG_KASAN_GENERIC)) + return 0xff; + /* * 1. When an object is kmalloc()'ed, two hooks are called: * kasan_slab_alloc() and kasan_kmalloc(). We assign the @@ -276,8 +279,8 @@ void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache, __memset(alloc_meta, 0, sizeof(*alloc_meta)); } - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) - object = set_tag(object, assign_tag(cache, object, true, false)); + /* Tag is ignored in set_tag() without CONFIG_KASAN_SW/HW_TAGS */ + object = set_tag(object, assign_tag(cache, object, true, false)); return (void *)object; } @@ -364,7 +367,7 @@ static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object, { unsigned long redzone_start; unsigned long redzone_end; - u8 tag = 0xff; + u8 tag; if (gfpflags_allow_blocking(flags)) quarantine_reduce(); @@ -379,9 +382,7 @@ static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object, KASAN_GRANULE_SIZE); redzone_end = round_up((unsigned long)object + cache->object_size, KASAN_GRANULE_SIZE); - - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) - tag = assign_tag(cache, object, false, keep_tag); + tag = assign_tag(cache, object, false, keep_tag); /* Tag is ignored in set_tag without CONFIG_KASAN_SW/HW_TAGS */ unpoison_range(set_tag(object, tag), size);