Skip to content

root on symlinked path causes panic when using "Watch for changes" #5043

Closed

Description

@larroy

I think the logic here has problems when the path is symlinked:

https://github.com/syncthing/syncthing/blob/master/lib/fs/basicfs_watch.go#L113

I have a "storage" folder symlinked to mnt: /home/piotr/storage -> /mnt/storage/storage/

This causes panic when using the notify backend

panic: bug: Notify backend is processing a change outside of the filesystem root: root==/home/piotr/storage/synced/oneplus5/, rootSymEval==/home/piotr/storage/synced/oneplus5/, path==/mnt/storage/storage/synced/oneplus5/.stfolder

Version Information

Syncthing Version: v0.14.48
OS Version: Linux 64 Ubuntu 16.04 (installed from apt)
Browser Version: (if applicable, for GUI issues)

Activity

  1. imsodin commented on Jul 1, 2018

    @imsodin
    Member

    Can you run the following script on your system and report the results, i.e. install Go and run go run test.go

    package main
    
    import (
    	"fmt"
    	"path/filepath"
    )
    
    func main() {
    	fmt.Println(filepath.EvalSymlinks("/home/piotr/storage/synced/oneplus5/"))
    }

    In any case we need to act on, not just ignore an error when determining the root with symlinks evaluated: https://github.com/syncthing/syncthing/blob/master/lib/fs/basicfs.go#L56
    Either panic already there (probably a bad idea, though I don't get why it should ever fail), or disable watching to prevent panics.

  2. larroy commented on Jul 6, 2018

    @larroy
    Author
    /mnt/storage/storage/synced/oneplus5 <nil>
    
  3. larroy commented on Jul 6, 2018

    @larroy
    Author

    Why the assertion in the first place? what are we trying to accomplish in unrootedChecked ?

  4. imsodin commented on Jul 6, 2018

    @imsodin
    Member

    @larroy

    Why asserting/panicing is a good question - it makes life easy for me as I don't need to think about how to handle a case that should never happen. A panic is ideal for that, as one line of code guarantees that the issue will come to my attention if it ever arises. Obviously, it's not quite user-friendly. All of that is tangential to your actual case though.

    What needs figuring out is where the evaluation of symlinks in your filesystem instance failed, i.e. why there is this conflict:

    panic: bug: Notify backend is processing a change outside of the filesystem root: root==/home/piotr/storage/synced/oneplus5/, rootSymEval==/home/piotr/storage/synced/oneplus5/, path==/mnt/storage/storage/synced/oneplus5/.stfolder

    fmt.Println(filepath.EvalSymlinks("/home/piotr/storage/synced/oneplus5/"))
    /mnt/storage/storage/synced/oneplus5

    I can't reproduce this issue, so a bit of back and forth will be necessary (maybe I am also just missing the obvious). Can you check what's the path for your folder in config.xml and then adjust the path at the bottom of the following gist and run it (it's basically the relevant syncthing code with lots of verbosity):
    https://gist.github.com/imsodin/b8ec2ec226a0575f7619997b287e6e28

  5. larroy commented on Jul 6, 2018

    @larroy
    Author

    Because the mount point is in /mnt/storage but in my home folder there's a link from ~/storage to /mnt/storage

  6. imsodin commented on Jul 9, 2018

    @imsodin
    Member

    The point of rootSymEval is exactly to resolve this issue, i.e. it should be the evaluated symlink as returned by filepath.EvalSymlinks und thus the same. Please run the gist and report the results.

  7. perpetual-hydrofoil commented on Aug 6, 2018

    @perpetual-hydrofoil

    Same panic happening here, setup similar to larroy's:

    /oldssd/jamieson/ $ ls -l /home/
    lrwxrwxrwx 1 root root 17 Feb 6 21:36 jamieson -> /oldssd/jamieson/

    Basically ran out of space on one of my SSD's, so just symlinked from another one with free space available. Reproduce: just add a new user and then symlink the home directory from somewhere else.

    Here's the result of that gist:

    newBasicFilesystem start: /home/jamieson/Essential-Ph1-Camera/
    newBasicFilesystem windows root hack: /home/jamieson/Essential-Ph1-Camera
    newBasicFilesystem tilde expansion: /home/jamieson/Essential-Ph1-Camera
    newBasicFilesystem EvalSymlinks: /oldssd/jamieson/Essential-Ph1-Camera
    adjustRoot in: /home/jamieson/Essential-Ph1-Camera
    adjustRoot result: /home/jamieson/Essential-Ph1-Camera/
    adjustRoot in: /oldssd/jamieson/Essential-Ph1-Camera
    adjustRoot result: /oldssd/jamieson/Essential-Ph1-Camera/
    &{/home/jamieson/Essential-Ph1-Camera/ /oldssd/jamieson/Essential-Ph1-Camera/}
    
  8. larroy commented on Aug 6, 2018

    @larroy
    Author

    Sorry I haven't been able to rerun, hadn't had access to that desktop for a bit.

  9. imsodin commented on Aug 7, 2018

    @imsodin
    Member

    @jamiesonbecker What was the panic message in your case (I am interested in the paths)? Thanks for running the gist!

  10. perpetual-hydrofoil commented on Aug 7, 2018

    @perpetual-hydrofoil

    @imsodin sure:

    Panic at 2018-08-06T15:47:05-05:00
    panic: bug: Notify backend is processing a change outside of the filesystem root: 
      root==/home/jamieson/Essential-Ph1-Camera/, 
      rootSymEval==/home/jamieson/Essential-Ph1-Camera/, 
      path==/oldssd/jamieson/Essential-Ph1-Camera/.stfolder
    
  11. imsodin commented on Aug 7, 2018

    @imsodin
    Member

    The weird thing is, that the gist (which is the exact same code with some debug statements) produces the correct result for the evaluated path &{/home/jamieson/Essential-Ph1-Camera/ /oldssd/jamieson/Essential-Ph1-Camera/} but it's wrong in the panic rootSymEval==/home/jamieson/Essential-Ph1-Camera/,. I have no idea, the next thing I'd try is move the debug info into the Syncthing binary and test again. A version on top of master from the build servers is here
    https://build.syncthing.net/repository/download/Syncthing_BuildLinuxCross/24994:id/syncthing-linux-amd64-v0.14.50-rc.1%2B3-gf9798d8.tar.gz%21/syncthing-linux-amd64-v0.14.50-rc.1%2B3-gf9798d8/syncthing
    and a version on top of 0.14.49 compile by me is here
    https://polybox.ethz.ch/index.php/s/ImkcFgiqQHxkCHt

    Please run either of those until you get the panic again and post the logs here.

  12. perpetual-hydrofoil commented on Aug 7, 2018

    @perpetual-hydrofoil

    (Also, I was also getting a panic regarding "panic: cannot start already running folder", but that stopped once I disabled Auto-Accept and created that folder manually, with the same id: see also #5063 )

  13. perpetual-hydrofoil commented on Aug 7, 2018

    @perpetual-hydrofoil

    (403 on build.syncthing URL)

    Can you confirm SHA256 d8a9982d4a196d86ec0fc648f3c19860c5095852e372db176ed5ec8c69e3d7e9 on your polybox link above?

  14. perpetual-hydrofoil commented on Aug 7, 2018

    @perpetual-hydrofoil

    If I pause the folder that I'm getting running folder error on (from the same device) instead of disabling Auto-Accept, then I get this nice little issue (this is still running stock v0.14.49 on Arch):

    [SGBHH] 09:52:17 INFO: Auto-accepted abcdef1234 folder "Ph1" (abc123) at path ~/Ph1
    [SGBHH] 09:52:17 INFO: Connection to XXX at [yyy]:58648-[zzz]:22000/tcp-client closed: <nil>
    panic: runtime error: invalid memory address or nil pointer dereference
    

    (I can email you the full uncensored panic if you like.)

    Just a hunch: these two issues (#5063 and this one, #5043) might be related to each other, especially when symlinks are thrown into the mix.

  15. imsodin commented on Aug 7, 2018

    @imsodin
    Member

    @jamiesonbecker Yes, that hash is correct.

    Maybe you need to login somehow to teamcity before the link can be accessed.

    And yes, I'd be interested in the panic trace. The trace shouldn't contain any personal information, but you can email it to me if you like. It might be related, but in that case it was a "folder already running" panic, not a nil deref.

  16. 2 remaining items

  17. perpetual-hydrofoil commented on Aug 7, 2018

    @perpetual-hydrofoil

    Resuming the problematic device and folder:

    [SGBHH] 10:28:35 INFO: newBasicFilesystem windows root hack: /home/jamieson/XXX
    [SGBHH] 10:28:35 INFO: newBasicFilesystem tilde expansion: /home/jamieson/XXX
    [SGBHH] 10:28:35 INFO: newBasicFilesystem EvalSymlinks: /oldssd/jamieson/XXX
    [SGBHH] 10:28:35 INFO: newBasicFilesystem start: ~/Ph1
    [SGBHH] 10:28:35 INFO: newBasicFilesystem windows root hack: ~/Ph1
    [SGBHH] 10:28:35 INFO: newBasicFilesystem tilde expansion: /home/jamieson/Ph1
    [SGBHH] 10:28:35 INFO: newBasicFilesystem EvalSymlinks failed: /home/jamieson/Ph1 lstat /oldssd/jamieson/Ph1: no such file or directory
    [SGBHH] 10:28:35 INFO: Adding folder "XXX" (xxx)
    panic: cannot start already running folder xxx
    [monitor] 10:28:35 WARNING: Panic detected, writing to "zzz/panic-20180807-102835.log"
    
  18. perpetual-hydrofoil commented on Aug 7, 2018

    @perpetual-hydrofoil

    N.B., this running folder issue is a different folder than the original camera folder shared from device; disabling auto accept got that original folder working, and I haven't been able to reproduce that issue until this new one popped up.

  19. imsodin commented on Aug 7, 2018

    @imsodin
    Member

    The nil deref is completely unrelated to everything else - thanks anyway for finding it ;)

    The cannot start already running folder almost certainly is #5063.

    Does a folder for /oldssd/jamieson/Ph1 actually exist? Because above in the gist and panic, it was /home/jamieson/Essential-Ph1-Camera/.

  20. perpetual-hydrofoil commented on Aug 7, 2018

    @perpetual-hydrofoil

    Great. Yes, that one was fixed as soon as I turned off auto-accept and restarted on both sides. Ph1 is a new one to try to force reproduction of this issue again, but I haven't gotten it to trigger the same symlink issue. (The directory wasn't created on the desktop side, so it still doesn't exist.)

  21. added a commit that references this issue on Aug 8, 2018
    214aba8
  22. imsodin commented on Aug 8, 2018

    @imsodin
    Member

    @jamiesonbecker

    I still don't understand what exactly is happening, but regardless the way symlinks in the root path are handled today is clearly bad and may lead to panics. Therefore I proposed a change that probably will fix this issue: #5105

    The nil deref trace from #5043 (comment) turned out to be less obvious than I thought initially, it's actually very confusing. If you do have the full trace and logs leading to it, I would be very interested to get them (by email or in the forum please, as it's not related to this issue).

  23. added a commit that references this issue on Aug 11, 2018
    77005c1
  24. added this to the v0.14.51 milestone on Aug 15, 2018
  25. modified the milestones: v0.14.51, v0.14.50 on Sep 2, 2018
  26. added 2 commits that reference this issue on Sep 2, 2018
    c2ff49e
    22d8a37
  27. added
    frozen-due-to-age
    on Aug 12, 2019
  28. locked and limited conversation to collaborators on Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    frozen-due-to-age

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions