linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 18:21:03 +0800	[thread overview]
Message-ID: <20190424102103.11816-1-swkhack@gmail.com> (raw)

From: swkhack <swkhack@gmail.com>

The function lkdtm_WRITE_AFTER_FREE calls kfree(base) to free the memory
of base. However, following kfree(base),
it write the memory which base point to via base[offset] = 0x0abcdef0. This may result in a
use-after-free bug. This patch moves kfree(base) after the write.

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..0b9141525 100644
--- a/drivers/misc/lkdtm/heap.c
+++ b/drivers/misc/lkdtm/heap.c
@@ -40,8 +40,8 @@ void lkdtm_WRITE_AFTER_FREE(void)
 	pr_info("Allocated memory %p-%p\n", base, &base[offset * 2]);
 	pr_info("Attempting bad write to freed memory at %p\n",
 		&base[offset]);
-	kfree(base);
 	base[offset] = 0x0abcdef0;
+	kfree(base);
 	/* Attempt to notice the overwrite. */
 	again = kmalloc(len, GFP_KERNEL);
 	kfree(again);
-- 
2.17.1


             reply	other threads:[~2019-04-24 10:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24 10:21 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  9:59 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=20190424102103.11816-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;
as well as URLs for NNTP newsgroup(s).