// This filter is meant to be installed in addition to a regular allowlist filter. // Therefore, it's default action has to be Allow, except when the evaluated // system call matches setresuid/setresgid and the arguments don't fall within the // passed in range. // // The regular allowlist only allows setresuid/setresgid for UID/GID changes, so // that's the only system call we need to check here. A CTS test ensures the other // calls will remain blocked. staticvoid ValidateSetUidGid(filter& f, uint32_t uid_gid_min, uint32_t uid_gid_max, bool primary) { #ifdefined(SECONDARY_ARCH)
__u32 setresuid_nr = primary ? primary_setresuid : secondary_setresuid;
__u32 setresgid_nr = primary ? primary_setresgid : secondary_setresgid; #else
__u32 setresuid_nr = primary_setresuid;
__u32 setresgid_nr = primary_setresgid;
UNUSED(primary); #endif
// Check setresuid(ruid, euid, sguid) fall within range
ExamineSyscall(f);
f.push_back(BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, setresuid_nr, 0, 12)); for (int arg = 0; arg < 3; arg++) {
ValidateSyscallArgInRange(f, arg, uid_gid_min, uid_gid_max);
}
// Check setresgid(rgid, egid, sgid) fall within range
ExamineSyscall(f);
f.push_back(BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, setresgid_nr, 0, 12)); for (int arg = 0; arg < 3; arg++) {
ValidateSyscallArgInRange(f, arg, uid_gid_min, uid_gid_max);
}
// Default is to allow; other filters may still reject this call.
Allow(f);
}
staticbool install_filter(filter const& f) { struct sock_fprog prog = { static_cast<unsignedshort>(f.size()), const_cast<struct sock_filter*>(&f[0]),
}; // This assumes either the current process has CAP_SYS_ADMIN, or PR_SET_NO_NEW_PRIVS bit is set. if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog) < 0) {
PLOG(FATAL) << "Could not set seccomp filter of size " << f.size(); returnfalse;
} returntrue;
}
bool _install_setuidgid_filter(uint32_t uid_gid_min, uint32_t uid_gid_max) {
filter f; #ifdefined(SECONDARY_ARCH) // Note that for mixed 64/32 bit architectures, ValidateArchitecture inserts a // jump that must be changed to point to the start of the 32-bit policy // 32 bit syscalls will not hit the policy between here and the call to SetJump auto offset_to_secondary_filter = ValidateArchitectureAndJumpIfNeeded(f); #else
ValidateArchitecture(f); #endif
switch (type) { case APP:
p = primary_app_filter;
p_size = primary_app_filter_size; #ifdefined(SECONDARY_ARCH)
s = secondary_app_filter;
s_size = secondary_app_filter_size; #endif break; case APP_ZYGOTE:
p = primary_app_zygote_filter;
p_size = primary_app_zygote_filter_size; #ifdefined(SECONDARY_ARCH)
s = secondary_app_zygote_filter;
s_size = secondary_app_zygote_filter_size; #endif break; case SYSTEM:
p = primary_system_filter;
p_size = primary_system_filter_size; #ifdefined(SECONDARY_ARCH)
s = secondary_system_filter;
s_size = secondary_system_filter_size; #endif break;
}
#ifdefined(SECONDARY_ARCH) // Note that for mixed 64/32 bit architectures, ValidateArchitecture inserts a // jump that must be changed to point to the start of the 32-bit policy // 32 bit syscalls will not hit the policy between here and the call to SetJump auto offset_to_secondary_filter = ValidateArchitectureAndJumpIfNeeded(f); #else
ValidateArchitecture(f); #endif
ExamineSyscall(f);
for (size_t i = 0; i < p_size; ++i) {
f.push_back(p[i]);
}
Disallow(f);
#ifdefined(SECONDARY_ARCH) if (!SetValidateArchitectureJumpTarget(offset_to_secondary_filter, f)) { returnfalse;
}
ExamineSyscall(f);
for (size_t i = 0; i < s_size; ++i) {
f.push_back(s[i]);
}
Disallow(f); #endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.