From patchwork Wed Apr 19 13:58:18 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: 1770747 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=DXG4Oblk; 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 4Q1j7T3XZVz1ybF for ; Wed, 19 Apr 2023 23:58:45 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5FA9A385694D for ; Wed, 19 Apr 2023 13:58:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FA9A385694D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681912723; bh=VKnHtfOVro/p9A4uVAxFNPRXOt9wK8cgVhqLA7/Zfu0=; 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=DXG4OblkLOTlQEzZoCDl1jUKFHcrVhhkq2qYLKQ3cuiXCfOb311KAOkDMow+P71MP gzQjnljvPxw5vJ6buYdo+8s7K7r4JPu39yJ2P5V6IX59mkbOQ1WZnrWihoio3P/VQ8 oFr41XHeAHebmQfBiW83mYAwJIhfTOPpjeyuacnM= 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 1935B3858D33 for ; Wed, 19 Apr 2023 13:58:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1935B3858D33 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-634-acVCIpltP2aUAQQKbuErGQ-1; Wed, 19 Apr 2023 09:58:25 -0400 X-MC-Unique: acVCIpltP2aUAQQKbuErGQ-1 Received: by mail-qk1-f200.google.com with SMTP id r22-20020a37a816000000b0074abffe8a68so10297083qke.5 for ; Wed, 19 Apr 2023 06:58:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681912704; x=1684504704; 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=VKnHtfOVro/p9A4uVAxFNPRXOt9wK8cgVhqLA7/Zfu0=; b=ODGwgOqGgWcolT7/UhKQmxePfWfJYKRHFLtHgzjecAk57f+nApZ1N9rtTIniB6IPvH FOWpbaqArmjewri0ZPKp6w7MmFm4sCZwaingjeiEBDyNf/qMwjfqLRTwlPLAfwGLWveW pj8OEaB4ziRhZcoAucbkiBtugQ1q/z4od6sLYVFAyg8+qYJd1h5Dsl+UT+YfLWDRw1Y8 Ru4GotKe9q0v/v74PqD+aQML6gpz1cd0yCRuK790cWO30vk3WofRLYkdUVEWolyr+tbM HYzsDpVmw1ta3U/69b3Mk9SBgNcng3sl9V8BfZnXaqhAmOV/U9R33L9CZlgr2reZ+t1J X6IQ== X-Gm-Message-State: AAQBX9cIbnKSY0D1FGUweXQHEZF73zRQ7QI6ZiiWlgXd9kxeO9lKHShq 4W6zaajqrW2UnmiE5n3lb2q0lplarBfz2viS2XKENNUSIRFsMY++BGVuSSYGFkk41ySS/sMaGlf +NPVCsbtnPR/Nf+15Bd30pujO7q6adJDKCM3fbkMzty/NX+e4J1x8eOegbx7yUxFgKCMwt0qMKI yjeLN/ X-Received: by 2002:a05:6214:ac3:b0:5ef:8161:cb9a with SMTP id g3-20020a0562140ac300b005ef8161cb9amr5950495qvi.7.1681912704623; Wed, 19 Apr 2023 06:58:24 -0700 (PDT) X-Google-Smtp-Source: AKy350YLfTDH0xe3GiEUnBE58zQRrdISd1ps0jShA1QqN2stpUl/ThKGLSXbFTdjj9denfLi4pJfnQ== X-Received: by 2002:a05:6214:ac3:b0:5ef:8161:cb9a with SMTP id g3-20020a0562140ac300b005ef8161cb9amr5950456qvi.7.1681912704338; Wed, 19 Apr 2023 06:58:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 06:58:23 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v5 0/3] x86_64: aarch64: Set call number just before syscall Date: Wed, 19 Apr 2023 09:58:18 -0400 Message-Id: <20230419135821.4113156-1-josimmon@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411133004.2268170-1-josimmon@redhat.com> References: <20230411133004.2268170-1-josimmon@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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 binary call tree analysis easier place the syscall number into the register just before the syscall is made. Only do this if the syscall number is a constant integer. 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. Tested on x86_64 and aarch64. Changes to v4: * aarch64: Move generated comment. Remove unused macros from earlier version. * Added patch - nptl: Convert indirect syscall numbers to compile time numeric values. Changes to v3: * x86_64: Combine two inline asms into one. - Suggested by "H.J. Lu" Changes to v2: * Add a more detailed commit message. Changes to v1: * aarch64: Combine two inline asms into one. Avoid loading name twice. Joe Simmons-Talbott (3): x86_64: Set the syscall register right before doing the syscall. aarch64: Set the syscall register right before doing the syscall. nptl: Use direct syscall numbers in setxid nptl/nptl_setxid.c | 136 ++++++++++++++++++++++- sysdeps/unix/sysv/linux/aarch64/sysdep.h | 29 +++-- sysdeps/unix/sysv/linux/x86_64/sysdep.h | 27 +++-- 3 files changed, 167 insertions(+), 25 deletions(-)