Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp666812pxf; Wed, 24 Mar 2021 12:52:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVM7Wzs3fdieQekA/STFstVchCcdFPpbI9URHp/s/Nq8gqqbQju9ZEaTYZ1vXby3pt0fZr X-Received: by 2002:a17:907:d1f:: with SMTP id gn31mr5497540ejc.536.1616615541323; Wed, 24 Mar 2021 12:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616615541; cv=none; d=google.com; s=arc-20160816; b=Mu1iLqoHvIMZVn1nv58wO+m+3RMcCUYwlG14/MzYbEAQesz6sMSznja0UDr44pLxLL wwqF9UJZ1GF5lYI26bWn2mivMcoCFvBuK07QuZkc3hOOrJNb4+GlfgBlJYfv5RHhYNob jmE7KZ0q8v28NcwDBoum1NDkXVMrRR22E9t3vyy1/Vrl7YRTnLpIdQbAidCSJkbtsY1+ Gqa2EQka2Pyg2cSFSBrAB5iroDbnSHZBejU+ge3CrwDJZaUvW3+QsXuSw5c2/Nf/fHwd vBm04AieLd5LPMBQcGlmJvl6J2Ru+JrI8Wvk7plHaJju9WCwXNMqwqebPcGeAHg1tPuJ kFdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:sender:dkim-signature; bh=REq/3z6pobNdfYBuuoG456AWgVOTbPT0o3Axmb0eQnU=; b=Zr42ewFmpPEIq44gGuQCTjp9gh2JT9VPXjYZ+kO6mi+imPYxXjfWbKkaGd7QlX7kd8 +yYbGd08kCA8CMr9aldtKQufQ5jenGLS6Vjq7d3KLVgEj8jb+44tpNiHlKQuDqjYz4AQ kG4/PwXH4u3UsGf8+IxM/Z4/hR1tPj2XxgrfcbVNFWKtfdzTvLurwJzrvBM732rStUN8 3iHEXKbEL4nOM/5mXa6DNlvp+QT/FB8DxrhKlTm/WIKUsOjr3u/SxvEr/ASymoqY93ah v2CqgLKFXkIx+sK5ETBCFkTVtAca7yPKwLUmqmpYuZneQQF5+vG2axKbVWJ5S1C0SiR8 UH2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EQom7EY9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a18si2443112ejk.339.2021.03.24.12.51.57; Wed, 24 Mar 2021 12:52:21 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EQom7EY9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237860AbhCXTuJ (ORCPT + 99 others); Wed, 24 Mar 2021 15:50:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238014AbhCXTtg (ORCPT ); Wed, 24 Mar 2021 15:49:36 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEAE0C061763 for ; Wed, 24 Mar 2021 12:49:36 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id j6-20020a17090adc86b02900cbfe6f2c96so1770409pjv.1 for ; Wed, 24 Mar 2021 12:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=REq/3z6pobNdfYBuuoG456AWgVOTbPT0o3Axmb0eQnU=; b=EQom7EY91nsoHrk6i+8Z4HSRLQUvIqpEXmT0vMrTK51fD2N4RreS32PXSNRAzz4R9I HrRlXTZFEOGH0+ls+8Qt1eBAQ4u7UoEOsHaAwvVOfEu+dg6gd3POhtudd12XTwJyS3Jg dYsnTdZukhlrYmuqkoegp0sdX0B5vT9MMvnEvvdXdjCaZXooe5V0wi5gwvvFCT2mYSTf g48MWGkaWtfU6oIpM4MRfWbCEhuufEUbSOuVCXx6zHAZRWBuOS1jWig6x0UI9sZH+yQG 0yqiPwC8TnTMJdtEw6mExrlZiG2BUU9iGtf7h5KAIt+apl44NpMNrcidaWiwLJsJDgAH uXrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to; bh=REq/3z6pobNdfYBuuoG456AWgVOTbPT0o3Axmb0eQnU=; b=gm1BpsMWtyFielNjV6QY2goPSag5BoSo4d7Kma5D1+BvCW1g/MN6rSXPsKE4ODYzKR EDR5jgZP78i1c2o5YRITrqIQM4LDyGFX5m5DDi5I0Gg4s3kpP/NcU0fDqWUYJUoOt1+M zCU03jZ1k1av8zK/VxjpBKtXRhuBrIrIWoFEQR3WZqkFLmILuvgvjCUJICV95dXdr0D3 N+0diOrYqd/vEq4w/5yyQe2lAO8mPFSHRnV0gJfIjfMd7Ki4VGsOeio87+0bHBCWJcWP 6NtGHWx5+D/SntQpnkZ/+kwhWlG5ygc1cqhD2ABMAm22nacFxycm7Q5mtk4Ao2nGcbFV H2Ag== X-Gm-Message-State: AOAM532ZtE40rJU1/MJxjIfqVgwcZ3XVfWx66OGckpLEMCrQJrl/yVax Czk/ir8PJu5B5ACABOvRLGE= X-Received: by 2002:a17:90a:840a:: with SMTP id j10mr4840404pjn.97.1616615376345; Wed, 24 Mar 2021 12:49:36 -0700 (PDT) Received: from google.com ([2620:15c:211:201:7dfa:1e53:536:7976]) by smtp.gmail.com with ESMTPSA id u24sm3620158pfm.214.2021.03.24.12.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 12:49:35 -0700 (PDT) Sender: Minchan Kim Date: Wed, 24 Mar 2021 12:49:32 -0700 From: Minchan Kim To: Dmitry Osipenko Cc: Andrew Morton , linux-mm , LKML , gregkh@linuxfoundation.org, surenb@google.com, joaodias@google.com, jhubbard@nvidia.com, willy@infradead.org Subject: Re: [PATCH] mm: cma: fix corruption cma_sysfs_alloc_pages_count Message-ID: References: <20210324192044.1505747-1-minchan@kernel.org> <18ee5c3e-fba2-0d8d-bd93-5fb8d0dd7a01@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <18ee5c3e-fba2-0d8d-bd93-5fb8d0dd7a01@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 24, 2021 at 10:43:49PM +0300, Dmitry Osipenko wrote: > 24.03.2021 22:20, Minchan Kim пишет: > > static int __init cma_sysfs_init(void) > > { > > - int i = 0; > > + struct kobject *cma_kobj_root; > > + struct cma_kobject *cma_kobj; > > struct cma *cma; > > + unsigned int i; > > > while (--i >= 0) { > > Do you realize that this doesn't work anymore? > > > cma = &cma_areas[i]; > > - kobject_put(&cma->stat->kobj); > > - } > > > > - kfree(cma_stats); > > - kobject_put(cma_kobj); > > + kobject_put(&cma->cma_kobj->kobj); > > + kfree(cma->cma_kobj); > > Freeing a null pointer? Need coffee. diff --git a/mm/cma_sysfs.c b/mm/cma_sysfs.c index a670a80aad6f..73463be08df7 100644 --- a/mm/cma_sysfs.c +++ b/mm/cma_sysfs.c @@ -79,8 +79,7 @@ static int __init cma_sysfs_init(void) struct kobject *cma_kobj_root; struct cma_kobject *cma_kobj; struct cma *cma; - unsigned int i; - int err; + int i, err; cma_kobj_root = kobject_create_and_add("cma", mm_kobj); if (!cma_kobj_root) @@ -108,10 +107,7 @@ static int __init cma_sysfs_init(void) out: while (--i >= 0) { cma = &cma_areas[i]; - kobject_put(&cma->cma_kobj->kobj); - kfree(cma->cma_kobj); - cma->cma_kobj = NULL; } kobject_put(cma_kobj_root);