Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3230881imc; Wed, 13 Mar 2019 12:13:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIFh5pFtxTtsvDqINIkhqLnZmgNXqblMMWZfmPW7QE0r+dCZzeT2v8+XKiXfwrdGl3fqqE X-Received: by 2002:a63:2c8b:: with SMTP id s133mr41299515pgs.448.1552504381934; Wed, 13 Mar 2019 12:13:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552504381; cv=none; d=google.com; s=arc-20160816; b=gD7MExw1QZCWni4xLzGa6/CaXV/obHYIFigV5doDh+BrGtqUqFG1phpjqLNT/ghbQY nFf2UDOdT00SjOmt8Wdp1pQcVbR2t5a4e9sQpxclODD8pKUuuWzqkax+HOw3C9ZfkF5i ueLifCZF8lntrLyF0+1iuTf9lJnzD3kzTp6GuaQoVI9iUezYBahtgEHqxWHB1bPatfkk ttKSnCVlnu60xJSmc23OyarBbXrj8vxwT5Bx5WHwMB9Hj/SabEJp5eHZocjHnSmP1F9E F7BjL+dfP4pCWTQiVqT/Bph5FqewQGOJgYV3Q8M0t3U77WUTzqFgnIU1fx4tJKglyDCV AB4w== 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=IiJQCRYaGRhFgOIweSzPyVuWURp6thxugB4m+P+RWZ4=; b=G/ayu3QqmTIaUAQ0cODqf+/jHyfOtnXIRcAbEVYSdols5HoPfOTonxKvSf1SjN644s giKQlIdCwyCsCqQDh9Fe7nfHVZtV9P9cvn+5UP4hbwya7yYeMhI7Fcl8lQNPV4RYaQ9W PsfS86mpi0XDhVsc0+9C+cdCXfiqiSI5fEAwSJxa2MZF+zE2jxFWS7ieAwBDf5DY9LRE G9RCEZyMr0jkbwPteE9jAzYTJRV5VxT02Sk02BMGPvz1hlwwTZSHCut2KOWjG6TKXNMg YcZD9BnzAYiXtQABbj4lpnTTdJdLmRarrOLqjfvaeewQVGkR4l3r2hjeRsuJXsSp19iL BUpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dnGvUOBy; 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 n1si5489132plp.26.2019.03.13.12.12.46; Wed, 13 Mar 2019 12:13:01 -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=dnGvUOBy; 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 S1727012AbfCMTLv (ORCPT + 99 others); Wed, 13 Mar 2019 15:11:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:42502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726638AbfCMTLu (ORCPT ); Wed, 13 Mar 2019 15:11:50 -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 4EA13213A2; Wed, 13 Mar 2019 19:11:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552504309; bh=3GT+9B2z4QYam/gzFSmgOQrgzOiFBtJq+nV5XdgLzmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dnGvUOByVOhcs8WnogHwEIO8jEfui3jB1HBcbLEZoEKJYPXtDT9VBQ5HSiZAQbcN5 GNcQChQRz3kVoyGObhcRuPo9zc5iHsF5KvxXZg57eJ9d8HNgSDD84gkTbNk75qsVJF +C4lo+hdL2vr8Y0uoT91T2BmARBsWtXeShc8u3LY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andrey Konovalov , Alexander Potapenko , Andrey Ryabinin , Catalin Marinas , Dmitry Vyukov , Evgeniy Stepanov , Kostya Serebryany , Vincenzo Frascino , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.20 39/60] kasan, slab: make freelist stored without tags Date: Wed, 13 Mar 2019 15:10:00 -0400 Message-Id: <20190313191021.158171-39-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 51dedad06b5f6c3eea7ec1069631b1ef7796912a ] Similarly to "kasan, slub: move kasan_poison_slab hook before page_address", move kasan_poison_slab() before alloc_slabmgmt(), which calls page_address(), to make page_address() return value to be non-tagged. This, combined with calling kasan_reset_tag() for off-slab slab management object, leads to freelist being stored non-tagged. Link: http://lkml.kernel.org/r/dfb53b44a4d00de3879a05a9f04c1f55e584f7a1.1550602886.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov Tested-by: Qian Cai Cc: Alexander Potapenko Cc: Andrey Ryabinin Cc: Catalin Marinas Cc: Dmitry Vyukov Cc: Evgeniy Stepanov Cc: Kostya Serebryany Cc: Vincenzo Frascino Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/slab.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/slab.c b/mm/slab.c index 05f21f736be8..b85524f2ab35 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -2381,6 +2381,7 @@ static void *alloc_slabmgmt(struct kmem_cache *cachep, /* Slab management obj is off-slab. */ freelist = kmem_cache_alloc_node(cachep->freelist_cache, local_flags, nodeid); + freelist = kasan_reset_tag(freelist); if (!freelist) return NULL; } else { @@ -2694,6 +2695,13 @@ static struct page *cache_grow_begin(struct kmem_cache *cachep, offset *= cachep->colour_off; + /* + * Call kasan_poison_slab() before calling alloc_slabmgmt(), so + * page_address() in the latter returns a non-tagged pointer, + * as it should be for slab pages. + */ + kasan_poison_slab(page); + /* Get slab management. */ freelist = alloc_slabmgmt(cachep, page, offset, local_flags & ~GFP_CONSTRAINT_MASK, page_node); @@ -2702,7 +2710,6 @@ static struct page *cache_grow_begin(struct kmem_cache *cachep, slab_map_pages(cachep, page, freelist); - kasan_poison_slab(page); cache_init_objs(cachep, page); if (gfpflags_allow_blocking(local_flags)) -- 2.19.1