Is it indeed possible to craft such a malicious payload in a filename [...] to get a root escalation?
The first step is to run an arbitrary command; getting a root escalation is then a question of exploiting separate privilege escalation bugs in the local system, which is a bit out-of-scope for a question about bash.
In terms of whether one can run an arbitrary command by data passed to a shell script: Not if the shell script is written correctly. If it has arbitrary, and potentially buggy, contents, then perhaps so. Without seeing a specific script to audit, how are we to say?
My concern is that users can get root privilege when they craft a filename in such a way that they can 'escape' the symlink command and execute code as root.
This isn't possible if your script is correctly written.
Use --
to prevent names from being treated as options, and double-quotes to prevent string-splitting and glob expansion.
ln -- "$source" "$dest"
Arguments such as -s
and -f
must go before the --
, which asserts that all following arguments are interpreted as positional.
Other parts of the script are also relevant: If you're parsing ls
, using eval
, or performing eval
-equivalent operations (such as expanding user-controlled variables in strings which are treated as scripts; ssh
arguments are an example of such; so are unquoted heredocs performing expansions), these can introduce vulnerabilities.
Which is to say: There are numerous things that can be done right (or wrong), and we'd need to see your code to audit it. Not that StackOverflow is the right place for that -- perhaps the Code Review StackExchange site? Be sure to run contents through http://shellcheck.net/ before submitting them for human review as well.