From patchwork Mon Apr 17 21:20:34 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: 1769864 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=Cb8hwOBV; 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 4Q0g2l3Cfpz1yZr for ; Tue, 18 Apr 2023 07:21:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6FF133856967 for ; Mon, 17 Apr 2023 21:21:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FF133856967 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681766461; bh=GqinhCm6/laQq8Y7vGTYum2iSmN3JT/vb/7qgG7EqqY=; 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=Cb8hwOBV43A62rYf7a6YhsLerREPZw1moQDjXlcvs7KgFKriKBbHu6n3diUYgVE9o 1vOSDW0JSFJ5gh3siFljXGvTDjHWqhKRdpI5IPGsbQqLUT1jWogP8E4d+Pr2u2LUai oR55e4rXqBmv0gymO1cxYv4KcI+sOzmMN3fvbYAA= 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 1BA833858422 for ; Mon, 17 Apr 2023 21:20:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BA833858422 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-145-Z6bDT4zlMg6pPcoPdCOjKQ-1; Mon, 17 Apr 2023 17:20:41 -0400 X-MC-Unique: Z6bDT4zlMg6pPcoPdCOjKQ-1 Received: by mail-qk1-f199.google.com with SMTP id t65-20020ae9df44000000b0074ac7436042so6715889qkf.4 for ; Mon, 17 Apr 2023 14:20:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681766441; x=1684358441; 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=GqinhCm6/laQq8Y7vGTYum2iSmN3JT/vb/7qgG7EqqY=; b=i8RQACnkhTl0Aq6izRk0YJAZo++qViRTZ+GbCEoFOW8jI6/6sIOBSHVhMiNc76jeH0 mj+02IQaouldh3BkCCLte70LGQ2YgPqAf/K2jbd4dw6QdRXda7/M6BcNhSN7wZKILKWC kbfBosqpRcPTcIDSCEhPjlDHy4xh0zBcWEyM1UZorCE1+ChjseStnK0DDd14lcik8PGR TQrj9mRbSDyegJfpj40FGP13OQ+r0oje1maf7+h3TceORDtz2/9y1lP9/9ev6kLojYTW Of/B+qVCtDL8nduIze/C0vl7BP6UikH+DAtrwOEODijPksefbCvi1INbQH2QQB2xL2J5 yB9Q== X-Gm-Message-State: AAQBX9fGGGI0gNqShW749RyLD7jf6yMOaoUgHzCWFEifMr9SdcI+SzET 1x7pWxvRGZ1TFygoELUkw1YcAg01BWqeIVhH0+VRJp7okWUngH0PdA9iYAv3cezVoDw9vWk3my3 lgDINTPxxoLzuoDX/mfFo+jETojJ9++sJMXGEYM+7z7Rap/5K9vdt/wJXqENFGfZZT1wnFpGPjq YZ7Vfl X-Received: by 2002:a05:6214:400b:b0:5ef:741a:6c0b with SMTP id kd11-20020a056214400b00b005ef741a6c0bmr7837184qvb.29.1681766440801; Mon, 17 Apr 2023 14:20:40 -0700 (PDT) X-Google-Smtp-Source: AKy350YenhwBQzA8CD6rXBKnlD0/vPUlJEByxjZZf+ZXexS+XxL2V3UI01SBlIcUMR7hFCkv5HtGUg== X-Received: by 2002:a05:6214:400b:b0:5ef:741a:6c0b with SMTP id kd11-20020a056214400b00b005ef741a6c0bmr7837157qvb.29.1681766440421; Mon, 17 Apr 2023 14:20:40 -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 q1-20020ad44341000000b005ef817d14casm668666qvs.83.2023.04.17.14.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 14:20:39 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v4 2/2] aarch64: Set the syscall register right before doing the syscall. Date: Mon, 17 Apr 2023 17:20:34 -0400 Message-Id: <20230417212034.3890596-3-josimmon@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417212034.3890596-1-josimmon@redhat.com> References: <20230411133004.2268170-1-josimmon@redhat.com> <20230417212034.3890596-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 | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h index e94d1703ad..b91656fdff 100644 --- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h +++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h @@ -167,14 +167,28 @@ # define HAVE_CLONE3_WRAPPER 1 +# define MSTR_HELPER(x) # x +# define MSTR(x) MSTR_HELPER(x) + # 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"); \ + if (__builtin_constant_p(name)) \ + asm volatile ("mov x8, %1\n" \ + "svc 0 // syscall " # name \ + : "=r" (_x0) \ + : "i" (name) ASM_ARGS_##nr \ + : "x8", "memory"); \ + else \ + { \ + register long _x8 asm ("x8") = (name); \ + asm volatile ("svc 0 // syscall " # name \ + : "=r" (_x0) \ + : "r"(_x8) ASM_ARGS_##nr \ + : "memory"); \ + } \ _sys_result = _x0; \ } \ _sys_result; })