Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp429911pxk; Sun, 30 Aug 2020 08:54:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyuYwlNF7xMnX2Gi2jvxyPUckBSCvyvB9udDWyPLq9S67WcTHS2eF6GqIcqBTpqamqlLge X-Received: by 2002:a17:907:20b6:: with SMTP id pw22mr8434723ejb.490.1598802853216; Sun, 30 Aug 2020 08:54:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598802853; cv=none; d=google.com; s=arc-20160816; b=q+I90Fs9vA/AKf+V9gktVX7HOmVv+F/NfoopMdtCLGcIuET0st4FnNvowaTFLRlXMI k5fyJaN3RfSH+DcZt1RPde37MZ0Lk4VBD5BDHbW0B1BecuMN2GbbxjvL978AVfY2a0By d7QBFUmfqsRLK3aAQXGActO5auc5HYDORKIDXRkBU4KSBzjeprOfaz+nJNEIh4gGK4L9 5xxkqMgBtocdmkrIGP362+XsYG7Gmt//nkpew2vR80lWML3EJiIRgceuMIezH6ijMYq4 YZm7O0N0w7eyuJr3fXGDLT22rjDgjaaf3ivo2km9XvOAbkupSUf7PkKi6QLoaGByICSc T/Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=JlbK3lIQW4Q7l4MwjdGLYYOQK/+UzNM74HyCOgdMYSU=; b=hfDFR1ZLEtDgq5AvjFLvwgJZ38tP5p3tAeFEH3kgFHu6Blctu5yKFBaJqXpkecdoSJ mCTtIBDyGSNnt/noHKG9Yol0pjjR8UvCqV2ZxmvvPNpO/hr92zImTbKtGjaxaXsjg8Z0 bnqMzyvanOivCRRcPsXJj6DfVLHr3tLwoQWidDO9umiwkkZe7GkdgVEPif9H297NBzdQ ZsU5f9LhjW7Qx8sOuJ6rnCUni2gFcYvRKYu57dFR7zSE7KEnOJoIEk3QGYPrcQn9B0II 9gmVz3wbQzGspcKlobXghXRUhDbtO9mTEgUMbypn+Dn0M42m10o+51NQLvjOvgvdC5ZT opEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NdzyBPli; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m19si3471512edq.355.2020.08.30.08.53.35; Sun, 30 Aug 2020 08:54:13 -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=@kernel.org header.s=default header.b=NdzyBPli; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726126AbgH3Pwu (ORCPT + 99 others); Sun, 30 Aug 2020 11:52:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:50560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726046AbgH3Pwr (ORCPT ); Sun, 30 Aug 2020 11:52:47 -0400 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E23D220EDD for ; Sun, 30 Aug 2020 15:52:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598802766; bh=OS6SXiqY+lshjjjCn0KjODoLYajvf991ognvS2HPuKs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=NdzyBPliWINf0MX6JY+vAWcuFhZ24x7rCOZuGvhkw/NRRrQwv1fKvEf8LsNV0EpCN jzYoFt5T8CAo/RDgIKSC7RZoaIJ5Z/VPNiH5FqMahOxm2I85y2vpEVELc3hw0R1oYg 2CzJSFHAy66HEqL5iHS/tTolWHetNUqGT8agDlaw= Received: by mail-wm1-f45.google.com with SMTP id z9so3210297wmk.1 for ; Sun, 30 Aug 2020 08:52:45 -0700 (PDT) X-Gm-Message-State: AOAM533P9pf8bVkLs4+5jrlEYcNygjwDkcCny0MI7CeX5HsqEbKrzcj7 qYV+M2tBKskhxCC7RGS27IVizcyy/knpUmg5TgJ0Mw== X-Received: by 2002:a05:600c:2183:: with SMTP id e3mr7795286wme.49.1598802764333; Sun, 30 Aug 2020 08:52:44 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andy Lutomirski Date: Sun, 30 Aug 2020 08:52:33 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: ptrace_syscall_32 is failing To: Brian Gerst Cc: Andy Lutomirski , Thomas Gleixner , X86 ML , LKML , Will Deacon , Christian Borntraeger , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Catalin Marinas , linux-arm-kernel , Heiko Carstens , Vasily Gorbik , linux-s390 , linuxppc-dev Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 29, 2020 at 9:40 PM Brian Gerst wrote: > > On Sat, Aug 29, 2020 at 12:52 PM Andy Lutomirski wrote: > > > > Seems to be a recent regression, maybe related to entry/exit work changes. > > > > # ./tools/testing/selftests/x86/ptrace_syscall_32 > > [RUN] Check int80 return regs > > [OK] getpid() preserves regs > > [OK] kill(getpid(), SIGUSR1) preserves regs > > [RUN] Check AT_SYSINFO return regs > > [OK] getpid() preserves regs > > [OK] kill(getpid(), SIGUSR1) preserves regs > > [RUN] ptrace-induced syscall restart > > Child will make one syscall > > [RUN] SYSEMU > > [FAIL] Initial args are wrong (nr=224, args=10 11 12 13 14 4289172732) > > [RUN] Restart the syscall (ip = 0xf7f3b549) > > [OK] Restarted nr and args are correct > > [RUN] Change nr and args and restart the syscall (ip = 0xf7f3b549) > > [OK] Replacement nr and args are correct > > [OK] Child exited cleanly > > [RUN] kernel syscall restart under ptrace > > Child will take a nap until signaled > > [RUN] SYSCALL > > [FAIL] Initial args are wrong (nr=29, args=0 0 0 0 0 4289172732) > > [RUN] SYSCALL > > [OK] Args after SIGUSR1 are correct (ax = -514) > > [OK] Child got SIGUSR1 > > [RUN] Step again > > [OK] pause(2) restarted correctly > > Bisected to commit 0b085e68f407 ("x86/entry: Consolidate 32/64 bit > syscall entry"). > It looks like it is because syscall_enter_from_user_mode() is called > before reading the 6th argument from the user stack. Ugh. I caught, in review, a potential related issue with exit (not a problem in current kernels), but I missed the entry version. Thomas, can we revert the syscall_enter() and syscall_exit() part of the series? I think that they almost work for x86, but not quite as indicated by this bug. Even if we imagine we can somehow hack around this bug, I imagine we're going to find other problems with this model, e.g. the potential upcoming exit problem I noted in my review. I really think the model should be: void do_syscall_whatever(...) { irqentry_enter(...); instrumentation_begin(); /* Do whatever arch ABI oddities are needed on entry. */ Then either: syscall_begin(arch, nr, regs); dispatch the syscall; syscall_end(arch, nr, regs); Or just: generic_do_syscall(arch, nr, regs); /* Do whatever arch ABI oddities are needed on exit from the syscall. */ instrumentation_end(); irqentry_exit(...); } x86 has an ABI oddity needed on entry: this fast syscall argument fixup. We also might end up with ABI oddities on exit if we ever try to make single-stepping of syscalls work fully correctly. x86 sort of gets away without specifying arch because the arch helpers that get called for audit, etc can deduce the arch, but this is kind of gross. I suppose we could omit arch as an explicit parameter. Or I suppose we could try to rejigger the API in time for 5.9. Fortunately only x86 uses the new APIs so far. I cc'd a bunch of other arch maintainers to see if other architectures fit well in the new syscall_enter() model, but I feel like the fact that x86 is already broken indicates that we messed it up a bit. --Andy