Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp896947pxk; Sat, 12 Sep 2020 04:10:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzh9Hka5vc/CwYBjUky4TGwNw+Qrn9nyTi/wnvAEVnFIjRq4tiOs1/znsGrriT+OxTem+z8 X-Received: by 2002:a17:906:d8cd:: with SMTP id re13mr5558328ejb.140.1599909036867; Sat, 12 Sep 2020 04:10:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599909036; cv=none; d=google.com; s=arc-20160816; b=u+n7HedCRmdShD0+4Jmb1bj6zIQSQPZ3QzOtPjyPyGKa6fX7II2nL4x6wL2Z/aRQoV UT8tMwiNaDDpnGQA6rAxbIA+9UF2qshRMTDm0wof88w1GnTX94KL07trCLcUMyeZ9+BU 7qjkKNdvL46Tp/qvaHxzwW1Yb/DRrOGdF+JbxlvW1vn/scxjkyS7fGsiSwSSUlCh33yi hczXDH1hdTOYNr9bCdTUiyFiHnYS+RNQROl3g4YLGfuBtg5aJPHmV946xiztO/xqdYGy CoGAUZyMyEEfUKgmcGkhyZ9mg8rjHtVxIOtQ7SeQSZCt2kVHzq/BHCHNHlqjejGfhQ00 RLdQ== 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=7i0gIW6ZVxe0Kz2oWVVjX2+xeMrxrMhOBimrxOQ4qek=; b=G7nvzAf4Yn7/BKGVgz51ayWn5mfGq2OZyc2V8/OuLQIoO8BOArrOevHcIQpBQH6QqY wJFbumJSKy3EKS/Mgr8yJu+jy4kpAwfsptW/M8NyktQJLTY5DuTjmpQamUFDFY6mUQtc v5FZ6siterIz7qsUykwFxsNfvJDh+O/ihYyxwKmWrfRfQPmdWc+zhYHdLOrd6HE734lX hvwsiq89aG4k/ZVTom5waQGRl0pve5OFbghMXQv3xeLnEcmpRqk8FkpI6+W6QDoDsQDX f4jkvyW+D1sziG/0TE2ZsDS/8K2qwASoR2vjeFRxw7eRL5R4gqJkJpXjNrog8Vqs0AEt nkbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=S5Lz8j1V; 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 d14si3185512edp.136.2020.09.12.04.10.14; Sat, 12 Sep 2020 04:10:36 -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=S5Lz8j1V; 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 S1725833AbgILLJ3 (ORCPT + 99 others); Sat, 12 Sep 2020 07:09:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725869AbgILLI0 (ORCPT ); Sat, 12 Sep 2020 07:08:26 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7477EC061786 for ; Sat, 12 Sep 2020 04:08:25 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id m5so8194415pgj.9 for ; Sat, 12 Sep 2020 04:08:25 -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=7i0gIW6ZVxe0Kz2oWVVjX2+xeMrxrMhOBimrxOQ4qek=; b=S5Lz8j1V+5MDhgIyUtO7Zuk5BIcx/fBEtHJ2uWE1T7i7NSSd7E5LmNCEC6ozr4kpjk NQGZhu80esKFrAatPhTFWLyQP2ihxEW1whGoQ8gIlktjuON8UyQm5Ypv2kMvHF8Y5Zyv VlZRUx6tzeRSyjNHg7sA1nyP3jA7Nlxc868Dw= 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=7i0gIW6ZVxe0Kz2oWVVjX2+xeMrxrMhOBimrxOQ4qek=; b=DsNtjNnQLFRtfyRRIlPK5mEoyydIA4HNnV74CYdATvB4tpx0S5FvWnjKyUwXV7HJZQ +hqgPBarijCVnZEKXNZUyFgK1GTwVhSLAOB0epeftcbRl3w04ujx/EJsHSdxJftSAiSP pb1mGRqN8O+5l5h09vpgenNF5Ujo8bCMOvafxsVR37XUKvs6iQYLedhnbskZ5Nz9Qeg7 TUYk2MR74QDYCCZepfYa5K0nwxgMl8DK2XJQzFdOuyWMarpnNEB4pROdPbWAiZWEmPzg D+RpG7Mt1Ond2pcEAxF4VRF11ISwxoAYhhJ3k6uy3AtoO7lld47Z9G2wIJBYJ2/Yc8JI /loA== X-Gm-Message-State: AOAM531RMJJB5dT1uOwiKnJT87OLsvXS1MCtxMhiN/tHNn8gFiQZwgUj E7ug+mm1Y+gzjygxquBzb4mqjg== X-Received: by 2002:a63:5e01:: with SMTP id s1mr58767pgb.421.1599908905027; Sat, 12 Sep 2020 04:08:25 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id mp3sm4063276pjb.33.2020.09.12.04.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 04:08:23 -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 02/15] selftests/seccomp: Provide generic syscall setting macro Date: Sat, 12 Sep 2020 04:08:07 -0700 Message-Id: <20200912110820.597135-3-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 In order to avoid "#ifdef"s in the main function bodies, create a new macro, SYSCALL_NUM_SET(), where arch-specific logic can live. Signed-off-by: Kees Cook --- tools/testing/selftests/seccomp/seccomp_bpf.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index fef15080b575..1c83e743bfb1 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c @@ -1760,6 +1760,17 @@ TEST_F(TRACE_poke, getpid_runs_normally) # error "Do not know how to find your architecture's registers and syscalls" #endif +/* + * Most architectures can change the syscall by just updating the + * associated register. This is the default if not defined above. + */ +#ifndef SYSCALL_NUM_SET +# define SYSCALL_NUM_SET(_regs, _nr) \ + do { \ + SYSCALL_NUM(_regs) = (_nr); \ + } while (0) +#endif + /* When the syscall return can't be changed, stub out the tests for it. */ #ifdef SYSCALL_NUM_RET_SHARE_REG # define EXPECT_SYSCALL_RETURN(val, action) EXPECT_EQ(-1, action) @@ -1830,14 +1841,14 @@ void change_syscall(struct __test_metadata *_metadata, defined(__s390__) || defined(__hppa__) || defined(__riscv) || \ defined(__xtensa__) || defined(__csky__) || defined(__sh__) { - SYSCALL_NUM(regs) = syscall; + SYSCALL_NUM_SET(regs, syscall); } #elif defined(__mips__) { if (SYSCALL_NUM(regs) == __NR_O32_Linux) regs.SYSCALL_SYSCALL_NUM = syscall; else - SYSCALL_NUM(regs) = syscall; + SYSCALL_NUM_SET(regs, syscall); } #elif defined(__arm__) -- 2.25.1