Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1614226ybl; Thu, 5 Dec 2019 04:22:02 -0800 (PST) X-Google-Smtp-Source: APXvYqyW8MIZjYppEWTFDNvK1sWF6wh3cfmgysXnXnGHqL+66yjZmgfipAz4fGEr2OOFgWOQIdX+ X-Received: by 2002:aca:4911:: with SMTP id w17mr1107888oia.22.1575548522433; Thu, 05 Dec 2019 04:22:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575548522; cv=none; d=google.com; s=arc-20160816; b=nfeP03NLxsJQCkeymMM/YJgmCCG4Dh4ABb3CepwcQSQymFsxIHT90QSN4TgY0QaYK5 xMoqTgoUNVAvT2AafVW1NXadXL1nZsVccckjf+EuDveI/g8hqXGwtMwsW4Rb65nHKTLY eKM1CI9KXFPvNhlDkD5tlEhtoe1aEB+W1Xqb2GWlKbR+NSp6c9ggyfi+LQvnXdCYNjKI 4e5mABVu41oB2upaGQoKAPJgBp09r4CvbKJuzD54XBXtLYFYjx1dJdLcnUY2Uonz7Nd0 3WGrUJDjN2NMs6Q33pPepqlGIkZjKR/grT9CqZ+d8BCeR2N07zCXxNFoo/UPoPzIOkbL /mTw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BUdxfMezipuf+7Gi4dRh9/tWWX+A3R341Vg7RWk4OKU=; b=J8IjoIi+5yeoSxbTXwXAPeKiyUPtFhDSN/XbJmhA3ROKAkCNN7xlWLmqlY9JlcgswK lTEVIXFYlr0E//vX+HtTvHu9vOVvR+BB2nSGCIfg7XlYbb3JCp44YV3DfPidXFNIJFXn YdOu9njc0AJ+CbfAmEmwhOnx3RhAU37IpnZ2d3v8StFd/RvGYeV3miNgWoVp0kgDLnn4 3VLCi9b/rRJ2VMb1798utEQqkKsqtKbnT9TtKTZ10+Sahtfwrw0ofvaoLDYE05nBCQ68 xul124IOY/5LHm76NrgnrGrBPHN+fDqcHI9e+XL99s9mk3pF6BuJO64nT2fG3THV8hAY f2xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wS7Hu+AF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 24si1964237oip.248.2019.12.05.04.21.50; Thu, 05 Dec 2019 04:22:02 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=wS7Hu+AF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729426AbfLEMVL (ORCPT + 99 others); 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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);