Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1684205ybh; Sun, 8 Mar 2020 10:17:26 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvPddoNAx5sxsbgA1SFbk+w39waiihrS8OlLjeEVOUcd8WRoLvT0nwv33u71wiUKctNHaws X-Received: by 2002:aca:c45:: with SMTP id i5mr4961239oiy.111.1583687846653; Sun, 08 Mar 2020 10:17:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583687846; cv=none; d=google.com; s=arc-20160816; b=do7zSX5i+I/ICuJQ3VCMu03q8OuGp5IVVH6neTbN3Wf9kmdYU2hOB63Wd48yt4gMOp cODdpELeLtKsmOeCKmGCL37YbpFsQL+/wDyl23QyMoYPaIFP7xLl+OCGocWlMDsfLL6Q vzj4kfOp7nD0RQRA3nXARGbNii/7IgEUi0BfAkg/fB43n5UHGWXHsIb80Poyx489c1cZ k37L2cQw1WgJ5S876hlVBLYRwxCyflftoAZwT2ZuXEd9fk7CDoUAluQAEHf1E+GvH/Dk ZarOv2WSc74sTBPpsqym54EaKrEVqe58R1OvPpmLAU/CHctXJgiLWIvPB279jRsx5TzY yX3A== 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; bh=kp2xK0AH3mSMqrV4acmfoDTBBI08YOeXN8JWCF43+/0=; b=ZJvRbzbSPSv6fmprlVibTBDFCOZ47YC7hE0I18vdyNZKBum4SgK5F49ZamZV+sCZUz j3QKTNBwjifXnECWN1dQE2CFiTTkYG6U/w5JJVvZuxWbLu8KN3QJ36nVu0zshbA09+We dfcz2tlnsXG5Gj2/Tymfm7jbQzCC95u7unayHR4Uj5/l+vi5eyMQ0Xx7DBnVmmLWLcRq DohVIKunR0jy9v8U/dg/NDXJyAlzX7Dyd3et7ZYiswk/45LNwBuaJM+/OmLT7+z+6BxZ KYmZcQ+r8UxlnMtGUtQl1RUC2YB/kD/z71F4k+rcKAFJiJS4aPUsLb6DDODZI+R2pAjW yPTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s2si2902728otp.266.2020.03.08.10.17.11; Sun, 08 Mar 2020 10:17:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726384AbgCHRQo (ORCPT + 99 others); Sun, 8 Mar 2020 13:16:44 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:56541 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726359AbgCHRQn (ORCPT ); Sun, 8 Mar 2020 13:16:43 -0400 Received: from ip5f5bf7ec.dynamic.kabel-deutschland.de ([95.91.247.236] helo=wittgenstein.fritz.box) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jAzXa-0007YQ-6f; Sun, 08 Mar 2020 17:16:38 +0000 From: Christian Brauner To: christian.brauner@ubuntu.com Cc: 0x7f454c46@gmail.com, areber@redhat.com, avagin@gmail.com, cminyard@mvista.com, linux-kernel@vger.kernel.org, minyard@acm.org, oleg@redhat.com Subject: [PATCH] selftests: add pid namespace ENOMEM regression test Date: Sun, 8 Mar 2020 18:16:27 +0100 Message-Id: <20200308171627.3157660-1-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200308171007.3155138-1-christian.brauner@ubuntu.com> References: <20200308171007.3155138-1-christian.brauner@ubuntu.com> 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 We recently regressed (cf. [1] and its corresponding fix in [2]) returning ENOMEM when trying to create a process in a pid namespace whose init process/child subreaper has already died. This has caused confusion at least once before that (cf. [3]). Let's add a simple regression test to catch this in the future. [1]: 49cb2fc42ce4 ("fork: extend clone3() to support setting a PID") [2]: b26ebfe12f34 ("pid: Fix error return value in some cases") [3]: 35f71bc0a09a ("fork: report pid reservation failure properly") Cc: Corey Minyard Cc: Oleg Nesterov Cc: Adrian Reber Cc: Dmitry Safonov <0x7f454c46@gmail.com> Cc: Andrei Vagin Signed-off-by: Christian Brauner --- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + .../selftests/pid_namespace/.gitignore | 1 + .../testing/selftests/pid_namespace/Makefile | 8 ++++ tools/testing/selftests/pid_namespace/config | 2 + .../pid_namespace/regression_enomem.c | 45 +++++++++++++++++++ tools/testing/selftests/pidfd/pidfd.h | 2 + 7 files changed, 60 insertions(+) create mode 100644 tools/testing/selftests/pid_namespace/.gitignore create mode 100644 tools/testing/selftests/pid_namespace/Makefile create mode 100644 tools/testing/selftests/pid_namespace/config create mode 100644 tools/testing/selftests/pid_namespace/regression_enomem.c diff --git a/MAINTAINERS b/MAINTAINERS index 6158a143a13e..e3a83c739ff3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13159,6 +13159,7 @@ S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git F: samples/pidfd/ F: tools/testing/selftests/pidfd/ +F: tools/testing/selftests/pid_namespace/ F: tools/testing/selftests/clone3/ K: (?i)pidfd K: (?i)clone3 diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 6ec503912bea..5fc587b7136f 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -38,6 +38,7 @@ TARGETS += netfilter TARGETS += networking/timestamping TARGETS += nsfs TARGETS += pidfd +TARGETS += pid_namespace TARGETS += powerpc TARGETS += proc TARGETS += pstore diff --git a/tools/testing/selftests/pid_namespace/.gitignore b/tools/testing/selftests/pid_namespace/.gitignore new file mode 100644 index 000000000000..93ab9d7e5b7e --- /dev/null +++ b/tools/testing/selftests/pid_namespace/.gitignore @@ -0,0 +1 @@ +regression_enomem diff --git a/tools/testing/selftests/pid_namespace/Makefile b/tools/testing/selftests/pid_namespace/Makefile new file mode 100644 index 000000000000..dcaefa224ca0 --- /dev/null +++ b/tools/testing/selftests/pid_namespace/Makefile @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +CFLAGS += -g -I../../../../usr/include/ + +TEST_GEN_PROGS := regression_enomem + +include ../lib.mk + +$(OUTPUT)/regression_enomem: regression_enomem.c ../pidfd/pidfd.h diff --git a/tools/testing/selftests/pid_namespace/config b/tools/testing/selftests/pid_namespace/config new file mode 100644 index 000000000000..26cdb27e7dbb --- /dev/null +++ b/tools/testing/selftests/pid_namespace/config @@ -0,0 +1,2 @@ +CONFIG_PID_NS=y +CONFIG_USER_NS=y diff --git a/tools/testing/selftests/pid_namespace/regression_enomem.c b/tools/testing/selftests/pid_namespace/regression_enomem.c new file mode 100644 index 000000000000..73d532556d17 --- /dev/null +++ b/tools/testing/selftests/pid_namespace/regression_enomem.c @@ -0,0 +1,45 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../kselftest.h" +#include "../kselftest_harness.h" +#include "../pidfd/pidfd.h" + +/* + * Regression test for: + * 35f71bc0a09a ("fork: report pid reservation failure properly") + * b26ebfe12f34 ("pid: Fix error return value in some cases") + */ +TEST(regression_enomem) +{ + pid_t pid; + + if (geteuid()) + EXPECT_EQ(0, unshare(CLONE_NEWUSER)); + + EXPECT_EQ(0, unshare(CLONE_NEWPID)); + + pid = fork(); + ASSERT_GE(pid, 0); + + if (pid == 0) + exit(EXIT_SUCCESS); + + EXPECT_EQ(0, wait_for_pid(pid)); + + pid = fork(); + ASSERT_LT(pid, 0); + ASSERT_EQ(errno, ENOMEM); +} + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/pidfd/pidfd.h b/tools/testing/selftests/pidfd/pidfd.h index d482515604db..c1921a53dbed 100644 --- a/tools/testing/selftests/pidfd/pidfd.h +++ b/tools/testing/selftests/pidfd/pidfd.h @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include "../kselftest.h" base-commit: 8deb24dcb89cb390110d2ccac830a84d1ab5cee4 -- 2.25.1