Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp897350pxk; Sat, 12 Sep 2020 04:11:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtmWQS0ZBCld60lPufSkdCMijCk9NP2VUAB453vhW42DSCNdzfhLjVjp/FcIdLYHXh8haC X-Received: by 2002:a17:906:b097:: with SMTP id x23mr5466545ejy.21.1599909087228; Sat, 12 Sep 2020 04:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599909087; cv=none; d=google.com; s=arc-20160816; b=o10E5JmeOb1Pfg/h93GQFyZlpqmr4z/v9DquMQKUrD5jXtohoGzYbdIcUKbw29v0lw hx5aOtGj2Y3BAujr9YSlbtXdspZwZ3E/vnuHE1lRQ2UZ7loH0+7eMIY8TTKR/CCJrAyh 8u2SV/4iSLLZwbtYDW3P6Azo9z50Jt4zZI1p/SZwnF9aj2kITpWvi+xir/C/JSDMOCfv 0AtSVY0lp2RSd8+n5Sl2NUbGYvIYqQXKPkol2HLU7fyLFSd3e36zb6rAGxE8N+rz8Gzs tAxzlOgQ3gq5TkbiJc3Gm4b6opwprFw09LphDAobCcFRmBr9v1x4JB/zVzM0Ct/iXAM1 /QMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=C4bs7CzTnl1kRyMgFNAx/cMdF4zfB7LMPrNYc0foUqg=; b=E2ma+w8Gir+C4TVJX6PRyhRwELPY9ux0ULlyBN2ahxNzVOVMd3tl2j8h8HW8stjMbq Dv9rBNmKZ21275H9I0J8R/iqILPsnNnKmpTg7WtXhe5K5QM5lej3X0bb0NWJyc+7rVZA mh3aLFYp/jdujSuGaN+rjILyWaa68k9fKNKVXihJW7qGj61ayfKEWiTLkgy2AsVseOMY pFyQQKdFfI1Nb/iRtCQaPi1GF1CLv7N82A8sAet5bR9CiJ1D50RR0pL9e4cCqvGEKDJq 7orGGefNtv00YAFGKBCOavnB/k/bJI+x/XDB+aA1tuCCqYuw0DyzlgcsEjL7Yt4NCavT 2Thw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dIji5loM; 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 x2si3394836ejy.84.2020.09.12.04.11.04; Sat, 12 Sep 2020 04:11:27 -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=dIji5loM; 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 S1725951AbgILLKF (ORCPT + 99 others); Sat, 12 Sep 2020 07:10:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725906AbgILLIz (ORCPT ); Sat, 12 Sep 2020 07:08:55 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 932FAC0617BA for ; Sat, 12 Sep 2020 04:08:31 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id md22so3616051pjb.0 for ; Sat, 12 Sep 2020 04:08:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C4bs7CzTnl1kRyMgFNAx/cMdF4zfB7LMPrNYc0foUqg=; b=dIji5loM94lPX2BlTVOZY2wSfFrN4iEdIXvEB9ZXwb9K/O+5wmsPzNlErfm8yXGVnj TZPx65IreQCDy5KfHVk+h3ribfRTCS3w07xBw9RenEHHmWnwHiCYzDqMOh8nMd28EDm/ Boz7+C1dQLQJ9R1+3Y82JwQo1BdlrCLDw68lI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C4bs7CzTnl1kRyMgFNAx/cMdF4zfB7LMPrNYc0foUqg=; b=e7fNvN9KTef2NcrVH3vJCHG3gjP4v58daLcNwKB7aibToS8MyymZWI83k9xuVpldMG 9ZEVZr309xp6J3Rd2TH4OjVBfmuJCNP8CEXGe01lu7PzJk5klf5uv8iw22nS73rDJPsU TXNzs3OhLlgQUPcWmQ4j/LxYBNNCoXyFWYXafwGHU6sBGMXJ+gYxy2fgfBl0kWExQhDJ od9u6xMDoq+govL18IYBN6GaPd4W0DPOvKuF+eHi84icPkY1tEi1tGdwenndsxOA1f6b dzBrwI7Vlb+rrfSSkGb+VliTeudr6moV2LoCEwW+RNx1XlC6i759pwk689dNLBPKsuwZ 6wcg== X-Gm-Message-State: AOAM533wrJDrpVUM5v7a4pH+pVZmvAYvcbZMPTeY5AIg++OFy1ngRhoc lSvDlAn60caS4zOWsOfMlPd7Fw== X-Received: by 2002:a17:902:c404:: with SMTP id k4mr5997422plk.70.1599908909955; Sat, 12 Sep 2020 04:08:29 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id bx22sm4345524pjb.23.2020.09.12.04.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 04:08:27 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Thadeu Lima de Souza Cascardo , Max Filippov , Michael Ellerman , Christian Brauner , Andy Lutomirski , Will Drewry , linux-kselftest@vger.kernel.org, linux-mips@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH 08/15] selftests/seccomp: Convert HAVE_GETREG into ARCH_GETREG/ARCH_SETREG Date: Sat, 12 Sep 2020 04:08:13 -0700 Message-Id: <20200912110820.597135-9-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200912110820.597135-1-keescook@chromium.org> References: <20200912110820.597135-1-keescook@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of special-casing the get/set-registers routines, move the HAVE_GETREG logic into the new ARCH_GETREG() and ARCH_SETREG() macros. Signed-off-by: Kees Cook --- tools/testing/selftests/seccomp/seccomp_bpf.c | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index 3b77bdbe7125..a986f2332327 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c @@ -1821,20 +1821,21 @@ TEST_F(TRACE_poke, getpid_runs_normally) } while (0) #endif -/* Use PTRACE_GETREGS and PTRACE_SETREGS when available. This is useful for +/* + * Use PTRACE_GETREGS and PTRACE_SETREGS when available. This is useful for * architectures without HAVE_ARCH_TRACEHOOK (e.g. User-mode Linux). */ #if defined(__x86_64__) || defined(__i386__) || defined(__mips__) -#define HAVE_GETREGS +# define ARCH_GETREGS(_regs) ptrace(PTRACE_GETREGS, tracee, 0, &(_regs)) +# define ARCH_SETREGS(_regs) ptrace(PTRACE_SETREGS, tracee, 0, &(_regs)) #endif /* Architecture-specific syscall fetching routine. */ int get_syscall(struct __test_metadata *_metadata, pid_t tracee) { ARCH_REGS regs; -#ifdef HAVE_GETREGS - EXPECT_EQ(0, ptrace(PTRACE_GETREGS, tracee, 0, ®s)) { - TH_LOG("PTRACE_GETREGS failed"); +#ifdef ARCH_GETREGS + EXPECT_EQ(0, ARCH_GETREGS(regs)) { return -1; } #else @@ -1855,17 +1856,19 @@ int get_syscall(struct __test_metadata *_metadata, pid_t tracee) void change_syscall(struct __test_metadata *_metadata, pid_t tracee, int syscall, int result) { - int ret; ARCH_REGS regs; -#ifdef HAVE_GETREGS - ret = ptrace(PTRACE_GETREGS, tracee, 0, ®s); +#ifdef ARCH_GETREGS + EXPECT_EQ(0, ARCH_GETREGS(regs)) { + return; + } #else + int ret; struct iovec iov; iov.iov_base = ®s; iov.iov_len = sizeof(regs); ret = ptrace(PTRACE_GETREGSET, tracee, NT_PRSTATUS, &iov); -#endif EXPECT_EQ(0, ret); +#endif SYSCALL_NUM_SET(regs, syscall); @@ -1878,14 +1881,14 @@ void change_syscall(struct __test_metadata *_metadata, #endif /* Flush any register changes made. */ -#ifdef HAVE_GETREGS - ret = ptrace(PTRACE_SETREGS, tracee, 0, ®s); +#ifdef ARCH_SETREGS + EXPECT_EQ(0, ARCH_SETREGS(regs)); #else iov.iov_base = ®s; iov.iov_len = sizeof(regs); ret = ptrace(PTRACE_SETREGSET, tracee, NT_PRSTATUS, &iov); -#endif EXPECT_EQ(0, ret); +#endif } void tracer_seccomp(struct __test_metadata *_metadata, pid_t tracee, -- 2.25.1