From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 E5E3D382380; Fri, 4 Sep 2026 05:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788498904; cv=none; b=bjEtXmUNyFkGszcnhkzrWBoNW3puE03nAITAEFb+j2meIrMzRvc3NL02RYUc09+z8gMnhG01tZT8KU+8mr8hlCQNbUIbSJEVxe1YaF60qrIviwayBOyFJ/XVdHu3tFpl5wOzRyHDNUa9mDyL3Yy3cgqH5dnfVjw1u7Z7leixumE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788498904; c=relaxed/simple; bh=b9fyR5OcCKwdzDrU31jW1KFjUPn40tAn7wldCvQfkSg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l5+8HyNL/LHxiTk3hOPYHEbm6P3TouwvkcwK3eQVI0XKgu9kGeBJJ7zsscR2HBTjncPZuTvIcLw5J6Aic09EFBiROT1w3CbxRPN67h4Uzkp7zBdWZXjN6bYd6o+8hz1TMcBt3kZ5tOXYVWqCLEQCi+ypD1bY4GouP1zOJ/P2Djc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=EGkUhmYV; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="EGkUhmYV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CB3A1F00A3D; Fri, 4 Sep 2026 05:15:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788498902; bh=r1isGLgaoZsDZVUWmMDD2f/AZ2xxXvpHA32tYPW2XxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EGkUhmYVri50n1j3GuBeQu4vBuKvkPg2tCufqeZetQy1r6ynzPy2YVlc6Nu00UWUa 9jq6vvEYqFNgT0r1ytjBA1USV1Gu+n8LvQXdBPoLMR5P5AkwGifuQsc6wmPh7oA5QN stu+ICV3Y3VcmJzKKtI6EoN1e1k5kiMqAoHGLwDw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable@kernel.org, =?UTF-8?q?J=C3=A9r=C3=A9my=20Jean?= , Ricardo Robaina , Paul Moore Subject: [PATCH 7.2 229/713] audit: avoid dropping live tree ref on fsnotify rule autoremove Date: Fri, 4 Sep 2026 06:53:17 +0200 Message-ID: <20260904045808.953096886@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904045803.810145556@linuxfoundation.org> References: <20260904045803.810145556@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jérémy Jean commit 783f0f0974c156aca630f4ffff248671082a098d upstream. audit_del_rule() is used for both netlink deletion templates and internal fsnotify autoremove. The former passes a parsed template which owns a temporary tree reference; the latter passes the installed entry itself. The unconditional audit_put_tree() at the end of audit_del_rule() assumes the template case. For mixed AUDIT_DIR plus AUDIT_EXE rules, an fsnotify autoremove event therefore drops the installed rule's live tree reference. Repeating this across rules sharing the same tree can free the tree while another rule still references it, and a later autoremove dereferences the freed pathname while comparing rules. Move the temporary-tree put to audit_rule_change(), the caller that owns deletion templates. Keep it in the AUDIT_DEL_RULE cleanup so both successful deletion and -ENOENT still release the parser-owned tree. Cc: stable@kernel.org Fixes: 34d99af52ad4 ("audit: implement audit by executable") Assisted-by: Codex:gpt-5 Signed-off-by: Jérémy Jean Reviewed-by: Ricardo Robaina Tested-by: Ricardo Robaina [PM: dropped unnecessary comment for line length reasons] Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- kernel/auditfilter.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c @@ -1023,7 +1023,6 @@ static inline int audit_add_rule(struct int audit_del_rule(struct audit_entry *entry) { struct audit_entry *e; - struct audit_tree *tree = entry->rule.tree; struct list_head *list; int ret = 0; #ifdef CONFIG_AUDITSYSCALL @@ -1071,9 +1070,6 @@ int audit_del_rule(struct audit_entry *e out: mutex_unlock(&audit_filter_mutex); - if (tree) - audit_put_tree(tree); /* that's the temporary one */ - return ret; } @@ -1158,6 +1154,8 @@ int audit_rule_change(int type, int seq, } if (err || type == AUDIT_DEL_RULE) { + if (type == AUDIT_DEL_RULE && entry->rule.tree) + audit_put_tree(entry->rule.tree); if (entry->rule.exe) audit_remove_mark(entry->rule.exe); audit_free_rule(entry);