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

ScanFile() increased memory by 300MB after scanning a large file and did not release #156

Open
xlango opened this issue Jul 30, 2024 · 6 comments

Comments

@xlango
Copy link

xlango commented Jul 30, 2024

s, err := yara.NewScanner(yaraRules)
if err != nil {
return matchRuleTypes, err
}

err = s.SetCallback(&matchRuleTypes).ScanFile(path)
if err != nil {
	return matchRuleTypes, err
}

I scanned a dockerd binary file 80MB, after scanning only found that the process memory increased 300MB and has not been released, May I ask why?

@xlango
Copy link
Author

xlango commented Jul 30, 2024

I've found this to happen whenever elf modules are used regularly:
import "elf"
rule golang {
meta:
description = "test"
strings:
$s1 = "gccgo" fullword
condition:
(elf.type == elf.ET_EXEC or elf.type == elf.ET_DYN) and
all of ($s*)
}

@hillu
Copy link
Owner

hillu commented Jul 30, 2024

If this go away if you don't import the elf module in your ruleset, I suggest that this is an issue in YARA itself. Is there anything specific about the file you are scanning or does the same memory leakage happen if you scan 300 MB zeroes? Can you share a file (or point me to a public file) that can be used to demonstrate the issue?

@ozanh
Copy link

ozanh commented Jul 31, 2024

Can you also share the Yara version you compiled with @xlango ?

@xlango
Copy link
Author

xlango commented Aug 1, 2024

I use ubuntu22.04 system, kernel version 5.19, yara version is compiled Yara-4.4.0 and Yara-4.3.2 both have this problem.
The file I scanned is a binary file /usr/bin/dockerd version information: Docker version 20.10.21, build 20.10.21-0Ubuntu1 ~22.04.3

@ozanh
Copy link

ozanh commented Aug 1, 2024

I've tested your rule with dockerd binary separately and also all the files under /usr/bin on Ubuntu22.04 arm64 with our product that uses Yara 4.5.1 and go-yara@latest.

I didn't see any memory issue. Maybe, you didn't call scanner's Destroy method explicitly or it's about Yara 4.4 but I didn't see anything related to elf module in the release notes.

Please, try calling Destroy() and/or runtime.GC() after scanning to see if there is such a big leak.

@hillu
Copy link
Owner

hillu commented Jan 13, 2025

@xlango ping?

Did you try @ozanh's suggestion?

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

No branches or pull requests

3 participants