From patchwork Wed Jan 31 18:49:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 194911 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp2107315dyb; Wed, 31 Jan 2024 11:15:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4J6Wk4moQnPCvk2lcyPEZIrhQ8hQ4AQffxf+idGUchcNvV1Jhnwa6RZha9pT7/0nu9ltg X-Received: by 2002:a17:902:e541:b0:1d8:f200:6ae2 with SMTP id n1-20020a170902e54100b001d8f2006ae2mr3363071plf.30.1706728554605; Wed, 31 Jan 2024 11:15:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706728554; cv=pass; d=google.com; s=arc-20160816; b=qq/rV2ua1K2CYT2fz2BjaNBAgXvFfdr9us9O3i4ZtUyfu0cXbb9X06djWL6u4TU55E 1Wmnoff7sIcZtzZGZCGE43LaIJ8sizZpsVSRS8wQCt/RcD7KYrXPoj0O5GrmYWGj9T67 TwQV0QciYtnoeJouwSvHSE4+splAbeoBJv8QaallMjdmcUleHcUK5NG5Y83lJJTE6uZ7 9Y9GyGP/FqVT67QMYQDlHXMKPxcnmoYKIRLA1uUPG8J4cD5rlbMRlO/CISc4X3ox4uGi FltiPox/MbTbGSaG85eM0jvffFLoygTMH++jcjMIRQMcPFF8vwMP/scLpUHk4+Bmp7rq BT3w== 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=BLEdrGS2Da0/DL+Bn5JBrytdx7X4xFks9AkFRO0h+xQ=; fh=wTjzPxNcwW1GffzqGN/XcZB7GpDbkM3wWPgqd9vPLQA=; b=PXf5WR63VaHH0aJg22/u6a62nd86jz7zqJyxRFwheRXqPCWsrFHshPVpmDnUdm32ht nW0yFYmIbgqPUjcwFkny6YeMGlWmCjJMaWy5UqcwUGTYRu0S0Tv5iOpdmeAsDv4PX2YX N9oAhUoP1MTKOS0tzSPTo00MSEYLRskhwk4Je3k4qwkKaVJgR/mzph82IMyRBZhsNlt2 WhTrVfoYo53lkbUkR/SfYROc7qD+7hfMjRxzDsMChVK4YwZVugPlciv7qa2VEhjQMh8L mqi+d9f7LKMFGgspnf8zidIxqIuSFUDIFchKzWBag9cFLkE3Iu05XYL6ZAKWjOFLbiiP odfg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-46988-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46988-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUp/KeiFURK5JrPrtCDSL3qLkO6I41+7sXpt15XkrSHqBJf7ag6kbjLAhyuZw429M97ZNP/dvxDTPOKyf3Fy6drEB8f4w== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q15-20020a170902dacf00b001d88bce4b30si541856plx.317.2024.01.31.11.15.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 11:15:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46988-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-46988-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46988-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 0B88CB274DB for ; Wed, 31 Jan 2024 18:56:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1C5312FF7C; Wed, 31 Jan 2024 18:54:59 +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 C79D938FA1; Wed, 31 Jan 2024 18:54:57 +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=1706727297; cv=none; b=VmkwwH+MDQoSEsw7ZnFrsyp0lsfw7PKc3U0IQkmTBPDAteA8ky815gfdDfO0xie6MUbUH0PUIug14czJvIeGyK9mLaXbErtkx1rCFdtZFPluNPC3//upCW2OIruXifMpZImTe3ORMOgaIOLFPWkQlK2vm9dvGPMj1xFyoA1ntc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706727297; c=relaxed/simple; bh=pfpMUH3tWGcM1lGwQK3NyStqZwiqHr8qawaLbZJl8tw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=T6AxM+xZwbHEwWwMTbX//V46Ogcnw9Rcs58K0Ere9mGIo046PaIMN36JPk+Cxnzf9ZCCNYXZuOf9KzU4PgzSqFN/P1NVQc2xXuE2c0k4l6LK3iQW0wZ21GvAwr46TCfL+i0wnto4wal8o5/l7s8QLehvkfQkAsByVY30nbhmTMY= 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 6C98CC433F1; Wed, 31 Jan 2024 18:54:57 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVFjs-000000055Ps-1v8J; Wed, 31 Jan 2024 13:55:12 -0500 Message-ID: <20240131185512.315825944@goodmis.org> User-Agent: quilt/0.67 Date: Wed, 31 Jan 2024 13:49:19 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot Subject: [PATCH v2 1/7] tracefs: Zero out the tracefs_inode when allocating it References: <20240131184918.945345370@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: 1789634601251459504 X-GMAIL-MSGID: 1789634601251459504 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. Cc: stable@vger.kernel.org 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) --- Changes since last version: https://lore.kernel.org/all/20240130230612.377a1933@gandalf.local.home/ - Moved vfs_inode to top of tracefs_inode structure so that the rest can be initialized with memset_after() as the vfs_inode portion is already cleared with a memset() itself in inode_init_once(). 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; }; /*