-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement secpolicy_vnode_setid_retain()
Don't unconditionally return 0 (i.e. retain SUID/SGID). Test CAP_FSETID capability. https://github.com/pjd/pjdfstest/blob/master/tests/chmod/12.t which expects SUID/SGID to be dropped on write(2) by non-owner fails without this. Most filesystems make this decision within VFS by using a generic file write for fops. Signed-off-by: Tomohiro Kusumi <[email protected]>
Showing
9 changed files
with
211 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ SUBDIRS = \ | |
snapshot \ | ||
snapused \ | ||
sparse \ | ||
suid \ | ||
threadsappend \ | ||
tmpfile \ | ||
trim \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/suid_write_to_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
include $(top_srcdir)/config/Rules.am | ||
|
||
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/suid | ||
|
||
dist_pkgdata_SCRIPTS = \ | ||
cleanup.ksh \ | ||
setup.ksh | ||
|
||
pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/suid | ||
|
||
pkgexec_PROGRAMS = suid_write_to_file | ||
suid_write_to_file_SOURCES = suid_write_to_file.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/ksh -p | ||
# | ||
# CDDL HEADER START | ||
# | ||
# The contents of this file are subject to the terms of the | ||
# Common Development and Distribution License (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
# | ||
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | ||
# or http://www.opensolaris.org/os/licensing. | ||
# See the License for the specific language governing permissions | ||
# and limitations under the License. | ||
# | ||
# When distributing Covered Code, include this CDDL HEADER in each | ||
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. | ||
# If applicable, add the following below this CDDL HEADER, with the | ||
# fields enclosed by brackets "[]" replaced with your own identifying | ||
# information: Portions Copyright [yyyy] [name of copyright owner] | ||
# | ||
# CDDL HEADER END | ||
# | ||
|
||
# | ||
# Copyright 2007 Sun Microsystems, Inc. All rights reserved. | ||
# Use is subject to license terms. | ||
# | ||
|
||
# | ||
# Copyright (c) 2019 by Tomohiro Kusumi. All rights reserved. | ||
# | ||
|
||
. $STF_SUITE/include/libtest.shlib | ||
|
||
#default_cleanup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/ksh -p | ||
# | ||
# CDDL HEADER START | ||
# | ||
# The contents of this file are subject to the terms of the | ||
# Common Development and Distribution License (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
# | ||
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | ||
# or http://www.opensolaris.org/os/licensing. | ||
# See the License for the specific language governing permissions | ||
# and limitations under the License. | ||
# | ||
# When distributing Covered Code, include this CDDL HEADER in each | ||
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. | ||
# If applicable, add the following below this CDDL HEADER, with the | ||
# fields enclosed by brackets "[]" replaced with your own identifying | ||
# information: Portions Copyright [yyyy] [name of copyright owner] | ||
# | ||
# CDDL HEADER END | ||
# | ||
|
||
# | ||
# Copyright 2007 Sun Microsystems, Inc. All rights reserved. | ||
# Use is subject to license terms. | ||
# | ||
|
||
# | ||
# Copyright (c) 2019 by Tomohiro Kusumi. All rights reserved. | ||
# | ||
|
||
. $STF_SUITE/include/libtest.shlib | ||
|
||
#DISK=${DISKS%% *} | ||
#default_setup $DISK |
122 changes: 122 additions & 0 deletions
122
tests/zfs-tests/tests/functional/suid/suid_write_to_file.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* CDDL HEADER START | ||
* | ||
* The contents of this file are subject to the terms of the | ||
* Common Development and Distribution License (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* | ||
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | ||
* or http://www.opensolaris.org/os/licensing. | ||
* See the License for the specific language governing permissions | ||
* and limitations under the License. | ||
* | ||
* When distributing Covered Code, include this CDDL HEADER in each | ||
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. | ||
* If applicable, add the following below this CDDL HEADER, with the | ||
* fields enclosed by brackets "[]" replaced with your own identifying | ||
* information: Portions Copyright [yyyy] [name of copyright owner] | ||
* | ||
* CDDL HEADER END | ||
*/ | ||
/* | ||
* Copyright (c) 2019 by Tomohiro Kusumi. All rights reserved. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
|
||
/* | ||
* DESCRIPTION: | ||
* Verify SUID/SGID bit on write(2) by non-owner. | ||
* Also see https://github.com/pjd/pjdfstest/blob/master/tests/chmod/12.t | ||
* | ||
* STRATEGY: | ||
* 1. creat(2) a file with SUID/SGID. | ||
* 2. write(2) to the file with uid=65534. | ||
* 3. stat(2) the file and verify .st_mode value. | ||
*/ | ||
|
||
static void | ||
test_stat_mode(mode_t mode) | ||
{ | ||
struct stat st; | ||
int i, fd; | ||
char fpath[1024]; | ||
char *penv[] = {"TESTDIR", "TESTFILE0"}; | ||
char buf[] = "test"; | ||
mode_t res; | ||
|
||
/* | ||
* Get the environment variable values. | ||
*/ | ||
for (i = 0; i < sizeof (penv) / sizeof (char *); i++) { | ||
if ((penv[i] = getenv(penv[i])) == NULL) { | ||
fprintf(stderr, "getenv(penv[%d])\n", i); | ||
exit(1); | ||
} | ||
} | ||
|
||
umask(0); | ||
if (stat(penv[0], &st) == -1 && mkdir(penv[0], mode) == -1) { | ||
perror("mkdir"); | ||
exit(2); | ||
} | ||
|
||
snprintf(fpath, sizeof (fpath), "%s/%s", penv[0], penv[1]); | ||
unlink(fpath); | ||
if (stat(fpath, &st) == 0) { | ||
fprintf(stderr, "%s exists\n", fpath); | ||
exit(3); | ||
} | ||
|
||
fd = creat(fpath, mode); | ||
if (fd == -1) { | ||
perror("creat"); | ||
exit(4); | ||
} | ||
close(fd); | ||
|
||
if (setuid(65534) == -1) { | ||
perror("setuid"); | ||
exit(5); | ||
} | ||
|
||
fd = open(fpath, O_RDWR); | ||
if (fd == -1) { | ||
perror("open"); | ||
exit(6); | ||
} | ||
|
||
if (write(fd, buf, sizeof (buf)) == -1) { | ||
perror("write"); | ||
exit(7); | ||
} | ||
close(fd); | ||
|
||
if (stat(fpath, &st) == -1) { | ||
perror("stat"); | ||
exit(8); | ||
} | ||
unlink(fpath); | ||
|
||
/* Verify SUID/SGID are dropped */ | ||
res = st.st_mode & (0777 | S_ISUID | S_ISGID); | ||
if (res != (mode & 0777)) { | ||
fprintf(stderr, "stat(2) %o\n", res); | ||
exit(9); | ||
} | ||
} | ||
|
||
int | ||
main(int argc, char *argv[]) | ||
{ | ||
fprintf(stdout, "Verify SUID/SGID bit on write(2) by non-owner\n"); | ||
test_stat_mode(0777 | S_ISUID | S_ISGID); | ||
|
||
return (0); | ||
} |