From patchwork Wed Aug 29 11:35:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10579965 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7BD5217DE for ; Wed, 29 Aug 2018 11:35:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 693B92AA9C for ; Wed, 29 Aug 2018 11:35:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C5EC2AB44; Wed, 29 Aug 2018 11:35:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAE9B2ABDA for ; Wed, 29 Aug 2018 11:35:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 67ECA6B4B82; Wed, 29 Aug 2018 07:35:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 62F526B4B83; Wed, 29 Aug 2018 07:35:43 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DCBE6B4B85; Wed, 29 Aug 2018 07:35:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f69.google.com (mail-wm0-f69.google.com [74.125.82.69]) by kanga.kvack.org (Postfix) with ESMTP id CB1FF6B4B82 for ; Wed, 29 Aug 2018 07:35:42 -0400 (EDT) Received: by mail-wm0-f69.google.com with SMTP id b134-v6so2796070wmd.6 for ; Wed, 29 Aug 2018 04:35:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=tx0f81qpatBTU8Zf6Dt4IAw08NEBAMzFHV/7KuZJzc4=; b=VMEg2gu7CWtofr1LGHXKcmLt0umRGafZeMsJohlzV0hdE9T4vd6wUzQQ7NN2uARGrs 8XmJyDXRCa1UBi+updhNBheSD1reQlzXIPaaWW+2amabnMKB8CeUUYQE0CWN6zhNYflt ByLhfxC2O+gso6YQ6oAikCU+e4/d07hj/Ttks4rp13zuUIEdLpkbn9s6oFt/ekq5Awuf P8ApRyi1QM14op4jua201iUN6BtPzkrpnCunuf6DuPvjVRTnCdx3L9Zv6TAIlS7SmngV CRwB3glUFKBTkqejH+Yh89d8NGh8JVBEjgqzRPlNYtXyPRdG/k7lUjmPdtwKoyc8YVQz zhAg== X-Gm-Message-State: APzg51B14qUtsj6RFLul+skm2d7QlzbISA8HYTsT675Nm0ugTqkpq500 6H5Ba1Y+OUcsNljpSaWCpihzfMZUlbuzps2k3z4EBpOqE0BHrdu9d6yfSsw6s7vDlUAr1Kbz7zO k3IEYSMtlMXdqS1Zjxs1sA9/4obxuqUtLaeKUWL6N9Eimib9DhOD32QK+M0Sh4GtshYfF66kiYe 1MJcaUC4Esph2GLBw5y3SvBiaPh/U/G+VftNUvDJkxyEBMGdGhZflDXdrGLNMPBsZ8MjQWgVxC3 hBfJKLWDfNQLroqotuDcBX5V+qhPVBysCM2PpvbqIQG+CHXutxn7QJZwHOevHR4eXWNL3Zg4PtZ EBlToEMIT9gOlLkXBRcjs2wAj0I4BNMU8Nfvq3nDXBMpmmGnoAkMIWGi0SmhXY1BUytpB0nQdMH I X-Received: by 2002:a1c:2108:: with SMTP id h8-v6mr71713wmh.108.1535542542290; Wed, 29 Aug 2018 04:35:42 -0700 (PDT) X-Received: by 2002:a1c:2108:: with SMTP id h8-v6mr71688wmh.108.1535542541565; Wed, 29 Aug 2018 04:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535542541; cv=none; d=google.com; s=arc-20160816; b=GkMzYd2r6KKoeqL/HBUHV0qzPvzKGGK901Q8F4JP37d4KwIMjjB8vDmuNzVF7RQgGH 1F1XBpoedjvKdqm5tea+jOh85DbfscGvwrJkeD7w0PywkaMuar7Yck+dfo9Aa1kWFLMH jZJMkj0RkdQligy6aNjvnd9RyZMAu9Qx5n6sdtzdpnq5XqcOg0kkPTXTCHmeZaUCEzxe YcMbEFsIrecYzfVc3eizEhtzvVpFhme+TdRWd8iET6vvV4YzNcnsH6N7SmZZubXn7m2Z rcXxr2TowQNCVHSEk8MkCGcPNkSMq0/4iofxpzpEUh8O6K2VVvgI4fTAnoPqzMpxPK3y 8wyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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=UUend2KQeZECX8zRwm4Kup8zjlYnZOdH4ZUFzBFnxe2hKPoJy34oKalKY4wvf5yuNH JvxIa1ZlEM38zgdaox1FGE2bx5DgNYkwzZfLKTQahOc7EWUBvyYBeEO0raKe0SNcsQYM g4nr4AezJ8/ftv21uYvDMXUwBAfOhu0dDvTeaoZVHznmx3sGTVcrZrOsJHV9JkLpIATw yX6ZCz1w/UK6/93301rp1+G22voks6bxkgZG/GBRtryqizj8LRyyrU7m0hOWAREq6rCm /XwHYUTHZ/yaMoDPi2kTXfIEXfmRPcTRuZGW72ZQ2Ic5yckzHKADn6YZUaf0sPgbV6j1 lU3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tGIcisOz; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 15-v6sor1122665wmm.59.2018.08.29.04.35.41 for (Google Transport Security); Wed, 29 Aug 2018 04:35:41 -0700 (PDT) Received-SPF: pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tGIcisOz; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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-Smtp-Source: ANB0VdY0nxFKwxx75PWHyKBWLlnvXmuWojLgvitD/kFGr51SPbBFXRZ2fLWPnFpHFc/eIOY2zo7EzA== 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Christoph Lameter --- 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