google / syzkaller

syzkaller is an unsupervised coverage-guided kernel fuzzer
Apache License 2.0
5.34k stars 1.21k forks source link

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

Open dvyukov opened 3 months ago

dvyukov commented 3 months ago

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

jiangenj commented 3 months ago

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.

dvyukov commented 3 months ago

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?

jiangenj commented 3 months ago

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.

dvyukov commented 3 months ago

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