Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752715AbdHAVnG (ORCPT ); Tue, 1 Aug 2017 17:43:06 -0400 Received: from ozlabs.org ([103.22.144.67]:54309 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752379AbdHAVnF (ORCPT ); Tue, 1 Aug 2017 17:43:05 -0400 Date: Wed, 2 Aug 2017 07:43:02 +1000 From: Stephen Rothwell To: Arnd Bergmann Cc: Kees Cook , Andrew Morton , LKML Subject: Re: [PATCH 2/2] adfs: use 'unsigned' types for memcpy length Message-ID: <20170802074302.6d5a7648@canb.auug.org.au> In-Reply-To: References: <20170726185219.GA57833@beast> <20170801120438.1582336-1-arnd@arndb.de> <20170801120438.1582336-2-arnd@arndb.de> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1554 Lines: 38 Hi Arnd, On Tue, 1 Aug 2017 11:20:26 -0700 Kees Cook wrote: > > On Tue, Aug 1, 2017 at 5:04 AM, Arnd Bergmann wrote: > > After commit 62d1034f53e3 ("fortify: use WARN instead of BUG for now"), we > > get a warning in adfs about a possible buffer overflow: > > > > In function 'memcpy', > > inlined from '__adfs_dir_put' at fs/adfs/dir_f.c:318:2, > > inlined from 'adfs_f_update' at fs/adfs/dir_f.c:403:2: > > include/linux/string.h:305:4: error: call to '__read_overflow2' declared with attribute error: detected read beyond size of object passed as 2nd parameter > > __read_overflow2(); > > ^~~~~~~~~~~~~~~~~~ > > > > The warning is correct in the sense that a negative 'pos' argument > > to the function would have that result. However, this is not a bug, > > as we know the position is always positive (in fact, between 5 > > and 2007, inclusive) when the function gets called. > > > > Changing the variable to a unsigned type avoids the problem. I decided > > to use 'unsigned int' for the position in the directory and the block > > number, as they are both counting things, but use size_t for the > > offset and length that get passed into memcpy. This shuts up the > > warning. > > > > Signed-off-by: Arnd Bergmann > > Acked-by: Kees Cook > > Thanks for the fix! (Added sfr to Cc since he noticed this too.) Can someone please send me the patch so I can use it if Andrew doesn't get around to updating mmotd today? -- Cheers, Stephen Rothwell