termux / proot

An chroot-like implementation using ptrace.
https://wiki.termux.com/wiki/PRoot
Other
774 stars 160 forks source link

Permission denied (src/ip_resolver.cpp:542) #248

Closed HITers2018 closed 1 year ago

HITers2018 commented 1 year ago

I guess the latest proot or proot-distro may have some bugs. If I install python and jupyter notebook in termux directly , ipykernel can work well. But if I install python and jupyter notebook in alpine (with the latest proot-distro), it gets the err 'Permission denied (src/ip_resolver.cpp:542)' and the ipykernel cannot start. The bug also influence users who upgrade proot and proot-distro. Here are the codes I use to install python and jupyter notebook.

proot-distro install alpine proot-distro login alpine apk add python3 python3 -m ensurepip pip3 install wheel apk add gcc python3-dev apk add build-base libjpeg-turbo-dev zlib-dev libxslt-dev jpeg-dev openjpeg libxft libzmq qhull pixman cairo libgfortran openblas-dev brotli-dev freetype-dev libffi-dev pip3 install notebook

if you run jupyter notebook --allow-root and open a notebook, console displays the err 'Permission denied (src/ip_resolver.cpp:542)' and the ipykernel cannot start. Screenshot_2022-12-29-11-21-30-411_com termux

HITers2018 commented 1 year ago

I just found that the bug only appears on my android 13 device (miui14), so the problem may be caused by android 13. It is strange that ipykernel runs well in termux directly but cannot run in termux-proot. Is it possible to solve the problem?

michalbednarski commented 1 year ago

As a workaround you can LD_PRELOAD following library to make libzmq believe that getifaddrs() is unavailable as in WSL:

#include <errno.h>
#include <ifaddrs.h>
int getifaddrs(struct ifaddrs **ifap) {
    errno = EOPNOTSUPP;
    return -1;
}
gcc skip_getifaddrs.c -o skip_getifaddrs.so -shared
LD_PRELOAD=/root/skip_getifaddrs.so jupyter notebook --allow-root

Proper solution would be probably to ask libzmq to not abort() when getifaddrs() reports EACCES (due to SELinux denial). Bionic, unlike glibc, knows about RTM_GETLINK being unavailable and is able to handle that case, but ultimately I'd say that the bug is libzmq crashing when getifaddrs() reports unexpected errno


Besides RTM_GETLINK unavailability, getifaddrs() in glibc (but not in musl) hiccups at attempting doing bind() on AF_NETLINK socket so errno there comes from bind(). In musl, errno comes from sendto(..., {nlmsg_type=RTM_GETLINK}) (which would also happen in glibc if we'd skip bind()). In both cases errno is set to EACCES

Overriding bind() error however is in my opinion risks breaking other uses and implementing sendto(..., {nlmsg_type=RTM_GETLINK}) would introduce significant amount of state into proot, so I'd like to avoid doing these on proot side

feer9 commented 1 year ago

Hey, same issue here trying to run Spyder IDE inside of Termux. The workaround mentioned above works, but is there any chance this gets fixed upstream? Do libzmq maintainers know about this? Just asking to know if I should file an issue there.

HITers2018 commented 1 year ago

i have not reported it to libzmq maintainers, so you can file the issuse there if you want the issuse to be fixed upatream.

ericli2333 commented 1 year ago

@HITers2018 I met the same problem today. So how did you deal with it? Have you found a good solution rather than change the cpp file?

HITers2018 commented 1 year ago

i just use the workaround mentioned above, maybe it is better to get the help from the libzmq maintainers. the workaround is easy and useful, which is just a hook by using LD_PRELOAD. it does not change any cpp source file.

feer9 commented 1 year ago

Yeah, I ended up using the workaround too. I wanted to report the bug but didn't take the time to present it properly to the devs

Cateners commented 10 months ago

I asked Bing to help me write the code for using the getifaddrs function in Android within a proot container. This code does work for me. https://github.com/Cateners/tiny_computer/tree/master/extra/getifaddrs_bridge

ashengstd commented 5 months ago

i encoutered the same probem in a flutter based code-server gui app, but it seems that no option is available in code-server to add the environment variable, is there any way to fix the problem, or how to make it work in vscode?

ericli2333 commented 5 months ago

i encoutered the same probem in a flutter based code-server gui app, but it seems that no option is available in code-server to add the environment variable, is there any way to fix the problem, or how to make it work in vscode?

Actually, I gave it up long ago.But I remember that before I gave it up, I used the proot environment to run the code-server or the jupyter. And that works. You can refer to my blog And follow my steps to make it work.My blog is written in Chinese, and you may try to use Google translator to understand it.

josesho commented 2 months ago

The workaround wasn't successful for me. Am on Android 14, running proot-distro Ubuntu. I believe I've linked the library properly; see below.

Any help would be appreciated! Else I will just use virtualenv in Termux itself instead of Conda... :( Screenshot_20240713_102402_Termux

josesho commented 2 months ago

OK, I realize you have to run the full command each time.

LD_PRELOAD=/root/skip_getifaddrs.so jupyter lab --allow-root

This works! Yay!!

ericli2333 commented 2 months ago

congratulation, actually even i fail from time to time. this proot is not that stable.

josesho commented 2 months ago

For reference, this was the full list of steps I followed to successfully install Ubuntu in Termux via proot-distro, then get conda and Jupyter running inside the proot distro, and lastly having to manually create Jupyter kernels in the correct folder so Jupyter can see them.

https://www.notion.so/josesho/Installing-Analytics-Stack-in-Termux-4a6ff82d32974db4a4de27ee5e24ba45

sofair commented 1 week ago

I managed to patch libzmq by changing EINVAL(22) to EACCES(13), So zmq can return before the assertion fail. Patch the aarch64 binary with perl -pi -e "/\x1F\x7C\x01\x71\x04\x18\x56\x7A\x60\x0E\x00\x54/\x1F\x7C\x01\x71\x04\x18\x56\x7A\x6E\x0E\x00\x54/g" /path/to/libzmq.so.5.2.5

feer9 commented 6 days ago

I managed to patch libzmq by changing EINVAL(22) to EACCES(13), So zmq can return before the assertion fail. Patch the aarch64 binary with perl -pi -e "/\x1F\x7C\x01\x71\x04\x18\x56\x7A\x60\x0E\x00\x54/\x1F\x7C\x01\x71\x04\x18\x56\x7A\x6E\x0E\x00\x54/g" /path/to/libzmq.so.5.2.5

Won't that work only for the specific build you have?