Skip to content

Commit 4868a24

Browse files
uudiingregkh
authored andcommitted
integrity: Fix possible multiple allocation in integrity_inode_get()
commit 9df6a48 upstream. When integrity_inode_get() is querying and inserting the cache, there is a conditional race in the concurrent environment. The race condition is the result of not properly implementing "double-checked locking". In this case, it first checks to see if the iint cache record exists before taking the lock, but doesn't check again after taking the integrity_iint_lock. Fixes: bf2276d ("ima: allocating iint improvements") Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com> Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com> Cc: <stable@vger.kernel.org> # v3.10+ Signed-off-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d24e1c4 commit 4868a24

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

security/integrity/iint.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ static struct integrity_iint_cache *__integrity_iint_find(struct inode *inode)
4343
else if (inode > iint->inode)
4444
n = n->rb_right;
4545
else
46-
break;
46+
return iint;
4747
}
48-
if (!n)
49-
return NULL;
5048

51-
return iint;
49+
return NULL;
5250
}
5351

5452
/*
@@ -112,10 +110,15 @@ struct integrity_iint_cache *integrity_inode_get(struct inode *inode)
112110
parent = *p;
113111
test_iint = rb_entry(parent, struct integrity_iint_cache,
114112
rb_node);
115-
if (inode < test_iint->inode)
113+
if (inode < test_iint->inode) {
116114
p = &(*p)->rb_left;
117-
else
115+
} else if (inode > test_iint->inode) {
118116
p = &(*p)->rb_right;
117+
} else {
118+
write_unlock(&integrity_iint_lock);
119+
kmem_cache_free(iint_cache, iint);
120+
return test_iint;
121+
}
119122
}
120123

121124
iint->inode = inode;

0 commit comments

Comments
 (0)