From patchwork Tue Feb 6 11:32:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197331 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1478628dyb; Tue, 6 Feb 2024 03:43:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEUv2AbmUW6ctoSLRt0YNJGGyNtGFo/Nm56csV/gmw3NARq7I2Z0j3e2u60FCpe0Drf+FT X-Received: by 2002:a05:6402:1a24:b0:560:58f:7148 with SMTP id be4-20020a0564021a2400b00560058f7148mr1730140edb.34.1707219824718; Tue, 06 Feb 2024 03:43:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707219824; cv=pass; d=google.com; s=arc-20160816; b=j1WinulbFmFCS7Vgg8uKdGRHABj6DOdjRRcKQgRh7jHSY0MFnRSk/e6JlLX3w5usQb lLvFQB42qZfBvr6xiI/LqfadCQr9woq1kKXt80tUFHb/HRlusvf7XHU6nhxg+nnoy2bN Dxll0ZhQWiipz4PEjbnfnvTfB/dUx5Vk6MfNxljBJ9misBV6HQqWKq9UMLuS2WiRuvtO oY1FMF0bRkbu3oAwwaK4VqFUVWKszOQWA0kc2iXjjcYN6UqZ2Y2l/LOqJv4EsLvmykDg ubt72hdLcGp3wky6gWpjF1imACzWPu0UM5/0g/hUu13Osg6SgNLSrppSMhUBfdSt45F3 Qylg== 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=w/iPhJOudMj5zSlscWJCTndr2nhDIzagNWRmI9xY/Ss=; fh=usQ77r2XR8Mt8SclEXuQnRAFRnlBhV9qUfte7MB+pMA=; b=XcyqcobXzvW2oxl8UjyslDH+U63loLjGViDTILocu4PJc+YdqMRZoeJoTg8GLDpK5u LjTUXuBydmUChMMJC+BnmYnteSdSFiH/ZiOh9/+5cKA8t/HwPE7XEJT0EpNgz8JJh9rO TzR+kQcNb+V3VudL7TacTcTaEcjXEvcZ6wD6pBacyEvXy/ilAW+rwnO2RdRug360DDNr q9MPpTHQ31OEZ/XfqKo50k3iqMGmYI7UaR9pYwhX5/yZnn71hZJpcQTNlcxEliWBIMZ+ OVpghZak8FQbyo86L37RqoiD7AQQ4L27bAUZZQrdb28zkt392ArIw9JVV8YpSX0Lxae9 uDbw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54789-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54789-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCU+GTW1PsqZmXL5X5INZC3OwwXxUtPMvxDNWaQHFomFsW09iWuNHIYS4G+vVbtwk75D81PjSgEGrWicO82VYBCnWPcPaA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w8-20020aa7cb48000000b0055ff974eb1bsi995363edt.508.2024.02.06.03.43.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:43:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54789-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54789-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54789-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 DC9941F22706 for ; Tue, 6 Feb 2024 11:43:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 832B513474D; Tue, 6 Feb 2024 11:33:32 +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 C089F130E53; Tue, 6 Feb 2024 11:33:30 +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=1707219210; cv=none; b=TlCeMx91WGzxUc+RubxIzep94PCwmxOqfTQIwTT5SqK01Lcc2e4ZG4dKBHh1tsUTAQRPquGVSpqtjBaeoHMTc67IQx721OlgIu4FMsFJ4X8tIpexwGMyNaCVC+4ef9/X093rDN6KWICoxkbgv+ys3xPdFk0GkoL5bzyH0TP3ZKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219210; c=relaxed/simple; bh=3jDSxRh6ezDXpMpe9bCVmX2ZEPsqcyYEs+U1X03bFjY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=KUPv4lJ8XwGwNoxzOlZxVcfKonx3LNAIpbneJAwqGfP0sv8hLu7/3ywRDtisybqvYgigpBZGzXkoobEJOBQIW+EkSo7gR4EVCHSdyFlpLrzuIxUgr/HDWku/Ci0437Bd1SI3hOk6/MNNG4pModXqdNfONEDTArZ/cWSrO4Mck5Q= 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 7D193C43601; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiA-00000006aIN-3fhr; Tue, 06 Feb 2024 06:33:58 -0500 Message-ID: <20240206113358.729003384@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:02 -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 , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.7][PATCH v2 04/23] eventfs: Have eventfs_iterate() stop immediately if ei->is_freed is set 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: 1790149734865780610 X-GMAIL-MSGID: 1790149734865780610 From: "Steven Rostedt (Google)" If ei->is_freed is set in eventfs_iterate(), it means that the directory that is being iterated on is in the process of being freed. Just exit the loop immediately when that is ever detected, and separate out the return of the entry->callback() from ei->is_freed. Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.016261289@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Signed-off-by: Steven Rostedt (Google) (cherry picked from commit e109deadb73318cf4a3bd61287d969f705df278f) --- fs/tracefs/event_inode.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 72912b5f9a90..0aca6910efb3 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -788,11 +788,12 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) name = entry->name; mutex_lock(&eventfs_mutex); - /* If ei->is_freed, then the event itself may be too */ - if (!ei->is_freed) - r = entry->callback(name, &mode, &cdata, &fops); - else - r = -1; + /* If ei->is_freed then just bail here, nothing more to do */ + if (ei->is_freed) { + mutex_unlock(&eventfs_mutex); + goto out; + } + r = entry->callback(name, &mode, &cdata, &fops); mutex_unlock(&eventfs_mutex); if (r <= 0) continue;