Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4983084pxy; Tue, 27 Apr 2021 17:48:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJuD7NMV/L6i5yP7xEWtoXXE7UbMyMCrpTi0vdg9G3GdalGdgJUogxkUMNf2yOUTTgEBt2 X-Received: by 2002:a63:d74e:: with SMTP id w14mr11688233pgi.111.1619570904756; Tue, 27 Apr 2021 17:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619570904; cv=none; d=google.com; s=arc-20160816; b=c0zHiDbB8OkjEvmm7APSp621VnO59YJ8qulzDH2qsiQI5VeuSSbN2FbPr+/Ajt0OoI oD1gRjWqwPVUL1/RfYTBxFEyUd5NcecZeoktqLFHD/j3pGyLIAyroMmflKfTlH0U0SeF 8EA+sAjNWrLIGxQoaOkypVt/Q11h3+i9dSwfy0eNEyTEeNpcVP1JObkiI9qqhOwFx1iG fTpMsBzgUT3arsw66ce6mJzPsqHtlK9p/gxfeftiwlPRMnnrR+x8Gbj37DYF59sO4mXf UYArZ43WMr75ge/zft9dSG4BEowF8w44BQrxd1vcu2fI7ZsxyfqvLFcboBLwZMqZtZvD ACoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject:dkim-signature:dkim-filter; bh=dmXauy4p/ZbgFoR9+NLZaIKYk51ve+/9HGzgV4ivmlo=; b=TuZtxcjBucoBR9u5tulHfSwEqJeOha3juRD37ZH1hIH+taq4zWesR1ZyJ219Gl17ut UJZ6GMoL0Ac+X2JlnlublCgFWzYSA811guJb1R7Oe9nmB8D9hL2vkJ5dohRPllvWP6Ty zClpJiWZPaE6wYKyh+8rWX67NmiFgti1SK6V1Rebxj1nxfANBrEuvBdhn4L223XgViR+ R3cIfiZUHRKqqAWVWf0y2CRjr/ahmQ9exnqVbFXsMp/GEXWltsTNHA4cuIu2DjbxdE0N v5Z/lfV3U7r0aJbjELgiot/P1Kab38QIsWRMi4AIqx2T5bx3J3EEyxd4CHhf5lg8bJyO XhCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2021032801 header.b=H1c9xSxV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ei21si2445785pjb.1.2021.04.27.17.48.08; Tue, 27 Apr 2021 17:48:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2021032801 header.b=H1c9xSxV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235691AbhD1Arv (ORCPT + 99 others); Tue, 27 Apr 2021 20:47:51 -0400 Received: from terminus.zytor.com ([198.137.202.136]:45847 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230368AbhD1Aru (ORCPT ); Tue, 27 Apr 2021 20:47:50 -0400 Received: from tazenda.hos.anvin.org ([IPv6:2601:646:8602:8be0:7285:c2ff:fefb:fd4]) (authenticated bits=0) by mail.zytor.com (8.16.1/8.15.2) with ESMTPSA id 13S0klxe959418 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Tue, 27 Apr 2021 17:46:50 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 13S0klxe959418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2021032801; t=1619570813; bh=dmXauy4p/ZbgFoR9+NLZaIKYk51ve+/9HGzgV4ivmlo=; h=Subject:From:To:Cc:References:Date:In-Reply-To:From; b=H1c9xSxVl6ReDt1lyolUEzmpdZcBKTlHspe6Xu3xLQtDTNgN0FGOXYTpVobb1DbFt NmXpyUu/n+m5XxTu2w61n8l5p3A/r7trSh56C4VJJHEOX9D4+pqvPPd1wej8TyWjiN CUnGRcXxsPjjU34RhitKOYldu+yOowDuap/vzvhK4kYCxy5Ta+GwvSF/HBS2TBGpqm uNi6YwFXJaRTk/HJ3XEoJAASqkLMfBQRdhMsvzdLw97LmW8lZiVLF/lmK8l7WFLtoN EuG53rdhc8JwC+PuAMq0TECMmXWNHT3thsZ5lGbgI0UkSPI5CppDRRQ8d3t3DbMyuY OGFk2IYygp1Rg== Subject: Re: pt_regs->ax == -ENOSYS From: "H. Peter Anvin" To: Andy Lutomirski Cc: Linus Torvalds , Ingo Molnar , Thomas Gleixner , Borislav Petkov , LKML , Oleg Nesterov , Kees Cook , Will Drewry References: <06a5e088-b0e6-c65e-73e6-edc740aa4256@zytor.com> <3626eea3-524e-4dbd-78dd-9ade5a346a08@zytor.com> <3a502aae-4124-5cb2-1dac-bc18b8158fbe@zytor.com> Message-ID: <87bda691-9201-06cd-9850-c92a05a399c7@zytor.com> Date: Tue, 27 Apr 2021 17:46:42 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <3a502aae-4124-5cb2-1dac-bc18b8158fbe@zytor.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/27/21 5:20 PM, H. Peter Anvin wrote: > > We *used* to truncate the system call number; that was unsigned. It > causes massive headache to ptrace if a 32-bit ptrace wants to write -1, > which is a bit hacky. > > I would personally like to see orig_ax to be the register passed in and > for the truncation to happen by syscall_get_nr(). > > I also note that kernel/seccomp.c and the tracing infrastructure all > expect a signed int as the system call number. Yes, orig_ax is a 64-bit > field, but so are the other register fields which doesn't necessarily > directly reflect the value of an argument -- like, say, %rdi in the case > of sys_write - it is an int argument so it gets sign extended; this is > *not* reflected in ptrace. > >     -hpa We could even do this, to make it perhaps harder to mess up: diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h index 409f661481e1..4e8e5c2e35f4 100644 --- a/arch/x86/include/asm/ptrace.h +++ b/arch/x86/include/asm/ptrace.h @@ -41,7 +41,10 @@ struct pt_regs { unsigned short gs; unsigned short __gsh; /* On interrupt, this is the error code. */ - unsigned long orig_ax; + union { + unsigned long orig_ax; + int syscall_nr; + }; unsigned long ip; unsigned short cs; unsigned short __csh; @@ -78,7 +81,10 @@ struct pt_regs { * On syscall entry, this is syscall#. On CPU exception, this is error code. * On hw interrupt, it's IRQ number: */ - unsigned long orig_ax; + union { + unsigned long orig_ax; + int syscall_nr; + }; /* Return frame for iretq */ unsigned long ip; unsigned long cs;