Avoiding wordexp prevents environment variables being used
I just came up against the patch below; it prevents useful snippets of alsa-conf like this:
@hooks [
{
func load
files [
"~/.asoundrc-$HOSTNAME"
]
errors false
}
]as the evalutation of all but "~" has been removed.
Seems like removal of a perfectly good feature in the name of security; because wordexp()
1) is not used (and should not be used) on data originating from an untrusted source
2) is already used with WRDE_NOCMD, which the same POSIX spec documents as:
"The WRDE_NOCMD flag is provided for applications that, for security
or other reasons, want to prevent a user from executing shell commands."
3) on glibc can be seen (with strace) not to execute other commands
If one is to treat the POSIX doc as gospel (as cited by the patch) the cause of firefox (circa July 2017) not working would actually be that musl does not honour WRDE_NOCMD to the letter. I agree the spec of wordexp() could be more useful, though.
Also, hypothesising the attacks of an already-compromised application would get into a sticky conversation about the thread safety of getenv("HOME") (and associated buffer wrangling) vs. a library function being used for its intended purpose.
In practice, Firefox may have moved on here (no ALSA support anymore) so should quirks of its sandbox be driving this?
Signature · 1 line
Mark
Quoted 1 line
From
cb34cee0d8da2fb131986d5782ddf5cec985c532Mon Sep 17 00:00:00 2001
From: Natanael Copa <[email protected]>
Date: Fri, 14 Jul 2017 18:47:05 +0200
Subject: [PATCH] snd_user_file: avoid use wordexp
As suggested in POSIX[1], wordexp might execute the shell. If the libc implementation does so, it will break the firefox sandbox which does not allow exec. This happened on Alpine Linux with musl libc[2].
Since we cannot guarantee that the system wordexp implementation does not execute shell, we cannot really use it, and need to implement the ~/ expansion ourselves.
We provide a configure option --with-wordexp for users that still may need it, but we leave this off by default because wordexp is a large attack vector and it is better to avoid it.
[1]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/wordexp.html#tag_16_684_08
[2]: http://bugs.alpinelinux.org/issues/7454#note-2
--- configure.ac | 19 ++++++++++++++++- src/userfile.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 75 insertions(+), 9 deletions(-)
configure.ac +18 -1
@@ -303,8 +303,25 @@ fi AC_SUBST(ALSA_DEPLIBS) +dnl Check for use of wordexp... +AC_MSG_CHECKING(for use of wordexp) +AC_ARG_WITH(wordexp, + AS_HELP_STRING([--with-wordexp], + [Use wordexp when expanding configs (default = no)]), + [case "$withval" in + y|yes) wordexp=yes ;; + *) wordexp=no ;; + esac],) +if test "$wordexp" = "yes" ; then + AC_DEFINE(HAVE_WORDEXP, "1", [Enable use of wordexp]) + AC_MSG_RESULT(yes) + AC_CHECK_HEADER([wordexp.h],[], [AC_MSG_ERROR([Couldn't find wordexp.h])]) +else + AC_MSG_RESULT(no) +fi + dnl Check for headers -AC_CHECK_HEADERS([wordexp.h endian.h sys/endian.h sys/shm.h]) +AC_CHECK_HEADERS([endian.h sys/endian.h sys/shm.h]) dnl Check for resmgr support... AC_MSG_CHECKING(for resmgr support)
src/userfile.c +57 -8
90 lines not on this page · raw message
Signature · 1 line
2.14.1
Quoted 36 lines · Mark Hills
I just came up against the patch below; it prevents useful snippets of alsa-conf like this:
@hooks [ { func load files [ "~/.asoundrc-$HOSTNAME" ] errors false } ]as the evalutation of all but "~" has been removed.
Seems like removal of a perfectly good feature in the name of security; because
wordexp()1) is not used (and should not be used) on data originating from an untrusted source
2) is already used with
WRDE_NOCMD, which the same POSIX spec documents as:"The
WRDE_NOCMDflag is provided for applications that, for security
or other reasons, want to prevent a user from executing shell commands."3) on glibc can be seen (with strace) not to execute other commands
If one is to treat the POSIX doc as gospel (as cited by the patch) the cause of firefox (circa July 2017) not working would actually be that musl does not honour
WRDE_NOCMDto the letter. I agree the spec ofwordexp()could be more useful, though.
Quoted 7 lines
Also, hypothesising the attacks of an already-compromised application would get into a sticky conversation about the thread safety of
getenv("HOME")(and associated buffer wrangling) vs. a library function being used for its intended purpose.In practice, Firefox may have moved on here (no ALSA support anymore) so should quirks of its sandbox be driving this?
What's wrong with you building the alsa-lib with --with-wordexp if you prefer having that behavior?
Takashi
Quoted 43 lines · Takashi Iwai
Quoted 41 lines · Mark Hills
I just came up against the patch below; it prevents useful snippets of alsa-conf like this:
@hooks [ { func load files [ "~/.asoundrc-$HOSTNAME" ] errors false } ]as the evalutation of all but "~" has been removed.
Seems like removal of a perfectly good feature in the name of security; because
wordexp()1) is not used (and should not be used) on data originating from an untrusted source
2) is already used with
WRDE_NOCMD, which the same POSIX spec documents as:"The
WRDE_NOCMDflag is provided for applications that, for security
or other reasons, want to prevent a user from executing shell commands."3) on glibc can be seen (with strace) not to execute other commands
If one is to treat the POSIX doc as gospel (as cited by the patch) the cause of firefox (circa July 2017) not working would actually be that musl does not honour
WRDE_NOCMDto the letter. I agree the spec ofwordexp()could be more useful, though.Also, hypothesising the attacks of an already-compromised application would get into a sticky conversation about the thread safety of
getenv("HOME")(and associated buffer wrangling) vs. a library function being used for its intended purpose.
Quoted 5 lines
Quoted 2 lines
In practice, Firefox may have moved on here (no ALSA support anymore) so should quirks of its sandbox be driving this?
What's wrong with you building the alsa-lib with --with-wordexp if you prefer having that behavior?
Practically, I must build custom packages for all machines (some I do not control, eg. my employer's)
My case here is both that the default behaviour should not have changed; and that the security rationale offered here is misleading.
Signature · 1 line
Mark
Quoted 49 lines · Mark Hills
Quoted 46 lines · Takashi Iwai
Quoted 43 lines · Mark Hills
I just came up against the patch below; it prevents useful snippets of alsa-conf like this:
@hooks [ { func load files [ "~/.asoundrc-$HOSTNAME" ] errors false } ]as the evalutation of all but "~" has been removed.
Seems like removal of a perfectly good feature in the name of security; because
wordexp()1) is not used (and should not be used) on data originating from an untrusted source
2) is already used with
WRDE_NOCMD, which the same POSIX spec documents as:"The
WRDE_NOCMDflag is provided for applications that, for security
or other reasons, want to prevent a user from executing shell commands."3) on glibc can be seen (with strace) not to execute other commands
If one is to treat the POSIX doc as gospel (as cited by the patch) the cause of firefox (circa July 2017) not working would actually be that musl does not honour
WRDE_NOCMDto the letter. I agree the spec ofwordexp()could be more useful, though.Also, hypothesising the attacks of an already-compromised application would get into a sticky conversation about the thread safety of
getenv("HOME")(and associated buffer wrangling) vs. a library function being used for its intended purpose.In practice, Firefox may have moved on here (no ALSA support anymore) so should quirks of its sandbox be driving this?
Quoted 8 lines
Quoted 2 lines
What's wrong with you building the alsa-lib with --with-wordexp if you prefer having that behavior?
Practically, I must build custom packages for all machines (some I do not control, eg. my employer's)
My case here is both that the default behaviour should not have changed; and that the security rationale offered here is misleading.
How can you assure you'll never hit a badly written wordexp() in the wild old binary?
Takashi