Received: by 10.192.165.148 with SMTP id m20csp198644imm; Fri, 20 Apr 2018 05:29:24 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ZwhNEa1ihTBpJJm76knazoDRWg1mG+uaUepYpic5pYhC5TZuAb9yJiQCPM26y2Ir6Nt7x X-Received: by 2002:a17:902:ba88:: with SMTP id k8-v6mr9831807pls.305.1524227364250; Fri, 20 Apr 2018 05:29:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524227364; cv=none; d=google.com; s=arc-20160816; b=CzDm7es6/SXM20PlGJgjhwd8meXkhCCNfozSVyZnPcBd60O+dI33tStfrzC9TmvTWL x7lw0eU9987HdVvIoGgeyDf6kfUNQRIuj6ie6kozIYHeHYifdhTsXfikwxoA6DV2zov6 LSrM4Edub/8mkWFMQMDq9S6/mYHVG648+M5xavnglP5QExy9GWqkvrYPCftk9V1u7vib sq5Moi9qFuB/bWaQ5XJkaKbsFuABxqDFfwg+HGCnFNYIHs7vJhVB73R2AgJWw/tafwRr UR9rq72fH+Tr4QJ+KE0bagFgwGV+OTtV4AN4dkAW2qN8K50PNtf8YtOPhAoOGfh2vD7H 41nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=vCLwXtRz5oHWPN49S5fbQqpbQmswXNOAY3Xjd5cqsRE=; b=ZbJgguKmZBC1LItx+OkilSG+Z2fKdWZ54YF7DZC/FUVoC56zmqSjPEXy9xHHQU1AVv m6Vp4C4W1AEIzT8JLRdmtDQxu7YwLuKnhyrEFXTN0Ks3avCao5tB8dYBUDjqcXVfT5Av wepvNFc6TD7shIpya39A9Ej7KmhREN7hv5m6fevx8n5PnG1S25epuxM+GPAt89K0T9nm wsOyMdrw0i1HtZuXqQgmlFkxaD0lBK5pbEQQLJnJofOumcf9qb497PE3aPiKVqjxmAtl C7ciCycBHTitq063ffn7IrVggaWbIHXvzEPtHKRChsAFJElbTuwPsynOKLUODPNHjPFc DMVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h16-v6si5738201pli.474.2018.04.20.05.29.09; Fri, 20 Apr 2018 05:29:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754803AbeDTM1t (ORCPT + 99 others); Fri, 20 Apr 2018 08:27:49 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:45090 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754591AbeDTM1s (ORCPT ); Fri, 20 Apr 2018 08:27:48 -0400 Received: from static-242-42-24-46.ipcom.comunitel.net ([46.24.42.242] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1f9V8j-0003rf-E4; Fri, 20 Apr 2018 14:27:45 +0200 Date: Fri, 20 Apr 2018 14:25:37 +0200 (CEST) From: Thomas Gleixner To: Dan Carpenter cc: LKML , Peter Zijlstra , "Gustavo A. R. Silva" , Oleg Nesterov Subject: Re: Smatch check for Spectre stuff In-Reply-To: <20180419051510.GA21898@mwanda> Message-ID: References: <20180419051510.GA21898@mwanda> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 19 Apr 2018, Dan Carpenter wrote: > Several people have asked me to write this and I think one person was > maybe working on writing it themselves... > > The point of this check is to find place which might be vulnerable to > the Spectre vulnerability. In the kernel we have the array_index_nospec() > macro which turns off speculation. There are fewer than 10 places where > it's used. Meanwhile this check complains about 800 places where maybe > it could be used. Probably the 100x difference means there is something > that I haven't understood... > > What the test does is it looks at array accesses where the user controls > the offset. It asks "is this a read?" and have we used the > array_index_nospec() macro? If the answers are yes, and no respectively > then print a warning. > > http://repo.or.cz/smatch.git/blob/HEAD:/check_spectre.c Cool stuff! > The other thing is that speculation probably goes to 200 instructions > ahead at most. But the Smatch doesn't have any concept of CPU > instructions. I've marked the offsets which were recently compared to > something as "local cap" because they were probably compared to the > array limit. Those are maybe more likely to be under the 200 CPU > instruction count. > > This obviously a first draft. > > What would help me, is maybe people could tell me why there are so many > false positives. Saying "the lower level checks for that" is not > helpful but if you could tell me the exact function name where the check > is that helps a lot... Actually checks in the lower level codepath are not helping because speculation forgoes the checks. What would help is that something before that array access limits the array index, which is unlikely. So we probably need to go through all the places and have a look. > kernel/signal.c:3457 do_sigaction() warn: potential spectre issue 'p->sighand->action' This one is correctly detected > kernel/signal.c:65 sig_handler() warn: potential spectre issue 't->sighand->action' It's unclear from a quick look whether it's really possible to speculate all over the other things there, but we probably err out on the safe side Thanks, tglx