Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1394077pxk; Sun, 13 Sep 2020 00:45:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/x6JvOyA3D9c52IvlhL662/vlwinCfS5bX5HOd7rRnQXaDTosKhBV0swnQB19MxGjlct2 X-Received: by 2002:a50:d98d:: with SMTP id w13mr12132118edj.37.1599983152488; Sun, 13 Sep 2020 00:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599983152; cv=none; d=google.com; s=arc-20160816; b=NtvPQGTDkX3gdbqZR18pWdIe0Wf9dHuoDsAi+Sb4MQSRpvIzCRac6sJRBm2ApuZ1VP V3YgSs3i5P0zaysY4qrHhcD56czkprUOWh14imCPzVfmrrx4uRvDLU7bOIqjEx6Hkoyx dwjvdn8IuCm6rxhstUrm/sivm7QbMp0aDdPZwg6oHLpuqqMXjhvUZwAUZcLI1OcG57/s pbdY2YGFusX91FloPAoUxi2xleltGUxgbIOVr65E8gSeyS80gJbB70UtgfIi4HhM531M i5+cp4OakAktfSGFiaWJ3x42wFp2VyLEP1H0drnaTqK1NGP9y6uaTISJXNQKmdFqcIJH qIDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=5zNF6K8gHni5PzsG38f7oD1jlVDT3xS+ei6jUnBOImw=; b=Nhbm1hNscZA51/Z30uHRSTJl+ITevCXFuRnWnD0k6v5Cn9sdPk9mVpns2dYTuecaEG WUzl4+ekFyQGmE7u/uDipW6Bg5xMowKrPm/BKu2eFn9LdWPQK4/gs00y0gBRJmPbxUh8 EqldexkC2zWXSpUWc7POnquvcQkn6Pw526xfzUWHaHMDVAG17s7MaU8hy5yBfQM/6781 sjDg2qeAN5Oe8bYppV8//LlO6VJiqtwb0C/W5oVlgG/Mh5rd3utB83RuWbdFsjhiABjV iZQqyuie+Bkig6NO9byoh6PQPHrP1L4SsEHPUsRwbpcgCGESRgbgVqNigpj4xbLf+26U Tlcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=YFWcemGv; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z15si5071564ejr.202.2020.09.13.00.45.18; Sun, 13 Sep 2020 00:45:52 -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=@ellerman.id.au header.s=201909 header.b=YFWcemGv; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725927AbgIMHoR (ORCPT + 99 others); Sun, 13 Sep 2020 03:44:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725912AbgIMHoP (ORCPT ); Sun, 13 Sep 2020 03:44:15 -0400 Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC729C061573; Sun, 13 Sep 2020 00:44:13 -0700 (PDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Bq1hp3411z9sTS; Sun, 13 Sep 2020 17:44:10 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1599983052; bh=czRzqse3LcOYZ30/6LCMJ8nuNlZbjy30OEAHsP1OmHU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=YFWcemGvYU4YxnGdEwoQv4snJqlwHLH2V/kScnwSVek6LrbZ23UmZRC1NQJHAh/3C 0VTCObFzg5Z0SQRWQ5CdFvb8rEiZZ+33WSEvHZwwlh+J13RLx+tV6Um0wZB7qZGEBF qETyK/vhO3DTKXyV3KdzLev30YnMyDmAfAvAxSAVZ9b5VLurhK6AJ9ldS1FMLzZNpR d9IKT7vsjaH+5g14Fk8v+3SG4FYe3nwMjje+7G8TCudb9NYWhPFtNDbpHxTExiE2+i Hl3FC+2HacrKuM/TirIre1WH0ujUH1h3If4gG0Gs3cUG6gKomVQD1agZzW0kuGez1y 5hVHV0d6sgHXg== From: Michael Ellerman To: Kees Cook Cc: Thomas Gleixner , Robert O'Callahan , LKML , "maintainer\:X86 ARCHITECTURE \(32-BIT AND 64-BIT\)" , linux-arch@vger.kernel.org, Will Deacon , Arnd Bergmann , Mark Rutland , Keno Fischer , Paolo Bonzini , kvm list , Gabriel Krisman Bertazi , Sean Christopherson , Kyle Huey Subject: Re: [REGRESSION] x86/entry: Tracer no longer has opportunity to change the syscall number at entry via orig_ax In-Reply-To: <202009111609.61E7875B3@keescook> References: <87blj6ifo8.fsf@nanos.tec.linutronix.de> <87a6xzrr89.fsf@mpe.ellerman.id.au> <202009111609.61E7875B3@keescook> Date: Sun, 13 Sep 2020 17:44:09 +1000 Message-ID: <87d02qqfxy.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kees Cook writes: > On Wed, Sep 09, 2020 at 11:53:42PM +1000, Michael Ellerman wrote: >> I can observe the difference between v5.8 and mainline, using the >> raw_syscall trace event and running the seccomp_bpf selftest which turns >> a getpid (39) into a getppid (110). >> >> With v5.8 we see getppid on entry and exit: >> >> seccomp_bpf-1307 [000] .... 22974.874393: sys_enter: NR 110 (7ffff22c46e0, 40a350, 4, fffffffffffff7ab, 7fa6ee0d4010, 0) >> seccomp_bpf-1307 [000] .N.. 22974.874401: sys_exit: NR 110 = 1304 >> >> Whereas on mainline we see an enter for getpid and an exit for getppid: >> >> seccomp_bpf-1030 [000] .... 21.806766: sys_enter: NR 39 (7ffe2f6d1ad0, 40a350, 7ffe2f6d1ad0, 0, 0, 407299) >> seccomp_bpf-1030 [000] .... 21.806767: sys_exit: NR 110 = 1027 > > For my own notes, this is how I reproduced it: > > # ./perf-$VER record -e raw_syscalls:sys_enter -e raw_syscalls:sys_exit & > # ./seccomp_bpf > # fg > ctrl-c > # ./perf-$VER script | grep seccomp_bpf | awk '{print $7}' | sort | uniq -c > $VER.log > *repeat* > # diff -u old.log new.log > ... > > (Is there an easier way to get those results?) I did more or less the same thing, except I ran the trace event manually (via debugfs), which is no better really. I think the right way to test it would be to have a test that modifies the syscall via seccomp and also monitors the trace event using perf events. But that wouldn't be easier :) > I will go see if I can figure out the best way to correct this. I think this works? diff --git a/kernel/entry/common.c b/kernel/entry/common.c index 18683598edbc..901361e2f8ea 100644 --- a/kernel/entry/common.c +++ b/kernel/entry/common.c @@ -60,13 +60,15 @@ static long syscall_trace_enter(struct pt_regs *regs, long syscall, return ret; } + syscall = syscall_get_nr(current, regs); + if (unlikely(ti_work & _TIF_SYSCALL_TRACEPOINT)) trace_sys_enter(regs, syscall); syscall_enter_audit(regs, syscall); /* The above might have changed the syscall number */ - return ret ? : syscall_get_nr(current, regs); + return ret ? : syscall; } static __always_inline long cheers