From: Askar Safin <safinaskar@zohomail.com>
To: "Adhemerval Zanella Netto" <adhemerval.zanella@linaro.org>,
"dalias" <dalias@libc.org>
Cc: "libc-alpha" <libc-alpha@sourceware.org>, "carlos" <carlos@redhat.com>
Subject: Re: [PATCH, RFC] Add public function syscall_no_errno
Date: Thu, 01 Feb 2024 23:32:41 +0400 [thread overview]
Message-ID: <18d6628ba70.12a99fe2719939.4022957090731865688@zohomail.com> (raw)
In-Reply-To: <380959fd-3414-4fc6-ae3f-85abdee2a9a0@linaro.org>
Hi, Rich and Adhemerval!
---- On Thu, 01 Feb 2024 21:53:44 +0400 Adhemerval Zanella Netto wrote ---
> Indeed there some old syscalls where trying to issue them directly with
> syscall is problematic (like 'time' and 'brk' for some ABIs), but getuid
> is not one of them.
It *is* one of them!
Keep in mind that Linux supports 32-bit uids.
Run this code as root as 32-bit i386 binary (my letter continues after code). It is okay to run it on 64-bit amd64 kernel, you just have to make sure the binary itself is compiled as i386
=*=*=*=*=
#if !defined(__i386__)
#error
#endif
#include <stdint.h>
#include <stdio.h>
#include <sys/syscall.h>
#include <unistd.h>
int
main (void)
{
// 4294967286 is (2^32)-10
uint32_t a = 4294967286U;
if (syscall (SYS_setuid32, a) == -1)
{
perror("setuid");
return 1;
}
uint32_t b = syscall (SYS_getuid32);
// Now b is equal to (uint32_t)-1 instead of wanted 4294967286 (i. e. (uint32_t)-10)
printf("%u (wanted)\n", a);
printf("%u (got)\n", b);
return 0;
}
=*=*=*=*=
(Also, when I said "getuid", I meant "SYS_getuid32".)
I see this output:
=*=*=*=*=
4294967286 (wanted)
4294967295 (got)
=*=*=*=*=
So, yes, function "syscall" is incompatible with SYS_getuid32.
I'm nearly sure the same is true about getpid.
Rich:
> If someone really wants to write code that's
> independent of libc -- like to run in a vforked child or CLONE_VM
This is another use case I want to support. I. e. I want to
have portable function (i. e. independent of arch) for issuing
syscall in such case. And I don't
want to write assembly.
> but might inspect TLS to
> determine how to make the syscall
Okay, so syscall_no_errno should not do this. I. e. it should
always do some way to make syscall, which always works,
even if it is slow. For i386 it is "int 0x80" as well as I understand.
Also, even if we read TLS to determine how to make syscall,
what will go wrong? Child shares TLS with its parent after CLONE_VM,
so we simply will read parent's TLS
next prev parent reply other threads:[~2024-02-01 19:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-28 16:39 Askar Safin
2024-02-01 17:53 ` Adhemerval Zanella Netto
2024-02-01 18:18 ` Rich Felker
2024-02-01 19:32 ` Askar Safin [this message]
2024-02-01 20:16 ` dalias
2024-02-01 20:57 ` Adhemerval Zanella Netto
2024-02-08 15:02 ` [PATCH v2] " Askar Safin
2024-02-08 17:48 ` Szabolcs Nagy
2024-02-12 14:24 ` Florian Weimer
2024-02-12 14:44 ` Rich Felker
2024-02-12 16:16 ` Askar Safin
2024-02-12 17:25 ` Zack Weinberg
2024-02-12 17:43 ` Andreas Schwab
2024-02-12 18:22 ` Zack Weinberg
2024-02-13 9:10 ` Andreas Schwab
2024-02-13 11:57 ` Adhemerval Zanella Netto
2024-02-12 17:55 ` Adhemerval Zanella Netto
2024-02-12 18:34 ` Askar Safin
2024-02-07 0:59 ` [PATCH, RFC] " Askar Safin
2024-02-07 20:59 ` dalias
2024-02-08 17:08 ` Askar Safin
2024-02-07 1:57 ` Mike Frysinger
2024-02-07 12:55 ` Askar Safin
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=18d6628ba70.12a99fe2719939.4022957090731865688@zohomail.com \
--to=safinaskar@zohomail.com \
--cc=adhemerval.zanella@linaro.org \
--cc=carlos@redhat.com \
--cc=dalias@libc.org \
--cc=libc-alpha@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).