How Ubuntu-specific modifications to OverlayFS skipped permission checks during inode copy-up, allowing unprivileged containers to forge root setuid binaries.
Imagine a photocopier at a library that has a rule: 'Customers cannot photocopy official government stamps with valid signatures'. But the library technicians modified their specific copy machine to make copying faster, accidentally skipping the rule. A student photocopies an empty hall pass with a forged presidential signature, and walks out as the commander-in-chief.
The attacker creates a user namespace and mounts an OverlayFS filesystem.
Inside the namespace, the attacker sets security.capability to cap_setuid on a binary.
The attacker touches the file, causing Ubuntu's custom OverlayFS to copy the file to the host upperdir.
Because Ubuntu skipped security checks, the file lands on the host disk with REAL root setuid capabilities.
Представлено на понятном высокоуровневом исходном коде (без ассемблера и бинарных дампов).
// VULNERABLE: fs/overlayfs/copy_up.c (Ubuntu kernel custom patch)
int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c, struct dentry *dentry) {
// ROOT CAUSE:
// Ubuntu used raw __vfs_setxattr_noperm() instead of vfs_setxattr()!
// This completely BYPASSED all security and user-namespace capability validations!
err = __vfs_setxattr_noperm(&init_user_ns, c->new_dentry,
XATTR_NAME_CAPS, value, size, 0);
return err;
}
// SECURE: fs/overlayfs/copy_up.c after security fix
int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c, struct dentry *dentry) {
// 1. Enforce strict capability namespace mapping checks
// Verifies whether the calling user has genuine authority over target capabilities
err = vfs_setxattr(ovl_dentry_user_ns(dentry), c->new_dentry,
XATTR_NAME_CAPS, value, size, 0);
if (err) {
return err; // Rejects unprivileged capability copy-up!
}
return 0;
}