Sh: 1: snap: Permission denied

I have had this particular error from Auto CPU Frequency since 4-5 days. I tried to reinstall but still the same

I heavily rely on Auto CPU for 21.10 Ubuntu. Otherwise, my battery drains quickly.

It would be nice to know if there is any solution possible. Thanks.

Do any apparmor denials show up? try running sudo dmesg |grep DENIED

1 Like

Nvm, I’ve installed the snap and can observe the problem. FWIW, I think the problem lies with the application and the sandbox correctly stops it from accessing locations it does not have permissions to access.

Specifically, the Python code appears to run somethin in a shell, which attempts to inherit the current directory. That is, if I’m inside my $HOME, and run sudo autocpu-freq, the current working directory is still my $HOME. SInce the snap does not plug home interface (nor it should afact), the sandbox will stop it from accessing that directory.

The denials are:

[36183.164426] audit: type=1327 audit(1646643943.662:720): proctitle=707974686F6E33002F736E61702F6175746F2D637075667265712F3130392F62696E2F6175746F2D63707566726571
[36183.382688] audit: type=1400 audit(1646643943.882:721): apparmor="DENIED" operation="open" profile="snap.auto-cpufreq.auto-cpufreq" name="/home/maciek/" pid=135123 comm="python3" requested_mask="r" denied_mask="r" fsuid=0 ouid=1000
[36183.382702] audit: type=1300 audit(1646643943.882:721): arch=c000003e syscall=257 success=no exit=-13 a0=ffffff9c a1=7f97e993bf80 a2=90800 a3=0 items=0 ppid=135122 pid=135123 auid=1000 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts11 ses=1 comm="python3" exe="/usr/bin/python3.8" subj==snap.auto-cpufreq.auto-cpufreq (enforce) key=(null)
[36183.382708] audit: type=1327 audit(1646643943.882:721): proctitle=707974686F6E33002F736E61702F6175746F2D637075667265712F3130392F62696E2F6175746F2D63707566726571
[36183.387306] audit: type=1400 audit(1646643943.885:722): apparmor="DENIED" operation="open" profile="snap.auto-cpufreq.auto-cpufreq" name="/home/maciek/" pid=135123 comm="python3" requested_mask="r" denied_mask="r" fsuid=0 ouid=1000

Which clearly identifies python3 (the app is in python), tryign to access my $HOME, which it isn’t allowed to:

apparmor="DENIED" operation="open" 
profile="snap.auto-cpufreq.auto-cpufreq" 
name="/home/maciek/" pid=135123 comm="python3" 
requested_mask="r" denied_mask="r" fsuid=0 ouid=1000

Contact the upstream and try to find out why they do it.

1 Like

I have updated the Github issue with a link to this topic.

Everything was working fine a week back. Is there any chance we can revert back to that release?

Try running snap list --all auto-cpufreq, if it shows more than one revision then you can run snap revert auto-cpufreq which should restore the previous revision.

1 Like

I got this

$ snap list --all auto-cpufreq

Name Version Rev Tracking Publisher Notes

auto-cpufreq 1.9.2 109 latest/stable fooctrl -

Hi @mborzecki this is the creator/author of auto-cpufreq.

I don’t have this problem and I can run auto-cpufreq just fine, but other users are facing issues as @meetdilip mentioned.

Are you saying that adding home interface to the list of plugs will help address this problem?

Thanks,

Adnan

1 Like

No, I’m saying auto-cpufreq tries to open the current working directory, which it does not necessarily have access to. I’ve tried a couple of locations and got these denials.

This is an attempt where cwd is /tmp (snap gets a private /tmp):

apparmor="DENIED" operation="exec" profile="snap.auto-cpufreq.auto-cpufreq" name="/snap/snapd/14978/usr/bin/snap" pid=6284 comm="sh" requested_mask="x" denied_mask="x" fsuid=1000 ouid=0
arch=c000003e syscall=59 success=no exit=-13 a0=561dceec3758 a1=561dceec32f0 a2=561dceec34e8 a3=7f2e6079ea10 items=0 ppid=6283 pid=6284 auid=1000 uid=1000 gid=1000 euid=1000 suid=1000 fsuid=1000 egid=1000 sgid=1000 fsgid=1000 tty=pts6 ses=1 comm="sh" exe="/usr/bin/dash" subj==snap.auto-cpufreq.auto-cpufreq (enforce) key=(null)
apparmor="DENIED" operation="exec" profile="snap.auto-cpufreq.auto-cpufreq" name="/snap/snapd/14978/usr/bin/snap" pid=6295 comm="sh" requested_mask="x" denied_mask="x" fsuid=1000 ouid=0
arch=c000003e syscall=59 success=no exit=-13 a0=55d265e00758 a1=55d265e002f0 a2=55d265e004e8 a3=7fec63282a10 items=0 ppid=6294 pid=6295 auid=1000 uid=1000 gid=1000 euid=1000 suid=1000 fsuid=1000 egid=1000 sgid=1000 fsgid=1000 tty=pts6 ses=1 comm="sh" exe="/usr/bin/dash" subj==snap.auto-cpufreq.auto-cpufreq (enforce) key=(null)
apparmor="DENIED" operation="exec" profile="snap.auto-cpufreq.auto-cpufreq" name="/snap/snapd/14978/usr/bin/snap" pid=6295 comm="sh" requested_mask="x" denied_mask="x" fsuid=1000 ouid=0

