From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) by sourceware.org (Postfix) with ESMTPS id D152438582A1 for ; Thu, 1 Feb 2024 19:32:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D152438582A1 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zohomail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D152438582A1 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=136.143.188.94 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706815970; cv=pass; b=FJ6nifF+wkNQCeQJWri4zf6Olg0p0Qz26NxtcdNXrHmaoaxrEdvsVJdsPSVAwz85/KEpmw3bwdm/k7ZUJyXZaOs2q1u8aeHjI9piz5dQFbyoSweRwTcIPFCFJd960iVzKyGoFJh6CjGURYi5PtFKSlwz748kKE7oskpYTi0qJjs= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706815970; c=relaxed/simple; bh=jo3TxjMKC+IkbiX+BxvIte74iMvmDs6fdqCnUW3w/Zk=; h=DKIM-Signature:Date:From:To:Message-ID:Subject:MIME-Version; b=sVVHR5SjPgtKlBhnrNCpAGqx+J7BNrsKB2nRYgrQiSzFlyNRUQwhSDKidIoAQl+/iM7G0DJuu1UAYryoEgLGqQS2+SKsnB3WIwpBEenCKPE1qBUH80mPiCwLV/p0ptX04/PCMPI+Kq/Zx2VX8RPySHZ4/dgQLy7t6ApxvqHoztw= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1706815963; cv=none; d=zohomail.com; s=zohoarc; b=g7o+Ikn+EZ1EIGPsOgye9OSuH+JeVZkQGj8uM5wc/yXnm+cM2VX3vLH9c572+lnZbCxyluDqlMoCX4uTcq7zxDHSGXcgU4hvER3htBequv3Jl+bW33baolIDDsbEUZilENgzVY0NaDvSJl0a/jhvA1syZ+QSSCbrtKlJmjdEAmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706815963; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=vgI6RnyxpdV07E+CcVh6UmXfGGI6aX36l3rhUe2r0dg=; b=PTh4xGmDCSzo37VnhKpW2tYU/M9Vx32gcrTwWYtbV+OjzN4yz0ESy/9qU/rwl+BPPiSPOwkxYpSX6ObIj2fe5kZLIi8CewpnqPSSXQFtlIXM61JUwcjkdEVVLgBwVVuDm2jVgWf5wjfxhoo1Sbm7SiWrpKH0vXXpM5S7uYgnxIA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zohomail.com; spf=pass smtp.mailfrom=safinaskar@zohomail.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1706815963; s=zm2022; d=zohomail.com; i=safinaskar@zohomail.com; h=Date:Date:From:From:To:To:Cc:Cc:Message-ID:In-Reply-To:References:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Feedback-ID:Message-Id:Reply-To; bh=vgI6RnyxpdV07E+CcVh6UmXfGGI6aX36l3rhUe2r0dg=; b=GpM4urnfJ7Bc/0YfgnypLZu8yVKJ8uUCL2RRfBkiqOUWznzmcpvgQjywNjeN3lhb pvuba0Sova1qU3EKwUC9SDMeke9AblcBPPP3b3qACYFn9DNmMYDAdGKbk3l018Jomfn e1sjsaHKWMI1ke+ssqa/7qTzsEJwwnmS1xI/w5DA= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 17068159617281006.975284567536; Thu, 1 Feb 2024 11:32:41 -0800 (PST) Received: from [212.73.77.98] by mail.zoho.com with HTTP;Thu, 1 Feb 2024 11:32:41 -0800 (PST) Date: Thu, 01 Feb 2024 23:32:41 +0400 From: Askar Safin To: "Adhemerval Zanella Netto" , "dalias" Cc: "libc-alpha" , "carlos" Message-ID: <18d6628ba70.12a99fe2719939.4022957090731865688@zohomail.com> In-Reply-To: <380959fd-3414-4fc6-ae3f-85abdee2a9a0@linaro.org> References: <20240128163958.17421-1-safinaskar@zohomail.com> <380959fd-3414-4fc6-ae3f-85abdee2a9a0@linaro.org> Subject: Re: [PATCH, RFC] Add public function syscall_no_errno MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail Feedback-ID: rr08011227884efc7c1118cd401328fe5c00003225d8cee59603906fd0f66fc834ffd6b2d386ad5044b5a90a:zu08011227b59fc39ddad9020d646f07f40000566e813bf09a652b20521dbe3d5ec729ca47f5980f5790a93f:rf0801122c0f4bc4f79353f630ad5cb422000064006c707d6f85a3d031c431d227dac0c131e11f2cc591d313e381e0eec8:ZohoMail X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 #include #include #include 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