Return-Path: Received: from gateway30.websitewelcome.com ([192.185.198.26]:25990 "EHLO gateway30.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752333AbeDJMB3 (ORCPT ); Tue, 10 Apr 2018 08:01:29 -0400 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 08D0E2A4E7 for ; Tue, 10 Apr 2018 06:13:59 -0500 (CDT) Subject: Re: tracing back a variable References: <20180410101934.iyvjf2mocbl65cgy@mwanda> From: "Gustavo A. R. Silva" Message-ID: Date: Tue, 10 Apr 2018 06:12:29 -0500 MIME-Version: 1.0 In-Reply-To: <20180410101934.iyvjf2mocbl65cgy@mwanda> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: smatch-owner@vger.kernel.org List-ID: To: Dan Carpenter Cc: smatch@vger.kernel.org Hi Dan, On 04/10/2018 05:19 AM, Dan Carpenter wrote: > On Mon, Apr 09, 2018 at 11:25:48AM -0500, Gustavo A. R. Silva wrote: >> Hi all, >> >> I wonder if smatch can be used to trace back a particular variable in order >> to determine if such variable is directly or indirectly controlled from any >> syscall? >> > > Of course, you *could* build something like that... > > There is the get_implied_rl() function. You give it a variable and it > tells you if the variable can be controlled by the user. So it could > be from a syscall, kstrtol() or from skb->data etc. > > So say you have something like: > > u8 foo = *(char *)skb->data; > > if (foo > 8) > return; > > Then get_implied_rl() will say foo is 0-8 range. > > In theory there is enough information in the database so you could trace > function parameters to find out where they come from, but no one has > tested that so it probably doesn't work. > > What are you working on? Perhaps there is a different way to get the > information you want. > I'm analyzing code patterns that could be potentially vulnerable to variant 1 of Spectre. So I want to determine if the variable x in the sample below can somehow be controlled by the user: if (x < array1_size) { v = array2[array1[x]*256] } Thanks -- Gustavo