From patchwork Wed Jan 24 14:13:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Terry Tritton X-Patchwork-Id: 191588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1020363dyi; Wed, 24 Jan 2024 06:22:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQzQxC7yfW2UIOV17Nr/birHsDyuiY+N7nYyxtIKJh7DrNZ4dNomRo8xhaCBcHkJbVpc2f X-Received: by 2002:a17:90b:480b:b0:290:2405:aee7 with SMTP id kn11-20020a17090b480b00b002902405aee7mr1688134pjb.11.1706106157583; Wed, 24 Jan 2024 06:22:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706106157; cv=pass; d=google.com; s=arc-20160816; b=DEEZvnm2dVPx48m6b+NqZMGZfCrXX98qhtTe7n1kGT9Rbg2tUBNG/ERNUvi2lKYOo3 xu39TMLbWsgvGyWdtHPw14+pLA5MuoGOb8L1TEAlhNBxwB6yoMgIfj0vFg5zbIa86PsI NCkzuIDrWdSyNtPOKphz/2lJT47L+2Vharwr4lJtOHZg/H+yfZEQ2yedfO0+JAvPNOl7 2xeEuHbOOPJUQBopFFkdt/VEnV3pxThKSeCKzA/VWRM/RV8PhuZnq+fJ4cvp8My7Tgzp n8mHSEgRdwPTrYgqXWOgG5YW9wUqmDGgPx0o4P+5LscRoQ9ZoWx/Zmy04QrGIoUojQBp jkOQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kXWpKvuuFDRe0zzHcqHQWgdjThR4TPIPgqd6iq0g85c=; fh=pA9JhLexjB+OV5pnnYNCIXkC6iVsJegx2ipdtlnT5ok=; b=QK3GZif+OsHLZwvNWwZFf+y3iIavKtAiEaDWunvwsortINA4T1Ed8lag5sraZ3sN1W eUgn+8XmkWCZx+8VwC0f6e2maZcixXROKLfGBjOpbGO0gGvj9nV5BQi2Js6IKrs0GNfX B2CAJIw/wYcmPqgjtm9c88Tj2qEzNtkcuaRUVZBT1KKG4V40JyzJ5TZlHfJGdzk18kkd zOBmJ6SMMMAvgxVYVLDSiZkb82z2S3ptImk7vW6yZpy0XuVwEKgi9K6aGZB0oHacu2OA vX9sFwIToztLI0hOJPWdSyXHG9lj3ov01m5lcsMSd43EnQnZcXch4jUpvtjVOLqIZs41 CsbA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uoHhygbg; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-37094-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37094-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n7-20020a17090ade8700b00290cf4ad827si3060471pjv.169.2024.01.24.06.22.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 06:22:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37094-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uoHhygbg; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-37094-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37094-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DF00B295192 for ; Wed, 24 Jan 2024 14:15:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D1D67A73D; Wed, 24 Jan 2024 14:15:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="uoHhygbg" Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D12E563115 for ; Wed, 24 Jan 2024 14:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706105717; cv=none; b=N/MG+5gvAjjCFwU9gmozgkiu5hpdaQKADpZOwy8T433vkJKbvB4m6FTVs7MOOWGKT3h67RAADxjEdoi+On0dJ4n8EhOxnFznC46Ws5CcGPc7+IzIk6UHGSXfCeI453nknY3KW4HPnUZbyc7ZYdlILf2dxewxqdHpKAkIxXj0d+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706105717; c=relaxed/simple; bh=cE2W5KfsS/6abmLqZjvi1Wi0V0vV3k55AMuKwFWLxQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hsh9NIcJ+9lrFDqFkygUONnmiuXU/iyLiMsDElYPgo/tZzqyRiUMavSl17mKM1mZ6UHn4VIQ+bHCTYkIfPERKTQ0qMu0dnzm/3M8xFAv1av/WuGS38+dSXadK8kxbL1Fhr39N5foapmZIynRaQxfnDha3s1sl3SjgNbVoLSWJJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=uoHhygbg; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-51008c86ecbso2178240e87.2 for ; Wed, 24 Jan 2024 06:15:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706105714; x=1706710514; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kXWpKvuuFDRe0zzHcqHQWgdjThR4TPIPgqd6iq0g85c=; b=uoHhygbgkRGKW0AOymPGmBPfX+S8edJ2CS3+AQkFdE4A4dzLgoDwtON3QVLisH6zIc oQALN+yZSjNjlYOfSpYmNwsDbEpj4YkD2RnveO3UZEqS/lQUlso29Rgmd7ez0L4SZh3Z M1OUB4POLJ2Z/FKVgM84h4oQwqDjylVlJvNTCGAcAHrPMlGO4bN8HDj7zvrE127IIL6L IWtIQWvZbTlRaJcWzX9AZlDyAPdCdRXJKrC8lhuvR2DwfAQhT6MqZqWnO9ZhpGrPTBZh /DrhFyyDRyLBu+V/Sl5+/heE3LHNNjswkaT6B/NGM7N4pUH2GNqdZZ7p2OMDBAgz9Z5o fEsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706105714; x=1706710514; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kXWpKvuuFDRe0zzHcqHQWgdjThR4TPIPgqd6iq0g85c=; b=u6dXnLftXVDYMkBOsBxNMCOZXg+8yoUUlNJoED4evVpLcgDbACSEKCDZdi81vMsb3v 81w7ZNwegqhT8Z+rfinZPNHMiXmnQmym0cwwD969FKBh+Zqmd6DZ2dAFzIUqIQHCc/fS OjXcoEgnpM9WWjNKdnyW6ahLTe+3IgIAow9o+awZtCqT7FsFiIXHUmJaVmP5tcB8kUY0 AD/phsEDdPLUE8TlPBSGRZSlrh+vFHvpWMGdWWGp5gHn8f5BN/0c4YoRx519BCc2IfpC REIF/TDhqdXeyxzOBbte7IFBknqiiDsooIrv/qZ94lSyHq82a7DoIt/XhtobGHVKBXQI xfWg== X-Gm-Message-State: AOJu0Yz8xssWj9IcCO1Z79brDMB/ZdHyfpvRsQknqZYar1AM7giRN8sN k/ceLBqrWukrJcM0bL5Cev7d8kiiqJ0rQ/8K9NaUMrIFfwRFwFddZuGHUJjgRL0= X-Received: by 2002:a05:6512:2210:b0:50e:74ea:525c with SMTP id h16-20020a056512221000b0050e74ea525cmr3950398lfu.3.1706105713953; Wed, 24 Jan 2024 06:15:13 -0800 (PST) Received: from ttritton.c.googlers.com.com (64.227.90.34.bc.googleusercontent.com. [34.90.227.64]) by smtp.gmail.com with ESMTPSA id vu3-20020a170907a64300b00a2d7f63dd71sm12399097ejc.29.2024.01.24.06.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 06:15:13 -0800 (PST) From: Terry Tritton To: keescook@chromium.org, luto@amacapital.net, wad@chromium.org, shuah@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, peter.griffin@linaro.org, kernel-team@android.com, bettyzhou@google.com, Terry Tritton Subject: [PATCH 1/3] selftests/seccomp: Handle EINVAL on unshare(CLONE_NEWPID) Date: Wed, 24 Jan 2024 14:13:55 +0000 Message-ID: <20240124141357.1243457-2-terry.tritton@linaro.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240124141357.1243457-1-terry.tritton@linaro.org> References: <20240124141357.1243457-1-terry.tritton@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788981970800799292 X-GMAIL-MSGID: 1788981970800799292 unshare(CLONE_NEWPID) can return EINVAL if the kernel does not have the CONFIG_PID_NS option enabled. Add a check on these calls to skip the test if we receive EINVAL. Signed-off-by: Terry Tritton --- tools/testing/selftests/seccomp/seccomp_bpf.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index 38f651469968..5e705674b706 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c @@ -3709,7 +3709,12 @@ TEST(user_notification_sibling_pid_ns) ASSERT_GE(pid, 0); if (pid == 0) { - ASSERT_EQ(unshare(CLONE_NEWPID), 0); + ASSERT_EQ(unshare(CLONE_NEWPID), 0) { + if (errno == EPERM) + SKIP(return, "CLONE_NEWPID requires CAP_SYS_ADMIN"); + else if (errno == EINVAL) + SKIP(return, "CLONE_NEWPID is invalid (missing CONFIG_PID_NS?)"); + } pid2 = fork(); ASSERT_GE(pid2, 0); @@ -3727,6 +3732,8 @@ TEST(user_notification_sibling_pid_ns) ASSERT_EQ(unshare(CLONE_NEWPID), 0) { if (errno == EPERM) SKIP(return, "CLONE_NEWPID requires CAP_SYS_ADMIN"); + else if (errno == EINVAL) + SKIP(return, "CLONE_NEWPID is invalid (missing CONFIG_PID_NS?)"); } ASSERT_EQ(errno, 0); From patchwork Wed Jan 24 14:13:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Terry Tritton X-Patchwork-Id: 191590 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1023041dyi; Wed, 24 Jan 2024 06:27:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IHoYutxbElvzxp1X/BCWa1kumHC4B/EY4sz18Ox/I7drEV/2GgFbXQfEfVTVAiO2bcyJzA3 X-Received: by 2002:a17:90a:d313:b0:290:d1d0:9633 with SMTP id p19-20020a17090ad31300b00290d1d09633mr1749428pju.25.1706106433812; Wed, 24 Jan 2024 06:27:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706106433; cv=pass; d=google.com; s=arc-20160816; b=GHfhglA7N4Ogd1rFxj70hTr8tLeQbE9pEDBq5RMG57Qb5PosTluJLi1rrv1m/rBh0I V+G7k1C24xqikep6L6QwhAaytuR07ExmMy5MyJne63B/ge6zMAfT4ZctheyIH4f+LKWI B94bu6cpkLCJk7D2TWvc/qGUH6LcZEhU63xZxfBlQuvvHR2EBCwFZ0ElCN4Z7ZSJsKCR DnEI9QuRvjbdMBljuoxwkieT9vhekJAM/sW5tgzxgclnCzF69+EOawkdJLGIscciickI zvghOns142ZjHqQ13HljD2sSlJskI7iioaYBBG2JnfScgTVHdBtW9lDdqilhmZxZhiIS 6spQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kinIyrY0DiVL9FjvsbU90IrpJuAQN+qhOmTSZHZdLpE=; fh=pA9JhLexjB+OV5pnnYNCIXkC6iVsJegx2ipdtlnT5ok=; b=WVaqBh5wQzequ9UDSq1rs/zu+LgWxQVV7fy0za82hzc5ITuJcyKSSxcRjd1ckn1OpB /rS04ZD4RjmeS5Jv6JcvR9X3+rWlER4Quk+RTURQM5dpcJu94CKpqeCImlSQYZfCJCGa mRaiJULcWK1aTHODgI7LbwqHV6VGswg/8MWMkBEenF5AhhhnodKRezXI/P5RJQLvNZ2e wf/kk7tCBjp14qV+OnjPio9AlqqIkOCbq57zWeNXZdwtadmTqBpCvcSCGiDXghc/sXHJ DFp5gsaVa/UJg+MylfC4qYC73SNnh9ygMbyTudf4U68cJOn/h+N4l15ixg9dG1INAIq9 pHcA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DSINa5t3; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-37095-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37095-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id gt17-20020a17090af2d100b0028fef225e5asi11512310pjb.71.2024.01.24.06.27.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 06:27:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37095-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DSINa5t3; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-37095-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37095-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 87831295296 for ; Wed, 24 Jan 2024 14:15:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 065967A728; Wed, 24 Jan 2024 14:15:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DSINa5t3" Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD07263115 for ; Wed, 24 Jan 2024 14:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706105724; cv=none; b=W4DnE0/UtGir8SBtWNd8EXpfBIFLrxbHMASOUhDhCyqoGFTEeIBuQ6IiW9HEL2MouhmZgV8gWqqJ76sXjwa8l/J6eCwTuRXw87H7/N6yQTJT7TXFWgXUzbdOIrcBlbppFib8JMVarQpQ3pLdz2dJA4LA+nyLhw2dk1QunTABAz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706105724; c=relaxed/simple; bh=0UEj8Oof/abgmDFcrUPI79i5BHVw6bCbAYsJDPU2SAM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S4eVTyjor5zvfFgT7bw6fuJTt9cj2Dy9ZAPsCAadXiuEN+pGlJL75UnirNb4pg1zzWM32eYH6J9djeA4zHSPRcHcA/wOe1ALxgshuYm+1FuJZUic0+0gRioCznGO4w8dypKl2t/6wRirIpzuEsUOdohF3whBI8DjYVW7JBr3/YY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=DSINa5t3; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-55ad2a47b7aso4878890a12.3 for ; Wed, 24 Jan 2024 06:15:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706105720; x=1706710520; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kinIyrY0DiVL9FjvsbU90IrpJuAQN+qhOmTSZHZdLpE=; b=DSINa5t3MmDC8b2fbZ/xUX2D2ctlZnXEZf1qMjsrZPQmF1Chq0+fBQPztuxKmSTYzl jlPVPKICQBJThTEyqE2APseDp/9idHUSrfvC07LuCyJBJjNKn0IGMxMI28Yj8SeY2nv4 AARfcbe6g+zH5MSAffVrD+5g1KUsNjIJapezxudwGujChqw2I/2Bqh8eAjQ5AYpUwN7H omJgIPvIBfEnsicWt5Fi5lxfRnFxcoob5lHp/7dy9sm8LGlKyjA9WZNahRGK3oZ44CX2 QFI59jvPophJ2WO7t3tF5okxVF1PMcgk3D8bUIrkJ+I+4mctPB3p8Ig1iRCVwRtx3Cv8 9u3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706105720; x=1706710520; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kinIyrY0DiVL9FjvsbU90IrpJuAQN+qhOmTSZHZdLpE=; b=ZZBTdeTUvsqpC5Um9jvX6Y3vrqKn10LUIEBOdVhzyOn1yIwGABnYkGWvERmeF3lICE jgOkJKmPjYnozMGkNvbdrqZvrgyjPj7mCkutmUyXuNffvTf0W5N1kWoc4TvDQUnqkR/x epdu/aOrbErzQr/ZUmJXdzPN8nDR5RvM8cMLmeop6y59pQfMshQcjT0ez94R9DYeq7md dupgAo6Zib5l1e+c0MQzDI+4McMzD0vW+rHkxxe0359etTYCCBL9LgNgPYNaOrJD2D5i jeyLBznGbVikoWW2OUZs5VTtixpk8B+IKQR9hBwqbf09nPon9MRDjsSS+fUb1O5JrtVy 3F1Q== X-Gm-Message-State: AOJu0YxMvDF9Z4BGqM3dU6tsWJ1ZwdNNJoEDznBLttYys+fjUMGYqvgl YiixdzCBHCbs3YvVT3hLfU8moUsmWiPPG/orxLqwD4QmXYdjkMh6ImphPcnp+Y0= X-Received: by 2002:a17:907:30cd:b0:a30:de41:2c with SMTP id vl13-20020a17090730cd00b00a30de41002cmr447163ejb.161.1706105720026; Wed, 24 Jan 2024 06:15:20 -0800 (PST) Received: from ttritton.c.googlers.com.com (64.227.90.34.bc.googleusercontent.com. [34.90.227.64]) by smtp.gmail.com with ESMTPSA id vu3-20020a170907a64300b00a2d7f63dd71sm12399097ejc.29.2024.01.24.06.15.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 06:15:19 -0800 (PST) From: Terry Tritton To: keescook@chromium.org, luto@amacapital.net, wad@chromium.org, shuah@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, peter.griffin@linaro.org, kernel-team@android.com, bettyzhou@google.com, Terry Tritton Subject: [PATCH 2/3] selftests/seccomp: Change the syscall used in KILL_THREAD test Date: Wed, 24 Jan 2024 14:13:56 +0000 Message-ID: <20240124141357.1243457-3-terry.tritton@linaro.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240124141357.1243457-1-terry.tritton@linaro.org> References: <20240124141357.1243457-1-terry.tritton@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788982259731275161 X-GMAIL-MSGID: 1788982259731275161 The Bionic version of pthread_create used on Android calls the prctl function to give the stack and thread local storage a useful name. This will cause the KILL_THREAD test to fail as it will kill the thread as soon as it is created. change the test to use getpid instead of prctl. Signed-off-by: Terry Tritton --- tools/testing/selftests/seccomp/seccomp_bpf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index 5e705674b706..da11b95b8872 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c @@ -784,7 +784,7 @@ void *kill_thread(void *data) bool die = (bool)data; if (die) { - prctl(PR_GET_SECCOMP, 0, 0, 0, 0); + syscall(__NR_getpid); return (void *)SIBLING_EXIT_FAILURE; } @@ -803,11 +803,11 @@ void kill_thread_or_group(struct __test_metadata *_metadata, { pthread_t thread; void *status; - /* Kill only when calling __NR_prctl. */ + /* Kill only when calling __NR_getpid. */ struct sock_filter filter_thread[] = { BPF_STMT(BPF_LD|BPF_W|BPF_ABS, offsetof(struct seccomp_data, nr)), - BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_prctl, 0, 1), + BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_getpid, 0, 1), BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_KILL_THREAD), BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), }; @@ -819,7 +819,7 @@ void kill_thread_or_group(struct __test_metadata *_metadata, struct sock_filter filter_process[] = { BPF_STMT(BPF_LD|BPF_W|BPF_ABS, offsetof(struct seccomp_data, nr)), - BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_prctl, 0, 1), + BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_getpid, 0, 1), BPF_STMT(BPF_RET|BPF_K, kill), BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), }; From patchwork Wed Jan 24 14:13:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Terry Tritton X-Patchwork-Id: 191583 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1017476dyi; Wed, 24 Jan 2024 06:17:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZrXdBv6AjZPiDLhXJYkCV6QlDvqxHshJ3mQrmTwBmy8ltbv+qI/dyqzOCcmGLN0cwSdc5 X-Received: by 2002:a05:6402:d5f:b0:55c:2609:e3c8 with SMTP id ec31-20020a0564020d5f00b0055c2609e3c8mr1893859edb.19.1706105871138; Wed, 24 Jan 2024 06:17:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706105871; cv=pass; d=google.com; s=arc-20160816; b=VsA8TkU8WS/RlA1okL2opECAtEvoATkndfjR0Qqc9ofMJ1fc+EbxsUTjHSByHF/UaE DlcsZE34YJmC9oBuhhACzRn5SRP2KYePz+selrGoOs28fX8m9evjNV+yitWZlKhJImFJ YTXGN99B7DS+j/H7wk6qtXRJIkEAv+vlY7ZUvoYuvz7e/kXrPKIIU8onrKbXPQgkTOQs vGbPgLai3qaHvpvoPwoORgSye+39dfvNwI8rsxPMQK9fG4GBcYuS5GBVumJiMPqE/G2G ZKmskZOXSzjlIuuPdyqNzmn2mdZHMiDz9k2l8h958eYQ8KioOO4A63R1tNr8CUCNWhsR 91kg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Emu9TGmELjy3ceHR0soeUQYq/a/KfpUveoio5V7U5Xk=; fh=pA9JhLexjB+OV5pnnYNCIXkC6iVsJegx2ipdtlnT5ok=; b=KsbHlEuftYzoIyHdphXOPfenz2YRuustjdGh+505q9MB3GN5SOWEfTsvXRB7Wkqhbx EYeSOwjhUL8jIs0BxcHrh3KyTM96r+8PsX9de9zhJZCUA5EhubkoyxL9G2U9th9D7TrM sTf5Kr4KyxbX0zkHeKvDo7xpkZDYv74hF1XQ5UE7oFDKoeXVC79k7re2aWPYgvAghJVs zeNf376LjsIP3Ab3w+Ap7Zo/Vv3AtbtH3o5oMWcjJn+zPGC3GPPMWa/sDIzoG2jQMNEt QAeVVeHck60/HLrGOS4HWZhDIfr1UT/kOvq6WbqVj3uYjpP+/kmXvT/HRRPA1HtBYedf 8ZoQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dCtjoMkB; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-37096-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37096-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u2-20020a50a402000000b0055c9438efe0si1468642edb.201.2024.01.24.06.17.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 06:17:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37096-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dCtjoMkB; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-37096-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37096-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 376D91F21638 for ; Wed, 24 Jan 2024 14:16:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF8407A734; Wed, 24 Jan 2024 14:15:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dCtjoMkB" Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30AEF7C090 for ; Wed, 24 Jan 2024 14:15:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706105730; cv=none; b=KZqPHzcZ81ayUOjp9oq0qXbABZQ2/Njrcqj+i1mP1nC73o7WUF4IkOq1ev5R6VxpQWaVU5U9qWM4wPN1FfsBQYseog8cHB5EPDmK8NbdR0xVskr3sOSJT814bXZOaKxPmkdD9Qf9xK3Jd7GPYKXO5HH6EGaJqjQBmEH/Jm7XNqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706105730; c=relaxed/simple; bh=SXgjaHAj6mc5bUoF/0ublXUVySE2uQcKr8Ju/E+GUFI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kJBz6bISges2Ve605eq3VHzsED2gO7fURRwxWPs8I6XbYIwcVPdkxKSfzNhY4eJ9Y6/wzP8Iyhe3WwUY8BTf+wtGyClbya72FSClrCaHHHI9kP93yU5caPpgcNZ+16EEeUzqfI5O7I/U+kDNp4o0dnAwRvzJLxIGJ5sjyQdBIY4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=dCtjoMkB; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5100b424f8fso1717620e87.0 for ; Wed, 24 Jan 2024 06:15:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706105725; x=1706710525; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Emu9TGmELjy3ceHR0soeUQYq/a/KfpUveoio5V7U5Xk=; b=dCtjoMkBZiBnh1uqZqVSrH5uPUKKQEMZfoCYRJxAVUm9K6DVIuFeFoR/2eyzy6QEpq VW40pmawSkIQZbq4pyM20SSLWo2sEYrUrPUcv51OTcZzbGrQ6mixVLZv/wiZlfxs57A5 7wla1NLiBOoMg8nqJRkhWJ0kdaxzuqmFCUmAdTkJveYj0rFCWyiiRCkXIi7iTelCeWpm 5XMX2NEBCljrCdN7/uySTJg9dkcvOKiHfvUF8RcIEiyEBW6Q+6VapzYjnsEBcY75Yp9u z4jK7dt+st47mf3Zb0nXmifzAuctHiovfXDc+wFn+7Nipi6AcJLdavecTPPkYAvwD9wZ Bshg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706105725; x=1706710525; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Emu9TGmELjy3ceHR0soeUQYq/a/KfpUveoio5V7U5Xk=; b=dO0K5I1EJvjsU29Y1re6UYmkPI/mXbZhwOt611fyHtRC8usXTRV9I3k7mTd4ANSX/S vmLrQzgPVgoxA5cq9GGz+jV3BlBpxTZNRrbgiz18yuXWoW9yLwW+S2lDrVOgt9qTTZec XXcGtR7brcsCQj9Ium06A8gevd+O5WTTuM1WRvIhHTY9cA4fKjqqU+ZlvLd2DxGdgnq8 KVy2WeizjeawOqbZKQmVt7Qt9GeVGgzhwEMlJv2dohVmCmZeLtU6jYRFOFRGJFFJLqmj Iw1rK6MrPcYx5fRjFojCRTJIpdoKW0g5a1Y90v9CbgGz+MU4lC89vR6Nf1jb/jezsqUG nrKQ== X-Gm-Message-State: AOJu0Yw5e42Ny1/cQ7fGNh/StFy+C2TBR7PfXmDwxTYgviKyywy5PphX +8hzkkOpwyTWHLzJoPW6FY7iK300y130unOHNckRlGxKYs4yf+z7hVS98AFFei0= X-Received: by 2002:a05:6512:2808:b0:50e:ccfa:56c3 with SMTP id cf8-20020a056512280800b0050eccfa56c3mr4497154lfb.34.1706105725323; Wed, 24 Jan 2024 06:15:25 -0800 (PST) Received: from ttritton.c.googlers.com.com (64.227.90.34.bc.googleusercontent.com. [34.90.227.64]) by smtp.gmail.com with ESMTPSA id vu3-20020a170907a64300b00a2d7f63dd71sm12399097ejc.29.2024.01.24.06.15.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 06:15:25 -0800 (PST) From: Terry Tritton To: keescook@chromium.org, luto@amacapital.net, wad@chromium.org, shuah@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, peter.griffin@linaro.org, kernel-team@android.com, bettyzhou@google.com, Terry Tritton Subject: [PATCH 3/3] selftests/seccomp: user_notification_addfd check nextfd is available Date: Wed, 24 Jan 2024 14:13:57 +0000 Message-ID: <20240124141357.1243457-4-terry.tritton@linaro.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240124141357.1243457-1-terry.tritton@linaro.org> References: <20240124141357.1243457-1-terry.tritton@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788981669897328027 X-GMAIL-MSGID: 1788981669897328027 Currently the user_notification_addfd test checks what the next expected file descriptor will be by incrementing a variable nextfd. This does not account for file descriptors that may already be open before the test is started and will cause the test to fail if any exist. Replace nextfd++ with a function get_next_fd which will check and return the next available file descriptor. Signed-off-by: Terry Tritton --- tools/testing/selftests/seccomp/seccomp_bpf.c | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index da11b95b8872..cacf6507f690 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c @@ -4044,6 +4044,16 @@ TEST(user_notification_filter_empty_threaded) EXPECT_GT((pollfd.revents & POLLHUP) ?: 0, 0); } + +int get_next_fd(int prev_fd) +{ + for (int i = prev_fd + 1; i < FD_SETSIZE; ++i) { + if (fcntl(i, F_GETFD) == -1) + return i; + } + _exit(EXIT_FAILURE); +} + TEST(user_notification_addfd) { pid_t pid; @@ -4060,7 +4070,7 @@ TEST(user_notification_addfd) /* There may be arbitrary already-open fds at test start. */ memfd = memfd_create("test", 0); ASSERT_GE(memfd, 0); - nextfd = memfd + 1; + nextfd = get_next_fd(memfd); ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); ASSERT_EQ(0, ret) { @@ -4071,7 +4081,8 @@ TEST(user_notification_addfd) /* Check that the basic notification machinery works */ listener = user_notif_syscall(__NR_getppid, SECCOMP_FILTER_FLAG_NEW_LISTENER); - ASSERT_EQ(listener, nextfd++); + ASSERT_EQ(listener, nextfd); + nextfd = get_next_fd(nextfd); pid = fork(); ASSERT_GE(pid, 0); @@ -4126,14 +4137,16 @@ TEST(user_notification_addfd) /* Verify we can set an arbitrary remote fd */ fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd); - EXPECT_EQ(fd, nextfd++); + EXPECT_EQ(fd, nextfd); + nextfd = get_next_fd(nextfd); EXPECT_EQ(filecmp(getpid(), pid, memfd, fd), 0); /* Verify we can set an arbitrary remote fd with large size */ memset(&big, 0x0, sizeof(big)); big.addfd = addfd; fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD_BIG, &big); - EXPECT_EQ(fd, nextfd++); + EXPECT_EQ(fd, nextfd); + nextfd = get_next_fd(nextfd); /* Verify we can set a specific remote fd */ addfd.newfd = 42; @@ -4171,7 +4184,8 @@ TEST(user_notification_addfd) * Child has earlier "low" fds and now 42, so we expect the next * lowest available fd to be assigned here. */ - EXPECT_EQ(fd, nextfd++); + EXPECT_EQ(fd, nextfd); + nextfd = get_next_fd(nextfd); ASSERT_EQ(filecmp(getpid(), pid, memfd, fd), 0); /*