Crash occurs when doing recursive scan against a directory that is denied access by AppArmor

Open
#125 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
go
Domain
cli

Research direction

Start with utils/string_reader.go at StringArrayReader.ReadString and utils/do.go at Coordinator.DoWithStringsFromReader, then reproduce the AppArmor-denied recursive scan using the commands in the issue. Trace how the denied directory is reported through the reader and coordinator. Done means vt scan file -r ~/denied-dir reports the access problem without panicking.

Written by the indexing model from the issue text.

Description

Steps to reproduce

  1. Launch an Ubuntu VM (I use this Vagrant-based VM implementation).

  2. Install vt to /usr/local/bin as root.

  3. Setting up an API key.

  4. Run the following command to create a directory to be denied by AppArmor:

    mkdir -p ~/denied-dir
    
  5. Create the /etc/apparmor.d/usr.local.bin.vt Apparmor profile file as root with the following content:

    abi <abi/3.0>,
    
    include <tunables/global>
    
    /usr/local/bin/vt {
    include <abstractions/base>
    include <abstractions/nameservice>
    include <abstractions/ssl_certs>
    
    /home/*/** r,
    deny owner /home/*/denied-dir/ r,
    
    /etc/hosts r,
    /etc/nsswitch.conf r,
    /run/systemd/resolve/stub-resolv.conf r,
    /usr/local/bin/vt mr,
    owner /home/*/.cache/.vt.relationships.cache rw,
    owner /home/*/.vt.toml rw,
    }
    
  6. Run the following command as root to load the AppArmor profile in enforcing mode:

    apparmor_parser -r /etc/apparmor.d/usr.local.bin.vt
    
  7. Run the following command to trigger the crash:

    vt scan file -r ~/denied-dir
    

Current behavior

The program crashed with:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x82be08]

goroutine 7 [running]:
github.com/VirusTotal/vt-cli/utils.(*StringArrayReader).ReadString(0x0?)
	/home/runner/work/vt-cli/vt-cli/utils/string_reader.go:46 +0x8
github.com/VirusTotal/vt-cli/utils.(*Coordinator).DoWithStringsFromReader.func1()
	/home/runner/work/vt-cli/vt-cli/utils/do.go:69 +0x2f
created by github.com/VirusTotal/vt-cli/utils.(*Coordinator).DoWithStringsFromReader in goroutine 1
	/home/runner/work/vt-cli/vt-cli/utils/do.go:68 +0x95

Expected behavior

No crash

Version

1.3.0

Dominant language
Go
Stars
1.5k
Forks
147
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from VirusTotal/vt-cli

All issues in VirusTotal/vt-cli

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.