From patchwork Fri Feb 2 02:30:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195531 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp164844dyc; Thu, 1 Feb 2024 18:31:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvfd/rmdOEv5ASw7waN3l/+jZdmXePnY+19ks1vx0Bt6XGE+WpuvQcjmwiMnBRruVJ4HLO X-Received: by 2002:a17:906:3094:b0:a36:fa18:ba60 with SMTP id 20-20020a170906309400b00a36fa18ba60mr374598ejv.26.1706841066995; Thu, 01 Feb 2024 18:31:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841066; cv=pass; d=google.com; s=arc-20160816; b=OUmJ7UisNkIiVDD2KGQAzEpYJ0Xs3ZbMZENWkeQGtMh7lPENKMU7/lXVqV5fiPl/CL iQ+Q8le1pmgodncWt5bK6/ObWLlwQMz36z9EM1DEBwe0Q/0g2JpRVn1XhL2ogedYpaXd hQeqfF/nAR4jwVg0JLvtwQX0B0ygNh3aLHh5/dshOsYZtKaOGu/Kd1D+Himb968yvah+ iseAJmyJDkJKXfeZOhEgDGPmaupsglKHAQPGfu1rgX8zNaOpV7S/OTYg08u0xxBULKm1 ht2LmV3JExVoKkkQ22D11V4OTX4LBvrGh5WrNUwk6wrc8TXQ7/y8y0xaP536x6MNmmiB odRA== 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=9a6mlKxBAB+nG1o/FkoaS+LuUNdfuJ0NPVKe/J3/wfQ=; fh=JRjNVYZl3ghK5UnsgmNByJmHlDz2LQTp1xWPAXXL6BA=; b=lTx0s84evdhlZstqjEqyYyDgy8VVrRBQHyxQYFMxr2iOpBF8vYnBtDftDovWH9dmCV /r28CNagGnlGe1qkelDmWWwzL/mzXJTp9GSD/A83gnbPWUq8oVKtufx8j99LzFTbgKRE DeavwWAKCMEvmpgCwKLc0XAeGZaM2REqZLY6qZeBBX6IZkvsScXH7NuNPVHd7P/SfkRC u4F5n7XEEBxIxB8CtKFSFIux5xq+Veg/g0y+y1WZ86rkbIY8gxWhRODazkddd8nOmJFz qCzIHspXW7fK3JOBPhGbx8vrJwzYtUZTnoTxSuInVyq/Bj+dOj8sAbXxqgbA7naHLvUO pRhQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49095-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49095-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUvrCRBJyxId0gQyuzmujHjXpdVnTww7/ZvJOyTsuhAeqjXW93BX1/JV3H2BRpsQHVh3DJ5cFxCDf5jhYXLk46o+UAEJA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v10-20020a170906180a00b00a360a6e87e4si367861eje.400.2024.02.01.18.31.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:31:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49095-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49095-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49095-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9B5F41F256CC for ; Fri, 2 Feb 2024 02:31:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E758101C1; Fri, 2 Feb 2024 02:30:06 +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 ACBE8BA2C; Fri, 2 Feb 2024 02:30:04 +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=1706841004; cv=none; b=HSYF7+cYrKo4w3n0RthivfVzaJNt2caOc3sB2i6YFjZcA8me2vjVd0BBMj7KzBgY2NMuCs2KWpt7Z9Jr6Pk7PHHQciCxbN01jP4RWQnEBYLPXzA5yJABeVGLMx9iLXtba12SACsJDjLMCrMXExCgJ9lr3o5+bGij6sZpbmBBrT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841004; c=relaxed/simple; bh=3adZE3XRvsxSdhBsQIqBjy7xLEJW/dok2uD8qBYZMss=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=J5pt1w7VAeyOqlSkP+/m+pCL9FNQPkwscLJ5mX3tK3L5SPuul7TyKkuJ+tgGofwHb+Qe9HVaWcXx5PCnx6eVd5lEkYpyX+fhlWdWTZyI9X+M69+aOT7sjjrS1KJSts4PK00k/ZAC2CMn+t2CjU7ah+oWoOCZThE+bWe9kEduC2g= 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 52AEFC433A6; Fri, 2 Feb 2024 02:30:04 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJu-00000005k6e-1YVm; Thu, 01 Feb 2024 21:30:22 -0500 Message-ID: <20240202023022.238836873@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:01 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Christian Brauner , Al Viro , Ajay Kaher , Greg Kroah-Hartman , kernel test robot , Linus Torvalds Subject: [for-linus][PATCH 02/13] tracefs: Zero out the tracefs_inode when allocating it References: <20240202022959.515961549@goodmis.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: 1789752578233025297 X-GMAIL-MSGID: 1789752578233025297 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) --- 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 e1b172c0e091..888e42087847 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; }; /*