Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3906693pxb; Mon, 27 Sep 2021 05:26:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBfQgElEZ6rKsXg1HhlH4Cp6dguImqAp9bVfe+ISRVwzn7hPhXzodhfrQTRP4AR6V/VG5s X-Received: by 2002:a17:902:dac2:b0:13d:1db4:dcc2 with SMTP id q2-20020a170902dac200b0013d1db4dcc2mr21991926plx.77.1632745589814; Mon, 27 Sep 2021 05:26:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632745589; cv=none; d=google.com; s=arc-20160816; b=G2w5xgze4cpD+UV0SJWhUBtd7rcjzKwBIEUxUmo2fl2Dw8xmrIj4SsW7P8avCE4O5o NjYjqGsMlrK5+s4sglebKzDuwwMNHEG3Acb6uWBzi8HrLgopB8RWMFUJQ0iNHvmZ76df HqVcYpfj0EK+fFr1CKWe2cLM5tlPjwtt0ySx/56TujyB6nJ5s1dwU6YXPNI8nZY0VYGt uQ9HQg/vk0f0986Ww92t8Qd66ZnqysTro6+0Q6VxLTXxkJ4LGRPJ0miFEhvt6Ylri18Y 5dFE3+lC992CGZERpMcvxwBJ+6z3kymrN61r3WxMHeJ0ZsDjadTNADUCo3HV2PA0zNVI NgLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=8vNrspH259tl/a8ES79N2drwp6nKLSCnmwKN9is9MPM=; b=Bq6LBIWXOJAwexGuZVzF2PQmdm0JeQBVTLDNDUm5z1+gzApQxoMkl+n9i5uk7kPNIs +BwRlytsPIauzVdU0OlXLCaXF9WfX4woRXszFSjXR6s/HpeOwyt5znsZix+GW+CXEXhB n5/APqoYeNmziFpBjxG0/KG6qNWv+iQ0uZ59GHVZ3H2px92tFtgxCrtXh6w5V9oaumXz b+/kBclnRBqhyEU4zLpQuQi4x+a98gcfiKLoOHELjjLmJRY2zXsbPiZprzFu2QvY0i3s kn+59U3U95lSXSiwNP5xJIcc4ncnBiIehkm6K6xwOweAN86Yf7JgYCmLQhLSWS55twNI H47g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m23si21732969pgv.246.2021.09.27.05.26.16; Mon, 27 Sep 2021 05:26:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234282AbhI0MZs (ORCPT + 99 others); Mon, 27 Sep 2021 08:25:48 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:25941 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234073AbhI0MZq (ORCPT ); Mon, 27 Sep 2021 08:25:46 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HJ1sz2gJyzbmnv; Mon, 27 Sep 2021 20:19:51 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Mon, 27 Sep 2021 20:24:07 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Mon, 27 Sep 2021 20:24:06 +0800 From: Kefeng Wang To: , , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , , , Matthew Wilcox CC: Kefeng Wang Subject: [PATCH v2] slub: Add back check for free nonslab objects Date: Mon, 27 Sep 2021 20:26:46 +0800 Message-ID: <20210927122646.91934-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After commit ("f227f0faf63b slub: fix unreclaimable slab stat for bulk free"), the check for free nonslab page is replaced by VM_BUG_ON_PAGE, which only check with CONFIG_DEBUG_VM enabled, but this config may impact performance, so it only for debug. Commit ("0937502af7c9 slub: Add check for kfree() of non slab objects.") add the ability, which should be needed in any configs to catch the invalid free, they even could be potential issue, eg, memory corruption, use after free and double-free, so replace VM_BUG_ON_PAGE to WARN_ON, add dump_page() and object address printing to help use to debug the issue. Signed-off-by: Kefeng Wang --- v2: Add object address printing suggested by Matthew Wilcox mm/slub.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/slub.c b/mm/slub.c index 3095b889fab4..157973e22faf 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3522,7 +3522,11 @@ static inline void free_nonslab_page(struct page *page, void *object) { unsigned int order = compound_order(page); - VM_BUG_ON_PAGE(!PageCompound(page), page); + if (WARN_ON(!PageCompound(page))) { + dump_page(page, "invalid free nonslab page"); + pr_warn("object pointer: 0x%p\n", object); + } + kfree_hook(object); mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, -(PAGE_SIZE << order)); __free_pages(page, order); -- 2.26.2