From mboxrd@z Thu Jan 1 00:00:00 1970 From: Al Viro Subject: Re: [PATCH] fs: make sure we do not read beyond allocation Date: Thu, 3 Oct 2013 18:58:24 +0100 Message-ID: <20131003175824.GH13318@ZenIV.linux.org.uk> References: <20131003163411.GA17101@www.outflux.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Dmitry Vyukov To: Kees Cook Return-path: Content-Disposition: inline In-Reply-To: <20131003163411.GA17101@www.outflux.net> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Thu, Oct 03, 2013 at 09:34:11AM -0700, Kees Cook wrote: > 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. grep ^kmalloc /proc/slabinfo. Observe the suffix after "kmalloc-"... IOW, kmalloc() does round its argument up. Seeing that we allocate an external name only when allocation has to be longer than 32 bytes, the sucker is guaranteed to be at least a multiple of 32 by the time we pick the fitting cache (the worst case is when length is between 65 and 96; then we use kmalloc-96). When you start a port to a 512-bit architecture, you'll have much nastier problems than this one...