syzkaller icon indicating copy to clipboard operation
syzkaller copied to clipboard

sys/linux: glob ** is not working as expected

Open dvyukov opened this issue 1 year ago • 4 comments

We have this syscall:

openat$sysfs(fd const[AT_FDCWD], dir ptr[in, glob["/sys/**/*:-/sys/power/state"]], flags flags[open_flags], mode flags[open_mode]) fd

I guess the intention was that "**" does recursive dir search, but "**" does not work as recursive pattern for filepath.Glob (nor POSIX glob). I have 97948 files in /sys in total, but only 618 matched by "/sys/**/*" pattern.

Another problem is that filepath.Glob returns directories as well, and I suspect opening sysfs directories is generally not very useful. Out of 618 entries matched by "/sys/**/*", only 30 are normal files (not dirs).

So it seems we both don't open lots of useful things, and open lots of unuseful things.

cc @jiangenj

dvyukov avatar Jun 17 '24 12:06 dvyukov

I think it's actually missing feature in filepath.glob, while https://github.com/yargevad/filepathx support it A small filepath extension library that supports double star globbling.

Another point is, I normally use glob for subdir under sysfs for specific kernel subsystem nodes. Perhaps /sys/**/* is too big nodes to walk.

jiangenj avatar Jun 18 '24 00:06 jiangenj

Yes, pulling all 100K entries in /sys/ looks like too much. And there will probably be more dangerous ones that we will need to filter out. #4905 switches this to C++ and currently it uses POSIX glob, which also doesn't support **. If we want to support it, we will need to write custom C++ code, which is painful. So I am thinking we don't support ** now (was never supported anyway), but instead list some /sys subdir explicitly.

Another point is, I normally use glob for subdir under sysfs for specific kernel subsystem nodes.

Which subdirs do you use with glob?

dvyukov avatar Jun 18 '24 09:06 dvyukov

Yeah, I noted #4905, I think it's fine to remove glob support now. I can try to access these nodes one by one right now until there is a better solution in future.

jiangenj avatar Jun 19 '24 00:06 jiangenj

With #4905 glob will continue to work as it is now (except that matched directories will be filters out).

dvyukov avatar Jun 19 '24 04:06 dvyukov