Skip to content

Commit

Permalink
dump_common_audit_data(): fix racy accesses to ->d_name
Browse files Browse the repository at this point in the history
We are not guaranteed the locking environment that would prevent
dentry getting renamed right under us.  And it's possible for
old long name to be freed after rename, leading to UAF here.

Cc: [email protected] # v2.6.2+
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Jan 16, 2021
1 parent a959a97 commit d36a1dd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions security/lsm_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
struct inode *inode;

audit_log_format(ab, " name=");
spin_lock(&a->u.dentry->d_lock);
audit_log_untrustedstring(ab, a->u.dentry->d_name.name);
spin_unlock(&a->u.dentry->d_lock);

inode = d_backing_inode(a->u.dentry);
if (inode) {
Expand All @@ -293,8 +295,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
dentry = d_find_alias(inode);
if (dentry) {
audit_log_format(ab, " name=");
audit_log_untrustedstring(ab,
dentry->d_name.name);
spin_lock(&dentry->d_lock);
audit_log_untrustedstring(ab, dentry->d_name.name);
spin_unlock(&dentry->d_lock);
dput(dentry);
}
audit_log_format(ab, " dev=");
Expand Down

0 comments on commit d36a1dd

Please sign in to comment.