From patchwork Thu Feb 1 15:34:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195399 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp301577dyb; Thu, 1 Feb 2024 09:06:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRXDw296Z0zgzzL7kK3rcnSMg41+/acbfPYmDwdPr5l3KWXLSXECEmKGmNlqRSwNFF+Mz6 X-Received: by 2002:a17:903:2a84:b0:1d8:fc65:b601 with SMTP id lv4-20020a1709032a8400b001d8fc65b601mr3121597plb.38.1706807187101; Thu, 01 Feb 2024 09:06:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706807187; cv=pass; d=google.com; s=arc-20160816; b=Z3AKEgcpzLMM8GS8Ykh5rDhipDCaUxeACfAPgxwNz+2UqiJHA64IdzMhWqiotbvsZo 6wpLfMtzUMk+jBYBjlLwT5m4ev1QoYQgccH8DmQPX6jv3SL0HA1kLvlCMgVgFgsVwecI 5acuJwCJMZ5lbOZOpxmhcJwkt5EUAzXE+nod7kMVmtJ5ME++OnFbWSht2CM0f7CQhQh4 4cm2VTWEgHldkoIZasU/sYGBPBvzYazT8dWA5SmB7PZmc9Hye9US3pc1jkech0tsU2iD ujD0Lcfu9OQ00da41rR6XWI+G89BoD6JKm/CIY5WwboYB5GytVEDx3qNGFaMw5HbaYJT 3Y3w== 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=qBEhJQgbKU5rjcjasZEypzSiXTxSzrkaP1LV6r35Mgc=; fh=TmwqJtlfSddKDt/8JznN4P0RBNGyW5FUvohB8omhT/M=; b=ugsdh6IDU3xlTGr0MHlQEfw8C5DtVqzfVBfLCx5tnvh1ODW6Z607L4rW0sDG0EdwWR LYwRdSh44aFe+DvY4Yvbu+0G58dcvMO1qYAXOqBKJtIC0xEgapZw+Jc8S1uydzlgd6Vs NYf+tYbdV0jtvglGXURnGSPL5cecOk3dD746R6wrgCXRjowD89YYd3q1kkTQyd+7B0ez zkErpFfOq/90/s7u7Mj/GxeM2knkvxlECmjgRdP2f4izZbqotNu2BKbF2o4sxlMbLRbc RTx669vjy+9OqrC0FGd9iN54axI68vk5n/WhWzB8A8Rq09l80WSW+lOcMUpbYPO46Rha A10Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-48506-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48506-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX2Zlp5zedtppjQXp2qBhJnbRsPKyw2tpFQfCD3stjPaE46XBF0AZDbuZusIbun4mOvv/be1KiR6lIgjuLYg2uGqzmpJw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id n2-20020a1709026a8200b001d4891f73f0si66649plk.549.2024.02.01.09.06.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 09:06:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48506-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-48506-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48506-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 701C9B2C45B for ; Thu, 1 Feb 2024 16:21:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F0D37DCB9; Thu, 1 Feb 2024 16:16:04 +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 D885D161B59; Thu, 1 Feb 2024 16:16:00 +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=1706804160; cv=none; b=Mno0Fl39F0v3qA8PQ9EBSz1pJw9vulVwqRLlYPBEfEmGeVOBIzX42mIraN4Vh9MrLmcnFLo3WJetwMiKRTsLVTgO6rXJsLm/mPB+bXW5YQns5Z/b4GDp4bAIwkaJ4mHxKP2xqswZnQfDuR/sRiS+FM6NAEp7c2at0tlv7c96yCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706804160; c=relaxed/simple; bh=3+ZSFsB8n+3f4GqZyRsq0vWj2Y9oAbKeKdikbNmaVQ4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=FHYgZ6NObH+udnYmPxfXvRnGMvRHvdJ/LZOlNWuXCQkzCJ3e2MMVtAqGGC7cuC7XLAmfJOdlbAYBJ22m8b4w3oiOEqrkS0aI8q72omPmI8Hqq4UdwGtRFuhoS4W15anb80Cv2DAfHfvm5wowTZTkSgm9sw355qkdneWopfzyobE= 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 97DE6C43330; Thu, 1 Feb 2024 16:16:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVZjd-00000005Tkg-2gF8; Thu, 01 Feb 2024 11:16:17 -0500 Message-ID: <20240201161617.499712009@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 10:34:51 -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 , Al Viro Subject: [PATCH 5/6] eventfs: Add WARN_ON_ONCE() to checks in eventfs_root_lookup() References: <20240201153446.138990674@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: 1789717053305231291 X-GMAIL-MSGID: 1789717053305231291 From: "Steven Rostedt (Google)" There's a couple of if statements in eventfs_root_lookup() that should never be true. Instead of removing them, add WARN_ON_ONCE() around them. One is a tracefs_inode not being for eventfs. The other is a child being freed but still on the parent's children list. When a child is freed, it is removed from the list under the same mutex that is held during the iteration. Link: https://lore.kernel.org/linux-trace-kernel/20240201002719.GS2087318@ZenIV/ Reported-by: Al Viro Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 110e8a272189..1a831ba1042b 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -483,7 +483,7 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, struct dentry *result = NULL; ti = get_tracefs(dir); - if (!(ti->flags & TRACEFS_EVENT_INODE)) + if (WARN_ON_ONCE!(ti->flags & TRACEFS_EVENT_INODE))) return ERR_PTR(-EIO); mutex_lock(&eventfs_mutex); @@ -495,7 +495,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, list_for_each_entry(ei_child, &ei->children, list) { if (strcmp(ei_child->name, name) != 0) continue; - if (ei_child->is_freed) + /* A child is freed and removed from the list at the same time */ + if (WARN_ON_ONCE(ei_child->is_freed)) goto out; result = lookup_dir_entry(dentry, ei, ei_child); goto out;