Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 24, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fcf2db4
Add secure_modules() call
Aug 9, 2013
00d259d
PCI: Lock down BAR access when module security is enabled
Mar 8, 2012
b6df0aa
x86: Lock down IO port access when module security is enabled
Mar 8, 2012
23fd873
ACPI: Limit access to custom_method
Mar 9, 2012
cb9a638
asus-wmi: Restrict debugfs interface when module loading is restricted
Mar 9, 2012
eecc594
Restrict /dev/mem and /dev/kmem when module loading is restricted
Mar 9, 2012
e2d101b
acpi: Ignore acpi_rsdp kernel parameter when module loading is restri…
jwboyer Jun 25, 2012
cebac39
kexec: Disable at runtime if the kernel enforces module loading restr…
Nov 20, 2015
fe362fc
x86: Restrict MSR access when module loading is restricted
Feb 8, 2013
323216a
Add option to automatically enforce module signatures when in Secure …
Aug 9, 2013
dbfa35d
efi: Make EFI_SECURE_BOOT_SIG_ENFORCE depend on EFI
Aug 27, 2013
f8c98a5
efi: Add EFI_SECURE_BOOT bit
Aug 27, 2013
5cb706d
hibernate: Disable in a signed modules environment
Jun 20, 2014
7aa0a80
Security: Provide copy-up security hooks for unioned files
dhowells Jun 16, 2015
49ddbf5
Overlayfs: Use copy-up security hooks
dhowells Jun 16, 2015
80d3b14
SELinux: Stub in copy-up handling
dhowells Jun 16, 2015
c3bbdf4
SELinux: Handle opening of a unioned file
dhowells Jun 16, 2015
1f001c5
SELinux: Check against union label for file operations
dhowells Jun 16, 2015
664426d
overlayfs: use a minimal buffer in ovl_copy_xattr
Oct 20, 2015
88e8537
kbuild: derive relative path for KBUILD_SRC from CURDIR
Nov 25, 2015
8cbe9f6
Don't verify write permissions on lower inodes on overlayfs
Dec 22, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
SELinux: Handle opening of a unioned file
Handle the opening of a unioned file by trying to derive the label that would
be attached to the union-layer inode if it doesn't exist.

If the union-layer inode does exist (as it necessarily does in overlayfs, but
not in unionmount), we assume that it has the right label and use that.
Otherwise we try to get it from the superblock.

If the superblock has a globally-applied label, we use that, otherwise we try
to transition to an appropriate label.  This union label is then stored in the
file_security_struct.

We then perform an additional check to make sure that the calling task is
granted permission by the union-layer inode label to open the file in addition
to a check to make sure that the task is granted permission to open the lower
file with the lower inode label.

Signed-off-by: David Howells <[email protected]>
  • Loading branch information
dhowells authored and crawford committed Apr 5, 2016
commit c3bbdf49a0c26a6915ab50eab505daa64cf7220e
69 changes: 69 additions & 0 deletions security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -3584,10 +3584,72 @@ static int selinux_file_receive(struct file *file)
return file_has_perm(cred, file, file_to_av(file));
}

/*
* We have a file opened on a unioned file system that falls through to a file
* on a lower layer. If there is a union inode, we try to get the label from
* that, otherwise we need to get it from the superblock.
*
* file->f_path points to the union layer and file->f_inode points to the lower
* layer.
*/
static int selinux_file_open_union(struct file *file,
struct file_security_struct *fsec,
const struct cred *cred)
{
const struct superblock_security_struct *sbsec;
const struct inode_security_struct *isec, *dsec, *fisec;
const struct task_security_struct *tsec = current_security();
struct common_audit_data ad;
struct dentry *union_dentry = file->f_path.dentry;
const struct inode *union_inode = d_inode(union_dentry);
const struct inode *lower_inode = file_inode(file);
struct dentry *dir;
int rc;

sbsec = union_dentry->d_sb->s_security;

if (union_inode) {
isec = union_inode->i_security;
fsec->union_isid = isec->sid;
} else if ((sbsec->flags & SE_SBINITIALIZED) &&
(sbsec->behavior == SECURITY_FS_USE_MNTPOINT)) {
fsec->union_isid = sbsec->mntpoint_sid;
} else {
dir = dget_parent(union_dentry);
dsec = d_inode(dir)->i_security;

rc = security_transition_sid(
tsec->sid, dsec->sid,
inode_mode_to_security_class(lower_inode->i_mode),
&union_dentry->d_name,
&fsec->union_isid);
dput(dir);
if (rc) {
pr_warn("%s: security_transition_sid failed, rc=%d (name=%pD)\n",
__func__, -rc, file);
return rc;
}
}

/* We need to check that the union file is allowed to be opened as well
* as checking that the lower file is allowed to be opened.
*/
if (unlikely(IS_PRIVATE(lower_inode)))
return 0;

ad.type = LSM_AUDIT_DATA_PATH;
ad.u.path = file->f_path;

fisec = lower_inode->i_security;
return avc_has_perm(cred_sid(cred), fsec->union_isid, fisec->sclass,
open_file_to_av(file), &ad);
}

static int selinux_file_open(struct file *file, const struct cred *cred)
{
struct file_security_struct *fsec;
struct inode_security_struct *isec;
int rc;

fsec = file->f_security;
isec = inode_security(file_inode(file));
Expand All @@ -3608,6 +3670,13 @@ static int selinux_file_open(struct file *file, const struct cred *cred)
* new inode label or new policy.
* This check is not redundant - do not remove.
*/

if (d_inode(file->f_path.dentry) != file->f_inode) {
rc = selinux_file_open_union(file, fsec, cred);
if (rc < 0)
return rc;
}

return file_path_has_perm(cred, file, open_file_to_av(file));
}

Expand Down
1 change: 1 addition & 0 deletions security/selinux/include/objsec.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct file_security_struct {
u32 sid; /* SID of open file description */
u32 fown_sid; /* SID of file owner (for SIGIO) */
u32 isid; /* SID of inode at the time of file open */
u32 union_isid; /* SID of would-be inodes in union top (or 0) */
u32 pseqno; /* Policy seqno at the time of file open */
};

Expand Down