Another location /mnt/data:

apparmor="DENIED" operation="open" profile="snap.auto-cpufreq.auto-cpufreq" name="/mnt/data/" pid=6333 comm="python3" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
arch=c000003e syscall=257 success=no exit=-13 a0=ffffff9c a1=7f7865016a40 a2=90800 a3=0 items=0 ppid=6162 pid=6333 auid=1000 uid=1000 gid=1000 euid=1000 suid=1000 fsuid=1000 egid=1000 sgid=1000 fsgid=1000 tty=pts6 ses=1 comm="python3" exe="/usr/bin/python3.8" subj==snap.auto-cpufreq.auto-cpufreq (enforce) key=(null)
apparmor="DENIED" operation="open" profile="snap.auto-cpufreq.auto-cpufreq" name="/mnt/" pid=6333 comm="python3" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
arch=c000003e syscall=257 success=no exit=-13 a0=ffffff9c a1=7f7864886470 a2=90800 a3=0 items=0 ppid=6162 pid=6333 auid=1000 uid=1000 gid=1000 euid=1000 suid=1000 fsuid=1000 egid=1000 sgid=1000 fsgid=1000 tty=pts6 ses=1 comm="python3" exe="/usr/bin/python3.8" subj==snap.auto-cpufreq.auto-cpufreq (enforce) key=(null)
apparmor="DENIED" operation="open" profile="snap.auto-cpufreq.auto-cpufreq" name="/mnt/data/" pid=6333 comm="python3" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
arch=c000003e syscall=257 success=no exit=-13 a0=ffffff9c a1=7f7864666ad0 a2=90800 a3=0 items=0 ppid=6162 pid=6333 auid=1000 uid=1000 gid=1000 euid=1000 suid=1000 fsuid=1000 egid=1000 sgid=1000 fsgid=1000 tty=pts6 ses=1 comm="python3" exe="/usr/bin/python3.8" subj==snap.auto-cpufreq.auto-cpufreq (enforce) key=(null)
apparmor="DENIED" operation="open" profile="snap.auto-cpufreq.auto-cpufreq" name="/mnt/" pid=6333 comm="python3" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

The first one suggests it tries to run a shell. I don’t know why why there’s a need to run a shell, but it clearly indicates that trying to run something in cwd is a problem.

I looked at the code and there’s a couple of code paths that I believe would unconditionally attempt to run shell at startup, eg:

snap_check = os.system("snap list | grep auto-cpufreq >/dev/null 2>&1")
1 Like

Is possible to get the old version o f snap which was working fine? Thanks.

@mborzecki of course makes sense. In meantime I made changes in snap_detect_improve branch, which handles >/dev/null 2>&1 in a more graceful manner.

I just pushed v1.9.3 which is in development to Snap beta channel which should address this problem.

It can be installed by running: sudo snap install auto-cpufreq --beta, since it all works fine for me could you try it @meetdilip (@mborzecki you’re free to give it a try as well) and let me know if this fixes the issue.

Thanks!

2 Likes

Will try now. Thanks.

Tried and there was no error this time. How to make sure that Auto CPU Frequency is running properly? Thanks.

$ sudo auto-cpufreq

-------------------------------- auto-cpufreq ---------------------------------

Automatic CPU speed & power optimizer for Linux

Example usage: auto-cpufreq --monitor


Usage: auto-cpufreq [OPTIONS]

Options: –monitor Monitor and see suggestions for CPU optimizations –live Monitor and make (temp.) suggested CPU optimizations –install / --remove Install/remove daemon for (permanent) automatic CPU optimizations –stats View live stats of CPU optimizations made by daemon –config TEXT Use config file at defined path –debug Show debug info (include when submitting bugs) –version Show currently installed version –donate Support the project –help Show this message and exit.

When I try --stats, I got this

$ auto-cpufreq --stats

Note: You can quit stats mode by pressing “ctrl+c”

----------------------------------- Warning -----------------------------------

Unable to detect state of GNOME Power Profiles daemon service! This daemon might interfere with auto-cpufreq and should be disabled.

Steps to perform this action using auto-cpufreq: power_helper script: git clone https://github.com/AdnanHodzic/auto-cpufreq.git cd auto-cpufreq/auto_cpufreq python3 power_helper.py --gnome_power_disable

----------------------------------- Warning -----------------------------------

Unable to detect if you are using a TLP service! This daemon might interfere with auto-cpufreq which can lead to unexpected results. We strongly encourage you not to use TLP unless you really know what you are doing.

-------------------------------- Daemon check ---------------------------------

ERROR:

Daemon not enabled, must run install first, i.e: sudo auto-cpufreq --install


I tried --live and got this

@meetdilip LGTM, run sudo auto-cpufreq --install and have it run everything automatically on your behalf :slight_smile:

1 Like

Thanks to all

$ auto-cpufreq --version

-------------------------------------------------------------------------------

Linux distro: Ubuntu 21.10 (Impish Indri)
Linux kernel: 5.13.0-28-generic
auto-cpufreq version: (Snap) 1.9.3
2 Likes