From patchwork Tue Feb 6 11:32:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1481824dyb; Tue, 6 Feb 2024 03:51:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IENkl5CTbX0KWLNoi0+zimktum6LvAF0qo7oFeVJrXcJYswwRv+IJZC1PAAPlbWjevGzxLx X-Received: by 2002:a05:6a20:9f07:b0:19e:9adc:b274 with SMTP id mk7-20020a056a209f0700b0019e9adcb274mr638949pzb.41.1707220290082; Tue, 06 Feb 2024 03:51:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220290; cv=pass; d=google.com; s=arc-20160816; b=Rks5JSE+PxMwoTXt6QMgtnGW4DZgNngu1lvNXvIZhRfcAgVW0um3g6bYQg3hhO+0nO iNbeXh3m+a8OsrBayjTRyAkRc9FCzPCt1Bxcb07x21jjiJhSe5DwOerv06yrCeu2atgE 2ZWDxzq2Fd6xjzJHXLoQaXXlrSkUQMwVBR8783fwv4stlHdv0bb8xmJVKKaTGELNTgLW WqQ9bO5ijxzUxOA57KyO9xziSrQAfi3MxZmCkNqEqt+tyCmSBnVHVDeHFKyuHNNRNRBw rMxjwpdU75RJotrDO5rM8TuJ6eBxSCCpM3eKQB9yUYD7WVS4Rx0jPNT03gguhxw9pZkP 6gCA== 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=AcY/gmMvKwen29N+PLFW2SFwBOrjsupe21rRw/oEiNk=; fh=mdLRaWUXB/wyN2KcmuhLhgOCw8weVRAsoYfE0Im5BX4=; b=n+wl6xzPts8JuCWQkc/IZ51YswUfy6VpLbNG+4OandITad9DrqPveWfKzqduBdpsdG QkEqi8Lzdn9Pw3Jmyy1Zet5i2YPrJ7yvBK6mvoF04w5T5ZCUcTCFuH8eY/9WcivVDsHZ eoTf3kX7N3pYio9rPnRjqcMQ9jzXs1rkkHFRrimPbEe/WRH1voNG+w6/YHePLMtOD2FP yezqcCUT9qnr4e8Jg10sMut24A4VXgobMeH8nQBgbRxe1BVW2DvuoYbNkwVJdgLcDlx5 6qQ3wc6Ya3GhKvY0z8Ip48RuaDplx/pi2nLAXTyP9twv3dtiu2HWUPZIKrXhrBZvh0gk VywQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54800-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54800-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXAbqyL0+ZMR5LLVeUp8ow3RnNLMTL1Mb9t3yX3x3Ll6SVIpbvE/z4l2GccB6X4NmwHsZzbCs7s5rbcaVVbV6n2raCTzA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id it21-20020a056a00459500b006e04d1b0394si1479240pfb.48.2024.02.06.03.51.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:51:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54800-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54800-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54800-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D7A3D2857C8 for ; Tue, 6 Feb 2024 11:51:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E18C1384AF; Tue, 6 Feb 2024 11:33:38 +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 7354D134748; Tue, 6 Feb 2024 11:33:32 +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=1707219212; cv=none; b=toSh0inuM0BxM83f1Ztx+pY/fhvmgKmQGuo12vmIAgiai0KGYgbus55wAlSynXOqIIFDnmrE7QnOtXJ+qrK3+3nt6hUG/bzSVkyV5cOtNdIvGJsDSK25CsZEQMtZKj8WBBOFefurHj0c7QNrZZIzuPNWh6RETQh65IQ9hSDxmMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; c=relaxed/simple; bh=sfvjVRo/uEnLvIM2+rrv73QKbK6qOK2EnD7X46CxfoY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=hb3tnC/C6Y5E4VwA76ssI6bMjNdArdGl+HfIM4ZFKizne9War8xNBspclfGuD5qred3/c5orKlCNl6YieLCMroZdNB10x10nxfPEvUSWMhIoIbCGSct01Ay6pAwPUkpPHWwKxg58G/GDRkLr/FJYg6FwVbyYeKjwmW83HKHIIlc= 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 09E2DC43601; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiC-00000006aMp-1QiL; Tue, 06 Feb 2024 06:34:00 -0500 Message-ID: <20240206113400.202745776@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:11 -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.7][PATCH v2 13/23] tracefs: Zero out the tracefs_inode when allocating it References: <20240206113158.822006147@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: 1790150223367052655 X-GMAIL-MSGID: 1790150223367052655 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 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; }; /*