Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1689346pxj; Wed, 19 May 2021 11:31:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoKuWDaWMhWFR/rPeeWyqNH0O+jnks92hV5y9NZsSpkG0+wYqxgX+l0LliPZKKpPntTJI0 X-Received: by 2002:a17:906:5285:: with SMTP id c5mr508211ejm.282.1621449086272; Wed, 19 May 2021 11:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621449086; cv=none; d=google.com; s=arc-20160816; b=vGwZ1dOMU/aHBd47jLNsanTcGDdHbrG1FYekTD14vvIsODgHafqkwY7FpEKbPxbwEv aouw7fuHe5M48C9cnVZ5miyY7GW6Pqy0SMaLA6lByqO+XvGCaagcTc1LWMk/DJ+ibHi4 hbH7v9not2o8E37e5z+/MC0nI4kMXRPzbjkIkkdg+S0IElhE+dOgLb04y4emMGcHc5Z6 ls/pXCK44gH4QNNc+q9rvRPH0i+JYrpc+DR525+RZP5n1vc0OAyjzdSvlDt0ic9oH0I3 W9NtN4dAP1Q2Ydia9gvi8s9Y+HBmGWZgVxbFjPeWLNuDVtj6hIoltk9k8Q6Bi3D6MVVT W2rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=IkUrDnceIqhS7bpGhoBC0Vs+gxODxl4zuCvI4QlIfko=; b=zyQC4xoekDwruDcUlAmltOJrE1lr6q9CF9aIpiAFdja88vYeXVVjep5BQxXbXtUx/E Q9DsYQq8pkAG8A30BKhUewWsJ2qxmmpuBo12BXxtTVISkumCd5Y/6YEvpJr7RKZvs4TA caM9xtH3kbGyq4CHeqNClxalqASGGAD8HuTPza7xxXACkDE2pLu5Abi+SOfvHvIUOduc pJ0DwmLDlrZ+X13eBUg/+VVJJUGKcOOlyZxK0x47Ad5GPRA8toNqjEYBsH5KMIE2UXVB o1cmd7mLQ2jzZX2bEYO5jHE+E+5z4qOt23pIuUXLAIWdGs9Fq8oh9kX8bii+BYQrL9Ei nViw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2021042801 header.b=Uq6AZPtP; 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 h3si3003edw.187.2021.05.19.11.31.01; Wed, 19 May 2021 11:31:26 -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=2021042801 header.b=Uq6AZPtP; 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 S1351610AbhERTPK (ORCPT + 99 others); Tue, 18 May 2021 15:15:10 -0400 Received: from terminus.zytor.com ([198.137.202.136]:40973 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241036AbhERTPE (ORCPT ); Tue, 18 May 2021 15:15:04 -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 14IJDDRm4008171 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 18 May 2021 12:13:22 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 14IJDDRm4008171 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2021042801; t=1621365210; bh=IkUrDnceIqhS7bpGhoBC0Vs+gxODxl4zuCvI4QlIfko=; h=From:To:Cc:Subject:Date:From; b=Uq6AZPtPn1+A9SCuD4XC8s2nlmNeuPV/t/+tB+E3gZ8UwFVaR8ZytsNLtp70csful UxkJP28s6nGUBXaQbYOUl60VDXb0X6CouCdeNM8Q4CQYKFWZ8wjTnlT/aHEzs0s8R+ Ps/ad2hon/XSawDBMzpTUGoqvWxsrEZxD3xogpyNahXxsg+JJAsXO9Fnac4jlcJN/o MIOFwN+uo4Rm2l/zgBGOiHo9boeMnoAwgLfYW6U1lXlmvio69H43DsqLZlQG94TmP3 SrW7NjYI0PqAAPqxTaiNcBrZh1wQ+wSHV46JRBOsiUQCCOoaXjUUvQi1L9ftPUJWay FFoQIvKgD6daQ== From: "H. Peter Anvin" To: Thomas Gleixner , Ingo Molnar , Andy Lutomirski , Borislav Petkov , "H. Peter Anvin" Cc: Linux Kernel Mailing List Subject: [PATCH v4 0/6] x86/syscall: use int for x86-64 system calls Date: Tue, 18 May 2021 12:12:57 -0700 Message-Id: <20210518191303.4135296-1-hpa@zytor.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "H. Peter Anvin (Intel)" This patchset addresses several inconsistencies in the handling of system call numbers in x86-64 (and x32). Right now, *some* code will treat e.g. 0x00000001_00000001 as a system call and some will not. Some of the code, notably in ptrace and seccomp, will treat 0x00000001_ffffffff as a system call and some will not. Furthermore, right now, e.g. 335 for x86-64 will force the exit code to be set to -ENOSYS even if poked by ptrace, but 548 will not, because there is an observable difference between an out of range system call and a system call number that falls outside the range of the tables. Both of these issues are visible to the user; for example the syscall_numbering_64 kernel selftest fails if run under ptrace for this reason (system calls succeed with the high bits set, whereas they fail when not being traced.) The architecture independent code in Linux expects "int" for the system call number, per the API documented, but not implemented, in : system call numbers are expected to be "int", with -1 as the only non-system-call sentinel. Treating the same data in multiple ways in different context is at the very best confusing, but it also has the potential to cause security problems (no such security problems are known at this time, however.) This is an ABI change, but it is in fact a return to the original x86-64 ABI: the original assembly entry code would zero-extend the system call number passed and only the bottom 32 bits were examined. 1. Consistently treat the system call number as a signed int. This is what syscall_get_nr() already does, and therefore what all architecture-independent code (e.g. seccomp) already expects. 2. As per the defined semantics of syscall_get_nr(), only the value -1 is defined as a non-system call, so comparing >= 0 is incorrect. Change to != -1. 3. Call sys_ni_syscall() for system calls which are out of range except for -1, which is used by ptrace and seccomp as a "skip system call" marker) just as for system call numbers that correspond to holes in the table. 4. Updates and extends the syscall_numbering_64 selftest, including testing the system call numbering when running under ptrace. Changes from v3: * Reorganize the patchset to have the selftest change first. * Add tests running under ptrace to selftest. Changes from v2: * Factor out and split what was a single patch in the v2 patchset; the rest of the patches have already been applied. * Fix the syscall_numbering_64 selftest to match the definition changes, make its output more informative, and extend it to more tests. Avoid using the glibc syscall() wrapper to make sure we test what we think we are testing. * Better documentation of the changes. Changes from v1: * Only -1 should be a non-system call per the cross-architectural definition of sys_ni_syscall(). * Fix/improve patch descriptions. --- arch/x86/entry/common.c | 93 +++-- arch/x86/entry/entry_64.S | 2 +- arch/x86/include/asm/syscall.h | 2 +- tools/testing/selftests/x86/syscall_numbering.c | 488 +++++++++++++++++++++--- 4 files changed, 508 insertions(+), 77 deletions(-)