Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp180939pxb; Fri, 29 Oct 2021 07:59:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZzwdrDYRTK5vus8vv+f2Y1OReH/TwQtF+a9kl7+QxCCZPiljwdE7Jpc7u+RRh13NyP/RZ X-Received: by 2002:a05:6638:d90:: with SMTP id l16mr8608115jaj.36.1635519551183; Fri, 29 Oct 2021 07:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635519551; cv=none; d=google.com; s=arc-20160816; b=lDRFE5Jkax7Eg4JNME38O4hxBOtOa4XxXhTno63k5DwpSzwEvBSkHKeZMuB8Bl5gRG EA+dBQc5Lx/T7IgxpnthF9Yc+Qep3NoCyAz8KtePL9cCW4j38eI/xOsRJzR51czh3WrG 7nw2O6hgs2ZIP3USj6itPxDEAKnR+8+mqLrUDWTnReAMPIidgid5Z64qhH2eAs7/aHR8 NsLX5b7KsOnHNopVaDnn0tBvn8u4dUHDuo/pbwgpzF/5j/HV4LC0wdm195R+UfWjlksS ZBpTwxYb+se4wpvGl7cqAgWW1c9CuxdP8ne37IWSnKnmYTtAltDc7Us/g0KzJIO+jijb shAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VEe/u6gPdZlKSr0M6oaNVpmJO6541YBOxFo1iZy9jxY=; b=i6vvzFsE/XyyBTBTT/DETYnB92z23vNS7dDm20hNsDBlmUhrXhZq2UvInhfX4COQvr Oly3unrENgsrH9Aj4GLZ1z/Hq5uPMYJfLb5eY2CBxiSBf9rhdXkErEyG+EGa8j6iVVuO r7YzN4+gbcw7RW6AnPA92ljoLHiu5m45wl4Au0jAxlZ9kDdh7hSAYQtvg8aP59sTmLyz jHSOoWAWxWr2NAnofpGhhu+iddRzBdauRzG7VZPk/9L1VKIBIFjvX+B3FSGWPAMrC4AA cCXlE/HbEqvDn+IZGOm/vhAXJbF0q3ptw4sQWbY/4O6zjrVb598C+2E1WGtAl/X5ia0T XMHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XgNVKerM; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l25si2394145iok.6.2021.10.29.07.58.59; Fri, 29 Oct 2021 07:59:11 -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=@chromium.org header.s=google header.b=XgNVKerM; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229623AbhJ2PAe (ORCPT + 99 others); Fri, 29 Oct 2021 11:00:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbhJ2PAd (ORCPT ); Fri, 29 Oct 2021 11:00:33 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF3FDC061766 for ; Fri, 29 Oct 2021 07:58:04 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id z11so6994491plg.8 for ; Fri, 29 Oct 2021 07:58:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=VEe/u6gPdZlKSr0M6oaNVpmJO6541YBOxFo1iZy9jxY=; b=XgNVKerM9naMpOzlG/yHOv6MbIBkuVbdK2nh8u3B6CTSDzELhiTjOA/oXBPr38rHdb 4mKzpTPKz5GByJldq3UbYPi/RKcrp7ssrAvr/1T9GgQ0nRT/INmDXWhMBxNTT8pBD+4I q+FxMmeVtJEHyaB6fFMKC8p/Q2AnAHCTUeqS0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=VEe/u6gPdZlKSr0M6oaNVpmJO6541YBOxFo1iZy9jxY=; b=Jz7XYTWeDe1QhDMHoy5Jj/oz/+QaKoQ4AbV7IefCsWogpC/HRiDBnm2qGvUv6buf7U X662+29cLVVrGMmURW9RdKBoIOVoZE37VdMIPU9z2PlEwOI+r5L4lrVrSM0VunnyrL31 0nALRQGxj65lJicjQUku3Bb3VVssfnHelnR6fA/VKJo2NT10gaVBtxmDFg71MLB0b2Ot /Uv+K20dc7Rsk3aMT2VRfqCYLjVPc0u7HlRZoy3a+rMs6dSENjFxYGazchG3NMlUuH9l f78XrK0Lx6543D2l0uev6OJ80uod2WbF3RbBsFSei9yKioizHf5Tla9CEJVDjjIqTM7I rSFg== X-Gm-Message-State: AOAM530D3PwTF/+WNA6W0LeoBTqThJH7QLqo+acoTm1sRKvEl2cRLFmP RBfzpqRBYnR7EO3RCmfmzJEeWg== X-Received: by 2002:a17:90a:8592:: with SMTP id m18mr5199470pjn.184.1635519484215; Fri, 29 Oct 2021 07:58:04 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u11sm7009927pfk.151.2021.10.29.07.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Oct 2021 07:58:03 -0700 (PDT) Date: Fri, 29 Oct 2021 07:58:02 -0700 From: Kees Cook To: "Eric W. Biederman" Cc: Andrea Righi , Shuah Khan , Alexei Starovoitov , Andy Lutomirski , Will Drewry , linux-kselftest@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: selftests: seccomp_bpf failure on 5.15 Message-ID: <202110290755.451B036CE9@keescook> References: <202110280955.B18CB67@keescook> <878rydm56l.fsf@disp2133> <202110281136.5CE65399A7@keescook> <8735okls76.fsf@disp2133> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8735okls76.fsf@disp2133> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 28, 2021 at 05:06:53PM -0500, Eric W. Biederman wrote: > Kees Cook writes: > > > On Thu, Oct 28, 2021 at 12:26:26PM -0500, Eric W. Biederman wrote: > >> Kees Cook writes: > >> > >> > On Thu, Oct 28, 2021 at 06:21:12PM +0200, Andrea Righi wrote: > >> >> The following sub-tests are failing in seccomp_bpf selftest: > >> >> > >> >> 18:56:54 DEBUG| [stdout] # selftests: seccomp: seccomp_bpf > >> >> ... > >> >> 18:56:57 DEBUG| [stdout] # # RUN TRACE_syscall.ptrace.kill_after ... > >> >> 18:56:57 DEBUG| [stdout] # # seccomp_bpf.c:2023:kill_after:Expected entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY : PTRACE_EVENTMSG_SYSCALL_EXIT (1) == msg (0) > >> >> 18:56:57 DEBUG| [stdout] # # seccomp_bpf.c:2023:kill_after:Expected entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY : PTRACE_EVENTMSG_SYSCALL_EXIT (2) == msg (1) > >> >> 18:56:57 DEBUG| [stdout] # # seccomp_bpf.c:2023:kill_after:Expected entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY : PTRACE_EVENTMSG_SYSCALL_EXIT (1) == msg (2) > >> >> 18:56:57 DEBUG| [stdout] # # kill_after: Test exited normally instead of by signal (code: 12) > >> >> 18:56:57 DEBUG| [stdout] # # FAIL TRACE_syscall.ptrace.kill_after > >> >> ... > >> >> 18:56:57 DEBUG| [stdout] # # RUN TRACE_syscall.seccomp.kill_after ... > >> >> 18:56:57 DEBUG| [stdout] # # seccomp_bpf.c:1547:kill_after:Expected !ptrace_syscall (1) == IS_SECCOMP_EVENT(status) (0) > >> >> 18:56:57 DEBUG| [stdout] # # kill_after: Test exited normally instead of by signal (code: 0) > >> >> 18:56:57 DEBUG| [stdout] # # FAIL TRACE_syscall.seccomp.kill_after > >> >> 18:56:57 DEBUG| [stdout] # not ok 80 TRACE_syscall.seccomp.kill_after > >> >> ... > >> >> 18:56:57 DEBUG| [stdout] # # FAILED: 85 / 87 tests passed. > >> >> 18:56:57 DEBUG| [stdout] # # Totals: pass:85 fail:2 xfail:0 xpass:0 skip:0 error:0 > >> >> 18:56:57 DEBUG| [stdout] not ok 1 selftests: seccomp: seccomp_bpf # exit=1 > >> >> > >> >> I did some bisecting and found that the failures started to happen with: > >> >> > >> >> 307d522f5eb8 ("signal/seccomp: Refactor seccomp signal and coredump generation") > >> >> > >> >> Not sure if the test needs to be fixed after this commit, or if the > >> >> commit is actually introducing an issue. I'll investigate more, unless > >> >> someone knows already what's going on. > >> > > >> > Ah thanks for noticing; I will investigate... > >> > >> > >> I just did a quick read through of the test and while > >> I don't understand everything having a failure seems > >> very weird. > >> > >> I don't understand the comment: > >> /* Tracer will redirect getpid to getppid, and we should die. */ > >> > >> As I think what happens is it the bpf programs loads the signal > >> number. Tests to see if the signal number if GETPPID and allows > >> that system call and causes any other system call to be terminated. > > > > The test suite runs a series of seccomp filter vs syscalls under tracing, > > either with ptrace or with seccomp SECCOMP_RET_TRACE, to validate the > > expected behavioral states. It seems that what's happened is that the > > SIGSYS has suddenly become non-killing: > > > > # RUN TRACE_syscall.ptrace.kill_after ... > > # seccomp_bpf.c:1555:kill_after:Expected WSTOPSIG(status) & 0x80 (0) == 0x80 (128) > > # seccomp_bpf.c:1556:kill_after:WSTOPSIG: 31 > > # kill_after: Test exited normally instead of by signal (code: 12) > > # FAIL TRACE_syscall.ptrace.kill_after > > > > i.e. the ptracer no longer sees a dead tracee, which would pass through > > here: > > > > if (WIFSIGNALED(status) || WIFEXITED(status)) > > /* Child is dead. Time to go. */ > > return; > > > > So the above saw a SIG_TRAP|SIGSYS rather than a killing SIGSYS. i.e. > > instead of WIFSIGNALED(stauts) being true, it instead catches a > > PTRACE_EVENT_STOP for SIGSYS, which should be impossible (the process > > should be getting killed). > > Oh. This is being ptraced as part of the test? > > Yes. The signal started being delivered. As far as that goes that > sounds correct. > > Ptrace is allowed to intercept even fatal signals. Everything except > SIGKILL. > > Is this a condition we don't want even ptrace to be able to catch? > > I think we can arrange it so that even ptrace can't intercept this > signal. I need to sit this problem on the back burner for a few > minutes. It is an angle I had not considered. > > Is it a problem that the debugger can see the signal if the process does > not? Right, I'm trying to understand that too. However, my neighbor just lost power. :| What I was in the middle of checking was what ptrace "sees" going through a fatal SIGSYS; my initial debugging attempts were weird. -Kees -- Kees Cook