[erlang-bugs] Erlang R14B4 segfaults if /sys/devices/system/node is not readable

Sverker Eriksson sverker@REDACTED
Fri Mar 9 12:03:05 CET 2012


Thanks for excellent bug-report.

Here is what I've put in the pipe for R15B01:
 
diff --git a/erts/lib_src/common/erl_misc_utils.c 
b/erts/lib_src/common/erl_misc_utils.c
index 5e94ff1..4806311 100644
--- a/erts/lib_src/common/erl_misc_utils.c
+++ b/erts/lib_src/common/erl_misc_utils.c
@@ -834,8 +834,8 @@ read_topology(erts_cpu_info_t *cpuinfo)
     ix = -1;

     if (realpath(ERTS_SYS_NODE_PATH, npath)) {
-       got_nodes = 1;
        ndir = opendir(npath);
+       got_nodes = (ndir != NULL);
     }

/Sverker, Erlang/OTP Ericsson



Dennis Schridde wrote:
> Hello!
>
> I am using Erlang on a Gentoo/Hardened system, which restricts several things 
> for security reasons. For example /sys/devices/system/node is only read and 
> traversable (0700) by root, which makes erlexec segfault. I will describe how 
> I reproduce the segfault and attach a backtrace.
>
> In the following the directory "otp" refers to "otp_src_R14B04", which was the 
> one I started building Erlang in (the build process also never finishes due to 
> this issue).
>
> otp/bootstrap/bin/erl was modified to set:
> ---
> ROOTDIR=$ERL_TOP/bootstrap
> BINDIR=$ERL_TOP/bin/ia64-unknown-linux-gnu
> ---
>
> The script I use to reproduce is:
> ---
> export ERL_TOP=`pwd`/otp
> export PATH=$ERL_TOP/bootstrap/bin:${PATH}
>
> echo "run -W +debug_info +warn_exported_vars +warn_missing_spec 
> +warn_untyped_record -oebin misc/hipe_consttab.erl" > gdb.cmd
>
> gdb erlc -x gdb.cmd
> ---
>
> The segfault will happen in read_topology at common/erl_misc_utils.c:850.
> That line reads:
>   nde = readdir(ndir);
> The issue comes from ndir which is set a few lines before:
>   ndir = opendir(npath);
> The return value should be checked against NULL, because that is what opendir 
> returns on error - errno will tell the details.
>
> It would be nice if you could provide a fallback method in case 
> /sys/devices/system/node cannot be read.
>
> If you need any additional information, please ask.
>
> Kind regards,
> Dennis
>
> P.S: /sys/devices/system/cpu is readable by every user, so you could directly 
> fallback to that.
>
> The fix would then be to replace following code, starting from line 836:
>     if (realpath(ERTS_SYS_NODE_PATH, npath)) {
>         got_nodes = 1;
>         ndir = opendir(npath);
>     }
> with:
>     if (realpath(ERTS_SYS_NODE_PATH, npath)) {
>         ndir = opendir(npath);
>         if (ndir) {
>          got_nodes = 1;
>         }
>     }
>
> P.P.S: Does this list silently discard emails from non-subscribers? I did not 
> receive a is-in-moderation-queue confirmation when first sending this email 
> while not being subscribed...
> ------------------------------------------------------------------------
>
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs
>   




More information about the erlang-bugs mailing list