Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp467264imm; Wed, 29 Aug 2018 04:38:57 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZV1kxn1CRnNd6h/XLVaeuFV3G/qTUt1praAXK3jsWoxGVbswLxhBrZZJTQApoNiFC1/kvb X-Received: by 2002:a17:902:b492:: with SMTP id y18-v6mr1135419plr.208.1535542737128; Wed, 29 Aug 2018 04:38:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535542737; cv=none; d=google.com; s=arc-20160816; b=UJZwYM/dVXMMcbn08VsksIVFfdMUeOiqBml/zMeoEyucq/SK8MEn3EtJuvTrocbaQc h51Lg9HiulfzAYRQzSaBluMCsMKPK8z/uRGCJSEUrrLXdk8gMRcHqUzx0uf0QLfKuFZb POgpU0i8jnt4PAOe8j1C1w3sgOBqdWZJho/Db58fXFjUmYN+jycBzv4mLhtRK281au3v fWs3m4tdw+Be6/97i6Kap0k51ErHvUVaw+VLE4G3kq55YgfCeZ48KtzgFmpQA608xkoE i4iHwEs2CoijS8r4YKc69qlFBtfj8+w9awnK5Ovd/w6RvNlYb/CURPR12f0l/NTnS92b sMqQ== 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:arc-authentication-results; bh=tx0f81qpatBTU8Zf6Dt4IAw08NEBAMzFHV/7KuZJzc4=; b=KGVSA9CHaFxhLUDuQoz1GYU0FBzTDUYRAQnZpleH1C9wTBhYDaPA2rhsX0dnHYO5Gt 8z0x18x1d9mhtVVvpklo+1oOvvYLQcOmpvV0y3HEeJwZoJZX8kXCWVMXj1Rcelwa7HoH M/bwQ3BjtFAcFvs/D8lphGMBAG1Tx3SbDmNXTox1gkVFjJd1okZawmd22f32iYIz/fHx iPGBuT3Il53Kt+Rp287TvTjgV/HdmyMcyr7c+Pi/hhaVt70zfgAqIgebL4ioJGV4hfwB Pr+/XmtwZAVidoTWyk+4FxYVMvNVD9EEbeCAh94i9z5C8lc+nKH/ihjONicRUzEAm9jc TbWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tGIcisOz; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v34-v6si3530568plg.491.2018.08.29.04.38.41; Wed, 29 Aug 2018 04:38:57 -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=@google.com header.s=20161025 header.b=tGIcisOz; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728558AbeH2PcL (ORCPT + 99 others); Wed, 29 Aug 2018 11:32:11 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:54287 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728538AbeH2PcL (ORCPT ); Wed, 29 Aug 2018 11:32:11 -0400 Received: by mail-wm0-f65.google.com with SMTP id c14-v6so4939040wmb.4 for ; Wed, 29 Aug 2018 04:35:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tx0f81qpatBTU8Zf6Dt4IAw08NEBAMzFHV/7KuZJzc4=; b=tGIcisOz2STm0aJshASbTJeJ69RT8JMoAH3f4aCxVwgBItaA52XRJ9qdZYIaZsI2u5 84WxLKUwRjMLHaDEbGCci5rvpBoXQf4II3EtOgQRIvriYehFbI+64zM0dxij1O8dZcgA 0d4nuejpivMGGQO1gx9cPHhEWv7CdpbHsbyN8BudnoODPUQmrsBQrUnuYsKojZIqQrCt Y9gel9LN3l73cl3wtQZRwiyWtT1nUqrnnz+hgzlv/Tl+9TGC4ePGJhT2Lb0s6waiatxg 2jcKeIiW7gFzRHE/xwny+3A+SxEd+mYTqitxyw5Ii/nxehKFNx+YeMhys9uxy7VlTNq1 bVyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tx0f81qpatBTU8Zf6Dt4IAw08NEBAMzFHV/7KuZJzc4=; b=RCge9wnY/9K8WsPznOfDlaV2sKZFfJiw+oUucMGVQy6RPqgfvZpu/P81YKeSTE/b3r 8QynsHg7nrMBOdKIcNoZ2MYJ0HWHbYKiYJBIfLm6+ZriHsEK2govF+HBETMRGzXfoYKz bLWV+QFWlYvG78SLDkVv/CQvPtwcq2RzRudR5/+Tg1xnCfbqJEpRbZvPTkknh0TR7h8O bYBzb5Q84YHV+6gwYGJulAn2YN3Ifa++hPTonsyXUxwrGcJUKNsA6cOWIzr7ywitIbpP DVtP6np9d2ObE3To2Ar+oXvtEkK9+lBAGOzetIbXpaQATaqbfjLP9uYrfmDOYbuk8DBF 9ZQQ== X-Gm-Message-State: APzg51AKsIFDSflttYNCZbE2u8cbVK6duFJ95H3/ajEyG59coUCZorSR g0zF9jHGfHc8b6k19dPGS0YLCA== X-Received: by 2002:a1c:2dc8:: with SMTP id t191-v6mr4162464wmt.94.1535542540551; Wed, 29 Aug 2018 04:35:40 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id s10-v6sm7800454wmd.22.2018.08.29.04.35.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Aug 2018 04:35:39 -0700 (PDT) From: Andrey Konovalov To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Catalin Marinas , Will Deacon , Christoph Lameter , Andrew Morton , Mark Rutland , Nick Desaulniers , Marc Zyngier , Dave Martin , Ard Biesheuvel , "Eric W . Biederman" , Ingo Molnar , Paul Lawrence , Geert Uytterhoeven , Arnd Bergmann , "Kirill A . Shutemov" , Greg Kroah-Hartman , Kate Stewart , Mike Rapoport , kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sparse@vger.kernel.org, linux-mm@kvack.org, linux-kbuild@vger.kernel.org Cc: Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Jann Horn , Mark Brand , Chintan Pandya , Vishwath Mohan , Andrey Konovalov Subject: [PATCH v6 08/18] khwasan: preassign tags to objects with ctors or SLAB_TYPESAFE_BY_RCU Date: Wed, 29 Aug 2018 13:35:12 +0200 Message-Id: <95b5beb7ec13b7e998efe84c9a7a5c1fa49a9fe3.1535462971.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-goog In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An object constructor can initialize pointers within this objects based on the address of the object. Since the object address might be tagged, we need to assign a tag before calling constructor. The implemented approach is to assign tags to objects with constructors when a slab is allocated and call constructors once as usual. The downside is that such object would always have the same tag when it is reallocated, so we won't catch use-after-frees on it. Also pressign tags for objects from SLAB_TYPESAFE_BY_RCU caches, since they can be validy accessed after having been freed. Signed-off-by: Andrey Konovalov --- mm/slab.c | 6 +++++- mm/slub.c | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mm/slab.c b/mm/slab.c index 6fdca9ec2ea4..3b4227059f2e 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -403,7 +403,11 @@ static inline struct kmem_cache *virt_to_cache(const void *obj) static inline void *index_to_obj(struct kmem_cache *cache, struct page *page, unsigned int idx) { - return page->s_mem + cache->size * idx; + void *obj; + + obj = page->s_mem + cache->size * idx; + obj = khwasan_preset_slab_tag(cache, idx, obj); + return obj; } /* diff --git a/mm/slub.c b/mm/slub.c index 4206e1b616e7..086d6558a6b6 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1531,12 +1531,14 @@ static bool shuffle_freelist(struct kmem_cache *s, struct page *page) /* First entry is used as the base of the freelist */ cur = next_freelist_entry(s, page, &pos, start, page_limit, freelist_count); + cur = khwasan_preset_slub_tag(s, cur); page->freelist = cur; for (idx = 1; idx < page->objects; idx++) { setup_object(s, page, cur); next = next_freelist_entry(s, page, &pos, start, page_limit, freelist_count); + next = khwasan_preset_slub_tag(s, next); set_freepointer(s, cur, next); cur = next; } @@ -1613,8 +1615,10 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node) shuffle = shuffle_freelist(s, page); if (!shuffle) { + start = khwasan_preset_slub_tag(s, start); for_each_object_idx(p, idx, s, start, page->objects) { setup_object(s, page, p); + p = khwasan_preset_slub_tag(s, p); if (likely(idx < page->objects)) set_freepointer(s, p, p + s->size); else -- 2.19.0.rc0.228.g281dcd1b4d0-goog