From: Laura Abbott <labbott@fedoraproject.org>
To: Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Kees Cook <keescook@chromium.org>
Cc: Laura Abbott <labbott@fedoraproject.org>,
linux-kernel@vger.kernel.org,
kernel-hardening@lists.openwall.com
Subject: [PATCH 2/3] lkdtm: Update WRITE_AFTER_FREE test
Date: Thu, 25 Feb 2016 16:36:43 -0800 [thread overview]
Message-ID: <1456447004-21392-3-git-send-email-labbott@fedoraproject.org> (raw)
In-Reply-To: <1456447004-21392-1-git-send-email-labbott@fedoraproject.org>
The SLUB allocator may use the first word of a freed block to store the
freelist information. This may make it harder to test poisoning
features. Change the WRITE_AFTER_FREE test to better match what
the READ_AFTER_FREE test does and also print out a big more information.
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Laura Abbott <labbott@fedoraproject.org>
---
drivers/misc/lkdtm.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
index 8de4746..a00a2b1 100644
--- a/drivers/misc/lkdtm.c
+++ b/drivers/misc/lkdtm.c
@@ -411,12 +411,21 @@ static void lkdtm_do_action(enum ctype which)
break;
}
case CT_WRITE_AFTER_FREE: {
+ int *base;
size_t len = 1024;
- u32 *data = kmalloc(len, GFP_KERNEL);
+ /*
+ * The slub allocator uses the first word to store the free
+ * pointer in some configurations. Use the middle of the
+ * allocation to avoid running into the freelist
+ */
+ size_t offset = (len / sizeof(*base)) / 2;
- kfree(data);
- schedule();
- memset(data, 0x78, len);
+ base = kmalloc(len, GFP_KERNEL);
+ pr_info("Allocated memory %p-%p\n", base, &base[offset * 2]);
+ kfree(base);
+ pr_info("Attempting bad write to freed memory at %p\n",
+ &base[offset]);
+ base[offset] = 0x0abcdef0;
break;
}
case CT_READ_AFTER_FREE: {
--
2.5.0
next prev parent reply other threads:[~2016-02-26 0:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-26 0:36 [PATCHv2 0/3] LKDTM use after free test updates Laura Abbott
2016-02-26 0:36 ` [PATCHv4 1/3] lkdtm: Add READ_AFTER_FREE test Laura Abbott
2016-02-26 0:36 ` Laura Abbott [this message]
2016-02-26 0:36 ` [PATCHv2 3/3] lkdtm: Add read/write after free tests for buddy memory Laura Abbott
2016-02-26 21:39 ` [PATCHv2 0/3] LKDTM use after free test updates Kees Cook
2016-02-26 22:57 ` Greg Kroah-Hartman
2016-02-26 22:57 ` Kees Cook
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=1456447004-21392-3-git-send-email-labbott@fedoraproject.org \
--to=labbott@fedoraproject.org \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--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
all inboxes | Powered by JetHome®