From 123ac3f91e1f47108d74e5f294e0f7b6b5ba6033 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sat, 5 Mar 2016 00:22:52 +0300 Subject: [PATCH 189/189] setarch: fix personality syscall return code check Depending on architecture and kernel version, personality syscall is either capable or incapable of returning an error. If the return value is not an error, then it's the previous personality value, which can be an arbitrary value undistinguishable from an error value. To make things clear, a second call is needed. For more details about personality syscall peculiarities see https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=glibc-2.22-637-ge0043e17dfc5 Signed-off-by: Dmitry V. Levin Signed-off-by: Karel Zak Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1690102 Upstream: http://github.com/karelzak/util-linux/commit/ae7065760d9bbe776a93a73d88e85c7796acb8cc --- sys-utils/setarch.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c index bcde78f4c..0e45cfef9 100644 --- a/sys-utils/setarch.c +++ b/sys-utils/setarch.c @@ -223,8 +223,18 @@ set_arch(const char *pers, unsigned long options, int list) errx(EXIT_FAILURE, _("%s: Unrecognized architecture"), pers); pers_value = transitions[i].perval | options; - if (personality(pers_value) == -EINVAL) - return 1; + if (personality(pers_value) < 0) { + /* + * Depending on architecture and kernel version, personality + * syscall is either capable or incapable of returning an error. + * If the return value is not an error, then it's the previous + * personality value, which can be an arbitrary value + * undistinguishable from an error value. + * To make things clear, a second call is needed. + */ + if (personality(pers_value) < 0) + return 1; + } uname(&un); if(transitions[i].result_arch && -- 2.21.0