Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: add clean_rules config to help CleanPath for specific targets #5842

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jiangenj
Copy link
Contributor

In some targets like android, we got addr2line info like: /proc/self/cwd/common/kernel/kcov.c:852
To cleanup the path, we need to remove /proc/self/cwd/ prefix, and add relative path to common directory,
so we can have clean_rules like:
"/proc/self/cwd/common:kernel_platform/common"

More examples:
"clean_rules" : [
"/proc/self/cwd/common/../vendor:vendor",
"/proc/self/cwd/common/../soc-repo:kernel_platform/soc-repo",
"/proc/self/cwd/vendor:vendor",
"/proc/self/cwd/common:kernel_platform/common"
]


Before sending a pull request, please review Contribution Guidelines:
https://github.com/google/syzkaller/blob/master/docs/contributing.md


In some targets like android, we got addr2line info like:
/proc/self/cwd/common/kernel/kcov.c:852
To cleanup the path, we need to remove /proc/self/cwd/ prefix,
and add relative path to common directory,
so we can have clean_rules like:
"/proc/self/cwd/common:kernel_platform/common"

More examples:
"clean_rules" : [
	"/proc/self/cwd/common/../vendor:vendor",
	"/proc/self/cwd/common/../soc-repo:kernel_platform/soc-repo",
	"/proc/self/cwd/vendor:vendor",
	"/proc/self/cwd/common:kernel_platform/common"
]
@jiangenj
Copy link
Contributor Author

@a-nogikh there is no reviewer for the PR, can you check once?

@a-nogikh
Copy link
Collaborator

I'll take a closer look in a couple of days, somewhat short on time at the moment.

@a-nogikh a-nogikh self-requested a review March 19, 2025 03:38
@a-nogikh
Copy link
Collaborator

We already have quite extensive path rewriting logic around here:

// Source files for Android may be split between two subdirectories: the common AOSP kernel
// and the device-specific drivers: https://source.android.com/docs/setup/build/building-pixel-kernels.
// Android build system references these subdirectories in various ways, which often results in
// paths to non-existent files being recorded in the debug info.
//
// cleanPathAndroid() assumes that the subdirectories reside in `srcDir`, with their names being listed in
// `delimiters`.
// If one of the `delimiters` occurs in the `path`, it is stripped together with the path prefix, and the
// remaining file path is appended to `srcDir + delimiter`.
// If none of the `delimiters` occur in the `path`, `path` is treated as a relative path that needs to be
// looked up in `srcDir + delimiters[i]`.
func cleanPathAndroid(path, srcDir string, delimiters []string, existFn func(string) bool) (string, string) {
if len(delimiters) == 0 {
return "", ""
}
reStr := "(" + strings.Join(delimiters, "|") + ")(.*)"
re := regexp.MustCompile(reStr)
match := re.FindStringSubmatch(path)
if match != nil {
delimiter := match[1]
filename := match[2]
path := filepath.Clean(srcDir + delimiter + filename)
return filename, path
}
// None of the delimiters found in `path`: it is probably a relative path to the source file.
// Try to look it up in every subdirectory of srcDir.
for _, delimiter := range delimiters {
absPath := filepath.Clean(srcDir + delimiter + path)
if existFn(absPath) {
return path, absPath
}
}
return "", ""
}
func CleanPath(path, objDir, srcDir, buildDir string, splitBuildDelimiters []string) (string, string) {
filename := ""
path = filepath.Clean(path)
aname, apath := cleanPathAndroid(path, srcDir, splitBuildDelimiters, osutil.IsExist)
if aname != "" {
return aname, apath
}
absPath := osutil.Abs(path)
switch {
case strings.HasPrefix(absPath, objDir):
// Assume the file was built there.
path = strings.TrimPrefix(absPath, objDir)
filename = filepath.Join(objDir, path)
case strings.HasPrefix(absPath, buildDir):
// Assume the file was moved from buildDir to srcDir.
path = strings.TrimPrefix(absPath, buildDir)
filename = filepath.Join(srcDir, path)
default:
// Assume this is relative path.
filename = filepath.Join(srcDir, path)
}
return strings.TrimLeft(filepath.Clean(path), "/\\"), filename
}

So syzkaller already trims KernelBuildSrc and prepends KernelSrc (both are set in pkg/mgrconfig).

Why wouldn't it work in your case?

@jiangenj
Copy link
Contributor Author

No, it won't work, here's my full cleanRules

        "clean_rules": [
                "/proc/self/cwd/out/android16-6.12/common/security/selinux/flask.h:external/selinux/libsepol/src/flask.h",
                "/proc/self/cwd/out/android16-6.12/common/../vendor:vendor",
                "/proc/self/cwd/out/android16-6.12/common/../soc-repo:kernel_platform/soc-repo",
                "/proc/self/cwd/out/android16-6.12/common:kernel_platform/common",
                "/proc/self/cwd/common/../vendor:vendor",
                "/proc/self/cwd/common/../soc-repo:kernel_platform/soc-repo",
                "/proc/self/cwd/vendor:vendor",
                "/proc/self/cwd/common:kernel_platform/common",
                "/proc/self/cwd/soc-repo/../vendor:vendor",
                "/proc/self/cwd/soc-repo:kernel_platform/soc-repo"
        ]

as you can see there are different kinds of prefixes as in below from vmlinux, android gki modules and vendor modules.

/proc/self/cwd/out/android16-6.12/common/../vendor,
/proc/self/cwd/out/android16-6.12/common/../soc-repo,
/proc/self/cwd/out/android16-6.12/common,
/proc/self/cwd/common/../vendor,
/proc/self/cwd/common/../soc-repo,
/proc/self/cwd/vendor,
/proc/self/cwd/common,
/proc/self/cwd/soc-repo/../vendor,
/proc/self/cwd/soc-repo:kernel_platform/soc-repo

Vendor/OEM android trees are different from AOSP one (there is no rule to say where to put kernel and oot module tree), like my KernelSrc is like /TOPDIR, android kernel is inside /TOPDIR/kernel_platform/common, soc-repo in /TOPDIR/kernel_platform/soc-repo and vendor (oot tree) in /TOPDIR/vendor.

So these delimiters in the syzkaller code are not enough.

	if splitBuild {
		// Path prefixes used by Android Pixel kernels. See
		// https://source.android.com/docs/setup/build/building-pixel-kernels for more
		// details.
		delimiters = []string{"/aosp/", "/private/"}
	}

I think we need to allow a flexible way to cleanPath in config file for different build versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants