Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1745041pxb; Fri, 24 Sep 2021 10:52:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyt9JMhOFteoVVJmkRB2WpL2VUYDYKMacbh17c796/RiHsc+3MQV/EMPr1LQxcY312A//Kl X-Received: by 2002:a05:6638:41a2:: with SMTP id az34mr10510222jab.4.1632505924917; Fri, 24 Sep 2021 10:52:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632505924; cv=none; d=google.com; s=arc-20160816; b=jE2iLB7y8DsJJrXI1EoZte7goE8lpNuABz9vH/yGbcPXrrkQQm1kCCCISgTVUSc61r hYGXSQ2ZkIj+mxXLa1q1kltbavplrbq/vgMLKBQW8fPfjMdw4epsIgMh/uJMIVk9uPRu OYFjwfAnw5YQ3N+5xvcT0A0HroKC72g0Ngo0Pehj6HE+Vkgac5y7rryJFE5SKvK09GjL quTr/RU4GTFsszAKgaUYrop4hFNWIZUt1F7vXmO8eyN3Viiyr4WZKCmm/zTPi1ct7GKw eIiVMQvahWGL8JfhMUL7xzMqK4OuZuAGZkRZ5e/eyvD+4n5wY8nWOJSkRezn0Cf9WES7 q29g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Lql6iEkk8n1u+sxbQee7s4dy/RNLUX6VkwcmM0wKRh0=; b=PWY2u7BJQjERfIs86VNdrU1a/0aHwDLXYo7qN7etlxt6GDXqObbFaR6VhI0baAST/s qBP/58OhkntDHem5PvI0pTP87AUfnbDXUWm06IZ3vcvOs3OMtY66VEwCx8fn8KCB3hNH sxMs1zftouYaY1U1U5/cR1dvjIzJHRwXiGizUigdErw9z1/5Ajg9pNKq58Ie6dqUoeqF y9mZUxE3CoA9XmgcRtDUUt0uaK62/Nsn3kznITg2hhzjy/37x+qCqDXX8QnJldpq80EH QsTj1Jt0ytoNwItKEzfU8rV+sS8kILaQuWlNwxU9SpsyL5/imCbsUV3CNnUMQgQDrI1D OzrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AhWVyojI; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c3si8587169ilq.163.2021.09.24.10.51.51; Fri, 24 Sep 2021 10:52:04 -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=@linuxfoundation.org header.s=korg header.b=AhWVyojI; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344949AbhIXMxo (ORCPT + 99 others); Fri, 24 Sep 2021 08:53:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:49170 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344557AbhIXMvy (ORCPT ); Fri, 24 Sep 2021 08:51:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2C4E86124D; Fri, 24 Sep 2021 12:49:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632487757; bh=vvMHbaGr6fiwNtWWcVDXG+eal44ko7TI9VqLB8pA98g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AhWVyojIhv8EiDli/gICqQynXdlCDXEaOjQ9diPFzA+HoVHgwtpNP740vNgx6tEa9 ji2y2E1xUq1zBhsL5TzYjHXtkVEQeTH2K6fQiacbmKWSffjrqKNFjt/Rg5aXEuVNUU JeJabiWkyO+ySbzfsFohwEXbKiL419d6dgh3tnq4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nanyong Sun , Ryusuke Konishi , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 25/34] nilfs2: fix NULL pointer in nilfs_##name##_attr_release Date: Fri, 24 Sep 2021 14:44:19 +0200 Message-Id: <20210924124330.783018296@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210924124329.965218583@linuxfoundation.org> References: <20210924124329.965218583@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nanyong Sun [ Upstream commit dbc6e7d44a514f231a64d9d5676e001b660b6448 ] In nilfs_##name##_attr_release, kobj->parent should not be referenced because it is a NULL pointer. The release() method of kobject is always called in kobject_put(kobj), in the implementation of kobject_put(), the kobj->parent will be assigned as NULL before call the release() method. So just use kobj to get the subgroups, which is more efficient and can fix a NULL pointer reference problem. Link: https://lkml.kernel.org/r/20210629022556.3985106-3-sunnanyong@huawei.com Link: https://lkml.kernel.org/r/1625651306-10829-3-git-send-email-konishi.ryusuke@gmail.com Signed-off-by: Nanyong Sun Signed-off-by: Ryusuke Konishi Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/nilfs2/sysfs.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c index cbfc132206e8..ca720d958315 100644 --- a/fs/nilfs2/sysfs.c +++ b/fs/nilfs2/sysfs.c @@ -64,11 +64,9 @@ static const struct sysfs_ops nilfs_##name##_attr_ops = { \ #define NILFS_DEV_INT_GROUP_TYPE(name, parent_name) \ static void nilfs_##name##_attr_release(struct kobject *kobj) \ { \ - struct nilfs_sysfs_##parent_name##_subgroups *subgroups; \ - struct the_nilfs *nilfs = container_of(kobj->parent, \ - struct the_nilfs, \ - ns_##parent_name##_kobj); \ - subgroups = nilfs->ns_##parent_name##_subgroups; \ + struct nilfs_sysfs_##parent_name##_subgroups *subgroups = container_of(kobj, \ + struct nilfs_sysfs_##parent_name##_subgroups, \ + sg_##name##_kobj); \ complete(&subgroups->sg_##name##_kobj_unregister); \ } \ static struct kobj_type nilfs_##name##_ktype = { \ -- 2.33.0