From patchwork Tue Feb 6 12:09:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197435 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1506563dyb; Tue, 6 Feb 2024 04:36:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJ8hurkipSaJs0TtpCa2z1fUjes83bvoa85cSECiStoIDZ6JNxnREDAfBhiMIRXf9y2+2O X-Received: by 2002:a05:6a20:549e:b0:19e:499c:dd7 with SMTP id i30-20020a056a20549e00b0019e499c0dd7mr1782094pzk.52.1707223013928; Tue, 06 Feb 2024 04:36:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707223013; cv=pass; d=google.com; s=arc-20160816; b=AFotcGWwYu17O7zsEp+QtPmnfuBMplRSyIm3FbqMYHRJvTM4btbO864Wdk7gMO3/v2 hColZ8DFdUgV61UrQI0UhBBCiuCoertAw2d+l9//Qe+zZTPioyITTQX7NsRiIqIRO6Ld z81NZWCbGtkXmGaZZdGh6oHwyZXRbMvzjAndKqcAoxtbjAnCL66w7KI9MkV+Mkf2o4KZ vGLQJscOOLI0OQPMeIfEJ8ssQijsx5h1NNXeM0H65kAYdGu/CD4H2c+iHnSw2+HOAutr rzsMgKHcgfNxfmCuzmuWG6PnL0uu/zIejhALALyYkn/aNMyN34dRA3Tq12auwmBLwM/M ySpQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=RbZLtkYgrpGgmw3UH1Q8JIxmzSjl7CFs+4BWjGfroc0=; fh=RdAshnJ5invps6aa+A9wJKO/fyopsNdw/lln1iPQPzo=; b=uMIhqMZgVJbuTnuXNft4+vmav7fzjuFxuIZFW9gcTSta0s5F630Bza/JKzFsHYDACL eGYpYZ+U9S/jRzvbxfOl2sVbGSlsPk/KclgpOCKvSUuRLGAJ4nCkTN9owEVsW3q07i+B +mZ2YyIwVgXrW3p5fbnN0R2oQ9s7txWJUU1wezJK7DMOoWvNn2ksMoYSEh6htymEXDAY tykRfvI4dk6qnvjXDxwW2XNkjm9prUdxDYv6FaSdR//WPdMUmxitUzNQHagu+H7MbVbw bsagWNNjHcjjDLY7Ss78J3Qo1zL/KOUryoKoBUj37CLIggHJbSWms1dKFsUWkcLmfSdL sbmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54922-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54922-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWmEg1EzjmxVSvaPOntdwabAD27S3oE0vAnT/CbCcE9oijeWQRSKFUGtCl/Q7BDmzHelKauO7gMOfD/dzWjlRVXW0Yj3w== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id fm23-20020a056a002f9700b006e05cb7fd6csi714981pfb.243.2024.02.06.04.36.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:36:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54922-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54922-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54922-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 9FD23B27F85 for ; Tue, 6 Feb 2024 12:27:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4CBF4151468; Tue, 6 Feb 2024 12:09:41 +0000 (UTC) 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 F286913B2A5; Tue, 6 Feb 2024 12:09:25 +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=1707221366; cv=none; b=ETY56r58OlsvJMZEwJFAJmCMyggMfRMweutz6DoqzAXHpZCn0RbWOiaK0JlUQKcwWyWVI6SqjReLbyOJDBNXeK6DQ7CT3Vn5+ZNKw329BFQYbmvTwvgJAuEyPjRd+ZHuYOZdtvbywfW/kiUB1U5eVSPquAolBQaQ1nxOZ4/K8mc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221366; c=relaxed/simple; bh=lzb1sLgZCuUuHW8/jlSYK6Gi2ueBjuBQSwLGcv1JC0U=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=OB5XYlpmpPwltR7WmgBuQEj2uUqf7FXATtLJbpuJlZ8z9ky62XuI1WUvCX2NTzk3YS9mmhYDcCDlZ2xdubyXixLM0tf1k3yjuT5f9EhyJkjVRxo5eTSuTFW+OikBmv+ZgseNXCk/39JDVF2xtI493eAY2WSy6kHCh1LAvxV8Zfs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3317C433A6; Tue, 6 Feb 2024 12:09:25 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGw-00000006bOq-0lXv; Tue, 06 Feb 2024 07:09:54 -0500 Message-ID: <20240206120954.038732037@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:52 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , kernel test robot Subject: [v6.6][PATCH 47/57] tracefs: Zero out the tracefs_inode when allocating it References: <20240206120905.570408983@rostedt.homelinux.com> 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: 1790153079444321425 X-GMAIL-MSGID: 1790153079444321425 From: "Steven Rostedt (Google)" eventfs uses the tracefs_inode and assumes that it's already initialized to zero. That is, it doesn't set fields to zero (like ti->private) after getting its tracefs_inode. This causes bugs due to stale values. Just initialize the entire structure to zero on allocation so there isn't any more surprises. This is a partial fix to access to ti->private. The assignment still needs to be made before the dentry is instantiated. Link: https://lore.kernel.org/linux-trace-kernel/20240131185512.315825944@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202401291043.e62e89dc-oliver.sang@intel.com Suggested-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit d81786f53aec14fd4d56263145a0635afbc64617) --- fs/tracefs/inode.c | 6 ++++-- fs/tracefs/internal.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index fc0f133eefdb..ad4c137b7be9 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -38,8 +38,6 @@ static struct inode *tracefs_alloc_inode(struct super_block *sb) if (!ti) return NULL; - ti->flags = 0; - return &ti->vfs_inode; } @@ -779,7 +777,11 @@ static void init_once(void *foo) { struct tracefs_inode *ti = (struct tracefs_inode *) foo; + /* inode_init_once() calls memset() on the vfs_inode portion */ inode_init_once(&ti->vfs_inode); + + /* Zero out the rest */ + memset_after(ti, 0, vfs_inode); } static int __init tracefs_init(void) diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 91c2bf0b91d9..7d84349ade87 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -11,9 +11,10 @@ enum { }; struct tracefs_inode { + struct inode vfs_inode; + /* The below gets initialized with memset_after(ti, 0, vfs_inode) */ unsigned long flags; void *private; - struct inode vfs_inode; }; /*