Skip to content
Snippets Groups Projects
Commit d12487a1 authored by Stephen Rothwell's avatar Stephen Rothwell
Browse files
parents 6a24edf0 cd135105
No related branches found
No related tags found
No related merge requests found
......@@ -182,6 +182,21 @@ static void lkdtm_REFCOUNT_SUB_AND_TEST_NEGATIVE(void)
check_negative(&neg, 3);
}
/*
* A refcount_sub_and_test() by zero when the counter is at zero should act like
* refcount_sub_and_test() above when going negative.
*/
static void lkdtm_REFCOUNT_SUB_AND_TEST_ZERO(void)
{
refcount_t neg = REFCOUNT_INIT(0);
pr_info("attempting bad refcount_sub_and_test() at zero\n");
if (refcount_sub_and_test(0, &neg))
pr_warn("Weird: refcount_sub_and_test() reported zero\n");
check_negative(&neg, 0);
}
static void check_from_zero(refcount_t *ref)
{
switch (refcount_read(ref)) {
......@@ -400,6 +415,7 @@ static struct crashtype crashtypes[] = {
CRASHTYPE(REFCOUNT_DEC_NEGATIVE),
CRASHTYPE(REFCOUNT_DEC_AND_TEST_NEGATIVE),
CRASHTYPE(REFCOUNT_SUB_AND_TEST_NEGATIVE),
CRASHTYPE(REFCOUNT_SUB_AND_TEST_ZERO),
CRASHTYPE(REFCOUNT_INC_ZERO),
CRASHTYPE(REFCOUNT_ADD_ZERO),
CRASHTYPE(REFCOUNT_INC_SATURATED),
......
......@@ -266,12 +266,12 @@ bool __refcount_sub_and_test(int i, refcount_t *r, int *oldp)
if (oldp)
*oldp = old;
if (old == i) {
if (old > 0 && old == i) {
smp_acquire__after_ctrl_dep();
return true;
}
if (unlikely(old < 0 || old - i < 0))
if (unlikely(old <= 0 || old - i < 0))
refcount_warn_saturate(r, REFCOUNT_SUB_UAF);
return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment