From patchwork Tue Nov 10 22:20:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895731 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 77341C4742C for ; Tue, 10 Nov 2020 22:38:05 +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 F36A8206B6 for ; Tue, 10 Nov 2020 22:38:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="WOk4/Atm"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="QP7TuVPx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F36A8206B6 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=PYHVGfIfYqkNCAtkYRqxu4IJAWna9zNqio1VT5mAWaA=; b=WOk4/Atme9ejDL/0sPP/av9fT O2crtdNl7stao/ffy5hoUA3WrY2hGjVpBi0/kU3gmaae3o0i4CWGzTCV+Tzpbm3/jKB6ro/oTE3Ks Y7qU0v3ZcWUwrl4euOyedQZhARaA0uBPlCp7jYx8MyH8tLIP/+B790k2EPkUWdwYC/D6NoZ3555Fq Vw8YoSdC+iQE3uNpWqjCqjBcTXmlr6g+GI2REU8hvph1cKevwqQhpX7WfqSOyoFo57Cyfkzur/FT0 +fj6glfspn5pnNGKInw9mezi1zjDBqXQoNot4EgEyiNm+9iH6ySQmYHYShDRxu5uNHYsOvZLU/Miv FGDSh79aQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kccFT-0007Ev-Kd; Tue, 10 Nov 2020 22:36:23 +0000 Received: from mail-ed1-x54a.google.com ([2a00:1450:4864:20::54a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcc0q-0000Us-Tx for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 22:21:37 +0000 Received: by mail-ed1-x54a.google.com with SMTP id l24so1540409edt.16 for ; Tue, 10 Nov 2020 14:21:10 -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=UUb16eez1SBPDEo4INNWK7vyjFOxlmk1eUi1izfNnGk=; b=QP7TuVPxCEiWmmHgnEKJnNoGay3AQqR5W+nqoq/mV5uvCvY6CbJgGKtXz82KEG4kId KNMjnlvqyunp1Kqhwt3peDe0Vg4O+DQxvkw+MnRVzCq5Nvf0Ou/xBeqbAPV2XSIrqswu 9aKboBYNZGPP5klIdn8CMN07pjj/wj34ufercro9wLmyR/w6wCqGr66F7ztDXO4P9Y5P QoahP92EwMw+TLRC0EtcxvwFqReTRl6Xn1duRONdFajcKPyltvk3QlSDJFIhoKFiJo9K an+ewDBQH6xWC/JrFoJ/Z1WbXQtbEDByyh/6FVx/JJ1FMmIHAZ+hzFOiqtvuORTqVwpA AXpQ== 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=UUb16eez1SBPDEo4INNWK7vyjFOxlmk1eUi1izfNnGk=; b=Vb18fZM35PjuGuhe02FueWUUdkPfukGP2jyu7sstlIz4DHJW+6Fya0BGLoltGiqE0l +BeWP7zpp/keumTHH2o8r5oZXK9Cta+x/nIT/uvLG/wAV+rV5oa5VCj3P3RrRWOhc18V KBSxjauSYErIlyCQkwVqy8P6rTqK7vm6Oo7fWcQfiuYyjWjZ0OgjtLRQc1OeiCjAAVtr ssRKomDHdfVcbjDj8v/7oZ1ymdHqP5SKq61MBQdx9zwWUC3QZnhh8AfruiGVCW3SMf9p s/R4nMlZoOd26IoVhK5Yfl0kJQD/Oe/FkOQLEqFhcUrwu7YKInKq8Bx5TuL/ZDVlGbsI iG0Q== X-Gm-Message-State: AOAM531VRKPrcz5U7WNxrH1SD76FAWIOG3wMzY4SCVPnOAri0iXBnve9 KY7F4uDOPx4Do+LjF4wZNIjZ7qv/sy2GZUVP X-Google-Smtp-Source: ABdhPJy1APWb8IPIno5fyCxmFvAiY4V9ib3nnVEVsGk5gNukRVXnCQVuL8cF06lZdJfE+QXxRpZDFZp+aOWcujy4 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a17:906:b043:: with SMTP id bj3mr21951070ejb.543.1605046867367; Tue, 10 Nov 2020 14:21:07 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:20 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 16/20] kasan: simplify assign_tag and set_tag calls From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201110_172117_468255_83983129 X-CRM114-Status: GOOD ( 15.95 ) 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 , Catalin Marinas , Kevin Brodsky , Will Deacon , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Andrey Konovalov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Evgenii Stepanov 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 Link: https://linux-review.googlesource.com/id/I18905ca78fb4a3d60e1a34a4ca00247272480438 Reviewed-by: Marco Elver --- mm/kasan/common.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 69ab880abacc..40ff3ce07a76 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -238,6 +238,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 @@ -280,8 +283,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; } @@ -362,9 +365,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 */ kasan_unpoison_memory(set_tag(object, tag), size);