Virus or bug?

Hello! I encountering very strange behavior of my ubuntu 19.10. When I recomplie my snapd to solve xdg-open issues (basically allows everything) I stuck to get my resulting /usr/bin/snap to work.

I changed it, compiled it, install it and got no changes. Still unable to open xdg-open to work. I dig deeper. I change default snap “help” cmd output to “refresh !!! and remove snaps” added three excalamation marks. Then reinstall package… still no changes. Then I checked if my deb package containing correct file and got surprized, since when I run unpacked deb snap 123/usr/bin/snap I got my new out put with “refresh !!! and remove snaps”. So, I compared two files md5 sum unpacked and installed:

axet@axet-laptop:~/local$ md5sum 123/usr/bin/snap /usr/bin/snap
f6639f5060dcd23506082f6ff0699f72 123/usr/bin/snap
f6639f5060dcd23506082f6ff0699f72 /usr/bin/snap

Then a run booth of them:

axet@axet-laptop:~/local$ ./123/usr/bin/snap
The snap command lets you install, configure, refresh !!! and remove snaps.
Snaps are packages that work across many different Linux distributions,
enabling secure delivery and operation of the latest apps and utilities.

axet@axet-laptop:~/local$ /usr/bin/snap
The snap command lets you install, configure, refresh and remove snaps.
Snaps are packages that work across many different Linux distributions,
enabling secure delivery and operation of the latest apps and utilities.

That very confusing. Even when I copy /usr/bin/snap into 111111 then run 111111 I’m getting the correct output with “!!! and remove snaps”. Seems like when I ran snap I got one binary image, but when I read the same file I get different image. Look like virus, kernel, hardware or encryption bug. I’m running Ubuntu 19.10 with luks/lvm encryption.

I also tied to put simple “hello world” into /usr/bin/snap and get “hello world” output. But when I install snapd I always get “old” version.

Any one faced something like this? Maybe it is CPU bug, which caching something?

The snap command will re-execute itself into the version from the core snap or the snapd snap if the version number there is higher. Try setting the env var SNAPD_REEXEC=0 when running snap ... and see if that makes it work the way you expect.

Thank you for letting me know my system is not compromised. But It is very unpleasant to know this is the build-in feature. But, I still unable to run my original binary even when I run:

SNAPD_REEXEC=0 /usr/bin/snap --version

I see new 2.44.1

When I ran 123/usr/bin/snap --version

I see 2.42.1+19.10axet-laptop1

Can I disable REEXEC at system settings?

Sorry I don’t quite follow, are you saying that re-exec isn’t working? To make things clear let’s figure out where all of the possible “snap” binaries that your system could be re-execing to. What is the output of:

snap list
snap version
which snap

I want to remove restriction to xdg-open, and allow all protocols redirected to the system level. To do I rebuild snapd as deb file and install it. I unable to use it, since snap does not allow me to run it!

axet@axet-laptop:~$ snap list
Name Version Rev Tracking Publisher Notes
android-studio 3.6.2.0 87 latest/stable snapcrafters classic
atom 1.45.0 248 latest/stable snapcrafters classic
brackets 1.14.1 138 latest/stable snapcrafters classic
chromium 81.0.4044.92 1100 latest/stable canonical✓ -
chromium-ffmpeg 0.1 15 latest/stable canonical✓ -
core 16-2.44.1 8935 latest/stable canonical✓ core
core18 20200311 1705 latest/stable canonical✓ base
eclipse 2019-12 48 latest/stable snapcrafters classic
gnome-3-28-1804 3.28.0-16-g27c9498.27c9498 116 latest/stable/… canonical✓ -
gnome-calculator 3.34.1+git4.c387feb0 704 latest/stable/… canonical✓ -
gnome-characters v3.32.1+git4.e06f0b2 495 latest/stable/… canonical✓ -
gnome-logs 3.34.0 93 latest/stable/… canonical✓ -
go 1.14.2 5646 latest/stable mwhudson classic
google-cloud-sdk 289.0.0 127 latest/stable google-cloud-sdk✓ classic
gtk-common-themes 0.1-29-g45e78c5 1474 latest/stable/… canonical✓ -
opera 67.0.3575.137 71 latest/stable opera-software✓ -
axet@axet-laptop:~$ snap version
snap 2.44.1
snapd 2.44.1
series 16
ubuntu 19.10
kernel 5.3.0-46-generic
axet@axet-laptop:~$
axet@axet-laptop:~$ which snap
/usr/bin/snap
axet@axet-laptop:~$

File at /usr/bin/snap actual version is 2.42.1+19.10axet-laptop1, but it shows 2.44.1. I guess no, reexec not working

Turns out variable is “SNAP_REEXEC” and it is will be ignored in some cases. Just disable it in the source code by running:

sed -i ‘s/!osutil.GetenvBool(reExecKey, true)/true/’ snapd-*/cmd/cmd_linux.go

Thanks for the hint @ijohnson !!!