Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2332086pxk; Mon, 14 Sep 2020 10:25:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+NFaH0E9/fKTS6bDizgj+ff8wMp283Pqf/q1iRgixvpFI2hPvfvFs9kgTu0W1467A70Ps X-Received: by 2002:a17:906:43c9:: with SMTP id j9mr15509762ejn.542.1600104329443; Mon, 14 Sep 2020 10:25:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600104329; cv=none; d=google.com; s=arc-20160816; b=qdzuxGIiORETkq4w7o2MXcYIkgK04SyLy2+rXd1DiAsc01nn1kc8IVISr3RedG7E7n xpmk+akDmrTlyTmC4SsOBvz2i1L0UeSKBFE7YccKG/HoiishGnScJDMmVDtmDE5QX2Kw Xz/SlCSBja+YeXvU+vo7Nn0crTfnTnPbmToXQxCmgxI1GB3ZMqU0HWyS489fF96JAVIr 8nKPWmCJqTKj2sLX53jxUonFaZEZrkGPJBoIYrLhjAlx+TpplBG1F/KdCdkSoCC9cl6W 3O0EL0ajHe0zycZvChgD7moOAV4SaUy7M6BCf1SzoWosCM7NCVkWjPd+vnSOGZk8Drmt L0YA== 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=JVKTqBvAVL/A+UXC7zGaAyoWT6Nr8r3v+Ezj9S1yIPw=; b=n4V2uYCA9h3WTfIRGUsCxbg9jvAw1lQqGcefvGVosZJrmvPn3CK6RiPhXGlMecV5V5 ZQDZ32wMSODa89zHHfSpSptlTPSqgdQryc9dplghAmKFbd9S6/xEeWpXA0arXZUPqabn c79PwOGgZH+DjBPpIGjmiNDZegD5Ms4tanGyLG7Z6MnhgqJFRv2XcibmhrEwLsxdMicb GnUB0Y3PxJOdZhzOOGm+o6X5Y5nHgIc7ppEF5eXNNwyFOAHuhqoKIQKEL/ASE2MuF7OM rOW171waBeXuYDOfZCqUOTcXE+dI27/ZiT/N4jnJNTtfw8hsAymR5t7Ug9oYGjZ6HAAG 7XmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=c8PBdW9D; 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 mh13si7605844ejb.244.2020.09.14.10.25.06; Mon, 14 Sep 2020 10:25:29 -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=@kylehuey.com header.s=google header.b=c8PBdW9D; 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 S1726244AbgINRXF (ORCPT + 99 others); Mon, 14 Sep 2020 13:23:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726252AbgINRW6 (ORCPT ); Mon, 14 Sep 2020 13:22:58 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CBDDC061788 for ; Mon, 14 Sep 2020 10:22:56 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id n13so329395edo.10 for ; Mon, 14 Sep 2020 10:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=JVKTqBvAVL/A+UXC7zGaAyoWT6Nr8r3v+Ezj9S1yIPw=; b=c8PBdW9DTTtB3R0OvNB3DmIeloDYpsfHYcX2vuydwqfOpYaj5PuMqsXPfMcVdzbUHS mkI98smfe2aaC0v+Hjloh5C8KbwYLuhnbH426Qmcqnvr/VIaHbNiiW0bZsGd15Hkq83T OeC+eJwO78+wBSx3DvLUvawgY5kos7ZTFgiQQrkNHs7tJukVItOT+YSJg1925fhuR08q /VMJSW6ZhURYvyKytxe8G2ThFcHVCpamBbDHZgePl+EAM4lKU4tOmtIU9pKA14jl4843 waYot8MoJ8vVU9XAIALtH2hJypDZSdYZByMaxtapdnrp4B8G5yOFdFAYI1FaDv+lm7VD tqlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JVKTqBvAVL/A+UXC7zGaAyoWT6Nr8r3v+Ezj9S1yIPw=; b=d7RRzmC0NseWPa1RqW7QatSsGRgQYHfw9OzojPTONGbqePqvrbrv9tsPuvpFw+Yd9Z WB8MPUUshrSlKLq5rwES+biLpI30yc0WWzVdCYYntL7j9g/7K0D53Nb68jVHxZQ7/R2y qi47xNANjUxocewiiHMCrnb8P5gX51ditSuZ1+KnibPid4ENAhfLSOKdHUp8GrUWPRlC lwBVaRO13NKNUso/vhFRZyZqx570Umdt7vnBqEyoc6JQcMPVIGXa9vBtioDUpVpabMqO vW9fl0AfLjX85g1ysq5mmb5zvd9pSf5KMz0Y1MXGeYUJaRHLuoTxQd56MGlTk7JCByvE syig== X-Gm-Message-State: AOAM5328xo0wO1046yNAr2O2sRr8u3oK483gJmh1w2asbvd5Kp/fF0Kh nziKdmeKwne7qKDoIXt62HX3TdLel38bWZs7tcUZDSuZNxwvWw== X-Received: by 2002:a05:6402:17b9:: with SMTP id j25mr18533021edy.203.1600104174639; Mon, 14 Sep 2020 10:22:54 -0700 (PDT) MIME-Version: 1.0 References: <20200912005826.586171-1-keescook@chromium.org> In-Reply-To: <20200912005826.586171-1-keescook@chromium.org> From: Kyle Huey Date: Mon, 14 Sep 2020 10:22:40 -0700 Message-ID: Subject: Re: [PATCH] core/entry: Report syscall correctly for trace and audit To: Kees Cook Cc: Thomas Gleixner , Michael Ellerman , Andy Lutomirski , Ingo Molnar , x86@vger.kernel.org, open list 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 Fri, Sep 11, 2020 at 5:58 PM Kees Cook wrote: > > On v5.8 when doing seccomp syscall rewrites (e.g. getpid into getppid > as seen in the seccomp selftests), trace (and audit) correctly see the > rewritten syscall on entry and exit: > > seccomp_bpf-1307 [000] .... 22974.874393: sys_enter: NR 110 (... > seccomp_bpf-1307 [000] .N.. 22974.874401: sys_exit: NR 110 = 1304 > > With mainline we see a mismatched enter and exit (the original syscall > is incorrectly visible on entry): > > seccomp_bpf-1030 [000] .... 21.806766: sys_enter: NR 39 (... > seccomp_bpf-1030 [000] .... 21.806767: sys_exit: NR 110 = 1027 > > When ptrace or seccomp change the syscall, this needs to be visible to > trace and audit at that time as well. Update the syscall earlier so they > see the correct value. > > Reported-by: Michael Ellerman > Fixes: d88d59b64ca3 ("core/entry: Respect syscall number rewrites") > Cc: Thomas Gleixner > Cc: Kyle Huey > Cc: Andy Lutomirski > Cc: Ingo Molnar > Signed-off-by: Kees Cook > --- > kernel/entry/common.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/kernel/entry/common.c b/kernel/entry/common.c > index 18683598edbc..6fdb6105e6d6 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; > } > > + /* Either of the above might have changed the syscall number */ > + 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 > -- > 2.25.1 > lgtm - Kyle