From patchwork Tue Jan 30 19:03:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 194285 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1437980dyb; Tue, 30 Jan 2024 11:07:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+GM60aTL+ZSYirsP2k1EZBHDRG9YmX38tg+/6adDdVk1VjS1IrzxTUsz1eod64Pyyxar8 X-Received: by 2002:a05:6871:5210:b0:218:5163:d118 with SMTP id ht16-20020a056871521000b002185163d118mr8672829oac.8.1706641670749; Tue, 30 Jan 2024 11:07:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706641670; cv=pass; d=google.com; s=arc-20160816; b=lhbbk59U/bWD349x6byUlvSVbXtdMhs3v/znomyiQJ09AIzDzeqyEh3kpgqAupLJVU HOYuCzF8PStT7siv9Vq9rZETzARjfI7EvsyPhruJdW5d5RvLT9VORTNrzoC9LznORe1V UbdwkyfLjrecVs1UvXrMcY1JEaczWhvcjim5jYcmNb8MiQmgjfIPXKYHUD8/Z/7hiZpm RHBEL5k7uZqEJVmVbMCVmPPcNxJ6vwZl5kcyguEwon1u9zaF0DCE1ZuqVidGpPhH+zdg IbVLAiFEM6qy4GPWvemUgCgmVLxUfGLcj8ZzXjx6NGX99gqBI224qOeAiqBKFCLuCuu2 q+4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kxF++LiKDtDULdRc9IWq0v8KTlzVdnVwtGMDFPC/o08=; fh=aD/wDFT3pdBCiZXVST/riRN8xCPBouJr3XfOtoKVvRw=; b=XsaY3jpryTv2i9Q8IL2bxpsJvnvISbH+LaExEUz78C65gc3eHhHDRT5GqboWh+RM9/ dnfXx2iZIcDkD6jDBImjFwwSt7VUlZAKv/YUPLTLXR71tL2TpJlUM5Fhz9M+eJ43vJAa gfMUfH7VVHQe9dG7HEV5u7Q+lSZPv9nqMyrrKGLT5RbX3YsW3Vn3JIGETGLBLG+DTZTe HslHtH5zsxUdYpv2WY6dCB+U1NzaUl86CtuqNmvjQStCpfz6KAgztrMxTcuA2GvGt/Cx 9T5qlbc/WM+9CadWZenNm/k3xcNvxeBg2TV0W1RKxeRVZcH4kpXg/skWmn1jr0e8heuj QouQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=Vd1hrNDi; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-45155-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45155-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id i14-20020a63e44e000000b005d8b3138f64si6152424pgk.279.2024.01.30.11.07.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 11:07:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45155-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=Vd1hrNDi; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-45155-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45155-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B92CFB2326A for ; Tue, 30 Jan 2024 19:04:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B891079953; Tue, 30 Jan 2024 19:04:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="Vd1hrNDi" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE3DE7994D; Tue, 30 Jan 2024 19:04:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706641458; cv=none; b=QvZCbPjauh+biMAwaCIyFStY/sToMfJfvO910z+8NyjspITMR4b/2ePsYOisK3jB1OWhBtSpZS5qWlXbjH1JCGl6RqzoG+Fwp5JdO+AutVzXzE7Oj/HcWab6fTadbYZEIQ951aufQ7psAMRQP8wHy2ho6Ajuwob5ojArhUqofYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706641458; c=relaxed/simple; bh=UN73rU1wKgk+kPZG4I6r0l+EYowt6RDqJg5XsMuGiLQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V/2OZDZm7Le22C/grg8G+n782s3uw1yVqFq36mhl7SHuo9M2CtVK1hUCB4OWZuFkXB/i2OVPPr9YCh8OO6O9M9ziDF+LhtmEo75wpo+iC+xhNFarKmeNLJZMGX1oLexKPrJrWgaxfhenxKNTB/+oGtPpLOy0cngkKBkgg11ZhG4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=Vd1hrNDi; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B164C433F1; Tue, 30 Jan 2024 19:04:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1706641457; bh=UN73rU1wKgk+kPZG4I6r0l+EYowt6RDqJg5XsMuGiLQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vd1hrNDi9XyJiMLBg7nk96fWw9ntucwuoWji3NVvRxAagTIdMFOl0KoD36I7e+2VN VnHMY7fCpF6mvFH03bTwvvq/HhaKy3ufgcODBFOxIt/jukpRAqV9ZQPeNO61tr5hZy XzWvd6ERZDEGPk+VJTU5IUICtY1fOooFW2U32I7k= From: Linus Torvalds To: Steven Rostedt Cc: Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Linus Torvalds Subject: [PATCH 2/6] eventfsfs: initialize the tracefs inode properly Date: Tue, 30 Jan 2024 11:03:51 -0800 Message-ID: <20240130190355.11486-2-torvalds@linux-foundation.org> X-Mailer: git-send-email 2.43.0.5.g38fb137bdb In-Reply-To: <20240130190355.11486-1-torvalds@linux-foundation.org> References: <20240130190355.11486-1-torvalds@linux-foundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789543496708488528 X-GMAIL-MSGID: 1789543496708488528 The tracefs-specific fields in the inode were not initialized before the inode was exposed to others through the dentry with 'd_instantiate()'. And the ->flags file was initialized incorrectly with a '|=', when the old value was stale. It should have just been a straight assignment. Move the field initializations up to before the d_instantiate, and fix the use of uninitialized data. Signed-off-by: Linus Torvalds --- fs/tracefs/event_inode.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 2d128bedd654..c0d977e6c0f2 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -328,7 +328,9 @@ static struct dentry *create_file(const char *name, umode_t mode, inode->i_ino = EVENTFS_FILE_INODE_INO; ti = get_tracefs(inode); - ti->flags |= TRACEFS_EVENT_INODE; + ti->flags = TRACEFS_EVENT_INODE; + ti->private = NULL; // Directories have 'ei', files not + d_instantiate(dentry, inode); fsnotify_create(dentry->d_parent->d_inode, dentry); return eventfs_end_creating(dentry); @@ -367,7 +369,8 @@ static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent inode->i_ino = eventfs_dir_ino(ei); ti = get_tracefs(inode); - ti->flags |= TRACEFS_EVENT_INODE; + ti->flags = TRACEFS_EVENT_INODE; + ti->private = ei; inc_nlink(inode); d_instantiate(dentry, inode); @@ -513,7 +516,6 @@ create_file_dentry(struct eventfs_inode *ei, int idx, static void eventfs_post_create_dir(struct eventfs_inode *ei) { struct eventfs_inode *ei_child; - struct tracefs_inode *ti; lockdep_assert_held(&eventfs_mutex); @@ -523,9 +525,6 @@ static void eventfs_post_create_dir(struct eventfs_inode *ei) srcu_read_lock_held(&eventfs_srcu)) { ei_child->d_parent = ei->dentry; } - - ti = get_tracefs(ei->dentry->d_inode); - ti->private = ei; } /** @@ -943,7 +942,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry INIT_LIST_HEAD(&ei->list); ti = get_tracefs(inode); - ti->flags |= TRACEFS_EVENT_INODE | TRACEFS_EVENT_TOP_INODE; + ti->flags = TRACEFS_EVENT_INODE | TRACEFS_EVENT_TOP_INODE; ti->private = ei; inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;