From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753478AbcD0IH2 (ORCPT ); Wed, 27 Apr 2016 04:07:28 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:55144 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752262AbcD0IHV (ORCPT ); Wed, 27 Apr 2016 04:07:21 -0400 X-IronPort-AV: E=Sophos;i="5.24,540,1454972400"; d="scan'208";a="215999339" Date: Wed, 27 Apr 2016 10:07:05 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Dan Carpenter cc: Kees Cook , Pengfei Wang , "security@kernel.org" , LKML Subject: Re: Double-Fetch bug in Linux-4.5/drivers/scsi/aacraid/commctrl.c In-Reply-To: <20160427080105.GI17913@mwanda> Message-ID: References: <0484FFD3-4BAB-43B9-AD56-B4A098C3E8AE@gmail.com> <20160427080105.GI17913@mwanda> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 27 Apr 2016, Dan Carpenter wrote: > On Wed, Apr 27, 2016 at 07:42:04AM +0200, Julia Lawall wrote: > > > > > > On Tue, 26 Apr 2016, Kees Cook wrote: > > > > > On Mon, Apr 25, 2016 at 7:50 AM, Pengfei Wang wrote: > > > > Hello, > > > > > > > > I found this Double-Fetch bug in Linux-4.5/drivers/scsi/aacraid/commctrl.c > > > > when I was examining the source code. > > > > > > Thanks for these reports! I wrote a coccinelle script to find these, > > > but it requires some manual checking. For what it's worth, it found > > > your report as well: > > > > > > ./drivers/scsi/aacraid/commctrl.c:116:5-19: potentially dangerous > > > second copy_from_user() > > > > > > So I should probably get this added to the coccicheck run... Maybe it > > > can get some clean up from Julia. :) > > > > I looked a bit at the results, and didn't see anything obvious. What is > > the problem, exactly, and what would be a characteristic of a false > > positive? > > > > > copy_from_user(dest, src, sizeof(dest)); > > if (dest.extra > MAX_SIZE) > return -EINVAL; > > copy_from_user(dest, src, sizeof(dest) + dest.extra); > > for (i = 0; i < dest.extra; i++) { > dest.foo[i] = xxx; > > > We get dest.extra from the user, we verify the size, then we copy more > data from the user but that over writes dest.extra again. We use > dest.extra a second time without checking that it's still <= MAX_SIZE. OK, so the problem is when data that was checked on the first copy is used after the second copy? It would probably be possible to get rid of a lot of false positives with that. thanks, julia