From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935704AbdAKFts (ORCPT ); Wed, 11 Jan 2017 00:49:48 -0500 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:52639 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932505AbdAKFtr (ORCPT ); Wed, 11 Jan 2017 00:49:47 -0500 X-IronPort-AV: E=Sophos;i="5.33,345,1477954800"; d="scan'208";a="208703113" Date: Wed, 11 Jan 2017 06:49:43 +0100 (CET) From: Julia Lawall X-X-Sender: jll@hadrien To: Kees Cook cc: cocci@systeme.lip6.fr, Pengfei Wang , Vaishali Thakkar , LKML Subject: Re: [RFC] coccicheck: add a test for repeat memory fetches In-Reply-To: Message-ID: References: <20170109231323.GA89642@beast> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) 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 Tue, 10 Jan 2017, Kees Cook wrote: > On Tue, Jan 10, 2017 at 1:14 PM, Julia Lawall wrote: > > OK, I have the impression that what you are looking for is the following, > > that currently does not seem to work well. Still maybe it gives an idea. > > > > The basic pattern is the following sequence: > > > > 1. copy_from_user > > 2. test on a field of the copied value > > 3. another copy_from_user > > 4. a use of the same field as tested in step 2 from the structure obtained > > by the second copy_from_user or a function call with the structure as an > > argument > > This looks pretty good! > > > In the case where the second copy_from_user stores the result in a > > pointer, then a return with no reference of the tested field is also a > > concern, unless, the pointer was already kfreed. > > I think sequence "2" above missing just looking at a direct value, > like if instead of a field it was a u32. Also, should binop include > "=="? I wasn't sure what to do with a direct value, because one wouldn't know what field it would correspond to. A solution could be to pull the first field out of the structure declaration. I'll add == and !=. > And we need to add back in get_user() too... hmmm OK. julia