[PATCH] tracefs: avoid crash when open callback is not set

From
Vasily Gorbik <gor@linux.ibm.com>
Date
2019-08-13 14:58:58
Also in
lkml
Reply to
Vasily Gorbik, 2019-08-13
Some tracefs files, e.g. tracing/events/syscalls/*/id do not define
"open" file operation. Yet commit 757ff7244358 ("tracefs: Restrict
tracefs when the kernel is locked down") introduces "open" proxy which
unconditionally calls original open callback, which causes kernel crash
when the callback is 0.

Fix that by simply returning 0, if open callback is not set.

Fixes: 757ff7244358 ("tracefs: Restrict tracefs when the kernel is locked down")
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
---
 fs/tracefs/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c
index 12a325fb4cbd..77407632c916 100644
--- a/fs/tracefs/inode.c
+++ b/fs/tracefs/inode.c
@@ -43,7 +43,9 @@ static int default_open_file(struct inode *inode, struct file *filp)
 		return ret;
 
 	real_fops = dentry->d_fsdata;
-	return real_fops->open(inode, filp);
+	if (real_fops->open)
+		return real_fops->open(inode, filp);
+	return 0;
 }
 
 static ssize_t default_read_file(struct file *file, char __user *buf,
-- 
⣿⣿⣿⣿⢋⡀⣀⠹⣿⣿⣿⣿
⣿⣿⣿⣿⠠⣶⡦⠀⣿⣿⣿⣿
⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿
⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿
⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿
⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
Thread (8 messages) 8 messages, 4 authors, last reply 2019-08-14
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help