From: Weikang shi <swkhack@gmail.com>
To: keescook@chromium.org
Cc: arnd@arndb.de, gregkh@linuxfoundation.org,
linux-kernel@vger.kernel.org, swkhack <swkhack@gmail.com>
Subject: [PATCH] lkdtm: fix potential use after free
Date: Wed, 24 Apr 2019 17:59:52 +0800 [thread overview]
Message-ID: <20190424095952.10990-1-swkhack@gmail.com> (raw)
From: swkhack <swkhack@gmail.com>
The function lkdtm_READ_AFTER_FREE calls kfree(base) to free the memory
of base. However, following kfree(base),
it access the memory which base point to via base[offset]. This may result in a
use-after-free bug. This patch moves kfree(base) after the dereference.
Signed-off-by: swkhack <swkhack@gmail.com>
---
drivers/misc/lkdtm/heap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/misc/lkdtm/heap.c b/drivers/misc/lkdtm/heap.c
index 65026d7de..3e2f1580a 100644
--- a/drivers/misc/lkdtm/heap.c
+++ b/drivers/misc/lkdtm/heap.c
@@ -77,7 +77,6 @@ void lkdtm_READ_AFTER_FREE(void)
base[offset] = *val;
pr_info("Value in memory before free: %x\n", base[offset]);
- kfree(base);
pr_info("Attempting bad read from freed memory\n");
saw = base[offset];
@@ -88,6 +87,7 @@ void lkdtm_READ_AFTER_FREE(void)
}
pr_info("Memory was not poisoned\n");
+ kfree(base);
kfree(val);
}
--
2.17.1
next reply other threads:[~2019-04-24 10:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-24 9:59 Weikang shi [this message]
2019-04-24 12:24 ` [PATCH] lkdtm: fix potential use after free Mark Rutland
-- strict thread matches above, loose matches on Subject: below --
2019-04-24 10:21 Weikang shi
2019-04-24 12:24 ` Mark Rutland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190424095952.10990-1-swkhack@gmail.com \
--to=swkhack@gmail.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox