linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: make sure we do not read beyond allocation
@ 2013-10-03 16:34 Kees Cook
  2013-10-03 17:58 ` Al Viro
  0 siblings, 1 reply; 13+ messages in thread
From: Kees Cook @ 2013-10-03 16:34 UTC (permalink / raw)
  To: linux-kernel; +Cc: Alexander Viro, linux-fsdevel, Dmitry Vyukov

In dentry_string_cmp (via__d_lookup_rcu), when CONFIG_DCACHE_WORD_ACCESS
is set, word-width memory reads are performed. However, the string
allocation size may not be a multiple of the word size. To avoid reading
past the end of such an allocation, we must allocate in multiples of
the word size.

Found by the Kernel Address Sanitizer project:
https://code.google.com/p/address-sanitizer/wiki/AddressSanitizerForKernel

Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 fs/dcache.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index 4100030..23665e2 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1570,7 +1570,11 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
 	 */
 	dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
 	if (name->len > DNAME_INLINE_LEN-1) {
-		dname = kmalloc(name->len + 1, GFP_KERNEL);
+		size_t alloc_size = name->len + 1;
+#ifdef CONFIG_DCACHE_WORD_ACCESS
+		alloc_size = round_up(alloc_size, sizeof(unsigned long));
+#endif
+		dname = kmalloc(alloc_size, GFP_KERNEL);
 		if (!dname) {
 			kmem_cache_free(dentry_cache, dentry); 
 			return NULL;
-- 
1.7.9.5


-- 
Kees Cook
Chrome OS Security

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2013-10-11 11:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-03 16:34 [PATCH] fs: make sure we do not read beyond allocation Kees Cook
2013-10-03 17:58 ` Al Viro
2013-10-03 18:03   ` Kees Cook
2013-10-03 18:23     ` Al Viro
2013-10-03 19:36       ` Kees Cook
2013-10-03 20:57         ` Al Viro
2013-10-03 21:30           ` Kees Cook
2013-10-04  6:05           ` Dmitry Vyukov
2013-10-04 10:38             ` Richard Weinberger
2013-10-04 10:53               ` Dmitry Vyukov
2013-10-04 13:53                 ` Richard Weinberger
2013-10-11 11:26                   ` Dmitry Vyukov
2013-10-11 11:27                     ` Dmitry Vyukov

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).