From patchwork Thu Nov 5 00:02:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883321 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 6EEB5C00A89 for ; Thu, 5 Nov 2020 05:32:10 +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 CB1092083B for ; Thu, 5 Nov 2020 05:32:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cQwmy7Gc"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="cBI1znwq"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="QLuAbvZH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CB1092083B 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=amqobPqYoUfeCoIDTbX5vy3jU+Ebtwlx48wbupNwRHw=; b=cQwmy7GcvwOQTK4kMMnzrYsc5 DiVxdYc+se/og3ZO3NB/NMLfLUsAZVdHy0QgCq3+11v8QerBXddmzHhX9IujvIyU+dRzJFWviNgDM sD8dRHRQiK++raxBkRebCanr+fOIOJj0gL4D4xCMTKFy/KAkxfSQP9X1PtMQUAxLyatbXJshdtCjT 7O6tWb0vBoXnxqf8KODB8fWXAXKOfo3M21hRJ3RaIqNh5VXO4RDwjYiX+YJOjPJBZ+WBNMU65UgTc +QCngyZsoAefCD/hk3BNDolqW2GwKR5j01Pn9UlTH5lUT3Icvgyuk+AkwlOeaMzLyDrt6hOa+i63K UM9CdPCog==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXqZ-0007dm-Nv; Thu, 05 Nov 2020 05:30:08 +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-00016k-M6 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=KFrv2CeYC66xd7QOOp7G/eCqjg0M9rtzwQxn1AQSEo8=; b=cBI1znwqBarY6ZZ2m3dr5g+C/4 2qfRjJ+uuT2wDcwImAAt0jZ9fEltR4ejJvpl/ZNWnaz74BSEfqjljln1I+RyXv5higu55SK1PHGr1 tsULmXOriiJpfJzHgkmxowTD0203A80pA1/ZiOF/0/Qsn6LVSLHE5uUjFg74BQXJuZY2Y0IiYOfM4 oJDQ3T2Tj0AHIh7WZSCmcsFfj314R5bTz2aEg6SW9wkpnCLsUN7WfiibWQOgHBXRcJlN7cvqn7N6q esMRw7hfUZ2Xqoz52EoSVC+MCbkljy7ZRZe5nli03Zt8A/E9cFjejVYrwIoP76/nm8Y0UKG00WNV9 6aGUh0UQ==; Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaSlE-0000sO-3y for linux-arm-kernel@lists.infradead.org; Thu, 05 Nov 2020 00:04:18 +0000 Received: by mail-wm1-x349.google.com with SMTP id y187so5842wmy.3 for ; Wed, 04 Nov 2020 16:04:15 -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=KFrv2CeYC66xd7QOOp7G/eCqjg0M9rtzwQxn1AQSEo8=; b=QLuAbvZHFP2W58yhtR9vhBr55r8Hyf3S4Rs3PezTxrfLFhxyd7JT09PKnYS8oSsPPq gdRKQvVLLsai3OEzz4dyfxqzwtdGBwLP/JIK3nrPx65ohFOxXi8w41i17w7g8HswL0pM QsnWuFYb+DhqJ6xTCmfTf5pevVgWDcXouuFmLtrqO1Pnya8cbLcz2uUW+4+tBIDfCvWR NIBMGmdmtEOwmByJGW5M96WjPsZbCZh7VmiInUy7NkcWeP7l8Bovd9DsLTRHc6Tgd9yI lZqfbycXbtZhTw1t+934rBC373gyowgCXZJ0eV1iEKb+i/tEaSfzGY1H5Xkynl1uQ7FS 4S7w== 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=KFrv2CeYC66xd7QOOp7G/eCqjg0M9rtzwQxn1AQSEo8=; b=qA6SzM+9fxp1Iz2WBSfgZnJ4F+bM7eJH6JIURRhhiu+o2imk6N9M4uvPsJl64J6bkq OdH65pxWA3htchfCQ4gGY2yJvBmJZcEqODwEwHEhUL9/iQ6XcN5vl7GX5ToXhv/1fL3S f4VJuFa9g0B9+R18/ejarfjVMLk/f2astE1DYm8aAUyHRa8bXE1QrHd/F2MOhnC9hszj SmhguEr10PMYXoog/SCepoEhHwF7mJFtNOOGLdyTVFq+U5ZGIpjl45B8iRpWo0WWlyIb m0hJRtpIuYq4YtSz5qOYNGBnm5GlW0qHMDJfn6MErB2aQe4xvol5ypuI/ZYA6/40E5/p FV2Q== X-Gm-Message-State: AOAM530W1chffewOpjgmATFPoxnv9pEdNmNIot/iFluu/C0SF8RXZW6w m/TNbDuulQvnwo/vzFSGB2/UyJbxPxVM7uN5 X-Google-Smtp-Source: ABdhPJwQ27fD7Fc3ZNzuubZFZKWZfrYiXQ310vGkklvY3Ifyj2TvUAmaupP6a4qWeV/wlXVXw6iDgvs3qJM0Dpq1 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:9d02:: with SMTP id g2mr24703wme.110.1604534593196; Wed, 04 Nov 2020 16:03:13 -0800 (PST) Date: Thu, 5 Nov 2020 01:02:26 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH 16/20] kasan: simplify assign_tag and set_tag calls 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_000416_464200_AF9F9749 X-CRM114-Status: GOOD ( 12.80 ) 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 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 --- 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);