37
37
#include <linux/fs.h>
38
38
#include <linux/mount.h>
39
39
40
+ /* Defines AT_EXECVE_CHECK without type conflicts. */
41
+ #define _ASM_GENERIC_FCNTL_H
42
+ #include <linux/fcntl.h>
43
+
40
44
#include "common.h"
41
45
42
46
#ifndef renameat2
@@ -2008,6 +2012,22 @@ static void test_execute(struct __test_metadata *const _metadata, const int err,
2008
2012
};
2009
2013
}
2010
2014
2015
+ static void test_check_exec (struct __test_metadata * const _metadata ,
2016
+ const int err , const char * const path )
2017
+ {
2018
+ int ret ;
2019
+ char * const argv [] = { (char * )path , NULL };
2020
+
2021
+ ret = execveat (AT_FDCWD , path , argv , NULL ,
2022
+ AT_EMPTY_PATH | AT_EXECVE_CHECK );
2023
+ if (err ) {
2024
+ EXPECT_EQ (-1 , ret );
2025
+ EXPECT_EQ (errno , err );
2026
+ } else {
2027
+ EXPECT_EQ (0 , ret );
2028
+ }
2029
+ }
2030
+
2011
2031
TEST_F_FORK (layout1 , execute )
2012
2032
{
2013
2033
const struct rule rules [] = {
@@ -2025,20 +2045,27 @@ TEST_F_FORK(layout1, execute)
2025
2045
copy_binary (_metadata , file1_s1d2 );
2026
2046
copy_binary (_metadata , file1_s1d3 );
2027
2047
2048
+ /* Checks before file1_s1d1 being denied. */
2049
+ test_execute (_metadata , 0 , file1_s1d1 );
2050
+ test_check_exec (_metadata , 0 , file1_s1d1 );
2051
+
2028
2052
enforce_ruleset (_metadata , ruleset_fd );
2029
2053
ASSERT_EQ (0 , close (ruleset_fd ));
2030
2054
2031
2055
ASSERT_EQ (0 , test_open (dir_s1d1 , O_RDONLY ));
2032
2056
ASSERT_EQ (0 , test_open (file1_s1d1 , O_RDONLY ));
2033
2057
test_execute (_metadata , EACCES , file1_s1d1 );
2058
+ test_check_exec (_metadata , EACCES , file1_s1d1 );
2034
2059
2035
2060
ASSERT_EQ (0 , test_open (dir_s1d2 , O_RDONLY ));
2036
2061
ASSERT_EQ (0 , test_open (file1_s1d2 , O_RDONLY ));
2037
2062
test_execute (_metadata , 0 , file1_s1d2 );
2063
+ test_check_exec (_metadata , 0 , file1_s1d2 );
2038
2064
2039
2065
ASSERT_EQ (0 , test_open (dir_s1d3 , O_RDONLY ));
2040
2066
ASSERT_EQ (0 , test_open (file1_s1d3 , O_RDONLY ));
2041
2067
test_execute (_metadata , 0 , file1_s1d3 );
2068
+ test_check_exec (_metadata , 0 , file1_s1d3 );
2042
2069
}
2043
2070
2044
2071
TEST_F_FORK (layout1 , link )
0 commit comments