From patchwork Thu Dec 5 12:20:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11274697 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6268E109A for ; Thu, 5 Dec 2019 12:21:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F9E124249 for ; Thu, 5 Dec 2019 12:21:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575548463; bh=edquYFBHaofPMU3DDDEksKNwbLIT1/Uva327KZiKnv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=TDPLbgd2EKZhewZ1FVNeiZoVNSqjfruP5O7pZBGTzKJFtd5m15YwsnYYI+yoqcG4X rdF3nULuCuGfEIlSmvoh0Cs5tKPvXGVn3S2npSlUSCaNLAK3nEFEMJJnW52R0flymP OnWrT12Wge62rd80GolIszeOubEfFolebawRAZ7M= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729096AbfLEMVC (ORCPT ); Thu, 5 Dec 2019 07:21:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:37228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729074AbfLEMVC (ORCPT ); Thu, 5 Dec 2019 07:21:02 -0500 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 956EB24249; Thu, 5 Dec 2019 12:21:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575548461; bh=edquYFBHaofPMU3DDDEksKNwbLIT1/Uva327KZiKnv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UN6nYKbFRYTVks+DlN6AqIMri32etT5PbonNAOXosiwERnrxzF1krAtvzBBbofrpj pPfjnRG1NRuC6qbcpGm2Mo1w9PIo+HbLhOI7cSf69hmFTSVSfNHOAxT8XNgOyCPh5M U+EPq1v4+ubxg8ZMMeMGAD4i4BoN54lMyCPP3aVQ= From: Masami Hiramatsu To: Shuah Khan Cc: Micah Morton , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, jaswinder.singh@linaro.org Subject: [BUGFIX PATCH v2 1/3] selftests: safesetid: Move link library to LDLIBS Date: Thu, 5 Dec 2019 21:20:58 +0900 Message-Id: <157554845808.11018.11000592632669206853.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <157554844882.11018.13436399905210284553.stgit@devnote2> References: <157554844882.11018.13436399905210284553.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Move -lcap to LDLIBS from CFLAGS because it is a library to be linked. Without this, safesetid failed to build with link error as below. ---- /usr/bin/ld: /tmp/ccL8rZHT.o: in function `drop_caps': safesetid-test.c:(.text+0xe7): undefined reference to `cap_get_proc' /usr/bin/ld: safesetid-test.c:(.text+0x107): undefined reference to `cap_set_flag' /usr/bin/ld: safesetid-test.c:(.text+0x10f): undefined reference to `cap_set_proc' /usr/bin/ld: safesetid-test.c:(.text+0x117): undefined reference to `cap_free' /usr/bin/ld: safesetid-test.c:(.text+0x136): undefined reference to `cap_clear' collect2: error: ld returned 1 exit status ---- Fixes: c67e8ec03f3f ("LSM: SafeSetID: add selftest") Signed-off-by: Masami Hiramatsu --- tools/testing/selftests/safesetid/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/safesetid/Makefile b/tools/testing/selftests/safesetid/Makefile index 98da7a504737..cac42cd36a1b 100644 --- a/tools/testing/selftests/safesetid/Makefile +++ b/tools/testing/selftests/safesetid/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for mount selftests. -CFLAGS = -Wall -lcap -O2 +CFLAGS = -Wall -O2 +LDLIBS = -lcap TEST_PROGS := run_tests.sh TEST_GEN_FILES := safesetid-test From patchwork Thu Dec 5 12:21:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11274699 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0FE01109A for ; Thu, 5 Dec 2019 12:21:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2D742464D for ; Thu, 5 Dec 2019 12:21:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575548472; bh=SBlr5dGydninkCDGtDUbXFFCG6ezPnNxiEjeRYEwuos=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=QX/8rijCk29czmocSsd4jyTua/5OeYs+EvfL+T71hBT9f4vJ+SPj0qTnIAtcypLdm 3ymK0lcLf0fDebh/5TSkeYzeLScZnptRWgs01Z8eNNNhsElpfBqWmJZCFP/Q91zaR8 LIF+m3DorKJ2WCF9SCKBCrLoIhhokGumYc/58HMY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729416AbfLEMVL (ORCPT ); Thu, 5 Dec 2019 07:21:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:37480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729096AbfLEMVL (ORCPT ); Thu, 5 Dec 2019 07:21:11 -0500 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 88AE524648; Thu, 5 Dec 2019 12:21:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575548470; bh=SBlr5dGydninkCDGtDUbXFFCG6ezPnNxiEjeRYEwuos=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wS7Hu+AFxHo6F3Ux3telmAkxXMRJyIaC4LeXqZ241x1xRz0nq57mahCQBmbTBAtvH kDDrPa0CDYrKKQgvpXrNx7QRFWnosBEZ0MGS4A9vo2vafhsrypXxbpEzXSpqGcqPI4 LNUqtOLkAfgzXBqviZc/Iz8ikzc4bpTjgnwzb/4o= From: Masami Hiramatsu To: Shuah Khan Cc: Micah Morton , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, jaswinder.singh@linaro.org Subject: [BUGFIX PATCH v2 2/3] selftests: safesetid: Check the return value of setuid/setgid Date: Thu, 5 Dec 2019 21:21:07 +0900 Message-Id: <157554846729.11018.17578640397639892557.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <157554844882.11018.13436399905210284553.stgit@devnote2> References: <157554844882.11018.13436399905210284553.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Check the return value of setuid() and setgid(). This fixes the following warnings and improves test result. safesetid-test.c: In function ‘main’: safesetid-test.c:294:2: warning: ignoring return value of ‘setuid’, declared with attribute warn_unused_result [-Wunused-result] setuid(NO_POLICY_USER); ^~~~~~~~~~~~~~~~~~~~~~ safesetid-test.c:295:2: warning: ignoring return value of ‘setgid’, declared with attribute warn_unused_result [-Wunused-result] setgid(NO_POLICY_USER); ^~~~~~~~~~~~~~~~~~~~~~ safesetid-test.c:309:2: warning: ignoring return value of ‘setuid’, declared with attribute warn_unused_result [-Wunused-result] setuid(RESTRICTED_PARENT); ^~~~~~~~~~~~~~~~~~~~~~~~~ safesetid-test.c:310:2: warning: ignoring return value of ‘setgid’, declared with attribute warn_unused_result [-Wunused-result] setgid(RESTRICTED_PARENT); ^~~~~~~~~~~~~~~~~~~~~~~~~ safesetid-test.c: In function ‘test_setuid’: safesetid-test.c:216:3: warning: ignoring return value of ‘setuid’, declared with attribute warn_unused_result [-Wunused-result] setuid(child_uid); ^~~~~~~~~~~~~~~~~ Fixes: c67e8ec03f3f ("LSM: SafeSetID: add selftest") Signed-off-by: Masami Hiramatsu --- tools/testing/selftests/safesetid/safesetid-test.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/safesetid/safesetid-test.c b/tools/testing/selftests/safesetid/safesetid-test.c index 8f40c6ecdad1..0c4d50644c13 100644 --- a/tools/testing/selftests/safesetid/safesetid-test.c +++ b/tools/testing/selftests/safesetid/safesetid-test.c @@ -213,7 +213,8 @@ static void test_setuid(uid_t child_uid, bool expect_success) } if (cpid == 0) { /* Code executed by child */ - setuid(child_uid); + if (setuid(child_uid) < 0) + exit(EXIT_FAILURE); if (getuid() == child_uid) exit(EXIT_SUCCESS); else @@ -291,8 +292,10 @@ int main(int argc, char **argv) // First test to make sure we can write userns mappings from a user // that doesn't have any restrictions (as long as it has CAP_SETUID); - setuid(NO_POLICY_USER); - setgid(NO_POLICY_USER); + if (setuid(NO_POLICY_USER) < 0) + die("Error with set uid(%d)\n", NO_POLICY_USER); + if (setgid(NO_POLICY_USER) < 0) + die("Error with set gid(%d)\n", NO_POLICY_USER); // Take away all but setid caps drop_caps(true); @@ -306,8 +309,10 @@ int main(int argc, char **argv) die("test_userns failed when it should work\n"); } - setuid(RESTRICTED_PARENT); - setgid(RESTRICTED_PARENT); + if (setuid(RESTRICTED_PARENT) < 0) + die("Error with set uid(%d)\n", RESTRICTED_PARENT); + if (setgid(RESTRICTED_PARENT) < 0) + die("Error with set gid(%d)\n", RESTRICTED_PARENT); test_setuid(ROOT_USER, false); test_setuid(ALLOWED_CHILD1, true); From patchwork Thu Dec 5 12:21:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11274701 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3584109A for ; Thu, 5 Dec 2019 12:21:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A10F82464D for ; Thu, 5 Dec 2019 12:21:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575548480; bh=nQdhrd7aELhldb/xa20PECJL2oSRA7hAdzZouMGzijw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=QBugDOiIadna9eLmHuB4jh4oSG5/wd22wbrcxlFF3MiY9XbHM9stUNX7C3tfaEedj bqgH9YQnytWWU3ZmFNkSlY6TIeJo3riQrNdZX2flzmz8MSPwrIsGGqT8/lbGQJH3mc v5XsNmZe3ROvNpvwpJDxT0IcfQlYHwkpL0m1GSM4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729441AbfLEMVU (ORCPT ); Thu, 5 Dec 2019 07:21:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:37732 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729096AbfLEMVU (ORCPT ); Thu, 5 Dec 2019 07:21:20 -0500 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5FD2024648; Thu, 5 Dec 2019 12:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575548479; bh=nQdhrd7aELhldb/xa20PECJL2oSRA7hAdzZouMGzijw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zp/6DQPD5+nmSamf0+WXxxGdYksR3KTlW0NPjzgvNaiaBFZYEhflzIbAkYH0FfjJ0 s62LqD1Ap59hDC8WJjjWzI9YsIy9JgwWiCsQ+CjelffHtj3DI24ku1x2KWNNP+ql+W SUKYP2wgCDBSVEhnc3bIbHfobwCw0WT+G+3CJp8I= From: Masami Hiramatsu To: Shuah Khan Cc: Micah Morton , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, jaswinder.singh@linaro.org Subject: [BUGFIX PATCH v2 3/3] selftests: safesetid: Fix Makefile to set correct test program Date: Thu, 5 Dec 2019 21:21:16 +0900 Message-Id: <157554847591.11018.5631502480695471273.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <157554844882.11018.13436399905210284553.stgit@devnote2> References: <157554844882.11018.13436399905210284553.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Fix Makefile to set safesetid-test.sh to TEST_PROGS instead of non existing run_tests.sh. Without this fix, I got following error. ---- TAP version 13 1..1 # selftests: safesetid: run_tests.sh # Warning: file run_tests.sh is missing! not ok 1 selftests: safesetid: run_tests.sh ---- Fixes: c67e8ec03f3f ("LSM: SafeSetID: add selftest") Signed-off-by: Masami Hiramatsu --- tools/testing/selftests/safesetid/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/safesetid/Makefile b/tools/testing/selftests/safesetid/Makefile index cac42cd36a1b..fa02c4d5ec13 100644 --- a/tools/testing/selftests/safesetid/Makefile +++ b/tools/testing/selftests/safesetid/Makefile @@ -3,7 +3,7 @@ CFLAGS = -Wall -O2 LDLIBS = -lcap -TEST_PROGS := run_tests.sh +TEST_PROGS := safesetid-test.sh TEST_GEN_FILES := safesetid-test include ../lib.mk