Message ID | 20240206120951.738927603@rostedt.homelinux.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-54908-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1499958dyb; Tue, 6 Feb 2024 04:24:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhlWulReVeynWy5Wlb6Z6+IzwDxkh6kiElQGFV2LnS/gBKfqXhxS7VMDoOw2t1HvzPZ53q X-Received: by 2002:a17:903:11c6:b0:1d9:91a0:da43 with SMTP id q6-20020a17090311c600b001d991a0da43mr1679212plh.31.1707222288904; Tue, 06 Feb 2024 04:24:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222288; cv=pass; d=google.com; s=arc-20160816; b=x1xpkRavpUqkXB3aVOksWq8jzSeye/85hNq9pu+mjvCNaKULT3sR27rMlx8TkUySvx ob2wE6RHJaRb4Ek5VZ5bOYQ+ELWmq62pNur71UzI3oaOW8aF88FqKYILhgZr1cKR5Q9M o1WMBPHaXhxmfaKIXiyzrihB77Lbfa+cejGC89WWKv1q/2TL+Sq+ntzvjShKm17pQsA0 hcQQ6yTWY5HxLMkGQs7K0hfMRNzUtUSf+F6mRfWIyP+HFHVi8lpYrQ04Dr4wgCfTLLR2 SupuYgiriHFWs8S3zjN5tzlL5efpwfVNJgc2KKQFEsdamcCIUcPXoPRJjOLuU8PKPoa7 yiYA== 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=wE7EPYIHf2FfE+GXOOkTMGEZO80pH7kcFtx3B2zdVj8=; fh=YRpGb1PUiARXZtm6P5l+SWQtgUtnCJSlVroGFnBrqQs=; b=PXYWBBd5vg+fZ8LRRK0PO/B4OYHs8BtbP6RLWxMcxVDVfVXMWkiSCRmhIS5M9oPjK9 V7lf7MgcsIfn7PmyveL2p3aYUVNnDNZWzYUPyalRZRQinpcchv4h/9q2ij98CFJSGO2F qDRrtqeFWe4pn170jPAbWj9uYKZGiEBj5sc+uWvIJtEK2eXw/rTsSS97Hz4hF8oq7Lu2 S4M38SOgvBXlMOGuodMqaeWYNuiPCLDuFbFZm3v/MfDDpbxdoL7qzIw2YRKPxhI19X8I 1WObzWmrda/tb3ziffql7KYpx7GInL9Yzzz/4/ji/jqWcAND95z6h8CYloQL6xM+mw3t m0yg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54908-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54908-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUAFCQbyjKtT+JKco4LSzCciAI5T3ZQs8pUOnnMDvCEcddvLLcPR6weXM9abT7kQJQOk+ol67aIokiuuia9Q3SRpzZ+oQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z16-20020a170903019000b001d94c11e7ebsi1612096plg.372.2024.02.06.04.24.48 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:24:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54908-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-54908-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54908-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 642222816BF for <ouuuleilei@gmail.com>; Tue, 6 Feb 2024 12:23:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C5DB4149003; Tue, 6 Feb 2024 12:09:34 +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 85ADF1386DD; Tue, 6 Feb 2024 12:09:23 +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=1707221363; cv=none; b=exv13tten1F/yXmIzNi6zOU0f/JDQw+bXw9z5QKSSiaQjSGXO+Sx8LQOEYSbX3SMAlGdgKm3km3f0n0kEGuND/fykv5Cip35DZE+LR9bXIRfo66U0CtzsfDbBZXKfatbxPIlhoHxIPC3tH7PPdlxz84XkbuKxn+Cn2a1KOL30BQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221363; c=relaxed/simple; bh=uCRKBFI8oZi6Z1Cps+YjkEugAUzD0pvOcGwAbYn4DiE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=qXo+yvNaZXZlfi6rEv0QYuVHh/oi1zXrJZ4xiiGI1sWkZX0i1RiRJieTJAzjQ449o4eSOTU++ox0EaINzewYKNwMWQQ/vym/x8snUAxU5XczQhcMhBG1sAXNtk8E1gvprywFyzq5K3iHdw3+OasS72MMbILKHE6xnt3tAoJvK00= 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 72A2AC433C7; Tue, 6 Feb 2024 12:09:23 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from <rostedt@rostedt.homelinux.com>) id 1rXKGt-00000006bHq-3giE; Tue, 06 Feb 2024 07:09:51 -0500 Message-ID: <20240206120951.738927603@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:38 -0500 From: Steven Rostedt <rostedt@goodmis.org> To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds <torvalds@linux-foundation.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Sasha Levin <sashal@kernel.org>, Masami Hiramatsu <mhiramat@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Mathieu Desnoyers <mathieu.desnoyers@efficios.com>, "Ubisectech Sirius" <bugreport@ubisectech.com> Subject: [v6.6][PATCH 33/57] tracefs: Check for dentry->d_inode exists in set_gid() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152318408915314 X-GMAIL-MSGID: 1790152318408915314 |
Series |
eventfs: Linus's updates for 6.6
|
|
Commit Message
Steven Rostedt
Feb. 6, 2024, 12:09 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org> If a getdents() is called on the tracefs directory but does not get all the files, it can leave a "cursor" dentry in the d_subdirs list of tracefs dentry. This cursor dentry does not have a d_inode for it. Before referencing tracefs_inode from the dentry, the d_inode must first be checked if it has content. If not, then it's not a tracefs_inode and can be ignored. The following caused a crash: #define getdents64(fd, dirp, count) syscall(SYS_getdents64, fd, dirp, count) #define BUF_SIZE 256 #define TDIR "/tmp/file0" int main(void) { char buf[BUF_SIZE]; int fd; int n; mkdir(TDIR, 0777); mount(NULL, TDIR, "tracefs", 0, NULL); fd = openat(AT_FDCWD, TDIR, O_RDONLY); n = getdents64(fd, buf, BUF_SIZE); ret = mount(NULL, TDIR, NULL, MS_NOSUID|MS_REMOUNT|MS_RELATIME|MS_LAZYTIME, "gid=1000"); return 0; } That's because the 256 BUF_SIZE was not big enough to read all the dentries of the tracefs file system and it left a "cursor" dentry in the subdirs of the tracefs root inode. Then on remounting with "gid=1000", it would cause an iteration of all dentries which hit: ti = get_tracefs(dentry->d_inode); if (ti && (ti->flags & TRACEFS_EVENT_INODE)) eventfs_update_gid(dentry, gid); Which crashed because of the dereference of the cursor dentry which had a NULL d_inode. In the subdir loop of the dentry lookup of set_gid(), if a child has a NULL d_inode, simply skip it. Link: https://lore.kernel.org/all/20240102135637.3a21fb10@gandalf.local.home/ Link: https://lore.kernel.org/linux-trace-kernel/20240102151249.05da244d@gandalf.local.home Cc: stable@vger.kernel.org Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Fixes: 7e8358edf503e ("eventfs: Fix file and directory uid and gid ownership") Reported-by: "Ubisectech Sirius" <bugreport@ubisectech.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> (cherry picked from commit ad579864637af46447208254719943179b69d41a) --- fs/tracefs/inode.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 7b0ba379d6d7..c27b0cfff70c 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -215,6 +215,10 @@ static void set_gid(struct dentry *parent, kgid_t gid) struct dentry *dentry = list_entry(tmp, struct dentry, d_child); next = tmp->next; + /* Note, getdents() can add a cursor dentry with no inode */ + if (!dentry->d_inode) + continue; + spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); change_gid(dentry, gid);