Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp897827pxk; Sat, 12 Sep 2020 04:12:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlfeSA/4BqDDqHNhgvcAYLdo++oOQ4tQStmBxuStYTrLrne1koEUZXJoLbRBfoFangx7S3 X-Received: by 2002:aa7:d991:: with SMTP id u17mr7819737eds.11.1599909136032; Sat, 12 Sep 2020 04:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599909136; cv=none; d=google.com; s=arc-20160816; b=LuUclccsALn08+EDuDp8UJWkVDGYPuj5DtCq9UXVGxd0t1pzn6mBBfeuXvj3nFGkiH sh4eFF8BfoI3YtxHjscjD7rLpbfRf6VHb22Bvq8MbqZaHpnY5DZepwYsIlQ8VhqYszDi 7PtjIIoMZ/1d4/DFGGwecKlwZvTva6GAHxVU1Or+0fgvwJSn5/ckWLRfenR5Trz5acpu hiKg3Kqc2vWlrgA4b6SoJUtrg6Ca2woSp4qR0cmGXrA3FXDcJ6cDHLUtBCqLcthCXmnw E7MC//8LoLAT0wSKVz8dEedHtMZQjd7p6MOHvdTzzgNEe1EwP11bOiPOiPoY/GSug/A/ vIzQ== 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=F4tHM0L8tNnxsWtLsTsMp6Ii6Rnl8nRf7R1d/DJ5GX0=; b=mfM5JPaanFGloNewCzYilTso7ncQg7hc0grFNl6VZfIY3RId0MmtT+N+z67+GzOxyt ApdzEFaxrYlkWXthgBR/KFLy1K2/g+unrtlXJpTwWeNo6iFmbshcSQqMzcsfIJC2srnl o2jeRbcDXrTh5Lsow/uv6LZNe2P2e0wrsZMy1MmW0SFrNAU7NLZOm5izNtw8O8EcLQFc E65E37jN2KIhf1C+XD7oCmTut/Zufjtq21wXzFKbUW73m74oVGGg+K5Omf41YLSetZEL dytm96YvMYjBHVH46KHr5aAmwNGpIOzS0fRe5/IXsNk4Bzz9yRC7PcwfSJJhg1zbZ4ak N98w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Fl2bqtSL; 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 kt7si3235913ejb.282.2020.09.12.04.11.53; Sat, 12 Sep 2020 04:12:16 -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=Fl2bqtSL; 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 S1725970AbgILLKm (ORCPT + 99 others); Sat, 12 Sep 2020 07:10:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725924AbgILLJW (ORCPT ); Sat, 12 Sep 2020 07:09:22 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71788C061573 for ; Sat, 12 Sep 2020 04:08:34 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id md22so3616078pjb.0 for ; Sat, 12 Sep 2020 04:08:34 -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=F4tHM0L8tNnxsWtLsTsMp6Ii6Rnl8nRf7R1d/DJ5GX0=; b=Fl2bqtSL2iiRfZluzSWOTXzNL8dmVQDhsUPUUB10qGGSvjXPumusHfP3CokhnSfKCH +t1jc2Q7OaXG85BoTd0A91s9q9C//+V6czJh5bMgwh6mcmDIOuQaMrCFly9wGejcGRUz s31sojad768defEHNH0ElcsN5owiLsEYQ0XZ8= 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=F4tHM0L8tNnxsWtLsTsMp6Ii6Rnl8nRf7R1d/DJ5GX0=; b=DvaWC6m3ZwWwlGb0Hj0HIbrzsbGsbgP0yQpBmj3U3NIJq8Pitx9CwLb0x7tc2Zgsth NV6PxIeg310aAqRl2KaeuznxzoYaWwkJv80IV2Z1G2pxhNXwc9Xz0/sNZnW+ikifvLlg kAn0veMYwpkh1PM68o7lFlKGthUgrPXMDuvonP3tsNziplIOjUhEXg6XPhUDzU0Pmvz1 TfY+quI9mX4a5dDHjfE3FGPVDEtbIpLhGjcCTY6dPnoDeFiMtxfUN5dOZIJbgZYTbPCS 5fcKYEVCSpvh/s7qw+f4THkAL/+O4mkr5+1cGNI7z/dIg0rs25wyLMku5acQpZezplAe jJbw== X-Gm-Message-State: AOAM5337x8o5MR5t3EvYaKJbZH4OB7UNadqb3sA5MKcOldlhjSu3/uDy 3CEylTucjr2R8vd7NSmWPZvQAg== X-Received: by 2002:a17:90b:374b:: with SMTP id ne11mr5637226pjb.21.1599908913988; Sat, 12 Sep 2020 04:08:33 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id m24sm4069132pgn.44.2020.09.12.04.08.27 (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 11/15] selftests/seccomp: Remove SYSCALL_NUM_RET_SHARE_REG in favor of SYSCALL_RET_SET Date: Sat, 12 Sep 2020 04:08:16 -0700 Message-Id: <20200912110820.597135-12-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 specific case of shared registers, create a default SYSCALL_RET_SET() macro (mirroring SYSCALL_NUM_SET()), that writes to the SYSCALL_RET register. For architectures that can't set the return value (for whatever reason), they can define SYSCALL_RET_SET() without an associated SYSCALL_RET() macro. This also paves the way for architectures that need to do special things to set the return value (e.g. powerpc). Signed-off-by: Kees Cook --- tools/testing/selftests/seccomp/seccomp_bpf.c | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index 2790d9cd50f4..623953a53032 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c @@ -1753,8 +1753,8 @@ TEST_F(TRACE_poke, getpid_runs_normally) #elif defined(__s390__) # define ARCH_REGS s390_regs # define SYSCALL_NUM(_regs) (_regs).gprs[2] -# define SYSCALL_RET(_regs) (_regs).gprs[2] -# define SYSCALL_NUM_RET_SHARE_REG +# define SYSCALL_RET_SET(_regs, _val) \ + TH_LOG("Can't modify syscall return on this architecture") #elif defined(__mips__) # include # include @@ -1776,8 +1776,8 @@ TEST_F(TRACE_poke, getpid_runs_normally) else \ (_regs).regs[2] = _nr; \ } while (0) -# define SYSCALL_RET(_regs) (_regs).regs[2] -# define SYSCALL_NUM_RET_SHARE_REG +# define SYSCALL_RET_SET(_regs, _val) \ + TH_LOG("Can't modify syscall return on this architecture") #elif defined(__xtensa__) # define ARCH_REGS struct user_pt_regs # define SYSCALL_NUM(_regs) (_regs).syscall @@ -1804,9 +1804,26 @@ TEST_F(TRACE_poke, getpid_runs_normally) SYSCALL_NUM(_regs) = (_nr); \ } while (0) #endif +/* + * Most architectures can change the syscall return value by just + * writing to the SYSCALL_RET register. This is the default if not + * defined above. If an architecture cannot set the return value + * (for example when the syscall and return value register is + * shared), report it with TH_LOG() in an arch-specific definition + * of SYSCALL_RET_SET() above, and leave SYSCALL_RET undefined. + */ +#if !defined(SYSCALL_RET) && !defined(SYSCALL_RET_SET) +# error "One of SYSCALL_RET or SYSCALL_RET_SET is needed for this arch" +#endif +#ifndef SYSCALL_RET_SET +# define SYSCALL_RET_SET(_regs, _val) \ + do { \ + SYSCALL_RET(_regs) = (_val); \ + } while (0) +#endif /* When the syscall return can't be changed, stub out the tests for it. */ -#ifdef SYSCALL_NUM_RET_SHARE_REG +#ifndef SYSCALL_RET # define EXPECT_SYSCALL_RETURN(val, action) EXPECT_EQ(-1, action) #else # define EXPECT_SYSCALL_RETURN(val, action) \ @@ -1870,11 +1887,7 @@ void change_syscall(struct __test_metadata *_metadata, /* If syscall is skipped, change return value. */ if (syscall == -1) -#ifdef SYSCALL_NUM_RET_SHARE_REG - TH_LOG("Can't modify syscall return on this architecture"); -#else - SYSCALL_RET(regs) = result; -#endif + SYSCALL_RET_SET(regs, result); /* Flush any register changes made. */ if (memcmp(&orig, ®s, sizeof(orig)) != 0) -- 2.25.1