Cross-Platform Built-in NFS Client Symlinks handling bug (?)
#1
Way back on 2015-04-10 I started the following thread about what may or may not have been a related symlink bug to the one I intend to describe here today:

http://forum.kodi.tv/showthread.php?tid=223971

I provide the above link for the sake of completness. I don't know if that (NFS/symlinks) bug from 2015 is directly related to the one I wish to describe here today or not, but it seems possible, if not to say likely.

I am informally reporting the following bug here today just to ask if others can reproduce it. If so, I will file a formal bug report for it.

Bug Description:

If, on some NFS exported volume residing on some NFS server, a relative symlink (RS0) is created which (a) points to a directory and which also (b) itself begins with a leading ".." (dot-dot) pathname component, and if the target directory of the symlink (and/or some subdirectory/subdirectories thereof) itself/themselves also contain(s) one or more (secondary) relative symlinks (RSn) which themselves begin with leading ".." (dot-dot) pathname components, then if the NFS volume in question is browsed using Kodi, and if the original symlink (RS0) is traversed during this browsing, then any and all of the secondary relative symlinks will fail to even appear in Kodi directory listings during such browsing.

Important: Note that the secondary symlinks in such scenarios will appear in the Kodi directory listings, even when the original symlink (RS0) is followed, if and only if the target directory of the original symlink (RS0) has already been visited (during Kodi file/directory browsing) directly, i.e. without traversing the original symlink (RS0). In other words, there seems to be some sort of caching effect involved here. If you visit the target directory directly, without going through the (relative dot-dot) symlink, then you will see all of its contents properly, including any relative dot-dot symlinks contained therein. After you have done that once, then you can also browse back to that same directory via the symlink and now everything that should appear in that directory will appear in that directory, at least until you stop and restart Kodi, and then try browsing back to that same directory via the relative dot-dot symlink again. If you do that again, just after restarting Kodi, then again, the contents of the target directory will fail to show any other relative dot-dot symlinks that are present in there (but other things that are present in that directory, e.g. plain files, directories, and even non-relative or non-dot-dot symlinks will also show up properly there).

Important: This bug(s) require a variety of obscure factors to all be in perfect alignment in order to reproduce the bug(s). In particular, in the description of how to reproduce the bug(s), as given below, if any change is made, either to the specific filenames used, or to the ordering in which the steps are carried out, then the bug(s) may no longer present themselves. In my opinion, this is most likely indicative of the presence of multiple design errors, either in Kodi proper and/or in the NFS client library it is built with.

Affected:

Kodi on Android - Affected (16.1 Git:2016-04-24-f6ceced / Android 5.1.1)
SMPC on Android - Affected (SPMC 16.4-2 git:2016-08-15-46f733d-dirty / Android 5.1.1)
LibreELEC(arm) - Affected (Kodi 16.1 Git:c327c53 / LibreELEC 7.0.2.008)
Kodi on Ubuntu - affected (15.2 GitSadunknown)) (Compiled: 15.2+dfsg1+3ubuntu1 / Ubuntu 16.04 LTS)

Unaffected:

Kodi on Windows 7 (16.1)

How to Reproduce:

On the NFS server:
Login
cd to some convenient directory on some NSF exported filesystem
mkdir test
cd test
mkdir dir1
mkdir dir2
cd dir1
ln -s ../afile.jpg symlink-a.jpg
cd ../dir2
ln -s ../dir1 symlink-b
cd ..
cp <<someimagefile>>.jpg ./afile.jpg

On the NFS client (i.e. something running Kodi):

Shutdown Kodi/LibreELEC/SPMC -- power off if necessary
Re-start Kodi/LibreELEC/SPMC
If you have not already done so, go to Pictures->Files->Add Pictures... and add a source of the form:
nfs://<<IPv4 addr>>/path
where the URL designates the NFS volume within which you created the test directory in the steps above.
When done, go back to Pictures->Files and select this same NFS source
Browse to the test directory you created on the NFS server
While in that "test" directory do not browse into dir1.
Browse into dir2
While you are within dir2, click on symlink-b
Note that after you do so, the directory listing will be empty except for the dot-dot -- this is the bug
Click on the dot-dot to return to the directory you came from (dir2)
Click on the dot-dot to return to the test directory
Browse into the dir1 directory and note the correct presence of the symlink-a.jpg file/symlink
Click on the dot-dot to return to the test directory
Browse into dir2 (again)
While you are within dir2, click on symlink-b (again)
Note that now you will see the directory entry for symlink-a.jpg there. (This proves that the bug can be, and perhaps often will be hidden by caching effects.)

I would appreciate it if others would try to reproduce this bug/bugs using exactly the above steps and let me know if you can. Remember, if you change the order of the steps, or even just the filenames or directory names used, you may not see the bug(s). I tried using different filenames/directory names and/or a different ordering of the steps and in all those cases I was not able to reproduce the bug(s).


P.S. Just because all of the planets have to be in perfect alignment before one can reliably and repeatedly reproduce this bug/bugs, that does not mean it isn't potentially serious. Indeed, innumerable serious security bugs have been documented, over time, which relate to the explotation of directory traversal hacks involving "../".
Reply
#2
I can reproduce the issue. But only with confluence skin - with estuary it doesn't happen (maybe because of the view which might hit the dir1 before automatically).
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#3
https://github.com/xbmc/xbmc/pull/11049 <- will be fixed in master once this is merged.
https://github.com/xbmc/xbmc/pull/11050 <- will be fixed in krypton branch once this is merged.

thx for tracking it down.
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#4
Memphiz,

Thanks for confirming, and thanks also for doing so ever so quickly. And last but not least, thanks for fixing it! Yipee! I can look forward to the day when my convoluted symlinks all work.

Should I file a formal report in the bugtracker thing, or are we good? (I'd prefer not to have to type all this all over again, unless doing that would be especially helpful.)

As you see, this bug -was- really quite slippery, and really quite difficult to reproduce reliably. I'm not entirely sure why. But anyway, I did spend at least a couple of hours trying to get you an exact scenario where you could see the thing actually happening, and repeatably.

I feel vaguely inclined, just out of curiosity, to ask you all sorts of things about this bug, e.g. (1) if you think it may be the same one I reported in April 2015, and (2) why Kodi on Windows7 doesn't seem to have the problem, and (3) why the bug only appears in such very narrow circumstances, but my guess is that you would probably only be able to offer me educated guesses about all those things, so just forget I mentioned them. :-) I'm just happy to have helped, happy you found the issue in the code, and happy that you fixed it. Thanks again.
Reply
#5
(1) - maybe - who knows
(2) - i am pretty sure i would be able to reproduce it on windows if i had windows Smile. Its really skin and settings related you can't really steer the order the code traverses the nfs directories under the hood in some skins or with some settings
(3) - see (2)
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply

Logout Mark Read Team Forum Stats Members Help
Cross-Platform Built-in NFS Client Symlinks handling bug (?)0