Util-Linux package development
 help / color / mirror / Atom feed
From: "Dmitry V. Levin" <ldv@altlinux.org>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: [PATCH] setarch: fix personality syscall return code check
Date: Sat, 5 Mar 2016 00:22:52 +0300	[thread overview]
Message-ID: <20160304212252.GB22191@altlinux.org> (raw)
In-Reply-To: <20160224125641.kw2t37ofjhmealej@ws.net.home>

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 <ldv@altlinux.org>
---
 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 b6159c5..b5e401c 100644
--- a/sys-utils/setarch.c
+++ b/sys-utils/setarch.c
@@ -236,8 +236,18 @@ static int set_arch(const char *pers, unsigned long options, int list)
 	if (transitions[i].perval < 0)
 		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 && strcmp(un.machine, transitions[i].result_arch)) {
 		if (strcmp(transitions[i].result_arch, "i386")

-- 
ldv

  parent reply	other threads:[~2016-03-04 21:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-24 12:56 rc1 planning Karel Zak
2016-02-24 14:50 ` Ruediger Meier
2016-02-24 17:47   ` Karel Zak
2016-03-04 21:22 ` Dmitry V. Levin [this message]
2016-03-07 13:54   ` [PATCH] setarch: fix personality syscall return code check Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160304212252.GB22191@altlinux.org \
    --to=ldv@altlinux.org \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox