From patchwork Thu Dec 10 18:37:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Popov X-Patchwork-Id: 11965901 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 DBFF9C433FE for ; Thu, 10 Dec 2020 18:37:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 42A8F23DE3 for ; Thu, 10 Dec 2020 18:37:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 42A8F23DE3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5FDF86B005D; Thu, 10 Dec 2020 13:37:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5ACFB6B0068; Thu, 10 Dec 2020 13:37:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 426846B006C; Thu, 10 Dec 2020 13:37:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id 2840C6B005D for ; Thu, 10 Dec 2020 13:37:45 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E186A180AD837 for ; Thu, 10 Dec 2020 18:37:44 +0000 (UTC) X-FDA: 77578231248.12.slave32_48006d4273fa Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id C146918029286 for ; Thu, 10 Dec 2020 18:37:44 +0000 (UTC) X-HE-Tag: slave32_48006d4273fa X-Filterd-Recvd-Size: 3806 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Dec 2020 18:37:44 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id t4so6508074wrr.12 for ; Thu, 10 Dec 2020 10:37:44 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=qevJfY7dsLkmoNjN5cKll/uAr7AEc1whLJC/57i9ulU=; b=P8PwwNwOKYoUj96OsQO7QjWwrVDFC/R/IM54wAJiXnIKkNQANM8eKBUTjYo1czPRC9 RyDW2M/zyy2/BmkQVcgvgvbAIDkhci5H+B6uIglSisFLE2Z8uJB4MEwuywldGr2szWQB gfZgP27hUKSq+Ko2J1KEJxFwVaKTvMnyeanPF40WKXI1vB48i4KUheGELeRsL6yZpUAU dNBW2Kvyr/yzhs7S/Oksbc+oznqCGhHooBDmRFEz+Oh18JPHe7SotF/JtxqwROVOml4C gxWdo3XN+TVX1ZihVC8YsDzI76RdOwp6VI4IQxr7F9DEGSV5y8X2tn71qO9xQFUVBnKq Mvww== X-Gm-Message-State: AOAM532tmCcLHQuQO/O7F74R8wssh1XlrGmvi0tRlzf9/5eivuR/FAB9 jwCUhYsBb4WE3KoeuHP9P20= X-Google-Smtp-Source: ABdhPJxLzWse7Ykv1E/1SYot6r/6FwAHVz/IyRlUCr67SQMp43PAveKBidrqjrvsOUsVSGQ+8YocaA== X-Received: by 2002:a5d:504d:: with SMTP id h13mr9905265wrt.246.1607625463189; Thu, 10 Dec 2020 10:37:43 -0800 (PST) Received: from localhost.localdomain ([185.248.161.177]) by smtp.gmail.com with ESMTPSA id z21sm10216699wmk.20.2020.12.10.10.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 10:37:40 -0800 (PST) From: Alexander Popov To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alexander Potapenko , Dmitry Vyukov , kasan-dev@googlegroups.com, Alexander Popov Cc: notify@kernel.org Subject: [PATCH] mm/slab: Perform init_on_free earlier Date: Thu, 10 Dec 2020 21:37:29 +0300 Message-Id: <20201210183729.1261524-1-alex.popov@linux.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000046, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Currently in CONFIG_SLAB init_on_free happens too late, and heap objects go to the heap quarantine not being erased. Lets move init_on_free clearing before calling kasan_slab_free(). In that case heap quarantine will store erased objects, similarly to CONFIG_SLUB=y behavior. Signed-off-by: Alexander Popov Reviewed-by: Alexander Potapenko Acked-by: David Rientjes Acked-by: Joonsoo Kim --- mm/slab.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index b1113561b98b..344a101e37e0 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3416,6 +3416,9 @@ static void cache_flusharray(struct kmem_cache *cachep, struct array_cache *ac) static __always_inline void __cache_free(struct kmem_cache *cachep, void *objp, unsigned long caller) { + if (unlikely(slab_want_init_on_free(cachep))) + memset(objp, 0, cachep->object_size); + /* Put the object into the quarantine, don't touch it for now. */ if (kasan_slab_free(cachep, objp, _RET_IP_)) return; @@ -3434,8 +3437,6 @@ void ___cache_free(struct kmem_cache *cachep, void *objp, struct array_cache *ac = cpu_cache_get(cachep); check_irq_off(); - if (unlikely(slab_want_init_on_free(cachep))) - memset(objp, 0, cachep->object_size); kmemleak_free_recursive(objp, cachep->flags); objp = cache_free_debugcheck(cachep, objp, caller); memcg_slab_free_hook(cachep, &objp, 1);