Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3244290imc; Wed, 13 Mar 2019 12:34:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqyc0znIDeB1Ax/lRDMZ4yhRx0PfpzTQgtmyXNhl7e3NJXBWkVVQJ7d+upVyj/KVAeZGzU4A X-Received: by 2002:a17:902:968a:: with SMTP id n10mr47850442plp.283.1552505649142; Wed, 13 Mar 2019 12:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552505649; cv=none; d=google.com; s=arc-20160816; b=VrYwbEz/9TR9Ka3pw/6JyLLHe+OOXK5RSnFVwCb9lYUVeEDxmkz6QooDTXkTVwhW30 Az26wIwPxfZ076EgJ3Xyn4MfvouH5KU/1r7/o0IdhSP4EATBKmolagk3vyIfjyiDiGpN hOFxYRbKOeysx0H2pISKiIQtQuMyVVUUEHmO9FvoGc0opzjWOTStYwq6yoh6JiTW5PJm E7bvZbWhYB9OoNmua9PVrTIfiK1zBxZ1RlbnWrbgqpA1Cmfr+QP61nSNDMnX6LQpcVc+ dPMo+ge1hitAJ5sHC9mTp1h8vkfW6pUFs4ymu/Zb9fWUg8IKVwOdHVMrKysEAQzLaJX9 c1Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WLtfyjbYwZW+ZPLWGPFWUvVo/1Ppl6CC9qHgChQ7Xho=; b=1JXHuZ4727UuN/T3HUF8rlHxk6CJufJdKZNqGxVGkyy9PawMvuDZ11yNF0h1NOE9Je Q6PxOaUgYuWBGyawnbYLJvaxpbaUhqlCIRRSgJjoCPzC+9puMMH+kjAdBPxdktBkcrGE 1cfAg7j+bejgGmOV3W4LHXnBFAnY9DOm7yqBbfEREiqvHpLHTwCa7nQOcs41tn8VMIO7 gp6yjJiZg2XAPLcmg9VlbZK7+feSkOaW3Xn8rCDQd2bTVGBBc374VJBlmPkcseO8nkmY 0c3Mm+UhlC9xoa8jnwZdsU6Lma9HHvyDkcnHm4dnbW03BUahUnrTRz+ZZg+OvzSh8cgI C7sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bOU2LxVp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1si10091345pgv.418.2019.03.13.12.33.53; Wed, 13 Mar 2019 12:34:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bOU2LxVp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727532AbfCMTLk (ORCPT + 99 others); Wed, 13 Mar 2019 15:11:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:42164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727515AbfCMTLg (ORCPT ); Wed, 13 Mar 2019 15:11:36 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 76C2D2075C; Wed, 13 Mar 2019 19:11:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552504295; bh=BFMiFCb16F7+mfsZq3oOVj05LTsKXjadZiB9F30QfHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bOU2LxVplTTdlxMQHlWHeAlHxhN5R6qO2fIcr3vsy8RO3Y1bcfgPqGYhoKOfVpHAE PtqdDKHxsJUKoixTdPU9WpRPlQPduL21gJRXuRulOd64wMobb9gKPMiVpqee7aevkS VbXBHuQOBcUAG8QGXOH1LBtXSpD3pW8uvxe1vPi8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andrey Konovalov , Alexander Potapenko , Andrey Ryabinin , Catalin Marinas , Christoph Lameter , David Rientjes , Dmitry Vyukov , Evgeniy Stepanov , Joonsoo Kim , Kostya Serebryany , Pekka Enberg , Qian Cai , Vincenzo Frascino , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.20 34/60] kasan, slub: move kasan_poison_slab hook before page_address Date: Wed, 13 Mar 2019 15:09:55 -0400 Message-Id: <20190313191021.158171-34-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190313191021.158171-1-sashal@kernel.org> References: <20190313191021.158171-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Konovalov [ Upstream commit a71012242837fe5e67d8c999cfc357174ed5dba0 ] With tag based KASAN page_address() looks at the page flags to see whether the resulting pointer needs to have a tag set. Since we don't want to set a tag when page_address() is called on SLAB pages, we call page_kasan_tag_reset() in kasan_poison_slab(). However in allocate_slab() page_address() is called before kasan_poison_slab(). Fix it by changing the order. [andreyknvl@google.com: fix compilation error when CONFIG_SLUB_DEBUG=n] Link: http://lkml.kernel.org/r/ac27cc0bbaeb414ed77bcd6671a877cf3546d56e.1550066133.git.andreyknvl@google.com Link: http://lkml.kernel.org/r/cd895d627465a3f1c712647072d17f10883be2a1.1549921721.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov Cc: Alexander Potapenko Cc: Andrey Ryabinin Cc: Catalin Marinas Cc: Christoph Lameter Cc: David Rientjes Cc: Dmitry Vyukov Cc: Evgeniy Stepanov Cc: Joonsoo Kim Cc: Kostya Serebryany Cc: Pekka Enberg Cc: Qian Cai Cc: Vincenzo Frascino Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/slub.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index e3629cd7aff1..d1e053d48f46 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1075,6 +1075,16 @@ static void setup_object_debug(struct kmem_cache *s, struct page *page, init_tracking(s, object); } +static void setup_page_debug(struct kmem_cache *s, void *addr, int order) +{ + if (!(s->flags & SLAB_POISON)) + return; + + metadata_access_enable(); + memset(addr, POISON_INUSE, PAGE_SIZE << order); + metadata_access_disable(); +} + static inline int alloc_consistency_checks(struct kmem_cache *s, struct page *page, void *object, unsigned long addr) @@ -1330,6 +1340,8 @@ slab_flags_t kmem_cache_flags(unsigned int object_size, #else /* !CONFIG_SLUB_DEBUG */ static inline void setup_object_debug(struct kmem_cache *s, struct page *page, void *object) {} +static inline void setup_page_debug(struct kmem_cache *s, + void *addr, int order) {} static inline int alloc_debug_processing(struct kmem_cache *s, struct page *page, void *object, unsigned long addr) { return 0; } @@ -1640,12 +1652,11 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node) if (page_is_pfmemalloc(page)) SetPageSlabPfmemalloc(page); - start = page_address(page); + kasan_poison_slab(page); - if (unlikely(s->flags & SLAB_POISON)) - memset(start, POISON_INUSE, PAGE_SIZE << order); + start = page_address(page); - kasan_poison_slab(page); + setup_page_debug(s, start, order); shuffle = shuffle_freelist(s, page); -- 2.19.1