From patchwork Wed Apr 19 13:58:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Simmons-Talbott X-Patchwork-Id: 1770748 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=AOKGEkuH; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q1j7W3cpCz1ybF for ; Wed, 19 Apr 2023 23:58:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 78C163856974 for ; Wed, 19 Apr 2023 13:58:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78C163856974 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681912725; bh=rRmx6o/0M27Ci7AUJnnF4ye3AfWz/oUZ3PGh+V+oi3U=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=AOKGEkuHaVotujI81dcnyhBNHTCr7YXXhBfWXvUjZtSisoEWchll82d6O8Xe3iChZ 62T3FX+X6/JLAJ2JjUMfgcIiNYldDq6JeXpfcHK+Y1hUlQb6voZz4rQu1Vu8cEdhCv cDvmewy55PhIk4VsZnVi+BDB7zhSLU1eyvkUQds8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D57E03858D37 for ; Wed, 19 Apr 2023 13:58:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D57E03858D37 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-49-Wozhplg5P5mpVy5MwKMJYw-1; Wed, 19 Apr 2023 09:58:27 -0400 X-MC-Unique: Wozhplg5P5mpVy5MwKMJYw-1 Received: by mail-qv1-f72.google.com with SMTP id z7-20020a0cd787000000b005e8bb5961b3so15039327qvi.7 for ; Wed, 19 Apr 2023 06:58:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681912706; x=1684504706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rRmx6o/0M27Ci7AUJnnF4ye3AfWz/oUZ3PGh+V+oi3U=; b=IxO3ma6kJ3YzS86YlC+J/2JsxUp2Y4Pc/y4Kpnceieaa3PaL0zfswulGyRf1RTdLj4 G7GboTIGC0WWT93bnmvaR9A548PA5CERZLXmWAn+LpHu/2qv0QyAblQkqgE1mnhcXNG4 E3MVEawOsk1EfRaySNWKVEmMfyEfJyq4+mfRl3xnMtMu5pqxbzoPR0NPEczSN4FoUqal XOqTDz8ABl4uAAao/QqjtzmdEU/7EuUQr6znthSk7UdXWMIvKcWJxdS25XjT9UmRC4l8 3LNrogbhNPvyqDdhiSBfRrl4WsdGqmPoZCLzfOB2j237xi0KTiCQ9ucCuHYVNAHzNl2S 4VEw== X-Gm-Message-State: AAQBX9fqLM1iZsJacYEQ0e3i4MdRmwRpLF+Jx+Y6v+aXF8g9e07AdgrK WvjmbOHNe5Wa3HRuu6ZzA9ydMstCsE2O/qpwYnuaompFf7kAveO9EyhtBJxVvxZSYsviBgImZ7J GCRbwI0HRQsXG0R1r+WDcoQI3EksER+5THTZuKs952AWGxFS94713XQcJVkGU3rpvURYOy6pb8s LWHgcY X-Received: by 2002:ad4:5b8b:0:b0:5ea:c6f7:6d53 with SMTP id 11-20020ad45b8b000000b005eac6f76d53mr25225712qvp.31.1681912706562; Wed, 19 Apr 2023 06:58:26 -0700 (PDT) X-Google-Smtp-Source: AKy350Y5zwIwgHNo4a5OHy6Bkq/yhg6TOcYgTq2F7x86WFbJof5BqREh5PP89+SOQkOS6o9w01WH4A== X-Received: by 2002:ad4:5b8b:0:b0:5ea:c6f7:6d53 with SMTP id 11-20020ad45b8b000000b005eac6f76d53mr25225635qvp.31.1681912705604; Wed, 19 Apr 2023 06:58:25 -0700 (PDT) Received: from oak.redhat.com (c-71-206-142-238.hsd1.va.comcast.net. [71.206.142.238]) by smtp.gmail.com with ESMTPSA id ks7-20020a056214310700b005e8f61012e0sm4366953qvb.27.2023.04.19.06.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 06:58:24 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v5 1/3] x86_64: Set the syscall register right before doing the syscall. Date: Wed, 19 Apr 2023 09:58:19 -0400 Message-Id: <20230419135821.4113156-2-josimmon@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230419135821.4113156-1-josimmon@redhat.com> References: <20230411133004.2268170-1-josimmon@redhat.com> <20230419135821.4113156-1-josimmon@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Joe Simmons-Talbott via Libc-alpha From: Joe Simmons-Talbott Reply-To: Joe Simmons-Talbott Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" To make identifying syscalls easier during call tree analysis load the syscall number just before performing the syscall. Compiler optimizations can place quite a few instructions between the setting of the syscall number and the syscall instruction. During call tree analysis the number of instructions between the two can lead to more difficulty for both tools and humans in properly identifying the syscall number. Having the syscall number set in the prior instruction to the syscall instruction makes this task easier and less error prone. Being able to reliably identify syscalls made by a given API will make it easier to understand and verify the safety and security of glibc. --- sysdeps/unix/sysv/linux/x86_64/sysdep.h | 27 ++++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h index cfb51be8c5..fd9eb4b02f 100644 --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h @@ -250,6 +250,9 @@ (long int) resultvar; \ }) +#define MSTR_HELPER(x) #x +#define MSTR(x) MSTR_HELPER(x) + #undef internal_syscall1 #define internal_syscall1(number, arg1) \ ({ \ @@ -257,9 +260,9 @@ TYPEFY (arg1, __arg1) = ARGIFY (arg1); \ register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \ asm volatile ( \ - "syscall\n\t" \ + "movl %1, %k0\n\tsyscall\n\t" \ : "=a" (resultvar) \ - : "0" (number), "r" (_a1) \ + : "g" (number), "r" (_a1) \ : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \ (long int) resultvar; \ }) @@ -273,9 +276,9 @@ register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \ register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \ asm volatile ( \ - "syscall\n\t" \ + "movl %1, %k0\n\tsyscall\n\t" \ : "=a" (resultvar) \ - : "0" (number), "r" (_a1), "r" (_a2) \ + : "g" (number), "r" (_a1), "r" (_a2) \ : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \ (long int) resultvar; \ }) @@ -291,9 +294,9 @@ register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \ register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \ asm volatile ( \ - "syscall\n\t" \ + "movl %1, %k0\n\tsyscall\n\t" \ : "=a" (resultvar) \ - : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3) \ + : "g" (number), "r" (_a1), "r" (_a2), "r" (_a3) \ : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \ (long int) resultvar; \ }) @@ -311,9 +314,9 @@ register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \ register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \ asm volatile ( \ - "syscall\n\t" \ + "movl %1, %k0\n\tsyscall\n\t" \ : "=a" (resultvar) \ - : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4) \ + : "g" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4) \ : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \ (long int) resultvar; \ }) @@ -333,9 +336,9 @@ register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \ register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \ asm volatile ( \ - "syscall\n\t" \ + "movl %1, %k0\n\tsyscall\n\t" \ : "=a" (resultvar) \ - : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \ + : "g" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \ "r" (_a5) \ : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \ (long int) resultvar; \ @@ -358,9 +361,9 @@ register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \ register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \ asm volatile ( \ - "syscall\n\t" \ + "movl %1, %k0\n\tsyscall\n\t" \ : "=a" (resultvar) \ - : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \ + : "g" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \ "r" (_a5), "r" (_a6) \ : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \ (long int) resultvar; \ From patchwork Wed Apr 19 13:58:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Simmons-Talbott X-Patchwork-Id: 1770749 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=GxmD4ZtR; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q1j7d1jHWz1ybF for ; Wed, 19 Apr 2023 23:58:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 025023856DFC for ; Wed, 19 Apr 2023 13:58:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 025023856DFC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681912731; bh=pqVlhb74m4PzlBkGvZvanDQH+Ljkh3bgwE2tW+vK+qk=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=GxmD4ZtR8OKTSIQe8pI7oicdoVoGoNdXjnmDtuZZPFrx93N7f+uI7FpwzJnjkwW9z 3IG5cFePICK5hOGlTtjRVP1i8FFbF13UjO4LDU6HgxZ6HwswcjxtGYePWgqW+s0Mj4 fyVZB8UHv3Reoi2n/pZG6FoGoenkdPsiWXSfeS+A= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 067963858D39 for ; Wed, 19 Apr 2023 13:58:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 067963858D39 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-90-UXU-lXtKPay0f9RZUETS0A-1; Wed, 19 Apr 2023 09:58:28 -0400 X-MC-Unique: UXU-lXtKPay0f9RZUETS0A-1 Received: by mail-qv1-f72.google.com with SMTP id j4-20020a0cc344000000b005e94fb0d2b0so14242085qvi.4 for ; Wed, 19 Apr 2023 06:58:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681912707; x=1684504707; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pqVlhb74m4PzlBkGvZvanDQH+Ljkh3bgwE2tW+vK+qk=; b=GkGz6ctwNMY2xd2oUbFYMDUWcdPglf7r2/8myRTsRk8dssA64tx54z+6HHuGTv1lcP x3zqTD2e4ShjDu+8D3b5I9C8b1wcxgYfSRnaBMEu9dVDNybyd85fl2PQbCcVl4FZX2kH 1Lsc9wHhkEnCQBhKvwD2ah9qB7La0WhBApT++v+1XNc6vUNLG1XAS5p8zmSF9mQAgxzK Pw4BNCDSVK8YzT4sJ0SGeYbP/OHlc17Qcri1k3YpYIObn2NG+PRtbVOyvRVDojD5qAbk JJOTQJYrqm7sJrb/bv6/NTJ+kk7xLMh3MqUfrwgcMOCP5oNGpy8b0pF6syTrha7fVyG7 Ij1g== X-Gm-Message-State: AAQBX9dB7TciLvp76jHatajJ54pJQuOYMJ0cywtFa5WrERMoiuaVOr6n 9MM1S6F+KeoWal/8CQ4SArHTAdZv1Q9eadIsmyXz87dyYR9nIsniozhgJH+CLG4fZfio4v9X/mj pEu/B0kyN1+y5uS8DavacVbDXcIS2A7AB4Ll6NMOmMdlzC92gsG5xu9xzRLqLUidYRuQmX8Dz2r iK2m9T X-Received: by 2002:a05:6214:19cb:b0:5f1:89ba:c0b4 with SMTP id j11-20020a05621419cb00b005f189bac0b4mr4351483qvc.48.1681912707765; Wed, 19 Apr 2023 06:58:27 -0700 (PDT) X-Google-Smtp-Source: AKy350Z6n5z4eXpMqGvEiK3BqP2tpaNgW/rSwXyRIgAzMCOHEfqP++ZJUquXrahX4IELu6pKuTLo7Q== X-Received: by 2002:a05:6214:19cb:b0:5f1:89ba:c0b4 with SMTP id j11-20020a05621419cb00b005f189bac0b4mr4351457qvc.48.1681912707510; Wed, 19 Apr 2023 06:58:27 -0700 (PDT) Received: from oak.redhat.com (c-71-206-142-238.hsd1.va.comcast.net. [71.206.142.238]) by smtp.gmail.com with ESMTPSA id ks7-20020a056214310700b005e8f61012e0sm4366953qvb.27.2023.04.19.06.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 06:58:26 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v5 2/3] aarch64: Set the syscall register right before doing the syscall. Date: Wed, 19 Apr 2023 09:58:20 -0400 Message-Id: <20230419135821.4113156-3-josimmon@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230419135821.4113156-1-josimmon@redhat.com> References: <20230411133004.2268170-1-josimmon@redhat.com> <20230419135821.4113156-1-josimmon@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Joe Simmons-Talbott via Libc-alpha From: Joe Simmons-Talbott Reply-To: Joe Simmons-Talbott Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" To make identifying syscalls easier during call tree analysis load the syscall number just before performing the syscall. Compiler optimizations can place quite a few instructions between the setting of the syscall number and the syscall instruction. During call tree analysis the number of instructions between the two can lead to more difficulty for both tools and humans in properly identifying the syscall number. Having the syscall number set in the prior instruction to the syscall instruction makes this task easier and less error prone. Being able to reliably identify syscalls made by a given API will make it easier to understand and verify the safety and security of glibc. --- sysdeps/unix/sysv/linux/aarch64/sysdep.h | 29 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h index e94d1703ad..6fe40aaf89 100644 --- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h +++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h @@ -168,15 +168,26 @@ # define HAVE_CLONE3_WRAPPER 1 # undef INTERNAL_SYSCALL_RAW -# define INTERNAL_SYSCALL_RAW(name, nr, args...) \ - ({ long _sys_result; \ - { \ - LOAD_ARGS_##nr (args) \ - register long _x8 asm ("x8") = (name); \ - asm volatile ("svc 0 // syscall " # name \ - : "=r" (_x0) : "r"(_x8) ASM_ARGS_##nr : "memory"); \ - _sys_result = _x0; \ - } \ +# define INTERNAL_SYSCALL_RAW(name, nr, args...) \ + ({ long _sys_result; \ + { \ + LOAD_ARGS_##nr (args) \ + if (__builtin_constant_p(name)) \ + asm volatile ("mov x8, %1 // syscall " # name "\n" \ + "svc 0" \ + : "=r" (_x0) \ + : "i" (name) ASM_ARGS_##nr \ + : "x8", "memory"); \ + else \ + { \ + register long _x8 asm ("x8") = (name); \ + asm volatile ("svc 0\n\t" \ + : "=r" (_x0) \ + : "r"(_x8) ASM_ARGS_##nr \ + : "memory"); \ + } \ + _sys_result = _x0; \ + } \ _sys_result; }) # undef INTERNAL_SYSCALL From patchwork Wed Apr 19 13:58:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Simmons-Talbott X-Patchwork-Id: 1770750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=k4yt/FIx; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q1j8H5rbsz1ybF for ; Wed, 19 Apr 2023 23:59:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB5C3385702F for ; Wed, 19 Apr 2023 13:59:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB5C3385702F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681912765; bh=7SIiizsCRGCFrR7j0QDf6fo6H/b1wYWN8VDWlr7SfJQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=k4yt/FIxleN05zHQuAPjkqqChSiEKWbMMhUax+NJUuqzEVY4m2K3xKL5M+P1roNha rTY+v6v+5AQ5YOZN0agmlOoy26fTm4l7T46EDiowLhvgW881KjOZXg70twiw9w25ww tbKuWP0sbA9W387yANrpcYME8i9riWw638FlNEYI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 593643858425 for ; Wed, 19 Apr 2023 13:58:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 593643858425 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-593-hDuzT7ZSO0yHpWhN067vyg-1; Wed, 19 Apr 2023 09:58:30 -0400 X-MC-Unique: hDuzT7ZSO0yHpWhN067vyg-1 Received: by mail-qk1-f197.google.com with SMTP id r80-20020a374453000000b0074e1df79468so97946qka.3 for ; Wed, 19 Apr 2023 06:58:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681912709; x=1684504709; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7SIiizsCRGCFrR7j0QDf6fo6H/b1wYWN8VDWlr7SfJQ=; b=NLwHE5+GtLsgPWeMeZzovxYI/uUBUu2OCoEiTtdi8+4z1JDMzzKzkJMWEcZiEQW8cy OSCGthIKi5EsbeFovoCy1qPTJQ+tYCdB0RSBW0EL/LkXLQ+7QoAOVsL+AhjVkh09MX4L RHBP8g1rloPsO9au9L/k+M2kv+TsgX2zeWXmGAIZshDVfSlKzqs1cxMK3WeX/1Az9fJS x7J32Spa2LhNbVuWeHY5JzORWCPQb8zdQl30+QrAYrqtCB7yP2nO7gG2ds6r/8imgLDv s9VHEvISfqX8CWdmK4VJ9fhSnXrrYwh/Fn5qnvx0JpkQq113X3Olk0p+ha9DYTgRkmVj zj8g== X-Gm-Message-State: AAQBX9drQgN/g0X9QXrB9eeq2wFM6t/NoUQXOZEr/dQsNlE+czLYJpYb 1xJ/ZBGNh7whaYVsBrVWwS6BPmRfuj/GQZdpgjgkPkF3SnM0AE4GUbPOJQTPX7ziuOvAkIMEyfR 90yyp4Boq7ZMS8zFiy18k3eEwiSHLkraMXhHa/yr0dKZC/xKbh7q1xweNYBz+Ui76T8dVI+yr9G ebT08v X-Received: by 2002:a05:6214:621:b0:570:5389:2216 with SMTP id a1-20020a056214062100b0057053892216mr3624419qvx.22.1681912709065; Wed, 19 Apr 2023 06:58:29 -0700 (PDT) X-Google-Smtp-Source: AKy350bo4lxP6oVEC7sv4syAViPpg0uNQDvypHaXycQmpru/Td/cHtJzP7CmdhJRmCyvv8J/Ynt0hg== X-Received: by 2002:a05:6214:621:b0:570:5389:2216 with SMTP id a1-20020a056214062100b0057053892216mr3624391qvx.22.1681912708745; Wed, 19 Apr 2023 06:58:28 -0700 (PDT) Received: from oak.redhat.com (c-71-206-142-238.hsd1.va.comcast.net. [71.206.142.238]) by smtp.gmail.com with ESMTPSA id ks7-20020a056214310700b005e8f61012e0sm4366953qvb.27.2023.04.19.06.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 06:58:28 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v5 3/3] nptl: Use direct syscall numbers in setxid Date: Wed, 19 Apr 2023 09:58:21 -0400 Message-Id: <20230419135821.4113156-4-josimmon@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230419135821.4113156-1-josimmon@redhat.com> References: <20230411133004.2268170-1-josimmon@redhat.com> <20230419135821.4113156-1-josimmon@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Joe Simmons-Talbott via Libc-alpha From: Joe Simmons-Talbott Reply-To: Joe Simmons-Talbott Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Make all internal glibc syscalls use direct compile time numeric values rather than variables. This will make the syscall number easier to identify during static analysis. --- nptl/nptl_setxid.c | 136 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 132 insertions(+), 4 deletions(-) diff --git a/nptl/nptl_setxid.c b/nptl/nptl_setxid.c index 4bfcfe4188..797015def1 100644 --- a/nptl/nptl_setxid.c +++ b/nptl/nptl_setxid.c @@ -66,8 +66,72 @@ __nptl_setxid_sighandler (int sig, siginfo_t *si, void *ctx) || si->si_code != SI_TKILL) return; - result = INTERNAL_SYSCALL_NCS (xidcmd->syscall_no, 3, xidcmd->id[0], - xidcmd->id[1], xidcmd->id[2]); + switch(xidcmd->syscall_no) + { +#ifdef __NR_setuid32 + case __NR_setuid32: + result = INTERNAL_SYSCALL_NCS (__NR_setuid32, 3, xidcmd->id[0], + xidcmd->id[1], xidcmd->id[2]); + break; +#endif /* __NR_setuid32 */ + case __NR_setuid: + result = INTERNAL_SYSCALL_NCS (__NR_setuid, 3, xidcmd->id[0], + xidcmd->id[1], xidcmd->id[2]); + break; +#ifdef __NR_setreuid32 + case __NR_setreuid32: + result = INTERNAL_SYSCALL_NCS (__NR_setreuid32, 3, xidcmd->id[0], + xidcmd->id[1], xidcmd->id[2]); + break; +#endif /* __NR_setreuid32 */ + case __NR_setreuid: + result = INTERNAL_SYSCALL_NCS (__NR_setreuid, 3, xidcmd->id[0], + xidcmd->id[1], xidcmd->id[2]); + break; +#ifdef __NR_setresgid32 + case __NR_setresgid32: + result = INTERNAL_SYSCALL_NCS (__NR_setresgid32, 3, xidcmd->id[0], + xidcmd->id[1], xidcmd->id[2]); + break; +#endif /* __NR_setresgid32 */ + case __NR_setresgid: + result = INTERNAL_SYSCALL_NCS (__NR_setresgid, 3, xidcmd->id[0], + xidcmd->id[1], xidcmd->id[2]); + break; +#ifdef __NR_setregid32 + case __NR_setregid32: + result = INTERNAL_SYSCALL_NCS (__NR_setregid32, 3, xidcmd->id[0], + xidcmd->id[1], xidcmd->id[2]); + break; +#endif /* __NR_setregid32 */ + case __NR_setregid: + result = INTERNAL_SYSCALL_NCS (__NR_setregid, 3, xidcmd->id[0], + xidcmd->id[1], xidcmd->id[2]); + break; +#ifdef __NR_setgid32 + case __NR_setgid32: + result = INTERNAL_SYSCALL_NCS (__NR_setgid32, 3, xidcmd->id[0], + xidcmd->id[1], xidcmd->id[2]); + break; +#endif /* __NR_setgid32 */ + case __NR_setgid: + result = INTERNAL_SYSCALL_NCS (__NR_setgid, 3, xidcmd->id[0], + xidcmd->id[1], xidcmd->id[2]); + break; +#ifdef __NR_setgroups32 + case __NR_setgroups32: + result = INTERNAL_SYSCALL_NCS (__NR_setgroups32, 3, xidcmd->id[0], + xidcmd->id[1], xidcmd->id[2]); + break; +#endif /* __NR_setgroups32 */ + case __NR_setgroups: + result = INTERNAL_SYSCALL_NCS (__NR_setgroups, 3, xidcmd->id[0], + xidcmd->id[1], xidcmd->id[2]); + break; + default: + result = INTERNAL_SYSCALL_NCS (xidcmd->syscall_no, 3, xidcmd->id[0], + xidcmd->id[1], xidcmd->id[2]); + } int error = 0; if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result))) error = INTERNAL_SYSCALL_ERRNO (result); @@ -262,8 +326,72 @@ __nptl_setxid (struct xid_command *cmdp) /* This must be last, otherwise the current thread might not have permissions to send SIGSETXID syscall to the other threads. */ - result = INTERNAL_SYSCALL_NCS (cmdp->syscall_no, 3, - cmdp->id[0], cmdp->id[1], cmdp->id[2]); + switch(cmdp->syscall_no) + { +#ifdef __NR_setuid32 + case __NR_setuid32: + result = INTERNAL_SYSCALL_NCS (__NR_setuid32, 3, cmdp->id[0], + cmdp->id[1], cmdp->id[2]); + break; +#endif /* __NR_setuid32 */ + case __NR_setuid: + result = INTERNAL_SYSCALL_NCS (__NR_setuid, 3, cmdp->id[0], + cmdp->id[1], cmdp->id[2]); + break; +#ifdef __NR_setreuid32 + case __NR_setreuid32: + result = INTERNAL_SYSCALL_NCS (__NR_setreuid32, 3, cmdp->id[0], + cmdp->id[1], cmdp->id[2]); + break; +#endif /* __NR_setreuid32 */ + case __NR_setreuid: + result = INTERNAL_SYSCALL_NCS (__NR_setreuid, 3, cmdp->id[0], + cmdp->id[1], cmdp->id[2]); + break; +#ifdef __NR_setresgid32 + case __NR_setresgid32: + result = INTERNAL_SYSCALL_NCS (__NR_setresgid32, 3, cmdp->id[0], + cmdp->id[1], cmdp->id[2]); + break; +#endif /* __NR_setresgid32 */ + case __NR_setresgid: + result = INTERNAL_SYSCALL_NCS (__NR_setresgid, 3, cmdp->id[0], + cmdp->id[1], cmdp->id[2]); + break; +#ifdef __NR_setregid32 + case __NR_setregid32: + result = INTERNAL_SYSCALL_NCS (__NR_setregid32, 3, cmdp->id[0], + cmdp->id[1], cmdp->id[2]); + break; +#endif /* __NR_setregid32 */ + case __NR_setregid: + result = INTERNAL_SYSCALL_NCS (__NR_setregid, 3, cmdp->id[0], + cmdp->id[1], cmdp->id[2]); + break; +#ifdef __NR_setgid32 + case __NR_setgid32: + result = INTERNAL_SYSCALL_NCS (__NR_setgid32, 3, cmdp->id[0], + cmdp->id[1], cmdp->id[2]); + break; +#endif /* __NR_setgid32 */ + case __NR_setgid: + result = INTERNAL_SYSCALL_NCS (__NR_setgid, 3, cmdp->id[0], + cmdp->id[1], cmdp->id[2]); + break; +#ifdef __NR_setgroups32 + case __NR_setgroups32: + result = INTERNAL_SYSCALL_NCS (__NR_setgroups32, 3, cmdp->id[0], + cmdp->id[1], cmdp->id[2]); + break; +#endif /* __NR_setgroups32 */ + case __NR_setgroups: + result = INTERNAL_SYSCALL_NCS (__NR_setgroups, 3, cmdp->id[0], + cmdp->id[1], cmdp->id[2]); + break; + default: + result = INTERNAL_SYSCALL_NCS (cmdp->syscall_no, 3, cmdp->id[0], + cmdp->id[1], cmdp->id[2]); + } int error = 0; if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result))) {