From patchwork Fri May 4 08:28:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 908596 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40clXh1jT2z9s3D for ; Fri, 4 May 2018 18:28:50 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B2AD23E6D87 for ; Fri, 4 May 2018 10:28:46 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id CDFFE3E6CF8 for ; Fri, 4 May 2018 10:28:44 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 741A6601BCD for ; Fri, 4 May 2018 10:28:41 +0200 (CEST) Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C2931AB3A; Fri, 4 May 2018 08:28:40 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Fri, 4 May 2018 10:28:29 +0200 Message-Id: <20180504082829.10973-1-pvorel@suse.cz> X-Mailer: git-send-email 2.16.3 X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Cc: kernel-team@android.com Subject: [LTP] [PATCH 1/1] setregid: Fallback to `nogroup' group X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" if group `nobody' does not exist This is at least on default installation of Debian 9. Fixes: 1b7cf9474 setregid: use common user and group names. Signed-off-by: Petr Vorel Reported-by: Cyril Hrubis --- testcases/kernel/syscalls/setregid/setregid03.c | 15 ++++++++++++++- testcases/kernel/syscalls/setregid/setregid04.c | 11 ++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/testcases/kernel/syscalls/setregid/setregid03.c b/testcases/kernel/syscalls/setregid/setregid03.c index 97102e0ee..a4caf238d 100644 --- a/testcases/kernel/syscalls/setregid/setregid03.c +++ b/testcases/kernel/syscalls/setregid/setregid03.c @@ -195,7 +195,20 @@ static void setup(void) group ## _gr = *(junk); \ } while (0) - GET_GID(nobody); +#define GET_GID_FALLBACK(group, group2) do { \ + junk = getgrnam(#group); \ + if (junk == NULL) { \ + tst_resm(TINFO, "%s not found, trying fallback %s", #group, #group2); \ + junk = getgrnam(#group2); \ + if (junk == NULL) { \ + tst_brkm(TBROK, NULL, "%s or %s must be a valid group", #group, #group2); \ + } \ + } \ + GID16_CHECK(junk->gr_gid, setregid, NULL); \ + group ## _gr = *(junk); \ +} while (0) + + GET_GID_FALLBACK(nobody, nogroup); GET_GID(daemon); GET_GID(bin); diff --git a/testcases/kernel/syscalls/setregid/setregid04.c b/testcases/kernel/syscalls/setregid/setregid04.c index 73f8bcb03..bf744ff05 100644 --- a/testcases/kernel/syscalls/setregid/setregid04.c +++ b/testcases/kernel/syscalls/setregid/setregid04.c @@ -116,6 +116,15 @@ int main(int ac, char **av) } \ GROUPNAME ## _gr = *(getgrnam(#GROUPNAME)); +#define SAFE_GETGROUP_FALLBACK(GROUPNAME, GROUPNAME2) \ + if (getgrnam(#GROUPNAME) != NULL) \ + GROUPNAME ## _gr = *(getgrnam(#GROUPNAME)); \ + else if (getgrnam(#GROUPNAME2) != NULL) { \ + GROUPNAME ## _gr = *(getgrnam(#GROUPNAME2)); \ + tst_resm(TINFO, "`" #GROUPNAME "' group not found, trying fallback `" #GROUPNAME2 "' group"); \ + } else \ + tst_brkm(TBROK, NULL, "Couldn't find neither`" #GROUPNAME "' `" #GROUPNAME2 "' nor group"); + static void setup(void) { tst_require_root(); @@ -123,7 +132,7 @@ static void setup(void) tst_sig(FORK, DEF_HANDLER, cleanup); SAFE_GETGROUP(root); - SAFE_GETGROUP(nobody); + SAFE_GETGROUP_FALLBACK(nobody, nogroup); SAFE_GETGROUP(daemon); SAFE_GETGROUP(bin);